drivers/w1/masters/w1-gpio.c: add strong pullup emulation
authorEvgeny Boger <boger@contactless.ru>
Thu, 23 Jan 2014 23:56:18 +0000 (15:56 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 24 Jan 2014 00:37:04 +0000 (16:37 -0800)
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>
drivers/w1/masters/w1-gpio.c
drivers/w1/w1_int.c
include/linux/w1-gpio.h

index e36b18b2817b9e655f524d79e8edf753cabece68..9709b8b484bacc8fcd9ddb4c1a88e137e2afa961 100644 (file)
 #include <linux/of_gpio.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/delay.h>
 
 #include "../w1.h"
 #include "../w1_int.h"
 
+static u8 w1_gpio_set_pullup(void *data, int delay)
+{
+       struct w1_gpio_platform_data *pdata = data;
+
+       if (delay) {
+               pdata->pullup_duration = delay;
+       } else {
+               if (pdata->pullup_duration) {
+                       gpio_direction_output(pdata->pin, 1);
+
+                       msleep(pdata->pullup_duration);
+
+                       gpio_direction_input(pdata->pin);
+               }
+               pdata->pullup_duration = 0;
+       }
+
+       return 0;
+}
+
 static void w1_gpio_write_bit_dir(void *data, u8 bit)
 {
        struct w1_gpio_platform_data *pdata = data;
@@ -132,6 +153,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
        } else {
                gpio_direction_input(pdata->pin);
                master->write_bit = w1_gpio_write_bit_dir;
+               master->set_pullup = w1_gpio_set_pullup;
        }
 
        err = w1_add_master_device(master);
index 5a98649f6abc27d563bf8ac957ddc0523a21f8e0..590bd8a7cd1bf3f071b145a7a48c47c30cabe510 100644 (file)
@@ -117,18 +117,6 @@ int w1_add_master_device(struct w1_bus_master *master)
                printk(KERN_ERR "w1_add_master_device: invalid function set\n");
                return(-EINVAL);
         }
-       /* While it would be electrically possible to make a device that
-        * generated a strong pullup in bit bang mode, only hardware that
-        * controls 1-wire time frames are even expected to support a strong
-        * pullup.  w1_io.c would need to support calling set_pullup before
-        * the last write_bit operation of a w1_write_8 which it currently
-        * doesn't.
-        */
-       if (!master->write_byte && !master->touch_bit && master->set_pullup) {
-               printk(KERN_ERR "w1_add_master_device: set_pullup requires "
-                       "write_byte or touch_bit, disabling\n");
-               master->set_pullup = NULL;
-       }
 
        /* Lock until the device is added (or not) to w1_masters. */
        mutex_lock(&w1_mlock);
index 065e3ae79ab0e7f09138cceb19d8f35ce6d72d67..d58594a3232492e33f1dd4babd3798b03e0f0203 100644 (file)
@@ -20,6 +20,7 @@ struct w1_gpio_platform_data {
        unsigned int is_open_drain:1;
        void (*enable_external_pullup)(int enable);
        unsigned int ext_pullup_enable_pin;
+       unsigned int pullup_duration;
 };
 
 #endif /* _LINUX_W1_GPIO_H */