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
7 arch/arm/boot/dts/w1-gpio-overlay.dts | 4 +++-
8 arch/arm/boot/dts/w1-gpio-pullup-overlay.dts | 6 +++--
9 drivers/w1/masters/w1-gpio.c | 36 ++++++++++++++++++----------
10 include/linux/w1-gpio.h | 1 +
11 4 files changed, 32 insertions(+), 15 deletions(-)
13 --- a/arch/arm/boot/dts/w1-gpio-overlay.dts
14 +++ b/arch/arm/boot/dts/w1-gpio-overlay.dts
16 -// Definitions for lirc-rpi module
17 +// Definitions for w1-gpio module (without external pullup)
22 pinctrl-names = "default";
23 pinctrl-0 = <&w1_pins>;
25 + rpi,parasitic-power = <0>;
31 gpiopin = <&w1>,"gpios:4",
32 <&w1_pins>,"brcm,pins:0";
33 + pullup = <&w1>,"rpi,parasitic-power:0";
36 --- a/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts
37 +++ b/arch/arm/boot/dts/w1-gpio-pullup-overlay.dts
39 -// Definitions for lirc-rpi module
40 +// Definitions for w1-gpio module (with external pullup)
45 pinctrl-names = "default";
46 pinctrl-0 = <&w1_pins>;
47 gpios = <&gpio 4 0>, <&gpio 5 1>;
48 + rpi,parasitic-power = <0>;
54 gpiopin = <&w1>,"gpios:4",
55 <&w1_pins>,"brcm,pins:0";
56 - pullup = <&w1>,"gpios:16",
57 + extpullup = <&w1>,"gpios:16",
58 <&w1_pins>,"brcm,pins:4";
59 + pullup = <&w1>,"rpi,parasitic-power:0";
62 --- a/drivers/w1/masters/w1-gpio.c
63 +++ b/drivers/w1/masters/w1-gpio.c
66 #include "../w1_int.h"
68 -static int w1_gpio_pullup = -1;
69 -static int w1_gpio_pullup_orig = -1;
70 +static int w1_gpio_pullup = 0;
71 +static int w1_gpio_pullup_orig = 0;
72 module_param_named(pullup, w1_gpio_pullup, int, 0);
73 -MODULE_PARM_DESC(pullup, "GPIO pin pullup number");
74 +MODULE_PARM_DESC(pullup, "Enable parasitic power (power on data) mode");
75 +static int w1_gpio_pullup_pin = -1;
76 +static int w1_gpio_pullup_pin_orig = -1;
77 +module_param_named(extpullup, w1_gpio_pullup_pin, int, 0);
78 +MODULE_PARM_DESC(extpullup, "GPIO external pullup pin number");
79 static int w1_gpio_pin = -1;
80 static int w1_gpio_pin_orig = -1;
81 module_param_named(gpiopin, w1_gpio_pin, int, 0);
82 @@ -99,6 +103,7 @@ static int w1_gpio_probe_dt(struct platf
83 struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
84 struct device_node *np = pdev->dev.of_node;
88 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
90 @@ -107,6 +112,9 @@ static int w1_gpio_probe_dt(struct platf
91 if (of_get_property(np, "linux,open-drain", NULL))
92 pdata->is_open_drain = 1;
94 + if (of_property_read_u32(np, "rpi,parasitic-power", &value) == 0)
95 + pdata->parasitic_power = (value != 0);
97 gpio = of_get_gpio(np, 0);
99 if (gpio != -EPROBE_DEFER)
100 @@ -122,7 +130,7 @@ static int w1_gpio_probe_dt(struct platf
101 if (gpio == -EPROBE_DEFER)
103 /* ignore other errors as the pullup gpio is optional */
104 - pdata->ext_pullup_enable_pin = gpio;
105 + pdata->ext_pullup_enable_pin = (gpio >= 0) ? gpio : -1;
107 pdev->dev.platform_data = pdata;
109 @@ -158,17 +166,20 @@ static int w1_gpio_probe(struct platform
112 w1_gpio_pin_orig = pdata->pin;
113 - w1_gpio_pullup_orig = pdata->ext_pullup_enable_pin;
114 + w1_gpio_pullup_pin_orig = pdata->ext_pullup_enable_pin;
115 + w1_gpio_pullup_orig = pdata->parasitic_power;
117 if(gpio_is_valid(w1_gpio_pin)) {
118 pdata->pin = w1_gpio_pin;
119 pdata->ext_pullup_enable_pin = -1;
120 + pdata->parasitic_power = -1;
122 - if(gpio_is_valid(w1_gpio_pullup)) {
123 - pdata->ext_pullup_enable_pin = w1_gpio_pullup;
124 + pdata->parasitic_power |= w1_gpio_pullup;
125 + if(gpio_is_valid(w1_gpio_pullup_pin)) {
126 + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin;
129 - dev_info(&pdev->dev, "gpio pin %d, gpio pullup pin %d\n", pdata->pin, pdata->ext_pullup_enable_pin);
130 + 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);
132 err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
134 @@ -199,10 +210,10 @@ static int w1_gpio_probe(struct platform
135 master->set_pullup = w1_gpio_set_pullup;
138 - if (gpio_is_valid(w1_gpio_pullup)) {
139 + if (pdata->parasitic_power) {
140 if (pdata->is_open_drain)
141 - printk(KERN_ERR "w1-gpio 'pullup' option "
142 - "doesn't work with open drain GPIO\n");
143 + printk(KERN_ERR "w1-gpio 'pullup'(parasitic power) "
144 + "option doesn't work with open drain GPIO\n");
146 master->bitbang_pullup = w1_gpio_bitbang_pullup;
148 @@ -238,7 +249,8 @@ static int w1_gpio_remove(struct platfor
149 w1_remove_master_device(master);
151 pdata->pin = w1_gpio_pin_orig;
152 - pdata->ext_pullup_enable_pin = w1_gpio_pullup_orig;
153 + pdata->ext_pullup_enable_pin = w1_gpio_pullup_pin_orig;
154 + pdata->parasitic_power = w1_gpio_pullup_orig;
158 --- a/include/linux/w1-gpio.h
159 +++ b/include/linux/w1-gpio.h
161 struct w1_gpio_platform_data {
163 unsigned int is_open_drain:1;
164 + unsigned int parasitic_power:1;
165 void (*enable_external_pullup)(int enable);
166 unsigned int ext_pullup_enable_pin;
167 unsigned int pullup_duration;