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

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