Lines Matching +full:delay +full:- +full:line

1 // SPDX-License-Identifier: GPL-2.0-only
3 * w1-gpio - GPIO w1 bus master driver
12 #include <linux/w1-gpio.h>
17 #include <linux/delay.h>
21 static u8 w1_gpio_set_pullup(void *data, int delay) in w1_gpio_set_pullup() argument
25 if (delay) { in w1_gpio_set_pullup()
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()
31 * the line high for some time. 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()
36 * This will simply set the line as input since we are doing 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()
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()
87 * driver it high/low like we are in full control of the line and in w1_gpio_probe()
90 if (of_get_property(np, "linux,open-drain", NULL)) in w1_gpio_probe()
93 pdev->dev.platform_data = pdata; in w1_gpio_probe()
99 return -ENXIO; in w1_gpio_probe()
106 return -ENOMEM; in w1_gpio_probe()
109 pdata->gpiod = devm_gpiod_get_index(dev, NULL, 0, gflags); in w1_gpio_probe()
110 if (IS_ERR(pdata->gpiod)) { in w1_gpio_probe()
112 return PTR_ERR(pdata->gpiod); in w1_gpio_probe()
115 pdata->pullup_gpiod = in w1_gpio_probe()
117 if (IS_ERR(pdata->pullup_gpiod)) { in w1_gpio_probe()
120 return PTR_ERR(pdata->pullup_gpiod); in w1_gpio_probe()
123 master->data = pdata; in w1_gpio_probe()
124 master->read_bit = w1_gpio_read_bit; in w1_gpio_probe()
125 gpiod_direction_output(pdata->gpiod, 1); in w1_gpio_probe()
126 master->write_bit = w1_gpio_write_bit; in w1_gpio_probe()
130 * we need to use this pullup function that hammers the line in w1_gpio_probe()
131 * high using a raw accessor to provide pull-up for the w1 in w1_gpio_probe()
132 * line. in w1_gpio_probe()
135 master->set_pullup = w1_gpio_set_pullup; in w1_gpio_probe()
143 if (pdata->enable_external_pullup) in w1_gpio_probe()
144 pdata->enable_external_pullup(1); in w1_gpio_probe()
146 if (pdata->pullup_gpiod) in w1_gpio_probe()
147 gpiod_set_value(pdata->pullup_gpiod, 1); in w1_gpio_probe()
157 struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); in w1_gpio_remove()
159 if (pdata->enable_external_pullup) in w1_gpio_remove()
160 pdata->enable_external_pullup(0); in w1_gpio_remove()
162 if (pdata->pullup_gpiod) in w1_gpio_remove()
163 gpiod_set_value(pdata->pullup_gpiod, 0); in w1_gpio_remove()
174 if (pdata->enable_external_pullup) in w1_gpio_suspend()
175 pdata->enable_external_pullup(0); in w1_gpio_suspend()
184 if (pdata->enable_external_pullup) in w1_gpio_resume()
185 pdata->enable_external_pullup(1); in w1_gpio_resume()
194 .name = "w1-gpio",