0103-w1-gpio-Sort-out-the-pullup-parasitic-power-tangle.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. From 8ceb69e8548f27305e37866ec3b81a79e1402b1a Mon Sep 17 00:00:00 2001
  2. From: Phil Elwell <phil@raspberrypi.org>
  3. Date: Wed, 4 Feb 2015 12:59:36 +0000
  4. Subject: [PATCH 103/114] w1-gpio: Sort out the pullup/parasitic power tangle
  5. ---
  6. arch/arm/boot/dts/w1-gpio-overlay.dts | 4 +++-
  7. arch/arm/boot/dts/w1-gpio-pullup-overlay.dts | 6 +++--
  8. drivers/w1/masters/w1-gpio.c | 36 ++++++++++++++++++----------
  9. include/linux/w1-gpio.h | 1 +
  10. 4 files changed, 32 insertions(+), 15 deletions(-)
  11. --- a/arch/arm/boot/dts/w1-gpio-overlay.dts
  12. +++ b/arch/arm/boot/dts/w1-gpio-overlay.dts
  13. @@ -1,4 +1,4 @@
  14. -// Definitions for lirc-rpi module
  15. +// Definitions for w1-gpio module (without external pullup)
  16. /dts-v1/;
  17. /plugin/;
  18. @@ -14,6 +14,7 @@
  19. pinctrl-names = "default";
  20. pinctrl-0 = <&w1_pins>;
  21. gpios = <&gpio 4 0>;
  22. + rpi,parasitic-power = <0>;
  23. status = "okay";
  24. };
  25. };
  26. @@ -33,5 +34,6 @@
  27. __overrides__ {
  28. gpiopin = <&w1>,"gpios:4",
  29. <&w1_pins>,"brcm,pins:0";
  30. + pullup = <&w1>,"rpi,parasitic-power:0";
  31. };
  32. };
  33. --- a/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts
  34. +++ b/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts
  35. @@ -1,4 +1,4 @@
  36. -// Definitions for lirc-rpi module
  37. +// Definitions for w1-gpio module (with external pullup)
  38. /dts-v1/;
  39. /plugin/;
  40. @@ -14,6 +14,7 @@
  41. pinctrl-names = "default";
  42. pinctrl-0 = <&w1_pins>;
  43. gpios = <&gpio 4 0>, <&gpio 5 1>;
  44. + rpi,parasitic-power = <0>;
  45. status = "okay";
  46. };
  47. };
  48. @@ -33,7 +34,8 @@
  49. __overrides__ {
  50. gpiopin = <&w1>,"gpios:4",
  51. <&w1_pins>,"brcm,pins:0";
  52. - pullup = <&w1>,"gpios:16",
  53. + extpullup = <&w1>,"gpios:16",
  54. <&w1_pins>,"brcm,pins:4";
  55. + pullup = <&w1>,"rpi,parasitic-power:0";
  56. };
  57. };
  58. --- a/drivers/w1/masters/w1-gpio.c
  59. +++ b/drivers/w1/masters/w1-gpio.c
  60. @@ -23,10 +23,14 @@
  61. #include "../w1.h"
  62. #include "../w1_int.h"
  63. -static int w1_gpio_pullup = -1;
  64. -static int w1_gpio_pullup_orig = -1;
  65. +static int w1_gpio_pullup = 0;
  66. +static int w1_gpio_pullup_orig = 0;
  67. module_param_named(pullup, w1_gpio_pullup, int, 0);
  68. -MODULE_PARM_DESC(pullup, "GPIO pin pullup number");
  69. +MODULE_PARM_DESC(pullup, "Enable parasitic power (power on data) mode");
  70. +static int w1_gpio_pullup_pin = -1;
  71. +static int w1_gpio_pullup_pin_orig = -1;
  72. +module_param_named(extpullup, w1_gpio_pullup_pin, int, 0);
  73. +MODULE_PARM_DESC(extpullup, "GPIO external pullup pin number");
  74. static int w1_gpio_pin = -1;
  75. static int w1_gpio_pin_orig = -1;
  76. module_param_named(gpiopin, w1_gpio_pin, int, 0);
  77. @@ -99,6 +103,7 @@ static int w1_gpio_probe_dt(struct platf
  78. struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
  79. struct device_node *np = pdev->dev.of_node;
  80. int gpio;
  81. + u32 value;
  82. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  83. if (!pdata)
  84. @@ -107,6 +112,9 @@ static int w1_gpio_probe_dt(struct platf
  85. if (of_get_property(np, "linux,open-drain", NULL))
  86. pdata->is_open_drain = 1;
  87. + if (of_property_read_u32(np, "rpi,parasitic-power", &value) == 0)
  88. + pdata->parasitic_power = (value != 0);
  89. +
  90. gpio = of_get_gpio(np, 0);
  91. if (gpio < 0) {
  92. if (gpio != -EPROBE_DEFER)
  93. @@ -122,7 +130,7 @@ static int w1_gpio_probe_dt(struct platf
  94. if (gpio == -EPROBE_DEFER)
  95. return gpio;
  96. /* ignore other errors as the pullup gpio is optional */
  97. - pdata->ext_pullup_enable_pin = gpio;
  98. + pdata->ext_pullup_enable_pin = (gpio >= 0) ? gpio : -1;
  99. pdev->dev.platform_data = pdata;
  100. @@ -158,17 +166,20 @@ static int w1_gpio_probe(struct platform
  101. }
  102. w1_gpio_pin_orig = pdata->pin;
  103. - w1_gpio_pullup_orig = pdata->ext_pullup_enable_pin;
  104. + w1_gpio_pullup_pin_orig = pdata->ext_pullup_enable_pin;
  105. + w1_gpio_pullup_orig = pdata->parasitic_power;
  106. if(gpio_is_valid(w1_gpio_pin)) {
  107. pdata->pin = w1_gpio_pin;
  108. pdata->ext_pullup_enable_pin = -1;
  109. + pdata->parasitic_power = -1;
  110. }
  111. - if(gpio_is_valid(w1_gpio_pullup)) {
  112. - pdata->ext_pullup_enable_pin = w1_gpio_pullup;
  113. + pdata->parasitic_power |= w1_gpio_pullup;
  114. + if(gpio_is_valid(w1_gpio_pullup_pin)) {
  115. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin;
  116. }
  117. - dev_info(&pdev->dev, "gpio pin %d, gpio pullup pin %d\n", pdata->pin, pdata->ext_pullup_enable_pin);
  118. + dev_info(&pdev->dev, "gpio pin %d, external pullup pin %d, parasitic power %d\n", pdata->pin, pdata->ext_pullup_enable_pin, pdata->parasitic_power);
  119. err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
  120. if (err) {
  121. @@ -199,10 +210,10 @@ static int w1_gpio_probe(struct platform
  122. master->set_pullup = w1_gpio_set_pullup;
  123. }
  124. - if (gpio_is_valid(w1_gpio_pullup)) {
  125. + if (pdata->parasitic_power) {
  126. if (pdata->is_open_drain)
  127. - printk(KERN_ERR "w1-gpio 'pullup' option "
  128. - "doesn't work with open drain GPIO\n");
  129. + printk(KERN_ERR "w1-gpio 'pullup'(parasitic power) "
  130. + "option doesn't work with open drain GPIO\n");
  131. else
  132. master->bitbang_pullup = w1_gpio_bitbang_pullup;
  133. }
  134. @@ -238,7 +249,8 @@ static int w1_gpio_remove(struct platfor
  135. w1_remove_master_device(master);
  136. pdata->pin = w1_gpio_pin_orig;
  137. - pdata->ext_pullup_enable_pin = w1_gpio_pullup_orig;
  138. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin_orig;
  139. + pdata->parasitic_power = w1_gpio_pullup_orig;
  140. return 0;
  141. }
  142. --- a/include/linux/w1-gpio.h
  143. +++ b/include/linux/w1-gpio.h
  144. @@ -18,6 +18,7 @@
  145. struct w1_gpio_platform_data {
  146. unsigned int pin;
  147. unsigned int is_open_drain:1;
  148. + unsigned int parasitic_power:1;
  149. void (*enable_external_pullup)(int enable);
  150. unsigned int ext_pullup_enable_pin;
  151. unsigned int pullup_duration;