Skip to content

Commit d2323cf

Browse files
zonquegregkh
authored andcommitted
onewire: w1-gpio: add ext_pullup_enable pin in platform data
In the process of porting boards to devicetree implemenation, we should keep information about external circuitry where they belong - the individual drivers. This patch adds a way to specify a GPIO to drive the (optional) external pull-up logic, rather than using a function pointer for that. Signed-off-by: Daniel Mack <[email protected]> Acked-by: Evgeniy Polyakov <[email protected]> Acked-by: Ville Syrjälä <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5f3d138 commit d2323cf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

drivers/w1/masters/w1-gpio.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
104104
if (err)
105105
goto free_master;
106106

107+
if (gpio_is_valid(pdata->ext_pullup_enable_pin)) {
108+
err = gpio_request_one(pdata->ext_pullup_enable_pin,
109+
GPIOF_INIT_LOW, "w1 pullup");
110+
if (err < 0)
111+
goto free_gpio;
112+
}
113+
107114
master->data = pdata;
108115
master->read_bit = w1_gpio_read_bit;
109116

@@ -117,15 +124,21 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
117124

118125
err = w1_add_master_device(master);
119126
if (err)
120-
goto free_gpio;
127+
goto free_gpio_ext_pu;
121128

122129
if (pdata->enable_external_pullup)
123130
pdata->enable_external_pullup(1);
124131

132+
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
133+
gpio_set_value(pdata->ext_pullup_enable_pin, 1);
134+
125135
platform_set_drvdata(pdev, master);
126136

127137
return 0;
128138

139+
free_gpio_ext_pu:
140+
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
141+
gpio_free(pdata->ext_pullup_enable_pin);
129142
free_gpio:
130143
gpio_free(pdata->pin);
131144
free_master:
@@ -142,6 +155,9 @@ static int __exit w1_gpio_remove(struct platform_device *pdev)
142155
if (pdata->enable_external_pullup)
143156
pdata->enable_external_pullup(0);
144157

158+
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
159+
gpio_set_value(pdata->ext_pullup_enable_pin, 0);
160+
145161
w1_remove_master_device(master);
146162
gpio_free(pdata->pin);
147163
kfree(master);

include/linux/w1-gpio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct w1_gpio_platform_data {
1919
unsigned int pin;
2020
unsigned int is_open_drain:1;
2121
void (*enable_external_pullup)(int enable);
22+
unsigned int ext_pullup_enable_pin;
2223
};
2324

2425
#endif /* _LINUX_W1_GPIO_H */

0 commit comments

Comments
 (0)