freemyipod r317 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r316‎ | r317 | r318 >
Date:01:06, 4 December 2010
Author:theseven
Status:new
Tags:
Comment:
emBIOS: Some more ATA speed optimizations for iPod Classic
Modified paths:
  • /embios/trunk/target/ipodclassic/storage_ata.c (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodclassic/storage_ata.c
@@ -41,15 +41,15 @@
4242
4343 static uint16_t ata_read_cbr(uint32_t volatile* reg)
4444 {
45 - while (!(ATA_PIO_READY & 2)) sleep(0);
 45+ while (!(ATA_PIO_READY & 2)) yield();
4646 volatile uint32_t dummy = *reg;
47 - while (!(ATA_PIO_READY & 1)) sleep(0);
 47+ while (!(ATA_PIO_READY & 1)) yield();
4848 return ATA_PIO_RDATA;
4949 }
5050
5151 static void ata_write_cbr(uint32_t volatile* reg, uint16_t data)
5252 {
53 - while (!(ATA_PIO_READY & 2)) sleep(0);
 53+ while (!(ATA_PIO_READY & 2)) yield();
5454 *reg = data;
5555 }
5656
@@ -61,7 +61,6 @@
6262 uint8_t csd = ata_read_cbr(&ATA_PIO_CSD);
6363 if (!(csd & BIT(7))) return 0;
6464 if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(0);
65 - sleep(100);
6665 }
6766 }
6867
@@ -74,7 +73,6 @@
7574 uint8_t dad = ata_read_cbr(&ATA_PIO_DAD);
7675 if (dad & BIT(6)) return 0;
7776 if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(1);
78 - sleep(100);
7977 }
8078 }
8179
@@ -88,7 +86,6 @@
8987 if (dad & BIT(0)) RET_ERR(1);
9088 if ((dad & (BIT(7) | BIT(3))) == BIT(3)) return 0;
9189 if (TIMEOUT_EXPIRED(startusec, timeout)) RET_ERR(2);
92 - sleep(100);
9390 }
9491 }
9592
@@ -120,6 +117,17 @@
121118 ata_last_activity_value = USEC_TIMER;
122119 }
123120
 121+int ata_set_feature(uint32_t feature, uint32_t param)
 122+{
 123+ PASS_RC(ata_wait_for_rdy(500000), 1, 0);
 124+ ata_write_cbr(&ATA_PIO_DVR, 0);
 125+ ata_write_cbr(&ATA_PIO_FED, 3);
 126+ ata_write_cbr(&ATA_PIO_SCR, param);
 127+ ata_write_cbr(&ATA_PIO_CSD, feature);
 128+ PASS_RC(ata_wait_for_rdy(500000), 1, 1);
 129+ return 0;
 130+}
 131+
124132 int ata_power_up()
125133 {
126134 ata_set_active();
@@ -200,12 +208,9 @@
201209 }
202210 }
203211 ata_dma = param ? true : false;
204 - PASS_RC(ata_wait_for_rdy(500000), 2, 1);
205 - ata_write_cbr(&ATA_PIO_DVR, 0);
206 - ata_write_cbr(&ATA_PIO_FED, 3);
207 - ata_write_cbr(&ATA_PIO_SCR, param);
208 - ata_write_cbr(&ATA_PIO_CSD, 0xef);
209 - PASS_RC(ata_wait_for_rdy(500000), 2, 2);
 212+ PASS_RC(ata_set_feature(0xef, param), 2, 1);
 213+ if (ata_identify_data[82] & BIT(5)) PASS_RC(ata_set_feature(2, 0), 2, 2);
 214+ if (ata_identify_data[82] & BIT(6)) PASS_RC(ata_set_feature(0x55, 0), 2, 3);
210215 ATA_PIO_TIME = piotime;
211216 ATA_MDMA_TIME = mdmatime;
212217 ATA_UDMA_TIME = udmatime;
@@ -223,7 +228,7 @@
224229 ata_wait_for_rdy(1000000);
225230 sleep(30000);
226231 ATA_CONTROL = 0;
227 - while (!(ATA_CONTROL & BIT(1))) sleep(0);
 232+ while (!(ATA_CONTROL & BIT(1))) yield();
228233 clockgate_enable(5, false);
229234 i2c_sendbyte(0, 0xe6, 0x1b, 0);
230235 }
@@ -238,7 +243,7 @@
239244 ATA_COMMAND = BIT(1);
240245 while (count)
241246 {
242 - uint32_t cnt = MIN(32, count);
 247+ uint32_t cnt = MIN(ata_lba48 ? 8192 : 32, count);
243248 PASS_RC(ata_wait_for_rdy(100000), 2, 0);
244249 ata_write_cbr(&ATA_PIO_DVR, 0);
245250 if (ata_lba48)