brcm2708: update 3.10 patches with raspberrypi/rpi-3.10.y of 27 Apr. 2014
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.10 / 0055-Add-bitbanging-pullups-use-them-for-w1-gpio.patch
1 From 0a2fa5a85c2ed9599acb2215f24e06db0379a133 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Wed, 1 May 2013 21:14:28 +0100
4 Subject: [PATCH 055/196] Add bitbanging pullups, use them for w1-gpio
5
6 Allows parasite power to work, uses module option pullup=1
7 ---
8 drivers/w1/masters/w1-gpio.c | 20 ++++++++++++++++++++
9 drivers/w1/w1.h | 6 ++++++
10 drivers/w1/w1_int.c | 16 +++++++++-------
11 drivers/w1/w1_io.c | 18 +++++++++++++++---
12 4 files changed, 50 insertions(+), 10 deletions(-)
13
14 diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
15 index 46d9701..f615f80 100644
16 --- a/drivers/w1/masters/w1-gpio.c
17 +++ b/drivers/w1/masters/w1-gpio.c
18 @@ -23,6 +23,9 @@
19 #include "../w1.h"
20 #include "../w1_int.h"
21
22 +static int w1_gpio_pullup = 0;
23 +module_param_named(pullup, w1_gpio_pullup, int, 0);
24 +
25 static void w1_gpio_write_bit_dir(void *data, u8 bit)
26 {
27 struct w1_gpio_platform_data *pdata = data;
28 @@ -47,6 +50,16 @@ static u8 w1_gpio_read_bit(void *data)
29 return gpio_get_value(pdata->pin) ? 1 : 0;
30 }
31
32 +static void w1_gpio_bitbang_pullup(void *data, u8 on)
33 +{
34 + struct w1_gpio_platform_data *pdata = data;
35 +
36 + if (on)
37 + gpio_direction_output(pdata->pin, 1);
38 + else
39 + gpio_direction_input(pdata->pin);
40 +}
41 +
42 #if defined(CONFIG_OF)
43 static struct of_device_id w1_gpio_dt_ids[] = {
44 { .compatible = "w1-gpio" },
45 @@ -133,6 +146,13 @@ static int w1_gpio_probe(struct platform_device *pdev)
46 master->write_bit = w1_gpio_write_bit_dir;
47 }
48
49 + if (w1_gpio_pullup)
50 + if (pdata->is_open_drain)
51 + printk(KERN_ERR "w1-gpio 'pullup' option "
52 + "doesn't work with open drain GPIO\n");
53 + else
54 + master->bitbang_pullup = w1_gpio_bitbang_pullup;
55 +
56 err = w1_add_master_device(master);
57 if (err) {
58 dev_err(&pdev->dev, "w1_add_master device failed\n");
59 diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
60 index 45908e5..0ba75f6 100644
61 --- a/drivers/w1/w1.h
62 +++ b/drivers/w1/w1.h
63 @@ -148,6 +148,12 @@ struct w1_bus_master
64 */
65 u8 (*set_pullup)(void *, int);
66
67 + /**
68 + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
69 + * @return -1=Error, 0=completed
70 + */
71 + void (*bitbang_pullup) (void *, u8);
72 +
73 /** Really nice hardware can handles the different types of ROM search
74 * w1_master* is passed to the slave found callback.
75 */
76 diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
77 index 5a98649..a4d69b6 100644
78 --- a/drivers/w1/w1_int.c
79 +++ b/drivers/w1/w1_int.c
80 @@ -117,19 +117,21 @@ int w1_add_master_device(struct w1_bus_master *master)
81 printk(KERN_ERR "w1_add_master_device: invalid function set\n");
82 return(-EINVAL);
83 }
84 - /* While it would be electrically possible to make a device that
85 - * generated a strong pullup in bit bang mode, only hardware that
86 - * controls 1-wire time frames are even expected to support a strong
87 - * pullup. w1_io.c would need to support calling set_pullup before
88 - * the last write_bit operation of a w1_write_8 which it currently
89 - * doesn't.
90 - */
91 +
92 + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
93 + * and takes care of timing itself */
94 if (!master->write_byte && !master->touch_bit && master->set_pullup) {
95 printk(KERN_ERR "w1_add_master_device: set_pullup requires "
96 "write_byte or touch_bit, disabling\n");
97 master->set_pullup = NULL;
98 }
99
100 + if (master->set_pullup && master->bitbang_pullup) {
101 + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
102 + "be set when bitbang_pullup is used, disabling\n");
103 + master->set_pullup = NULL;
104 + }
105 +
106 /* Lock until the device is added (or not) to w1_masters. */
107 mutex_lock(&w1_mlock);
108 /* Search for the first available id (starting at 1). */
109 diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
110 index e10acc2..667fdd5 100644
111 --- a/drivers/w1/w1_io.c
112 +++ b/drivers/w1/w1_io.c
113 @@ -127,10 +127,22 @@ static void w1_pre_write(struct w1_master *dev)
114 static void w1_post_write(struct w1_master *dev)
115 {
116 if (dev->pullup_duration) {
117 - if (dev->enable_pullup && dev->bus_master->set_pullup)
118 - dev->bus_master->set_pullup(dev->bus_master->data, 0);
119 - else
120 + if (dev->enable_pullup) {
121 + if (dev->bus_master->set_pullup) {
122 + dev->bus_master->set_pullup(dev->
123 + bus_master->data,
124 + 0);
125 + } else if (dev->bus_master->bitbang_pullup) {
126 + dev->bus_master->
127 + bitbang_pullup(dev->bus_master->data, 1);
128 + msleep(dev->pullup_duration);
129 + dev->bus_master->
130 + bitbang_pullup(dev->bus_master->data, 0);
131 + }
132 + } else {
133 msleep(dev->pullup_duration);
134 + }
135 +
136 dev->pullup_duration = 0;
137 }
138 }
139 --
140 1.9.1
141