2222
2323#include "../w1.h"
2424#include "../w1_int.h"
25+ static int w1_gpio_pullup_pin = -1 ;
26+ static int w1_gpio_pullup_pin_orig = -1 ;
27+ module_param_named (extpullup , w1_gpio_pullup_pin , int , 0 );
28+ MODULE_PARM_DESC (extpullup , "GPIO external pullup pin number" );
29+ static int w1_gpio_pin = -1 ;
30+ static int w1_gpio_pin_orig = -1 ;
31+ module_param_named (gpiopin , w1_gpio_pin , int , 0 );
32+ MODULE_PARM_DESC (gpiopin , "GPIO pin number" );
2533
2634static u8 w1_gpio_set_pullup (void * data , int delay )
2735{
@@ -103,7 +111,7 @@ static int w1_gpio_probe_dt(struct platform_device *pdev)
103111 if (gpio == - EPROBE_DEFER )
104112 return gpio ;
105113 /* ignore other errors as the pullup gpio is optional */
106- pdata -> ext_pullup_enable_pin = gpio ;
114+ pdata -> ext_pullup_enable_pin = ( gpio >= 0 ) ? gpio : -1 ;
107115
108116 pdev -> dev .platform_data = pdata ;
109117
@@ -113,13 +121,15 @@ static int w1_gpio_probe_dt(struct platform_device *pdev)
113121static int w1_gpio_probe (struct platform_device * pdev )
114122{
115123 struct w1_bus_master * master ;
116- struct w1_gpio_platform_data * pdata ;
124+ struct w1_gpio_platform_data * pdata = pdev -> dev . platform_data ;
117125 int err ;
118126
119- if (of_have_populated_dt ()) {
120- err = w1_gpio_probe_dt (pdev );
121- if (err < 0 )
122- return err ;
127+ if (pdata == NULL ) {
128+ if (of_have_populated_dt ()) {
129+ err = w1_gpio_probe_dt (pdev );
130+ if (err < 0 )
131+ return err ;
132+ }
123133 }
124134
125135 pdata = dev_get_platdata (& pdev -> dev );
@@ -136,6 +146,19 @@ static int w1_gpio_probe(struct platform_device *pdev)
136146 return - ENOMEM ;
137147 }
138148
149+ w1_gpio_pin_orig = pdata -> pin ;
150+ w1_gpio_pullup_pin_orig = pdata -> ext_pullup_enable_pin ;
151+
152+ if (gpio_is_valid (w1_gpio_pin )) {
153+ pdata -> pin = w1_gpio_pin ;
154+ pdata -> ext_pullup_enable_pin = -1 ;
155+ }
156+ if (gpio_is_valid (w1_gpio_pullup_pin )) {
157+ pdata -> ext_pullup_enable_pin = w1_gpio_pullup_pin ;
158+ }
159+
160+ dev_info (& pdev -> dev , "gpio pin %d, external pullup pin %d\n" , pdata -> pin , pdata -> ext_pullup_enable_pin );
161+
139162 err = devm_gpio_request (& pdev -> dev , pdata -> pin , "w1" );
140163 if (err ) {
141164 dev_err (& pdev -> dev , "gpio_request (pin) failed\n" );
@@ -195,6 +218,9 @@ static int w1_gpio_remove(struct platform_device *pdev)
195218
196219 w1_remove_master_device (master );
197220
221+ pdata -> pin = w1_gpio_pin_orig ;
222+ pdata -> ext_pullup_enable_pin = w1_gpio_pullup_pin_orig ;
223+
198224 return 0 ;
199225}
200226
0 commit comments