ca71a915a8f698eb6601235652bc15c6db538295
[openwrt/openwrt.git] / target / linux / sunxi / patches-3.14 / 230-net-rfkill-changes.patch
1 From 5f6f6af41e39677c9b722376a4088d10732cdd44 Mon Sep 17 00:00:00 2001
2 From: Chen-Yu Tsai <wens@csie.org>
3 Date: Fri, 17 Jan 2014 14:47:26 +0800
4 Subject: [PATCH] net: rfkill: gpio: fix gpio name buffer size off by 1
5
6 snprintf should be passed the complete size of the buffer, including
7 the space for '\0'. The previous code resulted in the *_reset and
8 *_shutdown strings being truncated.
9
10 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
11 ---
12 net/rfkill/rfkill-gpio.c | 4 ++--
13 1 file changed, 2 insertions(+), 2 deletions(-)
14
15 diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
16 index bd2a5b9..97ec12a 100644
17 --- a/net/rfkill/rfkill-gpio.c
18 +++ b/net/rfkill/rfkill-gpio.c
19 @@ -117,8 +117,8 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
20 if (!rfkill->shutdown_name)
21 return -ENOMEM;
22
23 - snprintf(rfkill->reset_name, len + 6 , "%s_reset", rfkill->name);
24 - snprintf(rfkill->shutdown_name, len + 9, "%s_shutdown", rfkill->name);
25 + snprintf(rfkill->reset_name, len + 7 , "%s_reset", rfkill->name);
26 + snprintf(rfkill->shutdown_name, len + 10, "%s_shutdown", rfkill->name);
27
28 rfkill->clk = devm_clk_get(&pdev->dev, clk_name);
29
30 --
31 2.0.3
32
33 From d91c313c08167978c3fb20b327b6a7abb7b00ffd Mon Sep 17 00:00:00 2001
34 From: Chen-Yu Tsai <wens@csie.org>
35 Date: Fri, 17 Jan 2014 14:47:27 +0800
36 Subject: [PATCH] net: rfkill: gpio: use
37 clk_prepare_enable/clk_disable_unprepare
38
39 rfkill-gpio calls clk_enable() without first calling clk_prepare(),
40 resulting in a warning and no effect. Switch to clk_prepare_enable()
41 and clk_disable_unprepare.
42
43 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
44 ---
45 net/rfkill/rfkill-gpio.c | 4 ++--
46 1 file changed, 2 insertions(+), 2 deletions(-)
47
48 diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
49 index 97ec12a..c7081b7 100644
50 --- a/net/rfkill/rfkill-gpio.c
51 +++ b/net/rfkill/rfkill-gpio.c
52 @@ -51,10 +51,10 @@ static int rfkill_gpio_set_power(void *data, bool blocked)
53 gpiod_set_value(rfkill->shutdown_gpio, 0);
54 gpiod_set_value(rfkill->reset_gpio, 0);
55 if (!IS_ERR(rfkill->clk) && rfkill->clk_enabled)
56 - clk_disable(rfkill->clk);
57 + clk_disable_unprepare(rfkill->clk);
58 } else {
59 if (!IS_ERR(rfkill->clk) && !rfkill->clk_enabled)
60 - clk_enable(rfkill->clk);
61 + clk_prepare_enable(rfkill->clk);
62 gpiod_set_value(rfkill->reset_gpio, 1);
63 gpiod_set_value(rfkill->shutdown_gpio, 1);
64 }
65 --
66 2.0.3
67
68 From f6dc85e22d3215a26f509fb5b34ca34c56a0d8b4 Mon Sep 17 00:00:00 2001
69 From: Chen-Yu Tsai <wens@csie.org>
70 Date: Fri, 17 Jan 2014 14:47:28 +0800
71 Subject: [PATCH] net: rfkill: gpio: fix reversed clock enable state
72
73 rfkill-gpio has clk_enabled = blocked, which is true when rfkill
74 blocks the device. This results in calling clock enable/disable at
75 the wrong time. Reversing the value fixes this.
76
77 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
78 ---
79 net/rfkill/rfkill-gpio.c | 2 +-
80 1 file changed, 1 insertion(+), 1 deletion(-)
81
82 diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
83 index c7081b7..3084fa3 100644
84 --- a/net/rfkill/rfkill-gpio.c
85 +++ b/net/rfkill/rfkill-gpio.c
86 @@ -59,7 +59,7 @@ static int rfkill_gpio_set_power(void *data, bool blocked)
87 gpiod_set_value(rfkill->shutdown_gpio, 1);
88 }
89
90 - rfkill->clk_enabled = blocked;
91 + rfkill->clk_enabled = !blocked;
92
93 return 0;
94 }
95 --
96 2.0.3
97
98 From 57301a41d4a82902e967f6bd9f09ba6ca31fcbed Mon Sep 17 00:00:00 2001
99 From: Chen-Yu Tsai <wens@csie.org>
100 Date: Fri, 17 Jan 2014 14:47:29 +0800
101 Subject: [PATCH] net: rfkill: gpio: add device tree support
102
103 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
104 ---
105 .../devicetree/bindings/rfkill/rfkill-gpio.txt | 26 ++++++++++++++++++++++
106 net/rfkill/rfkill-gpio.c | 23 +++++++++++++++++++
107 2 files changed, 49 insertions(+)
108 create mode 100644 Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt
109
110 diff --git a/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt b/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt
111 new file mode 100644
112 index 0000000..8a07ea4
113 --- /dev/null
114 +++ b/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt
115 @@ -0,0 +1,26 @@
116 +GPIO controlled RFKILL devices
117 +
118 +Required properties:
119 +- compatible : Must be "rfkill-gpio".
120 +- rfkill-name : Name of RFKILL device
121 +- rfkill-type : Type of RFKILL device: 1 for WiFi, 2 for BlueTooth
122 +- NAME_shutdown-gpios : GPIO phandle to shutdown control
123 + (phandle must be the second)
124 +- NAME_reset-gpios : GPIO phandle to reset control
125 +
126 +NAME must match the rfkill-name property. NAME_shutdown-gpios or
127 +NAME_reset-gpios, or both, must be defined.
128 +
129 +Optional properties:
130 +- clocks : phandle to clock to enable/disable
131 +
132 +Example:
133 +
134 + rfkill_bt: rfkill@0 {
135 + compatible = "rfkill-gpio";
136 + rfkill-name = "bluetooth";
137 + rfkill-type = <2>;
138 + bluetooth_shutdown-gpios = <0>, <&pio 7 18 0>;
139 + bluetooth_reset-gpios = <&pio 7 24 0>;
140 + clocks = <&clk_out_a>;
141 + };
142 diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
143 index 3084fa3..48381a8 100644
144 --- a/net/rfkill/rfkill-gpio.c
145 +++ b/net/rfkill/rfkill-gpio.c
146 @@ -26,6 +26,7 @@
147 #include <linux/slab.h>
148 #include <linux/acpi.h>
149 #include <linux/gpio/consumer.h>
150 +#include <linux/of_gpio.h>
151
152 #include <linux/rfkill-gpio.h>
153
154 @@ -83,6 +84,18 @@ static int rfkill_gpio_acpi_probe(struct device *dev,
155 return 0;
156 }
157
158 +static int rfkill_gpio_dt_probe(struct device *dev,
159 + struct rfkill_gpio_data *rfkill)
160 +{
161 + struct device_node * np = dev->of_node;
162 +
163 + rfkill->name = np->name;
164 + of_property_read_string(np, "rfkill-name", &rfkill->name);
165 + of_property_read_u32(np, "rfkill-type", &rfkill->type);
166 +
167 + return 0;
168 +}
169 +
170 static int rfkill_gpio_probe(struct platform_device *pdev)
171 {
172 struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
173 @@ -100,6 +113,10 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
174 ret = rfkill_gpio_acpi_probe(&pdev->dev, rfkill);
175 if (ret)
176 return ret;
177 + } else if (&pdev->dev.of_node) {
178 + ret = rfkill_gpio_dt_probe(&pdev->dev, rfkill);
179 + if (ret)
180 + return ret;
181 } else if (pdata) {
182 clk_name = pdata->power_clk_name;
183 rfkill->name = pdata->name;
184 @@ -189,6 +206,11 @@ static const struct acpi_device_id rfkill_acpi_match[] = {
185 { },
186 };
187
188 +static const struct of_device_id rfkill_of_match[] = {
189 + { .compatible = "rfkill-gpio", },
190 + {},
191 +};
192 +
193 static struct platform_driver rfkill_gpio_driver = {
194 .probe = rfkill_gpio_probe,
195 .remove = rfkill_gpio_remove,
196 @@ -196,6 +218,7 @@ static struct platform_driver rfkill_gpio_driver = {
197 .name = "rfkill_gpio",
198 .owner = THIS_MODULE,
199 .acpi_match_table = ACPI_PTR(rfkill_acpi_match),
200 + .of_match_table = of_match_ptr(rfkill_of_match),
201 },
202 };
203
204 --
205 2.0.3
206
207 From 83c43937ee8c5fcb38241a8e89c2b93e5b0f9526 Mon Sep 17 00:00:00 2001
208 From: Chen-Yu Tsai <wens@csie.org>
209 Date: Fri, 17 Jan 2014 14:47:30 +0800
210 Subject: [PATCH] net: rfkill: gpio: add clock-frequency device tree property
211
212 Some devices, such as Broadcom Bluetooth devices, require a specific
213 clock rate for the clock tied to the rfkill device. Add clock-frequency
214 property so we can specify this from the device tree.
215
216 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
217 ---
218 Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt | 2 ++
219 net/rfkill/rfkill-gpio.c | 4 ++++
220 2 files changed, 6 insertions(+)
221
222 diff --git a/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt b/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt
223 index 8a07ea4..8b8db0a 100644
224 --- a/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt
225 +++ b/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt
226 @@ -13,6 +13,7 @@ NAME_reset-gpios, or both, must be defined.
227
228 Optional properties:
229 - clocks : phandle to clock to enable/disable
230 +- clock-frequency : clock rate to set for the given clock
231
232 Example:
233
234 @@ -23,4 +24,5 @@ Example:
235 bluetooth_shutdown-gpios = <0>, <&pio 7 18 0>;
236 bluetooth_reset-gpios = <&pio 7 24 0>;
237 clocks = <&clk_out_a>;
238 + clock-frequency = <32678>;
239 };
240 diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
241 index 48381a8..3092681 100644
242 --- a/net/rfkill/rfkill-gpio.c
243 +++ b/net/rfkill/rfkill-gpio.c
244 @@ -40,6 +40,7 @@ struct rfkill_gpio_data {
245 char *reset_name;
246 char *shutdown_name;
247 struct clk *clk;
248 + int clk_frequency;
249
250 bool clk_enabled;
251 };
252 @@ -92,6 +93,7 @@ static int rfkill_gpio_dt_probe(struct device *dev,
253 rfkill->name = np->name;
254 of_property_read_string(np, "rfkill-name", &rfkill->name);
255 of_property_read_u32(np, "rfkill-type", &rfkill->type);
256 + of_property_read_u32(np, "clock-frequency", &rfkill->clk_frequency);
257
258 return 0;
259 }
260 @@ -138,6 +140,8 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
261 snprintf(rfkill->shutdown_name, len + 10, "%s_shutdown", rfkill->name);
262
263 rfkill->clk = devm_clk_get(&pdev->dev, clk_name);
264 + if (!IS_ERR(rfkill->clk) && rfkill->clk_frequency > 0)
265 + clk_set_rate(rfkill->clk, rfkill->clk_frequency);
266
267 gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
268 if (!IS_ERR(gpio)) {
269 --
270 2.0.3
271