Commit | Line | Data |
---|---|---|
9d68d1ee LC |
1 | /* |
2 | * This file is part of wl12xx | |
3 | * | |
4 | * Copyright (C) 2009-2010 Nokia Corporation | |
5 | * Copyright (C) 2011 Texas Instruments Inc. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License | |
9 | * version 2 as published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
19 | * 02110-1301 USA | |
20 | * | |
21 | */ | |
22 | ||
23 | #include "../wlcore/cmd.h" | |
24 | #include "../wlcore/debug.h" | |
25 | ||
166b2136 | 26 | #include "wl12xx.h" |
9d68d1ee LC |
27 | #include "cmd.h" |
28 | ||
29 | int wl1271_cmd_ext_radio_parms(struct wl1271 *wl) | |
30 | { | |
31 | struct wl1271_ext_radio_parms_cmd *ext_radio_parms; | |
166b2136 LC |
32 | struct wl12xx_priv *priv = wl->priv; |
33 | struct wl12xx_conf_rf *rf = &priv->conf.rf; | |
9d68d1ee LC |
34 | int ret; |
35 | ||
36 | if (!wl->nvs) | |
37 | return -ENODEV; | |
38 | ||
39 | ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL); | |
40 | if (!ext_radio_parms) | |
41 | return -ENOMEM; | |
42 | ||
43 | ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM; | |
44 | ||
45 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_2, | |
46 | rf->tx_per_channel_power_compensation_2, | |
47 | CONF_TX_PWR_COMPENSATION_LEN_2); | |
48 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_5, | |
49 | rf->tx_per_channel_power_compensation_5, | |
50 | CONF_TX_PWR_COMPENSATION_LEN_5); | |
51 | ||
52 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ", | |
53 | ext_radio_parms, sizeof(*ext_radio_parms)); | |
54 | ||
55 | ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0); | |
56 | if (ret < 0) | |
57 | wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed"); | |
58 | ||
59 | kfree(ext_radio_parms); | |
60 | return ret; | |
61 | } | |
62 | ||
63 | int wl1271_cmd_general_parms(struct wl1271 *wl) | |
64 | { | |
65 | struct wl1271_general_parms_cmd *gen_parms; | |
66 | struct wl1271_ini_general_params *gp = | |
67 | &((struct wl1271_nvs_file *)wl->nvs)->general_params; | |
a5d751bb | 68 | struct wl12xx_priv *priv = wl->priv; |
9d68d1ee LC |
69 | bool answer = false; |
70 | int ret; | |
71 | ||
72 | if (!wl->nvs) | |
73 | return -ENODEV; | |
74 | ||
75 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { | |
76 | wl1271_warning("FEM index from INI out of bounds"); | |
77 | return -EINVAL; | |
78 | } | |
79 | ||
80 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); | |
81 | if (!gen_parms) | |
82 | return -ENOMEM; | |
83 | ||
84 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; | |
85 | ||
86 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); | |
87 | ||
88 | if (gp->tx_bip_fem_auto_detect) | |
89 | answer = true; | |
90 | ||
91 | /* Override the REF CLK from the NVS with the one from platform data */ | |
a5d751bb | 92 | gen_parms->general_params.ref_clock = priv->ref_clock; |
9d68d1ee LC |
93 | |
94 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); | |
95 | if (ret < 0) { | |
96 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); | |
97 | goto out; | |
98 | } | |
99 | ||
100 | gp->tx_bip_fem_manufacturer = | |
101 | gen_parms->general_params.tx_bip_fem_manufacturer; | |
102 | ||
103 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { | |
104 | wl1271_warning("FEM index from FW out of bounds"); | |
105 | ret = -EINVAL; | |
106 | goto out; | |
107 | } | |
108 | ||
109 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", | |
110 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); | |
111 | ||
112 | out: | |
113 | kfree(gen_parms); | |
114 | return ret; | |
115 | } | |
116 | ||
117 | int wl128x_cmd_general_parms(struct wl1271 *wl) | |
118 | { | |
119 | struct wl128x_general_parms_cmd *gen_parms; | |
120 | struct wl128x_ini_general_params *gp = | |
121 | &((struct wl128x_nvs_file *)wl->nvs)->general_params; | |
a5d751bb | 122 | struct wl12xx_priv *priv = wl->priv; |
9d68d1ee LC |
123 | bool answer = false; |
124 | int ret; | |
125 | ||
126 | if (!wl->nvs) | |
127 | return -ENODEV; | |
128 | ||
129 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { | |
130 | wl1271_warning("FEM index from ini out of bounds"); | |
131 | return -EINVAL; | |
132 | } | |
133 | ||
134 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); | |
135 | if (!gen_parms) | |
136 | return -ENOMEM; | |
137 | ||
138 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; | |
139 | ||
140 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); | |
141 | ||
142 | if (gp->tx_bip_fem_auto_detect) | |
143 | answer = true; | |
144 | ||
145 | /* Replace REF and TCXO CLKs with the ones from platform data */ | |
a5d751bb LC |
146 | gen_parms->general_params.ref_clock = priv->ref_clock; |
147 | gen_parms->general_params.tcxo_ref_clock = priv->tcxo_clock; | |
9d68d1ee LC |
148 | |
149 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); | |
150 | if (ret < 0) { | |
151 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); | |
152 | goto out; | |
153 | } | |
154 | ||
155 | gp->tx_bip_fem_manufacturer = | |
156 | gen_parms->general_params.tx_bip_fem_manufacturer; | |
157 | ||
158 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { | |
159 | wl1271_warning("FEM index from FW out of bounds"); | |
160 | ret = -EINVAL; | |
161 | goto out; | |
162 | } | |
163 | ||
164 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", | |
165 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); | |
166 | ||
167 | out: | |
168 | kfree(gen_parms); | |
169 | return ret; | |
170 | } | |
171 | ||
172 | int wl1271_cmd_radio_parms(struct wl1271 *wl) | |
173 | { | |
174 | struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs; | |
175 | struct wl1271_radio_parms_cmd *radio_parms; | |
176 | struct wl1271_ini_general_params *gp = &nvs->general_params; | |
177 | int ret; | |
178 | ||
179 | if (!wl->nvs) | |
180 | return -ENODEV; | |
181 | ||
182 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); | |
183 | if (!radio_parms) | |
184 | return -ENOMEM; | |
185 | ||
186 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; | |
187 | ||
188 | /* 2.4GHz parameters */ | |
189 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, | |
190 | sizeof(struct wl1271_ini_band_params_2)); | |
191 | memcpy(&radio_parms->dyn_params_2, | |
192 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, | |
193 | sizeof(struct wl1271_ini_fem_params_2)); | |
194 | ||
195 | /* 5GHz parameters */ | |
196 | memcpy(&radio_parms->static_params_5, | |
197 | &nvs->stat_radio_params_5, | |
198 | sizeof(struct wl1271_ini_band_params_5)); | |
199 | memcpy(&radio_parms->dyn_params_5, | |
200 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, | |
201 | sizeof(struct wl1271_ini_fem_params_5)); | |
202 | ||
203 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", | |
204 | radio_parms, sizeof(*radio_parms)); | |
205 | ||
206 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); | |
207 | if (ret < 0) | |
208 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); | |
209 | ||
210 | kfree(radio_parms); | |
211 | return ret; | |
212 | } | |
213 | ||
214 | int wl128x_cmd_radio_parms(struct wl1271 *wl) | |
215 | { | |
216 | struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs; | |
217 | struct wl128x_radio_parms_cmd *radio_parms; | |
218 | struct wl128x_ini_general_params *gp = &nvs->general_params; | |
219 | int ret; | |
220 | ||
221 | if (!wl->nvs) | |
222 | return -ENODEV; | |
223 | ||
224 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); | |
225 | if (!radio_parms) | |
226 | return -ENOMEM; | |
227 | ||
228 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; | |
229 | ||
230 | /* 2.4GHz parameters */ | |
231 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, | |
232 | sizeof(struct wl128x_ini_band_params_2)); | |
233 | memcpy(&radio_parms->dyn_params_2, | |
234 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, | |
235 | sizeof(struct wl128x_ini_fem_params_2)); | |
236 | ||
237 | /* 5GHz parameters */ | |
238 | memcpy(&radio_parms->static_params_5, | |
239 | &nvs->stat_radio_params_5, | |
240 | sizeof(struct wl128x_ini_band_params_5)); | |
241 | memcpy(&radio_parms->dyn_params_5, | |
242 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, | |
243 | sizeof(struct wl128x_ini_fem_params_5)); | |
244 | ||
245 | radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options; | |
246 | ||
247 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", | |
248 | radio_parms, sizeof(*radio_parms)); | |
249 | ||
250 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); | |
251 | if (ret < 0) | |
252 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); | |
253 | ||
254 | kfree(radio_parms); | |
255 | return ret; | |
256 | } |