Lines Matching +full:gpio +full:- +full:open +full:- +full:drain

1 // SPDX-License-Identifier: GPL-2.0-only
3 * w1-gpio - GPIO w1 bus master driver
12 #include <linux/w1-gpio.h>
13 #include <linux/gpio/consumer.h>
26 pdata->pullup_duration = delay; in w1_gpio_set_pullup()
28 if (pdata->pullup_duration) { in w1_gpio_set_pullup()
30 * This will OVERRIDE open drain emulation and force-pull in w1_gpio_set_pullup()
33 gpiod_set_raw_value(pdata->gpiod, 1); in w1_gpio_set_pullup()
34 msleep(pdata->pullup_duration); in w1_gpio_set_pullup()
37 * open drain emulation in the GPIO library. in w1_gpio_set_pullup()
39 gpiod_set_value(pdata->gpiod, 1); in w1_gpio_set_pullup()
41 pdata->pullup_duration = 0; in w1_gpio_set_pullup()
51 gpiod_set_value(pdata->gpiod, bit); in w1_gpio_write_bit()
58 return gpiod_get_value(pdata->gpiod) ? 1 : 0; in w1_gpio_read_bit()
63 { .compatible = "w1-gpio" },
73 struct device *dev = &pdev->dev; in w1_gpio_probe()
74 struct device_node *np = dev->of_node; in w1_gpio_probe()
75 /* Enforce open drain mode by default */ in w1_gpio_probe()
80 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in w1_gpio_probe()
82 return -ENOMEM; in w1_gpio_probe()
86 * already set the line into open drain mode, so we should just in w1_gpio_probe()
88 * open drain will happen transparently. in w1_gpio_probe()
90 if (of_property_present(np, "linux,open-drain")) in w1_gpio_probe()
93 pdev->dev.platform_data = pdata; in w1_gpio_probe()
99 return -ENXIO; in w1_gpio_probe()
105 return -ENOMEM; in w1_gpio_probe()
107 pdata->gpiod = devm_gpiod_get_index(dev, NULL, 0, gflags); in w1_gpio_probe()
108 if (IS_ERR(pdata->gpiod)) { in w1_gpio_probe()
110 return PTR_ERR(pdata->gpiod); in w1_gpio_probe()
113 pdata->pullup_gpiod = in w1_gpio_probe()
115 if (IS_ERR(pdata->pullup_gpiod)) { in w1_gpio_probe()
118 return PTR_ERR(pdata->pullup_gpiod); in w1_gpio_probe()
121 master->data = pdata; in w1_gpio_probe()
122 master->read_bit = w1_gpio_read_bit; in w1_gpio_probe()
123 gpiod_direction_output(pdata->gpiod, 1); in w1_gpio_probe()
124 master->write_bit = w1_gpio_write_bit; in w1_gpio_probe()
127 * If we are using open drain emulation from the GPIO library, in w1_gpio_probe()
129 * high using a raw accessor to provide pull-up for the w1 in w1_gpio_probe()
133 master->set_pullup = w1_gpio_set_pullup; in w1_gpio_probe()
141 if (pdata->enable_external_pullup) in w1_gpio_probe()
142 pdata->enable_external_pullup(1); in w1_gpio_probe()
144 if (pdata->pullup_gpiod) in w1_gpio_probe()
145 gpiod_set_value(pdata->pullup_gpiod, 1); in w1_gpio_probe()
155 struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); in w1_gpio_remove()
157 if (pdata->enable_external_pullup) in w1_gpio_remove()
158 pdata->enable_external_pullup(0); in w1_gpio_remove()
160 if (pdata->pullup_gpiod) in w1_gpio_remove()
161 gpiod_set_value(pdata->pullup_gpiod, 0); in w1_gpio_remove()
172 if (pdata->enable_external_pullup) in w1_gpio_suspend()
173 pdata->enable_external_pullup(0); in w1_gpio_suspend()
182 if (pdata->enable_external_pullup) in w1_gpio_resume()
183 pdata->enable_external_pullup(1); in w1_gpio_resume()
192 .name = "w1-gpio",
202 MODULE_DESCRIPTION("GPIO w1 bus master driver");