]> git.karo-electronics.de Git - linux-beck.git/commitdiff
NFC: Set the NFC device RF mode appropriately
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 30 May 2012 22:02:26 +0000 (00:02 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 4 Jun 2012 19:34:30 +0000 (21:34 +0200)
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
include/linux/nfc.h
include/net/nfc/nfc.h
net/nfc/core.c

index d124e9273fcbeee2e1e1cc4d1cbd46e266b91e0e..f4e6dd915b1c63c8c9d3bbf62ab545909d13ccd8 100644 (file)
@@ -146,6 +146,7 @@ enum nfc_attrs {
 /* NFC RF modes */
 #define NFC_RF_INITIATOR 0
 #define NFC_RF_TARGET    1
+#define NFC_RF_NONE      2
 
 /* NFC protocols masks used in bitsets */
 #define NFC_PROTO_JEWEL_MASK   (1 << NFC_PROTO_JEWEL)
index 41573b4bd78a1f44ae8fbc5b499b760c7e501f01..a6a7b49a3e2db68587d5cff8007c23569d326f1e 100644 (file)
@@ -100,10 +100,10 @@ struct nfc_dev {
        int targets_generation;
        struct device dev;
        bool dev_up;
+       u8 rf_mode;
        bool polling;
        struct nfc_target *active_target;
        bool dep_link_up;
-       u32 dep_rf_mode;
        struct nfc_genl_data genl_data;
        u32 supported_protocols;
 
index 17f147430b7c1b8b2cc5ae92407e5f34a1b759ca..722a0c76c669cd1ebc286b472f2917efe7896e2b 100644 (file)
@@ -144,8 +144,10 @@ int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols)
        }
 
        rc = dev->ops->start_poll(dev, im_protocols, tm_protocols);
-       if (!rc)
+       if (!rc) {
                dev->polling = true;
+               dev->rf_mode = NFC_RF_NONE;
+       }
 
 error:
        device_unlock(&dev->dev);
@@ -235,8 +237,10 @@ int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
        }
 
        rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len);
-       if (!rc)
+       if (!rc) {
                dev->active_target = target;
+               dev->rf_mode = NFC_RF_INITIATOR;
+       }
 
 error:
        device_unlock(&dev->dev);
@@ -264,7 +268,7 @@ int nfc_dep_link_down(struct nfc_dev *dev)
                goto error;
        }
 
-       if (dev->dep_rf_mode == NFC_RF_TARGET) {
+       if (dev->rf_mode == NFC_RF_TARGET) {
                rc = -EOPNOTSUPP;
                goto error;
        }
@@ -286,7 +290,6 @@ int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
                       u8 comm_mode, u8 rf_mode)
 {
        dev->dep_link_up = true;
-       dev->dep_rf_mode = rf_mode;
 
        nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode);
 
@@ -330,6 +333,7 @@ int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
        rc = dev->ops->activate_target(dev, target, protocol);
        if (!rc) {
                dev->active_target = target;
+               dev->rf_mode = NFC_RF_INITIATOR;
 
                if (dev->ops->check_presence)
                        mod_timer(&dev->check_pres_timer, jiffies +
@@ -470,6 +474,8 @@ int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
                        goto out;
        }
 
+       dev->rf_mode = NFC_RF_TARGET;
+
        if (protocol == NFC_PROTO_NFC_DEP_MASK)
                nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET);