Commit fab356a0b87d57d474d6e87408f1ede98a503150

Authored by Hans de Goede
Committed by Heiko Schocher
1 parent 557a331908

mvtwsi: Fix clock programming

The TWSI_FREQUENCY macro was wrong in 2 ways:
1) It was casting the result of the calculations to an u8, while i2c clk
rates are often >= 100Khz which won't fit in a u8, drop the cast.
2) It had an extra factor of 2 in the divider which neither the datasheet nor
the Linux driver have.

The comment for the default value was wrongly saying that m lives in
bits 4-7, while in reality it is in bits 3-6, as can be seen from the correct
shift by 3 used in i2c_init().

While at it remove the unused twsi_actual_speed variable.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Showing 1 changed file with 2 additions and 5 deletions Side-by-side Diff

drivers/i2c/mvtwsi.c
... ... @@ -216,7 +216,7 @@
216 216 */
217 217  
218 218 #define TWSI_FREQUENCY(m, n) \
219   - ((u8) (CONFIG_SYS_TCLK / (10 * (m + 1) * 2 * (1 << n))))
  219 + (CONFIG_SYS_TCLK / (10 * (m + 1) * (1 << n)))
220 220  
221 221 /*
222 222 * These are required to be reprogrammed before enabling the controller
223 223  
... ... @@ -225,10 +225,8 @@
225 225 * twsi_slave_address left uninitialized lest checkpatch.pl complains.
226 226 */
227 227  
228   -/* Baudrate generator: m (bits 7..4) =4, n (bits 3..0) =4 */
  228 +/* Baudrate generator: m (bits 6..3) = 8, n (bits 2..0) = 4 */
229 229 static u8 twsi_baud_rate = 0x44; /* baudrate at controller reset */
230   -/* Default frequency corresponding to default m=4, n=4 */
231   -static u8 twsi_actual_speed = TWSI_FREQUENCY(4, 4);
232 230 /* Default slave address is 0 (so is an uninitialized static) */
233 231 static u8 twsi_slave_address;
234 232  
... ... @@ -279,7 +277,6 @@
279 277 }
280 278 /* save baud rate and slave for later calls to twsi_reset */
281 279 twsi_baud_rate = baud;
282   - twsi_actual_speed = highest_speed;
283 280 twsi_slave_address = slaveadd;
284 281 /* reset controller */
285 282 twsi_reset();