wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004 |
| 3 | * Pierre AUBERT, Staubli Faverges, <p.aubert@staubli.com> |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | * Init is derived from Linux code. |
| 24 | */ |
| 25 | #include <common.h> |
| 26 | |
Jon Loeliger | 068b60a | 2007-07-10 10:27:39 -0500 | [diff] [blame] | 27 | #if defined(CONFIG_CMD_IDE) |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 28 | #include <mpc5xxx.h> |
| 29 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 32 | #define CALC_TIMING(t) (t + period - 1) / period |
| 33 | |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 34 | #ifdef CONFIG_IDE_RESET |
| 35 | extern void init_ide_reset (void); |
| 36 | #endif |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 37 | |
| 38 | int ide_preinit (void) |
| 39 | { |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 40 | long period, t0, t1, t2_8, t2_16, t4, ta; |
| 41 | vu_long reg; |
| 42 | struct mpc5xxx_sdma *psdma = (struct mpc5xxx_sdma *) MPC5XXX_SDMA; |
| 43 | |
| 44 | reg = *(vu_long *) MPC5XXX_GPS_PORT_CONFIG; |
wdenk | 6c7a140 | 2004-07-11 19:17:20 +0000 | [diff] [blame] | 45 | #if defined(CONFIG_TOTAL5200) |
| 46 | /* ATA cs0/1 on i2c2 clk/io */ |
| 47 | reg = (reg & ~0x03000000ul) | 0x02000000ul; |
| 48 | #else |
| 49 | /* ATA cs0/1 on Local Plus cs4/5 */ |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 50 | reg = (reg & ~0x03000000ul) | 0x01000000ul; |
wdenk | 6c7a140 | 2004-07-11 19:17:20 +0000 | [diff] [blame] | 51 | #endif /* CONFIG_TOTAL5200 */ |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 52 | *(vu_long *) MPC5XXX_GPS_PORT_CONFIG = reg; |
| 53 | |
| 54 | /* All sample codes do that... */ |
| 55 | *(vu_long *) MPC5XXX_ATA_SHARE_COUNT = 0; |
| 56 | |
Heiko Schocher | a861558 | 2007-08-28 17:40:33 +0200 | [diff] [blame] | 57 | #if defined(CONFIG_UC101) |
| 58 | /* Configure and reset host */ |
Wolfgang Denk | 6af2eeb | 2007-08-29 01:32:05 +0200 | [diff] [blame] | 59 | *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = |
Heiko Schocher | a861558 | 2007-08-28 17:40:33 +0200 | [diff] [blame] | 60 | MPC5xxx_ATA_HOSTCONF_SMR | MPC5xxx_ATA_HOSTCONF_FR; |
| 61 | udelay (10); |
| 62 | *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = 0; |
| 63 | #else |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 64 | /* Configure and reset host */ |
| 65 | *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY | |
| 66 | MPC5xxx_ATA_HOSTCONF_SMR | MPC5xxx_ATA_HOSTCONF_FR; |
| 67 | udelay (10); |
| 68 | *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY; |
Heiko Schocher | a861558 | 2007-08-28 17:40:33 +0200 | [diff] [blame] | 69 | #endif |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 70 | |
| 71 | /* Disable prefetch on Commbus */ |
| 72 | psdma->PtdCntrl |= 1; |
| 73 | |
| 74 | /* Init timings : we use PIO mode 0 timings */ |
| 75 | period = 1000000000 / gd->ipb_clk; /* period in ns */ |
| 76 | |
| 77 | t0 = CALC_TIMING (600); |
| 78 | t2_8 = CALC_TIMING (290); |
| 79 | t2_16 = CALC_TIMING (165); |
| 80 | reg = (t0 << 24) | (t2_8 << 16) | (t2_16 << 8); |
| 81 | *(vu_long *) MPC5XXX_ATA_PIO1 = reg; |
| 82 | |
| 83 | t4 = CALC_TIMING (30); |
| 84 | t1 = CALC_TIMING (70); |
| 85 | ta = CALC_TIMING (35); |
| 86 | reg = (t4 << 24) | (t1 << 16) | (ta << 8); |
| 87 | |
| 88 | *(vu_long *) MPC5XXX_ATA_PIO2 = reg; |
| 89 | |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 90 | #ifdef CONFIG_IDE_RESET |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 91 | init_ide_reset (); |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 92 | #endif /* CONFIG_IDE_RESET */ |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 93 | |
| 94 | return (0); |
| 95 | } |
Jon Loeliger | 068b60a | 2007-07-10 10:27:39 -0500 | [diff] [blame] | 96 | #endif |