From 57cbd777889010c39db892fe6e9f844f26eb3ed9 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 5 May 2008 13:00:08 +0000 Subject: Gigabeat S: Do the controller timing settings a more cleanly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17379 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/ata.c | 8 ++-- firmware/target/arm/imx31/gigabeat-s/ata-imx31.c | 48 ++++------------------- firmware/target/arm/imx31/gigabeat-s/ata-target.h | 6 +-- 3 files changed, 15 insertions(+), 47 deletions(-) diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index e949f38a9d..1dd05133fe 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -1090,10 +1090,6 @@ static int identify(void) #endif } -#ifdef ATA_NOTIFY_IDENTIFY_READY - ata_identify_ready(); -#endif - return 0; } @@ -1172,6 +1168,10 @@ static int set_features(void) } } +#ifdef ATA_SET_DEVICE_FEATURES + ata_set_pio_timings(pio_mode); +#endif + return 0; } 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 }, }; -static bool initialized = false; +static int pio_mode = 0; /* Setup mode 0 by default */ /* Setup the timing for PIO mode */ -static void ata_set_pio_mode(int mode) +void ata_set_pio_timings(int mode) { - const struct ata_pio_timings * const timings = &pio_timings[mode]; + while (!(ATA_INTERRUPT_PENDING & ATA_CONTROLLER_IDLE)); + const struct ata_pio_timings * const timings = &pio_timings[mode]; /* T = period in nanoseconds */ int T = 1000 * 1000 * 1000 / imx31_clkctl_get_ata_clk(); - while (!(ATA_INTERRUPT_PENDING & ATA_CONTROLLER_IDLE)); + pio_mode = mode; ATA_TIME_OFF = 3; ATA_TIME_ON = 3; @@ -128,40 +129,7 @@ void ata_device_init(void) { ATA_INTF_CONTROL |= ATA_ATA_RST; /* Make sure we're not in reset mode */ - if (!initialized) - { - initialized = true; - /* Setup mode 0 by default */ - ata_set_pio_mode(0); - /* mode may be switched later once identify info is ready in which - * case the main driver calls back */ - } - else - { - /* identify info will be ready */ - ata_identify_ready(); - } -} - -void ata_identify_ready(void) -{ - const unsigned short* identify_info = ata_get_identify(); - int mode = 0; - - if (identify_info[53] & (1 << 1)) - { - /* Set up advanced timings */ - if (identify_info[64] & (1 << 1)) - mode = 4; /* Mode 0, 1, 2, 3, 4 */ - else if (identify_info[64] & (1 << 0)) - mode = 3; /* Mode 0, 1, 2, 3 */ - else - mode = 2; /* Mode 0, 1, 2 */ - } - - /* If mode changed, actually set the timings */ - if (mode != 0) - { - ata_set_pio_mode(mode); - } + /* mode may be switched later once identify info is ready in which + * case the main driver calls back */ + ata_set_pio_timings(pio_mode); } diff --git a/firmware/target/arm/imx31/gigabeat-s/ata-target.h b/firmware/target/arm/imx31/gigabeat-s/ata-target.h index 7b61039c7e..6428e9f41f 100644 --- a/firmware/target/arm/imx31/gigabeat-s/ata-target.h +++ b/firmware/target/arm/imx31/gigabeat-s/ata-target.h @@ -68,7 +68,7 @@ void ata_reset(void); void ata_device_init(void); bool ata_is_coldstart(void); -#define ATA_NOTIFY_IDENTIFY_READY -void ata_identify_ready(void); +#define ATA_SET_DEVICE_FEATURES +void ata_set_pio_timings(int mode); -#endif +#endif /* ATA_TARGET_H */ -- cgit v1.2.3