From: Tomas Winkler <tomas.winkler@intel.com>
To: gregkh@linuxfoundation.org
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org,
Tomas Winkler <tomas.winkler@intel.com>
Subject: [char-misc-next 14/15 V2] mei: bus: simplify how we build nfc bus name
Date: Mon, 15 Jun 2015 21:56:54 +0300 [thread overview]
Message-ID: <1434394615-3754-15-git-send-email-tomas.winkler@intel.com> (raw)
In-Reply-To: <1434394615-3754-1-git-send-email-tomas.winkler@intel.com>
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>
---
V2: Fix the commit message
drivers/misc/mei/bus-fixup.c | 115 ++++++++++++++++++++-----------------------
drivers/misc/mei/bus.c | 2 +-
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 46d27d92db3f..74ac6a583456 100644
--- a/drivers/misc/mei/bus-fixup.c
+++ b/drivers/misc/mei/bus-fixup.c
@@ -145,7 +145,7 @@ struct mei_nfc_dev {
u8 fw_ivn;
u8 vendor_id;
u8 radio_type;
- char *bus_name;
+ const char *bus_name;
};
/* UUIDs for NFC F/W clients */
@@ -184,69 +184,30 @@ static void mei_nfc_free(struct mei_nfc_dev *ndev)
kfree(ndev);
}
-static int mei_nfc_build_bus_name(struct mei_nfc_dev *ndev)
-{
- struct mei_device *bus;
-
- if (!ndev->cl)
- return -ENODEV;
-
- bus = ndev->cl->dev;
-
- switch (ndev->vendor_id) {
- case MEI_NFC_VENDOR_INSIDE:
- switch (ndev->radio_type) {
- case MEI_NFC_VENDOR_INSIDE_UREAD:
- ndev->bus_name = "microread";
- return 0;
-
- default:
- dev_err(bus->dev, "Unknown radio type 0x%x\n",
- ndev->radio_type);
-
- return -EINVAL;
- }
-
- case MEI_NFC_VENDOR_NXP:
- switch (ndev->radio_type) {
- case MEI_NFC_VENDOR_NXP_PN544:
- ndev->bus_name = "pn544";
- return 0;
- default:
- dev_err(bus->dev, "Unknown radio type 0x%x\n",
- ndev->radio_type);
-
- return -EINVAL;
- }
-
- default:
- dev_err(bus->dev, "Unknown vendor ID 0x%x\n",
- ndev->vendor_id);
-
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int mei_nfc_if_version(struct mei_nfc_dev *ndev)
+/**
+ * mei_nfc_if_version - get NFC interface version
+ *
+ * @cl: host client (nfc info)
+ * @ver: NFC interface version to be filled in
+ *
+ * Return: 0 on success; < 0 otherwise
+ */
+static int mei_nfc_if_version(struct mei_cl *cl,
+ struct mei_nfc_if_version *ver)
{
struct mei_device *bus;
- struct mei_cl *cl;
-
- struct mei_nfc_cmd cmd;
+ struct mei_nfc_cmd cmd = {
+ .command = MEI_NFC_CMD_MAINTENANCE,
+ .data_size = 1,
+ .sub_command = MEI_NFC_SUBCMD_IF_VERSION,
+ };
struct mei_nfc_reply *reply = NULL;
- struct mei_nfc_if_version *version;
size_t if_version_length;
int bytes_recv, ret;
- cl = ndev->cl_info;
bus = cl->dev;
- memset(&cmd, 0, sizeof(struct mei_nfc_cmd));
- cmd.command = MEI_NFC_CMD_MAINTENANCE;
- cmd.data_size = 1;
- cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION;
+ WARN_ON(mutex_is_locked(&bus->device_lock));
ret = __mei_cl_send(cl, (u8 *)&cmd, sizeof(struct mei_nfc_cmd), 1);
if (ret < 0) {
@@ -262,6 +223,7 @@ static int mei_nfc_if_version(struct mei_nfc_dev *ndev)
if (!reply)
return -ENOMEM;
+ ret = 0;
bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length);
if (bytes_recv < 0 || bytes_recv < sizeof(struct mei_nfc_reply)) {
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)
goto err;
}
- version = (struct mei_nfc_if_version *)reply->data;
+ memcpy(ver, reply->data, sizeof(struct mei_nfc_if_version));
- ndev->fw_ivn = version->fw_ivn;
- ndev->vendor_id = version->vendor_id;
- ndev->radio_type = version->radio_type;
+ dev_info(bus->dev, "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n",
+ ver->fw_ivn, ver->vendor_id, ver->radio_type);
err:
kfree(reply);
return ret;
}
+/**
+ * mei_nfc_radio_name - derive nfc radio name from the interface version
+ *
+ * @ver: NFC radio version
+ *
+ * Return: radio name string
+ */
+static const char *mei_nfc_radio_name(struct mei_nfc_if_version *ver)
+{
+
+ if (ver->vendor_id == MEI_NFC_VENDOR_INSIDE) {
+ if (ver->radio_type == MEI_NFC_VENDOR_INSIDE_UREAD)
+ return "microread";
+ }
+
+ if (ver->vendor_id == MEI_NFC_VENDOR_NXP) {
+ if (ver->radio_type == MEI_NFC_VENDOR_NXP_PN544)
+ return "pn544";
+ }
+
+ return NULL;
+}
+
static void mei_nfc_init(struct work_struct *work)
{
struct mei_device *bus;
@@ -287,6 +271,7 @@ static void mei_nfc_init(struct work_struct *work)
struct mei_nfc_dev *ndev;
struct mei_cl *cl_info;
struct mei_me_client *me_cl_info;
+ struct mei_nfc_if_version version;
ndev = container_of(work, struct mei_nfc_dev, init_work);
@@ -313,12 +298,16 @@ static void mei_nfc_init(struct work_struct *work)
mei_me_cl_put(me_cl_info);
mutex_unlock(&bus->device_lock);
- if (mei_nfc_if_version(ndev) < 0) {
+ if (mei_nfc_if_version(cl_info, &version) < 0) {
dev_err(bus->dev, "Could not get the NFC interface version");
goto err;
}
+ ndev->fw_ivn = version.fw_ivn;
+ ndev->vendor_id = version.vendor_id;
+ ndev->radio_type = version.radio_type;
+
dev_info(bus->dev, "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n",
ndev->fw_ivn, ndev->vendor_id, ndev->radio_type);
@@ -333,7 +322,9 @@ static void mei_nfc_init(struct work_struct *work)
mutex_unlock(&bus->device_lock);
- if (mei_nfc_build_bus_name(ndev) < 0) {
+ ndev->bus_name = mei_nfc_radio_name(&version);
+
+ if (!ndev->bus_name) {
dev_err(bus->dev, "Could not build the bus ID name\n");
return;
}
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index f0b1ff8094c1..137104d339b6 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -709,7 +709,7 @@ static int mei_cl_bus_dev_add(struct mei_cl_device *cldev)
struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
struct mei_me_client *me_cl,
struct mei_cl *cl,
- char *name)
+ const char *name)
{
struct mei_cl_device *cldev;
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 {
struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
struct mei_me_client *me_cl,
struct mei_cl *cl,
- char *name);
+ const char *name);
void mei_cl_remove_device(struct mei_cl_device *cldev);
void mei_cl_dev_fixup(struct mei_cl_device *dev);
ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
--
2.4.3
next prev parent reply other threads:[~2015-06-15 18:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-15 18:56 [char-misc-next 00/15 V2] revamp mei bus Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 01/15 V2] mei: bus: fix drivers and devices names confusion Tomas Winkler
2015-07-23 4:30 ` Greg KH
2015-06-15 18:56 ` [char-misc-next 02/15 V2] mei: bus: rename nfc.c to bus-fixup.c Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 03/15 V2] mei: bus: move driver api functions at the start of the file Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 04/15] mei: bus: rename uevent handler to mei_cl_device_uevent Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 05/15 V2] mei: bus: don't enable events implicitly in device enable Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 06/15 V2] mei: bus: report if event registration failed Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 07/15 V2] mei: bus: revamp device matching Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 08/15 V2] mei: bus: revamp probe and remove functions Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 09/15 V2] mei: bus: add reference to bus device in struct mei_cl_client Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 10/15 V2] mei: bus: add me client device list infrastructure Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 11/15 V2] mei: bus: enable running fixup routines before device registration Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 12/15] mei: bus: blacklist the nfc info client Tomas Winkler
2015-06-15 18:56 ` [char-misc-next 13/15] mei: bus: blacklist clients by number of connections Tomas Winkler
2015-06-15 18:56 ` Tomas Winkler [this message]
2015-06-15 18:56 ` [char-misc-next 15/15 V2] mei: bus: link client devices instead of host clients Tomas Winkler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434394615-3754-15-git-send-email-tomas.winkler@intel.com \
--to=tomas.winkler@intel.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®