0121-Extend-clock-timeout-fix-modprobe-baudrate-parameter.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. From 7d0e8dc92007a9ad6193e8cda7d954e78e6556ee Mon Sep 17 00:00:00 2001
  2. From: Devon Fyson <devonfyson@gmail.com>
  3. Date: Wed, 30 Dec 2015 16:40:47 -0500
  4. Subject: [PATCH 121/381] Extend clock timeout, fix modprobe baudrate
  5. parameter.
  6. Set the BSC_CLKT clock streching timeout to 35ms as per SMBus specs.\n- Increase priority of baudrate parameter passed to modprobe (in /etc/modprobe.d/*.conf or command line). Currently custom baudrates don't work because they are overridden by clock-frequency in the platform_device passed to the function.
  7. ---
  8. drivers/i2c/busses/i2c-bcm2708.c | 45 ++++++++++++++++++++++++++--------------
  9. 1 file changed, 29 insertions(+), 16 deletions(-)
  10. --- a/drivers/i2c/busses/i2c-bcm2708.c
  11. +++ b/drivers/i2c/busses/i2c-bcm2708.c
  12. @@ -71,7 +71,8 @@
  13. #define DRV_NAME "bcm2708_i2c"
  14. -static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  15. +static unsigned int baudrate_default = CONFIG_I2C_BCM2708_BAUDRATE;
  16. +static unsigned int baudrate;
  17. module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  18. MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  19. @@ -87,6 +88,7 @@ struct bcm2708_i2c {
  20. int irq;
  21. struct clk *clk;
  22. u32 cdiv;
  23. + u32 clk_tout;
  24. struct completion done;
  25. @@ -126,7 +128,7 @@ static inline void bcm2708_bsc_fifo_fill
  26. static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  27. {
  28. - u32 cdiv, s;
  29. + u32 cdiv, s, clk_tout;
  30. u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  31. int wait_loops = I2C_WAIT_LOOP_COUNT;
  32. @@ -134,12 +136,14 @@ static inline int bcm2708_bsc_setup(stru
  33. * Use the value that we cached in the probe.
  34. */
  35. cdiv = bi->cdiv;
  36. + clk_tout = bi->clk_tout;
  37. if (bi->msg->flags & I2C_M_RD)
  38. c |= BSC_C_INTR | BSC_C_READ;
  39. else
  40. c |= BSC_C_INTT;
  41. + bcm2708_wr(bi, BSC_CLKT, clk_tout);
  42. bcm2708_wr(bi, BSC_DIV, cdiv);
  43. bcm2708_wr(bi, BSC_A, bi->msg->addr);
  44. bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  45. @@ -312,21 +316,24 @@ static int bcm2708_i2c_probe(struct plat
  46. struct bcm2708_i2c *bi;
  47. struct i2c_adapter *adap;
  48. unsigned long bus_hz;
  49. - u32 cdiv;
  50. -
  51. - if (pdev->dev.of_node) {
  52. - u32 bus_clk_rate;
  53. - pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
  54. - if (pdev->id < 0) {
  55. - dev_err(&pdev->dev, "alias is missing\n");
  56. - return -EINVAL;
  57. + u32 cdiv, clk_tout;
  58. +
  59. + if (!baudrate) {
  60. + baudrate = baudrate_default;
  61. + if (pdev->dev.of_node) {
  62. + u32 bus_clk_rate;
  63. + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
  64. + if (pdev->id < 0) {
  65. + dev_err(&pdev->dev, "alias is missing\n");
  66. + return -EINVAL;
  67. + }
  68. + if (!of_property_read_u32(pdev->dev.of_node,
  69. + "clock-frequency", &bus_clk_rate))
  70. + baudrate = bus_clk_rate;
  71. + else
  72. + dev_warn(&pdev->dev,
  73. + "Could not read clock-frequency property\n");
  74. }
  75. - if (!of_property_read_u32(pdev->dev.of_node,
  76. - "clock-frequency", &bus_clk_rate))
  77. - baudrate = bus_clk_rate;
  78. - else
  79. - dev_warn(&pdev->dev,
  80. - "Could not read clock-frequency property\n");
  81. }
  82. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  83. @@ -417,7 +424,13 @@ static int bcm2708_i2c_probe(struct plat
  84. cdiv = 0xffff;
  85. baudrate = bus_hz / cdiv;
  86. }
  87. +
  88. + clk_tout = 35/1000*baudrate; //35ms timeout as per SMBus specs.
  89. + if (clk_tout > 0xffff)
  90. + clk_tout = 0xffff;
  91. +
  92. bi->cdiv = cdiv;
  93. + bi->clk_tout = clk_tout;
  94. dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  95. pdev->id, (unsigned long)regs->start, irq, baudrate);