4b5149cec756369bd1acc132d2f133a213a2e176
[openwrt.git] / target / linux / omap / patches-3.12 / 903-wl12xx-use-frequency-instead-of-enumerations-for-pdata-clocks.patch
1 Instead of defining an enumeration with the FW specific values for the
2 different clock rates, use the actual frequency instead.  Also add a
3 boolean to specify whether the clock is XTAL or not.
4
5 Change all board files to reflect this.
6
7 Additionally, this reverts commit 26f45c (ARM: OMAP2+: Legacy support
8 for wl12xx when booted with devicetree), since this is not be needed
9 anymore, now that DT support for WiLink is implemented.
10
11 Cc: Tony Lindgren <tony@atomide.com>
12 Cc: Sekhar Nori <nsekhar@ti.com>
13 Signed-off-by: Luciano Coelho <coelho@ti.com>
14 Reviewed-by: Felipe Balbi <balbi@ti.com>
15
16 ---
17  arch/arm/mach-davinci/board-da850-evm.c      |  3 +-
18  arch/arm/mach-omap2/board-omap3evm.c         |  3 +-
19  arch/arm/mach-omap2/board-zoom-peripherals.c |  3 +-
20  arch/arm/mach-omap2/devices.c                | 39 -------------------
21  drivers/net/wireless/ti/wl12xx/main.c        | 58 +++++++++++++++++++++++++++-
22  drivers/net/wireless/ti/wl12xx/wl12xx.h      | 28 ++++++++++++++
23  include/linux/wl12xx.h                       | 27 ++-----------
24  7 files changed, 93 insertions(+), 68 deletions(-)
25
26 --- a/arch/arm/mach-davinci/board-da850-evm.c
27 +++ b/arch/arm/mach-davinci/board-da850-evm.c
28 @@ -1370,7 +1370,8 @@ static const short da850_wl12xx_pins[] _
29  
30  static struct wl12xx_platform_data da850_wl12xx_wlan_data __initdata = {
31         .irq                    = -1,
32 -       .board_ref_clock        = WL12XX_REFCLOCK_38,
33 +       .ref_clock_freq         = 38400000,
34 +       .ref_clock_xtal         = false,
35  };
36  
37  static __init int da850_wl12xx_init(void)
38 --- a/arch/arm/mach-omap2/board-omap3evm.c
39 +++ b/arch/arm/mach-omap2/board-omap3evm.c
40 @@ -473,7 +473,8 @@ static struct platform_device omap3evm_w
41  };
42  
43  struct wl12xx_platform_data omap3evm_wlan_data __initdata = {
44 -       .board_ref_clock = WL12XX_REFCLOCK_38, /* 38.4 MHz */
45 +       .ref_clock_freq = 38400000,
46 +       .ref_clock_xtal = false,
47  };
48  #endif
49  
50 --- a/arch/arm/mach-omap2/board-zoom-peripherals.c
51 +++ b/arch/arm/mach-omap2/board-zoom-peripherals.c
52 @@ -244,7 +244,8 @@ static struct platform_device *zoom_devi
53  };
54  
55  static struct wl12xx_platform_data omap_zoom_wlan_data __initdata = {
56 -       .board_ref_clock = WL12XX_REFCLOCK_26, /* 26 MHz */
57 +       .ref_clock_freq = 26000000,
58 +       .ref_clock_xtal = false,
59  };
60  
61  static struct omap2_hsmmc_info mmc[] = {
62 --- a/arch/arm/mach-omap2/devices.c
63 +++ b/arch/arm/mach-omap2/devices.c
64 @@ -8,7 +8,6 @@
65   * the Free Software Foundation; either version 2 of the License, or
66   * (at your option) any later version.
67   */
68 -#include <linux/gpio.h>
69  #include <linux/kernel.h>
70  #include <linux/init.h>
71  #include <linux/platform_device.h>
72 @@ -19,7 +18,6 @@
73  #include <linux/of.h>
74  #include <linux/pinctrl/machine.h>
75  #include <linux/platform_data/omap4-keypad.h>
76 -#include <linux/wl12xx.h>
77  #include <linux/platform_data/mailbox-omap.h>
78  
79  #include <asm/mach-types.h>
80 @@ -475,40 +473,6 @@ static void omap_init_vout(void)
81  static inline void omap_init_vout(void) {}
82  #endif
83  
84 -#if IS_ENABLED(CONFIG_WL12XX)
85 -
86 -static struct wl12xx_platform_data wl12xx __initdata;
87 -
88 -void __init omap_init_wl12xx_of(void)
89 -{
90 -       int ret;
91 -
92 -       if (!of_have_populated_dt())
93 -               return;
94 -
95 -       if (of_machine_is_compatible("ti,omap4-sdp")) {
96 -               wl12xx.board_ref_clock = WL12XX_REFCLOCK_26;
97 -               wl12xx.board_tcxo_clock = WL12XX_TCXOCLOCK_26;
98 -               wl12xx.irq = gpio_to_irq(53);
99 -       } else if (of_machine_is_compatible("ti,omap4-panda")) {
100 -               wl12xx.board_ref_clock = WL12XX_REFCLOCK_38;
101 -               wl12xx.irq = gpio_to_irq(53);
102 -       } else {
103 -               return;
104 -       }
105 -
106 -       ret = wl12xx_set_platform_data(&wl12xx);
107 -       if (ret) {
108 -               pr_err("error setting wl12xx data: %d\n", ret);
109 -               return;
110 -       }
111 -}
112 -#else
113 -static inline void omap_init_wl12xx_of(void)
114 -{
115 -}
116 -#endif
117 -
118  /*-------------------------------------------------------------------------*/
119  
120  static int __init omap2_init_devices(void)
121 @@ -531,9 +495,6 @@ static int __init omap2_init_devices(voi
122                 omap_init_sham();
123                 omap_init_aes();
124                 omap_init_rng();
125 -       } else {
126 -               /* These can be removed when bindings are done */
127 -               omap_init_wl12xx_of();
128         }
129         omap_init_sti();
130         omap_init_vout();
131 --- a/drivers/net/wireless/ti/wl12xx/main.c
132 +++ b/drivers/net/wireless/ti/wl12xx/main.c
133 @@ -1701,6 +1701,43 @@ static struct ieee80211_sta_ht_cap wl12x
134                 },
135  };
136  
137 +static const struct wl12xx_clock wl12xx_refclock_table[] = {
138 +       { 19200000,     false,  WL12XX_REFCLOCK_19      },
139 +       { 26000000,     false,  WL12XX_REFCLOCK_26      },
140 +       { 26000000,     true,   WL12XX_REFCLOCK_26_XTAL },
141 +       { 38400000,     false,  WL12XX_REFCLOCK_38      },
142 +       { 38400000,     true,   WL12XX_REFCLOCK_38_XTAL },
143 +       { 52000000,     false,  WL12XX_REFCLOCK_52      },
144 +       { 0,            false,  0 }
145 +};
146 +
147 +static const struct wl12xx_clock wl12xx_tcxoclock_table[] = {
148 +       { 16368000,     true,   WL12XX_TCXOCLOCK_16_368 },
149 +       { 16800000,     true,   WL12XX_TCXOCLOCK_16_8   },
150 +       { 19200000,     true,   WL12XX_TCXOCLOCK_19_2   },
151 +       { 26000000,     true,   WL12XX_TCXOCLOCK_26     },
152 +       { 32736000,     true,   WL12XX_TCXOCLOCK_32_736 },
153 +       { 33600000,     true,   WL12XX_TCXOCLOCK_33_6   },
154 +       { 38400000,     true,   WL12XX_TCXOCLOCK_38_4   },
155 +       { 52000000,     true,   WL12XX_TCXOCLOCK_52     },
156 +       { 0,            false,  0 }
157 +};
158 +
159 +static int wl12xx_get_clock_idx(const struct wl12xx_clock *table,
160 +                               u32 freq, bool xtal)
161 +{
162 +       int i = 0;
163 +
164 +       while(table[i].freq != 0) {
165 +               if ((table[i].freq == freq) &&
166 +                   (table[i].xtal == xtal))
167 +                       return table[i].hw_idx;
168 +               i++;
169 +       };
170 +
171 +       return -EINVAL;
172 +}
173 +
174  static int wl12xx_setup(struct wl1271 *wl)
175  {
176         struct wl12xx_priv *priv = wl->priv;
177 @@ -1722,7 +1759,16 @@ static int wl12xx_setup(struct wl1271 *w
178         wl12xx_conf_init(wl);
179  
180         if (!fref_param) {
181 -               priv->ref_clock = pdata->board_ref_clock;
182 +               priv->ref_clock = wl12xx_get_clock_idx(wl12xx_refclock_table,
183 +                                                      pdata->ref_clock_freq,
184 +                                                      pdata->ref_clock_xtal);
185 +               if (priv->ref_clock < 0) {
186 +                       wl1271_error("Invalid ref_clock frequency (%d Hz, %s)",
187 +                               pdata->ref_clock_freq,
188 +                               pdata->ref_clock_xtal ? "XTAL" : "not XTAL");
189 +
190 +                       return priv->ref_clock;
191 +               }
192         } else {
193                 if (!strcmp(fref_param, "19.2"))
194                         priv->ref_clock = WL12XX_REFCLOCK_19;
195 @@ -1741,7 +1787,15 @@ static int wl12xx_setup(struct wl1271 *w
196         }
197  
198         if (!tcxo_param) {
199 -               priv->tcxo_clock = pdata->board_tcxo_clock;
200 +               priv->tcxo_clock = wl12xx_get_clock_idx(wl12xx_tcxoclock_table,
201 +                                                       pdata->tcxo_clock_freq,
202 +                                                       true);
203 +               if (priv->tcxo_clock < 0) {
204 +                       wl1271_error("Invalid tcxo_clock frequency (%d Hz)",
205 +                               pdata->tcxo_clock_freq);
206 +
207 +                       return priv->tcxo_clock;
208 +               }
209         } else {
210                 if (!strcmp(tcxo_param, "19.2"))
211                         priv->tcxo_clock = WL12XX_TCXOCLOCK_19_2;
212 --- a/drivers/net/wireless/ti/wl12xx/wl12xx.h
213 +++ b/drivers/net/wireless/ti/wl12xx/wl12xx.h
214 @@ -79,4 +79,32 @@ struct wl12xx_priv {
215         struct wl127x_rx_mem_pool_addr *rx_mem_addr;
216  };
217  
218 +/* Reference clock values */
219 +enum {
220 +       WL12XX_REFCLOCK_19      = 0, /* 19.2 MHz */
221 +       WL12XX_REFCLOCK_26      = 1, /* 26 MHz */
222 +       WL12XX_REFCLOCK_38      = 2, /* 38.4 MHz */
223 +       WL12XX_REFCLOCK_52      = 3, /* 52 MHz */
224 +       WL12XX_REFCLOCK_38_XTAL = 4, /* 38.4 MHz, XTAL */
225 +       WL12XX_REFCLOCK_26_XTAL = 5, /* 26 MHz, XTAL */
226 +};
227 +
228 +/* TCXO clock values */
229 +enum {
230 +       WL12XX_TCXOCLOCK_19_2   = 0, /* 19.2MHz */
231 +       WL12XX_TCXOCLOCK_26     = 1, /* 26 MHz */
232 +       WL12XX_TCXOCLOCK_38_4   = 2, /* 38.4MHz */
233 +       WL12XX_TCXOCLOCK_52     = 3, /* 52 MHz */
234 +       WL12XX_TCXOCLOCK_16_368 = 4, /* 16.368 MHz */
235 +       WL12XX_TCXOCLOCK_32_736 = 5, /* 32.736 MHz */
236 +       WL12XX_TCXOCLOCK_16_8   = 6, /* 16.8 MHz */
237 +       WL12XX_TCXOCLOCK_33_6   = 7, /* 33.6 MHz */
238 +};
239 +
240 +struct wl12xx_clock {
241 +       u32     freq;
242 +       bool    xtal;
243 +       u8      hw_idx;
244 +};
245 +
246  #endif /* __WL12XX_PRIV_H__ */
247 --- a/include/linux/wl12xx.h
248 +++ b/include/linux/wl12xx.h
249 @@ -26,28 +26,6 @@
250  
251  #include <linux/err.h>
252  
253 -/* Reference clock values */
254 -enum {
255 -       WL12XX_REFCLOCK_19      = 0, /* 19.2 MHz */
256 -       WL12XX_REFCLOCK_26      = 1, /* 26 MHz */
257 -       WL12XX_REFCLOCK_38      = 2, /* 38.4 MHz */
258 -       WL12XX_REFCLOCK_52      = 3, /* 52 MHz */
259 -       WL12XX_REFCLOCK_38_XTAL = 4, /* 38.4 MHz, XTAL */
260 -       WL12XX_REFCLOCK_26_XTAL = 5, /* 26 MHz, XTAL */
261 -};
262 -
263 -/* TCXO clock values */
264 -enum {
265 -       WL12XX_TCXOCLOCK_19_2   = 0, /* 19.2MHz */
266 -       WL12XX_TCXOCLOCK_26     = 1, /* 26 MHz */
267 -       WL12XX_TCXOCLOCK_38_4   = 2, /* 38.4MHz */
268 -       WL12XX_TCXOCLOCK_52     = 3, /* 52 MHz */
269 -       WL12XX_TCXOCLOCK_16_368 = 4, /* 16.368 MHz */
270 -       WL12XX_TCXOCLOCK_32_736 = 5, /* 32.736 MHz */
271 -       WL12XX_TCXOCLOCK_16_8   = 6, /* 16.8 MHz */
272 -       WL12XX_TCXOCLOCK_33_6   = 7, /* 33.6 MHz */
273 -};
274 -
275  struct wl1251_platform_data {
276         void (*set_power)(bool enable);
277         /* SDIO only: IRQ number if WLAN_IRQ line is used, 0 for SDIO IRQs */
278 @@ -57,8 +35,9 @@ struct wl1251_platform_data {
279  
280  struct wl12xx_platform_data {
281         int irq;
282 -       int board_ref_clock;
283 -       int board_tcxo_clock;
284 +       int ref_clock_freq;     /* in Hertz */
285 +       bool ref_clock_xtal;    /* specify whether the clock is XTAL or not */
286 +       int tcxo_clock_freq;    /* in Hertz, tcxo is always XTAL */
287  };
288  
289  #ifdef CONFIG_WILINK_PLATFORM_DATA