2 * Freescale iMX51 ATA driver
4 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
7 * Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
9 * Based on code from original FSL ATA driver, which is
10 * part of eCos, the Embedded Configurable Operating System.
11 * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #include <asm/byteorder.h>
36 #include <asm/arch/imx-regs.h>
37 #include <asm/arch/clock.h>
39 /* MXC ATA register offsets */
40 struct mxc_ata_config_regs {
41 u8 time_off; /* 0x00 */
57 u8 time_zah; /* 0x10 */
65 u32 fifo_data_32; /* 0x18 */
69 u32 interrupt_pending;
75 struct mxc_data_hdd_regs {
76 u32 drive_data; /* 0xa0 */
78 u32 drive_sector_count;
88 /* PIO timing table */
89 #define NR_PIO_SPECS 5
90 static uint16_t pio_t1[NR_PIO_SPECS] = { 70, 50, 30, 30, 25 };
91 static uint16_t pio_t2_8[NR_PIO_SPECS] = { 290, 290, 290, 80, 70 };
92 static uint16_t pio_t4[NR_PIO_SPECS] = { 30, 20, 15, 10, 10 };
93 static uint16_t pio_t9[NR_PIO_SPECS] = { 20, 15, 10, 10, 10 };
94 static uint16_t pio_tA[NR_PIO_SPECS] = { 50, 50, 50, 50, 50 };
96 #define REG2OFF(reg) ((((uint32_t)reg) & 0x3) * 8)
97 static void set_ata_bus_timing(unsigned char mode)
99 uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
101 struct mxc_ata_config_regs *ata_regs;
102 ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;
104 if (mode >= NR_PIO_SPECS)
107 /* Write TIME_OFF/ON/1/2W */
108 writeb(3, &ata_regs->time_off);
109 writeb(3, &ata_regs->time_on);
110 writeb((pio_t1[mode] + T) / T, &ata_regs->time_1);
111 writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2w);
113 /* Write TIME_2R/AX/RDX/4 */
114 writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2r);
115 writeb((pio_tA[mode] + T) / T + 2, &ata_regs->time_ax);
116 writeb(1, &ata_regs->time_pio_rdx);
117 writeb((pio_t4[mode] + T) / T, &ata_regs->time_4);
119 /* Write TIME_9 ; the rest of timing registers is irrelevant for PIO */
120 writeb((pio_t9[mode] + T) / T, &ata_regs->time_9);
123 int ide_preinit(void)
125 struct mxc_ata_config_regs *ata_regs;
126 ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;
128 /* 46.3.3.4 @ FSL iMX51 manual */
129 /* FIFO normal op., drive reset */
130 writel(0x80, &ata_regs->ata_control);
131 /* FIFO normal op., drive not reset */
132 writel(0xc0, &ata_regs->ata_control);
134 /* Configure the PIO timing */
135 set_ata_bus_timing(CONFIG_MXC_ATA_PIO_MODE);
137 /* 46.3.3.4 @ FSL iMX51 manual */
138 /* Drive not reset, IORDY handshake */
139 writel(0x41, &ata_regs->ata_control);