summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/ata-imx31.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/ata-imx31.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/ata-imx31.c48
1 files changed, 8 insertions, 40 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/ata-imx31.c b/firmware/target/arm/imx31/gigabeat-s/ata-imx31.c
index 965b447651..92cc048d57 100644
--- a/firmware/target/arm/imx31/gigabeat-s/ata-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/ata-imx31.c
@@ -79,17 +79,18 @@ static const struct ata_pio_timings
79 }, 79 },
80}; 80};
81 81
82static bool initialized = false; 82static int pio_mode = 0; /* Setup mode 0 by default */
83 83
84/* Setup the timing for PIO mode */ 84/* Setup the timing for PIO mode */
85static void ata_set_pio_mode(int mode) 85void ata_set_pio_timings(int mode)
86{ 86{
87 const struct ata_pio_timings * const timings = &pio_timings[mode]; 87 while (!(ATA_INTERRUPT_PENDING & ATA_CONTROLLER_IDLE));
88 88
89 const struct ata_pio_timings * const timings = &pio_timings[mode];
89 /* T = period in nanoseconds */ 90 /* T = period in nanoseconds */
90 int T = 1000 * 1000 * 1000 / imx31_clkctl_get_ata_clk(); 91 int T = 1000 * 1000 * 1000 / imx31_clkctl_get_ata_clk();
91 92
92 while (!(ATA_INTERRUPT_PENDING & ATA_CONTROLLER_IDLE)); 93 pio_mode = mode;
93 94
94 ATA_TIME_OFF = 3; 95 ATA_TIME_OFF = 3;
95 ATA_TIME_ON = 3; 96 ATA_TIME_ON = 3;
@@ -128,40 +129,7 @@ void ata_device_init(void)
128{ 129{
129 ATA_INTF_CONTROL |= ATA_ATA_RST; /* Make sure we're not in reset mode */ 130 ATA_INTF_CONTROL |= ATA_ATA_RST; /* Make sure we're not in reset mode */
130 131
131 if (!initialized) 132 /* mode may be switched later once identify info is ready in which
132 { 133 * case the main driver calls back */
133 initialized = true; 134 ata_set_pio_timings(pio_mode);
134 /* Setup mode 0 by default */
135 ata_set_pio_mode(0);
136 /* mode may be switched later once identify info is ready in which
137 * case the main driver calls back */
138 }
139 else
140 {
141 /* identify info will be ready */
142 ata_identify_ready();
143 }
144}
145
146void ata_identify_ready(void)
147{
148 const unsigned short* identify_info = ata_get_identify();
149 int mode = 0;
150
151 if (identify_info[53] & (1 << 1))
152 {
153 /* Set up advanced timings */
154 if (identify_info[64] & (1 << 1))
155 mode = 4; /* Mode 0, 1, 2, 3, 4 */
156 else if (identify_info[64] & (1 << 0))
157 mode = 3; /* Mode 0, 1, 2, 3 */
158 else
159 mode = 2; /* Mode 0, 1, 2 */
160 }
161
162 /* If mode changed, actually set the timings */
163 if (mode != 0)
164 {
165 ata_set_pio_mode(mode);
166 }
167} 135}