]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/powerpc/cpu/mpc5xxx/ide.c
Move arch/ppc to arch/powerpc
[people/ms/u-boot.git] / arch / powerpc / cpu / mpc5xxx / ide.c
CommitLineData
132ba5fd
WD
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
068b60a0 27#if defined(CONFIG_CMD_IDE)
132ba5fd
WD
28#include <mpc5xxx.h>
29
d87080b7
WD
30DECLARE_GLOBAL_DATA_PTR;
31
132ba5fd
WD
32#define CALC_TIMING(t) (t + period - 1) / period
33
c3f9d493
WD
34#ifdef CONFIG_IDE_RESET
35extern void init_ide_reset (void);
36#endif
132ba5fd
WD
37
38int ide_preinit (void)
39{
132ba5fd
WD
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;
6a397ef0 45#if defined(CONFIG_SYS_ATA_CS_ON_I2C2)
6c7a1408
WD
46 /* ATA cs0/1 on i2c2 clk/io */
47 reg = (reg & ~0x03000000ul) | 0x02000000ul;
c9969947
JS
48#elif defined(CONFIG_SYS_ATA_CS_ON_TIMER01)
49 /* ATA cs0/1 on Timer 0/1 */
50 reg = (reg & ~0x03000000ul) | 0x03000000ul;
6c7a1408
WD
51#else
52 /* ATA cs0/1 on Local Plus cs4/5 */
132ba5fd 53 reg = (reg & ~0x03000000ul) | 0x01000000ul;
6c7a1408 54#endif /* CONFIG_TOTAL5200 */
132ba5fd
WD
55 *(vu_long *) MPC5XXX_GPS_PORT_CONFIG = reg;
56
57 /* All sample codes do that... */
58 *(vu_long *) MPC5XXX_ATA_SHARE_COUNT = 0;
59
a861558c
HS
60#if defined(CONFIG_UC101)
61 /* Configure and reset host */
6af2eeb1 62 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG =
a861558c
HS
63 MPC5xxx_ATA_HOSTCONF_SMR | MPC5xxx_ATA_HOSTCONF_FR;
64 udelay (10);
65 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = 0;
66#else
132ba5fd
WD
67 /* Configure and reset host */
68 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY |
69 MPC5xxx_ATA_HOSTCONF_SMR | MPC5xxx_ATA_HOSTCONF_FR;
70 udelay (10);
71 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY;
a861558c 72#endif
132ba5fd
WD
73
74 /* Disable prefetch on Commbus */
75 psdma->PtdCntrl |= 1;
76
77 /* Init timings : we use PIO mode 0 timings */
78 period = 1000000000 / gd->ipb_clk; /* period in ns */
79
80 t0 = CALC_TIMING (600);
81 t2_8 = CALC_TIMING (290);
82 t2_16 = CALC_TIMING (165);
83 reg = (t0 << 24) | (t2_8 << 16) | (t2_16 << 8);
84 *(vu_long *) MPC5XXX_ATA_PIO1 = reg;
85
86 t4 = CALC_TIMING (30);
87 t1 = CALC_TIMING (70);
88 ta = CALC_TIMING (35);
89 reg = (t4 << 24) | (t1 << 16) | (ta << 8);
90
91 *(vu_long *) MPC5XXX_ATA_PIO2 = reg;
92
c3f9d493 93#ifdef CONFIG_IDE_RESET
42dfe7a1 94 init_ide_reset ();
c3f9d493 95#endif /* CONFIG_IDE_RESET */
132ba5fd
WD
96
97 return (0);
98}
068b60a0 99#endif