diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2015-07-23 08:08:46 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-08-03 20:24:16 -0400 |
commit | b39910c2e0ac7c3d0e2f1999b04308c771b1d8fc (patch) | |
tree | 0b37ee4ee123a0f7d223750be079d5c87e3efde8 | |
parent | dd070a1694c563bd7ba5239dd3038ff1420cf856 (diff) |
mei: bus: simplify how we build nfc bus name
Remove the dependency on struct ndev from the nfc device
name creation function so it is possible to use it
in a fixup routine
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/misc/mei/bus-fixup.c | 115 | ||||
-rw-r--r-- | drivers/misc/mei/bus.c | 2 | ||||
-rw-r--r-- | drivers/misc/mei/mei_dev.h | 2 |
3 files changed, 55 insertions, 64 deletions
diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c index fd6470f42671..a4c6719d36b4 100644 --- a/drivers/misc/mei/bus-fixup.c +++ b/drivers/misc/mei/bus-fixup.c | |||
@@ -145,7 +145,7 @@ struct mei_nfc_dev { | |||
145 | u8 fw_ivn; | 145 | u8 fw_ivn; |
146 | u8 vendor_id; | 146 | u8 vendor_id; |
147 | u8 radio_type; | 147 | u8 radio_type; |
148 | char *bus_name; | 148 | const char *bus_name; |
149 | }; | 149 | }; |
150 | 150 | ||
151 | /* UUIDs for NFC F/W clients */ | 151 | /* UUIDs for NFC F/W clients */ |
@@ -184,69 +184,30 @@ static void mei_nfc_free(struct mei_nfc_dev *ndev) | |||
184 | kfree(ndev); | 184 | kfree(ndev); |
185 | } | 185 | } |
186 | 186 | ||
187 | static int mei_nfc_build_bus_name(struct mei_nfc_dev *ndev) | 187 | /** |
188 | { | 188 | * mei_nfc_if_version - get NFC interface version |
189 | struct mei_device *bus; | 189 | * |
190 | 190 | * @cl: host client (nfc info) | |
191 | if (!ndev->cl) | 191 | * @ver: NFC interface version to be filled in |
192 | return -ENODEV; | 192 | * |
193 | 193 | * Return: 0 on success; < 0 otherwise | |
194 | bus = ndev->cl->dev; | 194 | */ |
195 | 195 | static int mei_nfc_if_version(struct mei_cl *cl, | |
196 | switch (ndev->vendor_id) { | 196 | struct mei_nfc_if_version *ver) |
197 | case MEI_NFC_VENDOR_INSIDE: | ||
198 | switch (ndev->radio_type) { | ||
199 | case MEI_NFC_VENDOR_INSIDE_UREAD: | ||
200 | ndev->bus_name = "microread"; | ||
201 | return 0; | ||
202 | |||
203 | default: | ||
204 | dev_err(bus->dev, "Unknown radio type 0x%x\n", | ||
205 | ndev->radio_type); | ||
206 | |||
207 | return -EINVAL; | ||
208 | } | ||
209 | |||
210 | case MEI_NFC_VENDOR_NXP: | ||
211 | switch (ndev->radio_type) { | ||
212 | case MEI_NFC_VENDOR_NXP_PN544: | ||
213 | ndev->bus_name = "pn544"; | ||
214 | return 0; | ||
215 | default: | ||
216 | dev_err(bus->dev, "Unknown radio type 0x%x\n", | ||
217 | ndev->radio_type); | ||
218 | |||
219 | return -EINVAL; | ||
220 | } | ||
221 | |||
222 | default: | ||
223 | dev_err(bus->dev, "Unknown vendor ID 0x%x\n", | ||
224 | ndev->vendor_id); | ||
225 | |||
226 | return -EINVAL; | ||
227 | } | ||
228 | |||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static int mei_nfc_if_version(struct mei_nfc_dev *ndev) | ||
233 | { | 197 | { |
234 | struct mei_device *bus; | 198 | struct mei_device *bus; |
235 | struct mei_cl *cl; | 199 | struct mei_nfc_cmd cmd = { |
236 | 200 | .command = MEI_NFC_CMD_MAINTENANCE, | |
237 | struct mei_nfc_cmd cmd; | 201 | .data_size = 1, |
202 | .sub_command = MEI_NFC_SUBCMD_IF_VERSION, | ||
203 | }; | ||
238 | struct mei_nfc_reply *reply = NULL; | 204 | struct mei_nfc_reply *reply = NULL; |
239 | struct mei_nfc_if_version *version; | ||
240 | size_t if_version_length; | 205 | size_t if_version_length; |
241 | int bytes_recv, ret; | 206 | int bytes_recv, ret; |
242 | 207 | ||
243 | cl = ndev->cl_info; | ||
244 | bus = cl->dev; | 208 | bus = cl->dev; |
245 | 209 | ||
246 | memset(&cmd, 0, sizeof(struct mei_nfc_cmd)); | 210 | WARN_ON(mutex_is_locked(&bus->device_lock)); |
247 | cmd.command = MEI_NFC_CMD_MAINTENANCE; | ||
248 | cmd.data_size = 1; | ||
249 | cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION; | ||
250 | 211 | ||
251 | ret = __mei_cl_send(cl, (u8 *)&cmd, sizeof(struct mei_nfc_cmd), 1); | 212 | ret = __mei_cl_send(cl, (u8 *)&cmd, sizeof(struct mei_nfc_cmd), 1); |
252 | if (ret < 0) { | 213 | if (ret < 0) { |
@@ -262,6 +223,7 @@ static int mei_nfc_if_version(struct mei_nfc_dev *ndev) | |||
262 | if (!reply) | 223 | if (!reply) |
263 | return -ENOMEM; | 224 | return -ENOMEM; |
264 | 225 | ||
226 | ret = 0; | ||
265 | bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length); | 227 | bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length); |
266 | if (bytes_recv < 0 || bytes_recv < sizeof(struct mei_nfc_reply)) { | 228 | if (bytes_recv < 0 || bytes_recv < sizeof(struct mei_nfc_reply)) { |
267 | dev_err(bus->dev, "Could not read IF version\n"); | 229 | dev_err(bus->dev, "Could not read IF version\n"); |
@@ -269,17 +231,39 @@ static int mei_nfc_if_version(struct mei_nfc_dev *ndev) | |||
269 | goto err; | 231 | goto err; |
270 | } | 232 | } |
271 | 233 | ||
272 | version = (struct mei_nfc_if_version *)reply->data; | 234 | memcpy(ver, reply->data, sizeof(struct mei_nfc_if_version)); |
273 | 235 | ||
274 | ndev->fw_ivn = version->fw_ivn; | 236 | dev_info(bus->dev, "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n", |
275 | ndev->vendor_id = version->vendor_id; | 237 | ver->fw_ivn, ver->vendor_id, ver->radio_type); |
276 | ndev->radio_type = version->radio_type; | ||
277 | 238 | ||
278 | err: | 239 | err: |
279 | kfree(reply); | 240 | kfree(reply); |
280 | return ret; | 241 | return ret; |
281 | } | 242 | } |
282 | 243 | ||
244 | /** | ||
245 | * mei_nfc_radio_name - derive nfc radio name from the interface version | ||
246 | * | ||
247 | * @ver: NFC radio version | ||
248 | * | ||
249 | * Return: radio name string | ||
250 | */ | ||
251 | static const char *mei_nfc_radio_name(struct mei_nfc_if_version *ver) | ||
252 | { | ||
253 | |||
254 | if (ver->vendor_id == MEI_NFC_VENDOR_INSIDE) { | ||
255 | if (ver->radio_type == MEI_NFC_VENDOR_INSIDE_UREAD) | ||
256 | return "microread"; | ||
257 | } | ||
258 | |||
259 | if (ver->vendor_id == MEI_NFC_VENDOR_NXP) { | ||
260 | if (ver->radio_type == MEI_NFC_VENDOR_NXP_PN544) | ||
261 | return "pn544"; | ||
262 | } | ||
263 | |||
264 | return NULL; | ||
265 | } | ||
266 | |||
283 | static void mei_nfc_init(struct work_struct *work) | 267 | static void mei_nfc_init(struct work_struct *work) |
284 | { | 268 | { |
285 | struct mei_device *bus; | 269 | struct mei_device *bus; |
@@ -287,6 +271,7 @@ static void mei_nfc_init(struct work_struct *work) | |||
287 | struct mei_nfc_dev *ndev; | 271 | struct mei_nfc_dev *ndev; |
288 | struct mei_cl *cl_info; | 272 | struct mei_cl *cl_info; |
289 | struct mei_me_client *me_cl_info; | 273 | struct mei_me_client *me_cl_info; |
274 | struct mei_nfc_if_version version; | ||
290 | 275 | ||
291 | ndev = container_of(work, struct mei_nfc_dev, init_work); | 276 | ndev = container_of(work, struct mei_nfc_dev, init_work); |
292 | 277 | ||
@@ -313,12 +298,16 @@ static void mei_nfc_init(struct work_struct *work) | |||
313 | mei_me_cl_put(me_cl_info); | 298 | mei_me_cl_put(me_cl_info); |
314 | mutex_unlock(&bus->device_lock); | 299 | mutex_unlock(&bus->device_lock); |
315 | 300 | ||
316 | if (mei_nfc_if_version(ndev) < 0) { | 301 | if (mei_nfc_if_version(cl_info, &version) < 0) { |
317 | dev_err(bus->dev, "Could not get the NFC interface version"); | 302 | dev_err(bus->dev, "Could not get the NFC interface version"); |
318 | 303 | ||
319 | goto err; | 304 | goto err; |
320 | } | 305 | } |
321 | 306 | ||
307 | ndev->fw_ivn = version.fw_ivn; | ||
308 | ndev->vendor_id = version.vendor_id; | ||
309 | ndev->radio_type = version.radio_type; | ||
310 | |||
322 | dev_info(bus->dev, "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n", | 311 | dev_info(bus->dev, "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n", |
323 | ndev->fw_ivn, ndev->vendor_id, ndev->radio_type); | 312 | ndev->fw_ivn, ndev->vendor_id, ndev->radio_type); |
324 | 313 | ||
@@ -333,7 +322,9 @@ static void mei_nfc_init(struct work_struct *work) | |||
333 | 322 | ||
334 | mutex_unlock(&bus->device_lock); | 323 | mutex_unlock(&bus->device_lock); |
335 | 324 | ||
336 | if (mei_nfc_build_bus_name(ndev) < 0) { | 325 | ndev->bus_name = mei_nfc_radio_name(&version); |
326 | |||
327 | if (!ndev->bus_name) { | ||
337 | dev_err(bus->dev, "Could not build the bus ID name\n"); | 328 | dev_err(bus->dev, "Could not build the bus ID name\n"); |
338 | return; | 329 | return; |
339 | } | 330 | } |
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 68b7756bf384..7e51700515f4 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c | |||
@@ -710,7 +710,7 @@ static int mei_cl_bus_dev_add(struct mei_cl_device *cldev) | |||
710 | struct mei_cl_device *mei_cl_add_device(struct mei_device *bus, | 710 | struct mei_cl_device *mei_cl_add_device(struct mei_device *bus, |
711 | struct mei_me_client *me_cl, | 711 | struct mei_me_client *me_cl, |
712 | struct mei_cl *cl, | 712 | struct mei_cl *cl, |
713 | char *name) | 713 | const char *name) |
714 | { | 714 | { |
715 | struct mei_cl_device *cldev; | 715 | struct mei_cl_device *cldev; |
716 | int status; | 716 | int status; |
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index ad59ab776f2d..7098dcaccc96 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h | |||
@@ -333,7 +333,7 @@ struct mei_hw_ops { | |||
333 | struct mei_cl_device *mei_cl_add_device(struct mei_device *bus, | 333 | struct mei_cl_device *mei_cl_add_device(struct mei_device *bus, |
334 | struct mei_me_client *me_cl, | 334 | struct mei_me_client *me_cl, |
335 | struct mei_cl *cl, | 335 | struct mei_cl *cl, |
336 | char *name); | 336 | const char *name); |
337 | void mei_cl_remove_device(struct mei_cl_device *cldev); | 337 | void mei_cl_remove_device(struct mei_cl_device *cldev); |
338 | void mei_cl_dev_fixup(struct mei_cl_device *dev); | 338 | void mei_cl_dev_fixup(struct mei_cl_device *dev); |
339 | ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, | 339 | ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, |