d5e107875e033c8479efaa89d100c1529d1e7f66
[openwrt/staging/lynxis/omap.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 --- a/net/rfkill/rfkill-gpio.c
16 +++ b/net/rfkill/rfkill-gpio.c
17 @@ -26,6 +26,7 @@
18 #include <linux/slab.h>
19 #include <linux/acpi.h>
20 #include <linux/gpio/consumer.h>
21 +#include <linux/of_gpio.h>
22
23 #include <linux/rfkill-gpio.h>
24
25 @@ -39,6 +40,7 @@ struct rfkill_gpio_data {
26 char *reset_name;
27 char *shutdown_name;
28 struct clk *clk;
29 + int clk_frequency;
30
31 bool clk_enabled;
32 };
33 @@ -51,15 +53,15 @@ static int rfkill_gpio_set_power(void *d
34 gpiod_set_value(rfkill->shutdown_gpio, 0);
35 gpiod_set_value(rfkill->reset_gpio, 0);
36 if (!IS_ERR(rfkill->clk) && rfkill->clk_enabled)
37 - clk_disable(rfkill->clk);
38 + clk_disable_unprepare(rfkill->clk);
39 } else {
40 if (!IS_ERR(rfkill->clk) && !rfkill->clk_enabled)
41 - clk_enable(rfkill->clk);
42 + clk_prepare_enable(rfkill->clk);
43 gpiod_set_value(rfkill->reset_gpio, 1);
44 gpiod_set_value(rfkill->shutdown_gpio, 1);
45 }
46
47 - rfkill->clk_enabled = blocked;
48 + rfkill->clk_enabled = !blocked;
49
50 return 0;
51 }
52 @@ -83,6 +85,19 @@ static int rfkill_gpio_acpi_probe(struct
53 return 0;
54 }
55
56 +static int rfkill_gpio_dt_probe(struct device *dev,
57 + struct rfkill_gpio_data *rfkill)
58 +{
59 + struct device_node * np = dev->of_node;
60 +
61 + rfkill->name = np->name;
62 + of_property_read_string(np, "rfkill-name", &rfkill->name);
63 + of_property_read_u32(np, "rfkill-type", &rfkill->type);
64 + of_property_read_u32(np, "clock-frequency", &rfkill->clk_frequency);
65 +
66 + return 0;
67 +}
68 +
69 static int rfkill_gpio_probe(struct platform_device *pdev)
70 {
71 struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
72 @@ -100,6 +115,10 @@ static int rfkill_gpio_probe(struct plat
73 ret = rfkill_gpio_acpi_probe(&pdev->dev, rfkill);
74 if (ret)
75 return ret;
76 + } else if (&pdev->dev.of_node) {
77 + ret = rfkill_gpio_dt_probe(&pdev->dev, rfkill);
78 + if (ret)
79 + return ret;
80 } else if (pdata) {
81 clk_name = pdata->power_clk_name;
82 rfkill->name = pdata->name;
83 @@ -117,10 +136,12 @@ static int rfkill_gpio_probe(struct plat
84 if (!rfkill->shutdown_name)
85 return -ENOMEM;
86
87 - snprintf(rfkill->reset_name, len + 6 , "%s_reset", rfkill->name);
88 - snprintf(rfkill->shutdown_name, len + 9, "%s_shutdown", rfkill->name);
89 + snprintf(rfkill->reset_name, len + 7 , "%s_reset", rfkill->name);
90 + snprintf(rfkill->shutdown_name, len + 10, "%s_shutdown", rfkill->name);
91
92 rfkill->clk = devm_clk_get(&pdev->dev, clk_name);
93 + if (!IS_ERR(rfkill->clk) && rfkill->clk_frequency > 0)
94 + clk_set_rate(rfkill->clk, rfkill->clk_frequency);
95
96 gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
97 if (!IS_ERR(gpio)) {
98 @@ -189,6 +210,11 @@ static const struct acpi_device_id rfkil
99 { },
100 };
101
102 +static const struct of_device_id rfkill_of_match[] = {
103 + { .compatible = "rfkill-gpio", },
104 + {},
105 +};
106 +
107 static struct platform_driver rfkill_gpio_driver = {
108 .probe = rfkill_gpio_probe,
109 .remove = rfkill_gpio_remove,
110 @@ -196,6 +222,7 @@ static struct platform_driver rfkill_gpi
111 .name = "rfkill_gpio",
112 .owner = THIS_MODULE,
113 .acpi_match_table = ACPI_PTR(rfkill_acpi_match),
114 + .of_match_table = of_match_ptr(rfkill_of_match),
115 },
116 };
117
118 --- /dev/null
119 +++ b/Documentation/devicetree/bindings/rfkill/rfkill-gpio.txt
120 @@ -0,0 +1,28 @@
121 +GPIO controlled RFKILL devices
122 +
123 +Required properties:
124 +- compatible : Must be "rfkill-gpio".
125 +- rfkill-name : Name of RFKILL device
126 +- rfkill-type : Type of RFKILL device: 1 for WiFi, 2 for BlueTooth
127 +- NAME_shutdown-gpios : GPIO phandle to shutdown control
128 + (phandle must be the second)
129 +- NAME_reset-gpios : GPIO phandle to reset control
130 +
131 +NAME must match the rfkill-name property. NAME_shutdown-gpios or
132 +NAME_reset-gpios, or both, must be defined.
133 +
134 +Optional properties:
135 +- clocks : phandle to clock to enable/disable
136 +- clock-frequency : clock rate to set for the given clock
137 +
138 +Example:
139 +
140 + rfkill_bt: rfkill@0 {
141 + compatible = "rfkill-gpio";
142 + rfkill-name = "bluetooth";
143 + rfkill-type = <2>;
144 + bluetooth_shutdown-gpios = <0>, <&pio 7 18 0>;
145 + bluetooth_reset-gpios = <&pio 7 24 0>;
146 + clocks = <&clk_out_a>;
147 + clock-frequency = <32678>;
148 + };