3 * Pierre AUBERT, Staubli Faverges, <p.aubert@staubli.com>
5 * SPDX-License-Identifier: GPL-2.0+
7 * Init is derived from Linux code.
11 #if defined(CONFIG_CMD_IDE)
14 DECLARE_GLOBAL_DATA_PTR;
16 #define CALC_TIMING(t) (t + period - 1) / period
18 #ifdef CONFIG_IDE_RESET
19 extern void init_ide_reset (void);
22 int ide_preinit (void)
24 long period, t0, t1, t2_8, t2_16, t4, ta;
26 struct mpc5xxx_sdma *psdma = (struct mpc5xxx_sdma *) MPC5XXX_SDMA;
28 reg = *(vu_long *) MPC5XXX_GPS_PORT_CONFIG;
29 #if defined(CONFIG_SYS_ATA_CS_ON_I2C2)
30 /* ATA cs0/1 on i2c2 clk/io */
31 reg = (reg & ~0x03000000ul) | 0x02000000ul;
32 #elif defined(CONFIG_SYS_ATA_CS_ON_TIMER01)
33 /* ATA cs0/1 on Timer 0/1 */
34 reg = (reg & ~0x03000000ul) | 0x03000000ul;
36 /* ATA cs0/1 on Local Plus cs4/5 */
37 reg = (reg & ~0x03000000ul) | 0x01000000ul;
38 #endif /* CONFIG_TOTAL5200 */
39 *(vu_long *) MPC5XXX_GPS_PORT_CONFIG = reg;
41 /* All sample codes do that... */
42 *(vu_long *) MPC5XXX_ATA_SHARE_COUNT = 0;
44 #if defined(CONFIG_UC101)
45 /* Configure and reset host */
46 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG =
47 MPC5xxx_ATA_HOSTCONF_SMR | MPC5xxx_ATA_HOSTCONF_FR;
49 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = 0;
51 /* Configure and reset host */
52 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY |
53 MPC5xxx_ATA_HOSTCONF_SMR | MPC5xxx_ATA_HOSTCONF_FR;
55 *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY;
58 /* Disable prefetch on Commbus */
61 /* Init timings : we use PIO mode 0 timings */
62 period = 1000000000 / gd->arch.ipb_clk; /* period in ns */
64 t0 = CALC_TIMING (600);
65 t2_8 = CALC_TIMING (290);
66 t2_16 = CALC_TIMING (165);
67 reg = (t0 << 24) | (t2_8 << 16) | (t2_16 << 8);
68 *(vu_long *) MPC5XXX_ATA_PIO1 = reg;
70 t4 = CALC_TIMING (30);
71 t1 = CALC_TIMING (70);
72 ta = CALC_TIMING (35);
73 reg = (t4 << 24) | (t1 << 16) | (ta << 8);
75 *(vu_long *) MPC5XXX_ATA_PIO2 = reg;
77 #ifdef CONFIG_IDE_RESET
79 #endif /* CONFIG_IDE_RESET */