blob: 16f1a0191563e17de26c36346dada070e5037c18 [file] [log] [blame]
Wolfgang Denkde26ef92009-05-16 10:47:38 +02001/*
2 * (C) Copyright 2007-2009 DENX Software Engineering
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 *
22 */
23
24#include <common.h>
25#include <command.h>
26#include <asm/processor.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
30#if defined(CONFIG_IDE_RESET)
31
32void init_ide_reset (void)
33{
34 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
35 debug ("init_ide_reset\n");
36
37 /*
38 * Clear the reset bit to reset the interface
39 * cf. RefMan MPC5121EE: 28.4.1 Resetting the ATA Bus
40 */
41 immr->pata.pata_ata_control = 0;
42 udelay(100);
43 /* Assert the reset bit to enable the interface */
44 immr->pata.pata_ata_control = FSL_ATA_CTRL_ATA_RST_B;
45 udelay(100);
46}
47
48void ide_set_reset (int idereset)
49{
50 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
51 debug ("ide_set_reset(%d)\n", idereset);
52
53 if (idereset) {
54 immr->pata.pata_ata_control = 0;
55 udelay(100);
56 } else {
57 immr->pata.pata_ata_control = FSL_ATA_CTRL_ATA_RST_B;
58 udelay(100);
59 }
60}
61
62#define CALC_TIMING(t) (t + period - 1) / period
63
64int ide_preinit (void)
65{
66 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
67 long t;
68 const struct {
69 short t0;
70 short t1;
71 short t2_8;
72 short t2_16;
73 short t2i;
74 short t4;
75 short t9;
76 short tA;
77 } pio_specs = {
78 .t0 = 600,
79 .t1 = 70,
80 .t2_8 = 290,
81 .t2_16 = 165,
82 .t2i = 0,
83 .t4 = 30,
84 .t9 = 20,
85 .tA = 50,
86 };
87 union {
88 u32 config;
89 struct {
90 u8 field1;
91 u8 field2;
92 u8 field3;
93 u8 field4;
94 }bytes;
95 }cfg;
96
97 debug ("IDE preinit using PATA peripheral at IMMR-ADDR %08x\n",
98 (u32)&immr->pata);
99
100 /* Set the reset bit to 1 to enable the interface */
101 immr->pata.pata_ata_control = FSL_ATA_CTRL_ATA_RST_B;
102
103 /* Init timings : we use PIO mode 0 timings */
104 t = 1000000000 / gd->ips_clk; /* period in ns */
105 cfg.bytes.field1 = 3;
106 cfg.bytes.field2 = 3;
107 cfg.bytes.field3 = (pio_specs.t1 + t) / t;
108 cfg.bytes.field4 = (pio_specs.t2_8 + t) / t;
109
110 immr->pata.pata_time1 = cfg.config;
111
112 cfg.bytes.field1 = (pio_specs.t2_8 + t) / t;
113 cfg.bytes.field2 = (pio_specs.tA + t) / t + 2;
114 cfg.bytes.field3 = 1;
115 cfg.bytes.field4 = (pio_specs.t4 + t) / t;
116
117 immr->pata.pata_time2 = cfg.config;
118
119 cfg.config = immr->pata.pata_time3;
120 cfg.bytes.field1 = (pio_specs.t9 + t) / t;
121
122 immr->pata.pata_time3 = cfg.config;
123 debug ("PATA preinit complete.\n");
124
125 return 0;
126}
127
128#endif /* defined(CONFIG_IDE_RESET) */