Skip to content

Commit 3089a4c

Browse files
evgeny-bogertorvalds
authored andcommitted
drivers/w1/masters/w1-gpio.c: add strong pullup emulation
Strong pullup is emulated by driving pin logic high after write command when using tri-state push-pull GPIO. Signed-off-by: Evgeny Boger <boger@contactless.ru> Cc: Greg KH <greg@kroah.com> Acked-by: David Fries <david@fries.net> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 63509be commit 3089a4c

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎drivers/w1/masters/w1-gpio.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,31 @@
1818
#include <linux/of_gpio.h>
1919
#include <linux/err.h>
2020
#include <linux/of.h>
21+
#include <linux/delay.h>
2122

2223
#include "../w1.h"
2324
#include "../w1_int.h"
2425

26+
static u8 w1_gpio_set_pullup(void *data, int delay)
27+
{
28+
struct w1_gpio_platform_data *pdata = data;
29+
30+
if (delay) {
31+
pdata->pullup_duration = delay;
32+
} else {
33+
if (pdata->pullup_duration) {
34+
gpio_direction_output(pdata->pin, 1);
35+
36+
msleep(pdata->pullup_duration);
37+
38+
gpio_direction_input(pdata->pin);
39+
}
40+
pdata->pullup_duration = 0;
41+
}
42+
43+
return 0;
44+
}
45+
2546
static void w1_gpio_write_bit_dir(void *data, u8 bit)
2647
{
2748
struct w1_gpio_platform_data *pdata = data;
@@ -132,6 +153,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
132153
} else {
133154
gpio_direction_input(pdata->pin);
134155
master->write_bit = w1_gpio_write_bit_dir;
156+
master->set_pullup = w1_gpio_set_pullup;
135157
}
136158

137159
err = w1_add_master_device(master);

‎drivers/w1/w1_int.c‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ int w1_add_master_device(struct w1_bus_master *master)
117117
printk(KERN_ERR "w1_add_master_device: invalid function set\n");
118118
return(-EINVAL);
119119
}
120-
/* While it would be electrically possible to make a device that
121-
* generated a strong pullup in bit bang mode, only hardware that
122-
* controls 1-wire time frames are even expected to support a strong
123-
* pullup. w1_io.c would need to support calling set_pullup before
124-
* the last write_bit operation of a w1_write_8 which it currently
125-
* doesn't.
126-
*/
127-
if (!master->write_byte && !master->touch_bit && master->set_pullup) {
128-
printk(KERN_ERR "w1_add_master_device: set_pullup requires "
129-
"write_byte or touch_bit, disabling\n");
130-
master->set_pullup = NULL;
131-
}
132120

133121
/* Lock until the device is added (or not) to w1_masters. */
134122
mutex_lock(&w1_mlock);

‎include/linux/w1-gpio.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct w1_gpio_platform_data {
2020
unsigned int is_open_drain:1;
2121
void (*enable_external_pullup)(int enable);
2222
unsigned int ext_pullup_enable_pin;
23+
unsigned int pullup_duration;
2324
};
2425

2526
#endif /* _LINUX_W1_GPIO_H */

0 commit comments

Comments
 (0)