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)
100 uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
102 struct mxc_ata_config_regs *ata_regs;
103 ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;
105 if (mode >= NR_PIO_SPECS)
108 /* Write TIME_OFF/ON/1/2W */
109 val = (3 << REG2OFF(&ata_regs->time_off)) |
110 (3 << REG2OFF(&ata_regs->time_on)) |
111 (((pio_t1[mode] + T) / T) << REG2OFF(&ata_regs->time_1)) |
112 (((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2w));
113 writel(val, &ata_regs->time_off);
115 /* Write TIME_2R/AX/RDX/4 */
116 val = (((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2r)) |
117 (((pio_tA[mode] + T) / T + 2) << REG2OFF(&ata_regs->time_ax)) |
118 (1 << REG2OFF(&ata_regs->time_pio_rdx)) |
119 (((pio_t4[mode] + T) / T) << REG2OFF(&ata_regs->time_4));
120 writel(val, &ata_regs->time_2r);
122 /* Write TIME_9 ; the rest of timing registers is irrelevant for PIO */
123 val = (((pio_t9[mode] + T) / T) << REG2OFF(&ata_regs->time_9));
124 writel(val, &ata_regs->time_9);
127 int ide_preinit(void)
129 struct mxc_ata_config_regs *ata_regs;
130 ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;
132 /* 46.3.3.4 @ FSL iMX51 manual */
133 /* FIFO normal op., drive reset */
134 writel(0x80, &ata_regs->ata_control);
135 /* FIFO normal op., drive not reset */
136 writel(0xc0, &ata_regs->ata_control);
138 /* Configure the PIO timing */
139 set_ata_bus_timing(CONFIG_MXC_ATA_PIO_MODE);
141 /* 46.3.3.4 @ FSL iMX51 manual */
142 /* Drive not reset, IORDY handshake */
143 writel(0x41, &ata_regs->ata_control);