diff options
author | Bertrik Sikken <bertrik@sikken.nl> | 2010-06-21 21:41:07 +0000 |
---|---|---|
committer | Bertrik Sikken <bertrik@sikken.nl> | 2010-06-21 21:41:07 +0000 |
commit | 206227096477f328dfe16fee2d9ec13d631bd6e6 (patch) | |
tree | 0edd9336df4bb217186aa7799a522d3cacebc4f9 /firmware/target | |
parent | 06b9064205d3e8aaf7f743fb1486733dd369ce1c (diff) |
Apply FS #11423 - Use udelay in AMS driver for FM radio I2C
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27035 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/as3525/fmradio-i2c-as3525.c | 99 |
1 files changed, 45 insertions, 54 deletions
diff --git a/firmware/target/arm/as3525/fmradio-i2c-as3525.c b/firmware/target/arm/as3525/fmradio-i2c-as3525.c index 33d12f9fa7..9e8dc63144 100644 --- a/firmware/target/arm/as3525/fmradio-i2c-as3525.c +++ b/firmware/target/arm/as3525/fmradio-i2c-as3525.c @@ -28,6 +28,7 @@ */ #include "as3525.h" +#include "system.h" #include "generic_i2c.h" #include "fmradio_i2c.h" @@ -77,85 +78,75 @@ static int fm_i2c_bus; -static void fm_scl_hi(void) +static void fm_scl_dir(bool out) { - I2C_SCL_GPIO(I2C_SCL_PIN) = 1 << I2C_SCL_PIN; -} - -static void fm_scl_lo(void) -{ - I2C_SCL_GPIO(I2C_SCL_PIN) = 0; -} - -static void fm_sda_hi(void) -{ - I2C_SDA_GPIO(I2C_SDA_PIN) = 1 << I2C_SDA_PIN; -} - -static void fm_sda_lo(void) -{ - I2C_SDA_GPIO(I2C_SDA_PIN) = 0; + if (out) { + I2C_SCL_GPIO_DIR |= 1 << I2C_SCL_PIN; + } else { + I2C_SCL_GPIO_DIR &= ~(1 << I2C_SCL_PIN); + } } -static void fm_sda_input(void) +static void fm_sda_dir(bool out) { - I2C_SDA_GPIO_DIR &= ~(1 << I2C_SDA_PIN); + if (out) { + I2C_SDA_GPIO_DIR |= 1 << I2C_SDA_PIN; + } else { + I2C_SDA_GPIO_DIR &= ~(1 << I2C_SDA_PIN); + } } -static void fm_sda_output(void) +static void fm_scl_out(bool level) { - I2C_SDA_GPIO_DIR |= 1 << I2C_SDA_PIN; + if (level) { + I2C_SCL_GPIO(I2C_SCL_PIN) = 1 << I2C_SCL_PIN; + } else { + I2C_SCL_GPIO(I2C_SCL_PIN) = 0; + } } -static void fm_scl_input(void) +static void fm_sda_out(bool level) { - I2C_SCL_GPIO_DIR &= ~(1 << I2C_SCL_PIN); + if (level) { + I2C_SDA_GPIO(I2C_SDA_PIN) = 1 << I2C_SDA_PIN; + } else { + I2C_SDA_GPIO(I2C_SDA_PIN) = 0; + } } -static void fm_scl_output(void) +static bool fm_scl_in(void) { - I2C_SCL_GPIO_DIR |= 1 << I2C_SCL_PIN; + return I2C_SCL_GPIO(I2C_SCL_PIN); } -static int fm_sda(void) +static bool fm_sda_in(void) { return I2C_SDA_GPIO(I2C_SDA_PIN); } -static int fm_scl(void) +static void fm_delay(int delay) { - return I2C_SCL_GPIO(I2C_SCL_PIN); -} - -/* simple and crude delay, used for all delays in the generic i2c driver */ -static void fm_delay(void) -{ - volatile int i; - - /* this loop is uncalibrated and could use more sophistication */ - for (i = 0; i < 20; i++) { + if (delay != 0) { + udelay(delay); } } /* interface towards the generic i2c driver */ static const struct i2c_interface fm_i2c_interface = { - .scl_hi = fm_scl_hi, - .scl_lo = fm_scl_lo, - .sda_hi = fm_sda_hi, - .sda_lo = fm_sda_lo, - .sda_input = fm_sda_input, - .sda_output = fm_sda_output, - .scl_input = fm_scl_input, - .scl_output = fm_scl_output, - .scl = fm_scl, - .sda = fm_sda, - - .delay_hd_sta = fm_delay, - .delay_hd_dat = fm_delay, - .delay_su_dat = fm_delay, - .delay_su_sto = fm_delay, - .delay_su_sta = fm_delay, - .delay_thigh = fm_delay + .scl_out = fm_scl_out, + .scl_dir = fm_scl_dir, + .sda_out = fm_sda_out, + .sda_dir = fm_sda_dir, + .sda_in = fm_sda_in, + .scl_in = fm_scl_in, + .delay = fm_delay, + + .delay_hd_sta = 1, + .delay_hd_dat = 0, + .delay_su_dat = 1, + .delay_su_sto = 1, + .delay_su_sta = 1, + .delay_thigh = 2 }; /* initialise i2c for fmradio */ |