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/arm | |
parent | 06b9064205d3e8aaf7f743fb1486733dd369ce1c (diff) | |
download | rockbox-206227096477f328dfe16fee2d9ec13d631bd6e6.tar.gz rockbox-206227096477f328dfe16fee2d9ec13d631bd6e6.zip |
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/arm')
-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 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "as3525.h" | 30 | #include "as3525.h" |
31 | #include "system.h" | ||
31 | #include "generic_i2c.h" | 32 | #include "generic_i2c.h" |
32 | #include "fmradio_i2c.h" | 33 | #include "fmradio_i2c.h" |
33 | 34 | ||
@@ -77,85 +78,75 @@ | |||
77 | 78 | ||
78 | static int fm_i2c_bus; | 79 | static int fm_i2c_bus; |
79 | 80 | ||
80 | static void fm_scl_hi(void) | 81 | static void fm_scl_dir(bool out) |
81 | { | 82 | { |
82 | I2C_SCL_GPIO(I2C_SCL_PIN) = 1 << I2C_SCL_PIN; | 83 | if (out) { |
83 | } | 84 | I2C_SCL_GPIO_DIR |= 1 << I2C_SCL_PIN; |
84 | 85 | } else { | |
85 | static void fm_scl_lo(void) | 86 | I2C_SCL_GPIO_DIR &= ~(1 << I2C_SCL_PIN); |
86 | { | 87 | } |
87 | I2C_SCL_GPIO(I2C_SCL_PIN) = 0; | ||
88 | } | ||
89 | |||
90 | static void fm_sda_hi(void) | ||
91 | { | ||
92 | I2C_SDA_GPIO(I2C_SDA_PIN) = 1 << I2C_SDA_PIN; | ||
93 | } | ||
94 | |||
95 | static void fm_sda_lo(void) | ||
96 | { | ||
97 | I2C_SDA_GPIO(I2C_SDA_PIN) = 0; | ||
98 | } | 88 | } |
99 | 89 | ||
100 | static void fm_sda_input(void) | 90 | static void fm_sda_dir(bool out) |
101 | { | 91 | { |
102 | I2C_SDA_GPIO_DIR &= ~(1 << I2C_SDA_PIN); | 92 | if (out) { |
93 | I2C_SDA_GPIO_DIR |= 1 << I2C_SDA_PIN; | ||
94 | } else { | ||
95 | I2C_SDA_GPIO_DIR &= ~(1 << I2C_SDA_PIN); | ||
96 | } | ||
103 | } | 97 | } |
104 | 98 | ||
105 | static void fm_sda_output(void) | 99 | static void fm_scl_out(bool level) |
106 | { | 100 | { |
107 | I2C_SDA_GPIO_DIR |= 1 << I2C_SDA_PIN; | 101 | if (level) { |
102 | I2C_SCL_GPIO(I2C_SCL_PIN) = 1 << I2C_SCL_PIN; | ||
103 | } else { | ||
104 | I2C_SCL_GPIO(I2C_SCL_PIN) = 0; | ||
105 | } | ||
108 | } | 106 | } |
109 | 107 | ||
110 | static void fm_scl_input(void) | 108 | static void fm_sda_out(bool level) |
111 | { | 109 | { |
112 | I2C_SCL_GPIO_DIR &= ~(1 << I2C_SCL_PIN); | 110 | if (level) { |
111 | I2C_SDA_GPIO(I2C_SDA_PIN) = 1 << I2C_SDA_PIN; | ||
112 | } else { | ||
113 | I2C_SDA_GPIO(I2C_SDA_PIN) = 0; | ||
114 | } | ||
113 | } | 115 | } |
114 | 116 | ||
115 | static void fm_scl_output(void) | 117 | static bool fm_scl_in(void) |
116 | { | 118 | { |
117 | I2C_SCL_GPIO_DIR |= 1 << I2C_SCL_PIN; | 119 | return I2C_SCL_GPIO(I2C_SCL_PIN); |
118 | } | 120 | } |
119 | 121 | ||
120 | static int fm_sda(void) | 122 | static bool fm_sda_in(void) |
121 | { | 123 | { |
122 | return I2C_SDA_GPIO(I2C_SDA_PIN); | 124 | return I2C_SDA_GPIO(I2C_SDA_PIN); |
123 | } | 125 | } |
124 | 126 | ||
125 | static int fm_scl(void) | 127 | static void fm_delay(int delay) |
126 | { | 128 | { |
127 | return I2C_SCL_GPIO(I2C_SCL_PIN); | 129 | if (delay != 0) { |
128 | } | 130 | udelay(delay); |
129 | |||
130 | /* simple and crude delay, used for all delays in the generic i2c driver */ | ||
131 | static void fm_delay(void) | ||
132 | { | ||
133 | volatile int i; | ||
134 | |||
135 | /* this loop is uncalibrated and could use more sophistication */ | ||
136 | for (i = 0; i < 20; i++) { | ||
137 | } | 131 | } |
138 | } | 132 | } |
139 | 133 | ||
140 | /* interface towards the generic i2c driver */ | 134 | /* interface towards the generic i2c driver */ |
141 | static const struct i2c_interface fm_i2c_interface = { | 135 | static const struct i2c_interface fm_i2c_interface = { |
142 | .scl_hi = fm_scl_hi, | 136 | .scl_out = fm_scl_out, |
143 | .scl_lo = fm_scl_lo, | 137 | .scl_dir = fm_scl_dir, |
144 | .sda_hi = fm_sda_hi, | 138 | .sda_out = fm_sda_out, |
145 | .sda_lo = fm_sda_lo, | 139 | .sda_dir = fm_sda_dir, |
146 | .sda_input = fm_sda_input, | 140 | .sda_in = fm_sda_in, |
147 | .sda_output = fm_sda_output, | 141 | .scl_in = fm_scl_in, |
148 | .scl_input = fm_scl_input, | 142 | .delay = fm_delay, |
149 | .scl_output = fm_scl_output, | 143 | |
150 | .scl = fm_scl, | 144 | .delay_hd_sta = 1, |
151 | .sda = fm_sda, | 145 | .delay_hd_dat = 0, |
152 | 146 | .delay_su_dat = 1, | |
153 | .delay_hd_sta = fm_delay, | 147 | .delay_su_sto = 1, |
154 | .delay_hd_dat = fm_delay, | 148 | .delay_su_sta = 1, |
155 | .delay_su_dat = fm_delay, | 149 | .delay_thigh = 2 |
156 | .delay_su_sto = fm_delay, | ||
157 | .delay_su_sta = fm_delay, | ||
158 | .delay_thigh = fm_delay | ||
159 | }; | 150 | }; |
160 | 151 | ||
161 | /* initialise i2c for fmradio */ | 152 | /* initialise i2c for fmradio */ |