0139-FIXUP-i2c_bcm2708-Don-t-change-module-baudrate-param.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. From 6ddd618b031bc8f28f76114ac553f14bed1eb2ee Mon Sep 17 00:00:00 2001
  2. From: Phil Elwell <phil@raspberrypi.org>
  3. Date: Tue, 19 Jan 2016 16:28:05 +0000
  4. Subject: [PATCH] FIXUP i2c_bcm2708: Don't change module baudrate parameter
  5. Overwriting the baudrate module parameter creates an apparent
  6. forced baudrate for i2c busses after the first. Not only does this
  7. override the baudrate from DT it also prevents the bus ID from
  8. being initialised.
  9. Also fix whitespace errors.
  10. ---
  11. drivers/i2c/busses/i2c-bcm2708.c | 48 +++++++++++++++++++++-------------------
  12. 1 file changed, 25 insertions(+), 23 deletions(-)
  13. --- a/drivers/i2c/busses/i2c-bcm2708.c
  14. +++ b/drivers/i2c/busses/i2c-bcm2708.c
  15. @@ -71,7 +71,6 @@
  16. #define DRV_NAME "bcm2708_i2c"
  17. -static unsigned int baudrate_default = CONFIG_I2C_BCM2708_BAUDRATE;
  18. static unsigned int baudrate;
  19. module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  20. MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  21. @@ -317,25 +316,28 @@ static int bcm2708_i2c_probe(struct plat
  22. struct i2c_adapter *adap;
  23. unsigned long bus_hz;
  24. u32 cdiv, clk_tout;
  25. -
  26. - if (!baudrate) {
  27. - baudrate = baudrate_default;
  28. - if (pdev->dev.of_node) {
  29. - u32 bus_clk_rate;
  30. - pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
  31. - if (pdev->id < 0) {
  32. - dev_err(&pdev->dev, "alias is missing\n");
  33. - return -EINVAL;
  34. - }
  35. - if (!of_property_read_u32(pdev->dev.of_node,
  36. - "clock-frequency", &bus_clk_rate))
  37. - baudrate = bus_clk_rate;
  38. - else
  39. - dev_warn(&pdev->dev,
  40. - "Could not read clock-frequency property\n");
  41. + u32 baud;
  42. +
  43. + baud = CONFIG_I2C_BCM2708_BAUDRATE;
  44. +
  45. + if (pdev->dev.of_node) {
  46. + u32 bus_clk_rate;
  47. + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
  48. + if (pdev->id < 0) {
  49. + dev_err(&pdev->dev, "alias is missing\n");
  50. + return -EINVAL;
  51. }
  52. + if (!of_property_read_u32(pdev->dev.of_node,
  53. + "clock-frequency", &bus_clk_rate))
  54. + baud = bus_clk_rate;
  55. + else
  56. + dev_warn(&pdev->dev,
  57. + "Could not read clock-frequency property\n");
  58. }
  59. + if (baudrate)
  60. + baud = baudrate;
  61. +
  62. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  63. if (!regs) {
  64. dev_err(&pdev->dev, "could not get IO memory\n");
  65. @@ -419,21 +421,21 @@ static int bcm2708_i2c_probe(struct plat
  66. }
  67. bus_hz = clk_get_rate(bi->clk);
  68. - cdiv = bus_hz / baudrate;
  69. + cdiv = bus_hz / baud;
  70. if (cdiv > 0xffff) {
  71. cdiv = 0xffff;
  72. - baudrate = bus_hz / cdiv;
  73. + baud = bus_hz / cdiv;
  74. }
  75. -
  76. - clk_tout = 35/1000*baudrate; //35ms timeout as per SMBus specs.
  77. - if (clk_tout > 0xffff)
  78. +
  79. + clk_tout = 35/1000*baud; //35ms timeout as per SMBus specs.
  80. + if (clk_tout > 0xffff)
  81. clk_tout = 0xffff;
  82. bi->cdiv = cdiv;
  83. bi->clk_tout = clk_tout;
  84. dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  85. - pdev->id, (unsigned long)regs->start, irq, baudrate);
  86. + pdev->id, (unsigned long)regs->start, irq, baud);
  87. return 0;