Advertisement
jeanleflambeur

i2c-bcm2708

Feb 1st, 2015
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. 69,70c69
  2. < #define I2C_TIMEOUT_MS 1000
  3. < #define I2C_WAIT_LOOP_COUNT 40
  4. ---
  5. > #define I2C_TIMEOUT_MS 150
  6. 78c77
  7. < static bool combined = true;
  8. ---
  9. > static bool combined = false;
  10. 89d87
  11. < u32 cdiv;
  12. 113c111
  13. < BUG_ON(id != 0 && id != 1);
  14. ---
  15. > BUG_ON(id != 0 && id != 1);
  16. 116c114
  17. < printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  18. ---
  19. > printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  20. 155c153
  21. < static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  22. ---
  23. > static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  24. 157c155
  25. < // unsigned long bus_hz;
  26. ---
  27. > unsigned long bus_hz;
  28. 160d157
  29. < int wait_loops = I2C_WAIT_LOOP_COUNT;
  30. 162,166c159,162
  31. < // bus_hz = clk_get_rate(bi->clk);
  32. < // cdiv = bus_hz / baudrate;
  33. < // if (cdiv > 0xffff)
  34. < // cdiv = 0xffff;
  35. < cdiv = bi->cdiv;
  36. ---
  37. > bus_hz = clk_get_rate(bi->clk);
  38. > cdiv = bus_hz / baudrate;
  39. > if (cdiv > 0xffff)
  40. > cdiv = 0xffff;
  41. 183,184c179,180
  42. < !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  43. < (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  44. ---
  45. > !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  46. > (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  47. 186c182
  48. < while (bi->pos < bi->msg->len) {
  49. ---
  50. > while (bi->pos < bi->msg->len)
  51. 188d183
  52. < }
  53. 191d185
  54. <
  55. 195,201c189
  56. < } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)) && --wait_loops >= 0);
  57. <
  58. < /* did we time out or some error occured? */
  59. < if (wait_loops < 0 || (s & (BSC_S_ERR | BSC_S_CLKT))) {
  60. < return -1;
  61. < }
  62. <
  63. ---
  64. > } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)));
  65. 211,212d198
  66. <
  67. < return 0;
  68. 220d205
  69. < int ret;
  70. 225,226c210,211
  71. < Just return if we've not sent anything */
  72. < if (!bi->nmsgs || !bi->msg ) {
  73. ---
  74. > Just return if we've not sent anything */
  75. > if (!bi->nmsgs || !bi->msg )
  76. 228d212
  77. < }
  78. 236,237d219
  79. < bi->msg = 0; /* to inform the that all work is done */
  80. < bi->nmsgs = 0;
  81. 239c221
  82. < complete_all(&bi->done);
  83. ---
  84. > complete(&bi->done);
  85. 243c225
  86. < if (bi->msg->flags & I2C_M_RD) {
  87. ---
  88. > if (bi->msg->flags & I2C_M_RD)
  89. 245d226
  90. < }
  91. 253,262c234
  92. < ret = bcm2708_bsc_setup(bi);
  93. < if (ret < 0) {
  94. < bcm2708_bsc_reset(bi);
  95. < bi->error = true;
  96. < bi->msg = 0; /* to inform the that all work is done */
  97. < bi->nmsgs = 0;
  98. < /* wake up our bh */
  99. < complete_all(&bi->done);
  100. < goto early_exit;
  101. < }
  102. ---
  103. > bcm2708_bsc_setup(bi);
  104. 264,265d235
  105. < bi->msg = 0; /* to inform the that all work is done */
  106. < bi->nmsgs = 0;
  107. 267c237
  108. < complete_all(&bi->done);
  109. ---
  110. > complete(&bi->done);
  111. 298c268
  112. < ret = bcm2708_bsc_setup(bi);
  113. ---
  114. > bcm2708_bsc_setup(bi);
  115. 299a270
  116. > /* unlockig _after_ the setup to avoid races with the interrupt routine */
  117. 302,309c273,274
  118. < /* check trhe result of the setup */
  119. < if (ret < 0)
  120. < {
  121. < dev_err(&adap->dev, "transfer setup timed out\n");
  122. < goto error_timeout;
  123. < }
  124. <
  125. < ret = wait_for_completion_timeout(&bi->done, msecs_to_jiffies(I2C_TIMEOUT_MS));
  126. ---
  127. > ret = wait_for_completion_timeout(&bi->done,
  128. > msecs_to_jiffies(I2C_TIMEOUT_MS));
  129. 312c277,280
  130. < goto error_timeout;
  131. ---
  132. > spin_lock_irqsave(&bi->lock, flags);
  133. > bcm2708_bsc_reset(bi);
  134. > spin_unlock_irqrestore(&bi->lock, flags);
  135. > return -ETIMEDOUT;
  136. 315,324c283
  137. < ret = bi->error ? -EIO : num;
  138. < return ret;
  139. <
  140. < error_timeout:
  141. < spin_lock_irqsave(&bi->lock, flags);
  142. < bcm2708_bsc_reset(bi);
  143. < bi->msg = 0; /* to inform the interrupt handler that there's nothing else to be done */
  144. < bi->nmsgs = 0;
  145. < spin_unlock_irqrestore(&bi->lock, flags);
  146. < return -ETIMEDOUT;
  147. ---
  148. > return bi->error ? -EIO : num;
  149. 427d385
  150. < bi->cdiv = cdiv;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement