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

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