NFC RFKILL support
Subsystems (3)
v2 cover NFC RFKILL support
This is a RFC for adding RFKILL support to NFC>
As I said in v1, I'd like to pass this one through my next NFC pull request, I'm looking for Johannes and/or Marcel ACKs before doing so.
v2:
* Split the initial patch into 2: One for the core rfkill parts, another one for the NFC bits.
* Added a comment line for RFKILL_TYPE_NFC in rfkill.h
Samuel Ortiz (2):
rfkill: Add NFC to the list of supported radios
NFC: RFKILL support
include/net/nfc/nfc.h | 2 ++ include/uapi/linux/rfkill.h | 2 ++ net/nfc/core.c | 38 ++++++++++++++++++++++++++++++++++++++ net/rfkill/core.c | 4 +++- 4 files changed, 45 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.10.4
RFC PATCH v2 1/2 rfkill: Add NFC to the list of supported radios
And return the proper string for it.
--- include/uapi/linux/rfkill.h | 2 ++ net/rfkill/core.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
include/uapi/linux/rfkill.h +2 -0
@@ -37,6 +37,7 @@* @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. * @RFKILL_TYPE_GPS: switch is on a GPS device. * @RFKILL_TYPE_FM: switch is on a FM radio device. +* @RFKILL_TYPE_NFC: switch is on an NFC device. * @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type {
@@ -48,6 +49,7 @@ enum rfkill_type {RFKILL_TYPE_WWAN ,RFKILL_TYPE_GPS ,RFKILL_TYPE_FM , +RFKILL_TYPE_NFC , NUM_RFKILL_TYPES, };
net/rfkill/core.c +3 -1
@@ -587,7 +587,7 @@ static ssize_t rfkill_name_show(struct device *dev,static const char *rfkill_get_type_str (enum rfkill_type type) { -BUILD_BUG_ON (NUM_RFKILL_TYPES !=RFKILL_TYPE_FM +1 ); +BUILD_BUG_ON (NUM_RFKILL_TYPES !=RFKILL_TYPE_NFC +1 );switch (type) {case RFKILL_TYPE_WLAN :
@@ -604,6 +604,8 @@ static const char *rfkill_get_type_str(enum rfkill_type type)return "gps" ;case RFKILL_TYPE_FM :return "fm" ; +case RFKILL_TYPE_NFC : +return "nfc" ;default :BUG (); }
Signature · 1 line
1.7.10.4
Re: [RFC] [PATCH 1/2 v2] rfkill: Add NFC to the list of supported radios
Quoted 3 lines · Samuel Ortiz
And return the proper string for it.
Signed-off-by Samuel Ortiz <[email protected]>
Looks fine to me, feel free to take it through your tree.
johannes
Re: [RFC] [PATCH 1/2 v2] rfkill: Add NFC to the list of supported radios
In reply to Samuel OrtizHi Samuel,
Quoted 7 lines
And return the proper string for it.
Signed-off-by Samuel Ortiz <[email protected]>---
include/uapi/linux/rfkill.h | 2 ++ net/rfkill/core.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
Regards
RFC PATCH v2 2/2 NFC: RFKILL support
In reply to Samuel OrtizAll NFC devices will now get proper RFKILL support as long as they provide some dev_up and dev_down hooks. Rfkilling an NFC device will bring it down while it is left to userspace to bring it back up when being rfkill unblocked. This is very similar to what Bluetooth does.
--- include/net/nfc/nfc.h | 2 ++ net/nfc/core.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
include/net/nfc/nfc.h +2 -0
@@ -122,6 +122,8 @@ struct nfc_dev {bool shutting_down; +struct rfkill *rfkill; +struct nfc_ops *ops; };#define to_nfc_dev (_dev) container_of(_dev, struct nfc_dev, dev)
net/nfc/core.c +38 -0
@@ -27,6 +27,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/rfkill.h> #include <linux/nfc.h> #include <net/genetlink.h>
@@ -58,6 +59,11 @@ int nfc_dev_up(struct nfc_dev *dev)device_lock (&dev->dev); +if (dev->rfkill &&rfkill_blocked (dev->rfkill)) { + rc = -ERFKILL ; + goto error; + } +if (!device_is_registered (&dev->dev)) { rc = -ENODEV ; goto error;
@@ -117,6 +123,24 @@ error:return rc; } +static int nfc_rfkill_set_block (void *data,bool blocked) +{ +struct nfc_dev *dev = data; + +pr_debug ("%s blocked %d" ,dev_name (&dev->dev), blocked); + +if (!blocked) +return 0 ; + +nfc_dev_down (dev); + +return 0 ; +} + +static const struct rfkill_ops nfc_rfkill_ops = { + .set_block = nfc_rfkill_set_block, +}; +/** * nfc_start_poll - start polling for nfc targets *
@@ -840,6 +864,15 @@ int nfc_register_device(struct nfc_dev *dev)pr_debug ("The userspace won't be notified that the device %s was added\n" ,dev_name (&dev->dev)); + dev->rfkill =rfkill_alloc (dev_name (&dev->dev), &dev->dev, +RFKILL_TYPE_NFC , &nfc_rfkill_ops, dev); +if (dev->rfkill) { +if (rfkill_register (dev->rfkill) <0 ) { +rfkill_destroy (dev->rfkill); + dev->rfkill =NULL ; + } + } +return 0 ; }EXPORT_SYMBOL (nfc_register_device);
@@ -857,6 +890,11 @@ void nfc_unregister_device(struct nfc_dev *dev) id = dev->idx; +if (dev->rfkill) { +rfkill_unregister (dev->rfkill); +rfkill_destroy (dev->rfkill); + } +if (dev->ops->check_presence) {device_lock (&dev->dev); dev->shutting_down = true;
Signature · 1 line
1.7.10.4
Re: [RFC] [PATCH 2/2 v2] NFC: RFKILL support
Hi Samuel,
Quoted 4 lines
All NFC devices will now get proper RFKILL support as long as they provide some
dev_upanddev_downhooks. Rfkilling an NFC device will bring it down while it is left to userspace to bring it back up when being rfkill unblocked. This is very similar to what Bluetooth does.
this is almost a literal copy of my Bluetooth RFKILL patch ;)
Quoted 5 lines
Signed-off-by Samuel Ortiz <[email protected]>---
include/net/nfc/nfc.h| 2 ++net/nfc/core.c| 38 ++++++++++++++++++++++++++++++++++++++2 files changed, 40 insertions(+)
Regards
Marcel