summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorRakesh Goyal <rgoyal@nvidia.com>2011-10-11 18:56:21 +0530
committerVarun Colbert <vcolbert@nvidia.com>2011-11-07 13:33:09 -0800
commit71290851ce2c006272a7c5f36d543f6d2f64aec5 (patch)
treea716b67f5fbfeb9651bcfa09b1caedd60cb59dbb /drivers
parent7167931141ebe6a72c2d3baac57844d1d61f68d0 (diff)
driver: nfc: code clean-up to make it compilable
1. Code cleaning so it can compile 2. Adding Makefile and Kconfig 3. changes in pn544 driver to condition use of firmware download gpio Bug 846684 Bug 873017 Reviewed-on: http://git-master/r/57329 (cherry picked from commit ddde05ce297da3038a770d575bc27bdfe7444c35) Change-Id: I5f3f0791e35140aa6b3985b61ac4e3a5f3a2de8b Reviewed-on: http://git-master/r/59301 Reviewed-by: Rakesh Goyal <rgoyal@nvidia.com> Tested-by: Rakesh Goyal <rgoyal@nvidia.com> Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/nfc/Kconfig30
-rw-r--r--drivers/nfc/Makefile5
-rw-r--r--drivers/nfc/pn544.c71
5 files changed, 88 insertions, 21 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 6781b709cac5..f369f9d9a045 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -113,4 +113,6 @@ source "drivers/xen/Kconfig"
source "drivers/staging/Kconfig"
source "drivers/platform/Kconfig"
+
+source "drivers/nfc/Kconfig"
endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index d7f34f1a6cab..6d9c513a5997 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -116,3 +116,4 @@ obj-$(CONFIG_VLYNQ) += vlynq/
obj-$(CONFIG_STAGING) += staging/
obj-y += platform/
obj-y += ieee802154/
+obj-$(CONFIG_PN544_NFC) += nfc/
diff --git a/drivers/nfc/Kconfig b/drivers/nfc/Kconfig
new file mode 100644
index 000000000000..ea1580085347
--- /dev/null
+++ b/drivers/nfc/Kconfig
@@ -0,0 +1,30 @@
+#
+# Near Field Communication (NFC) devices
+#
+
+menuconfig NFC_DEVICES
+ bool "Near Field Communication (NFC) devices"
+ default n
+ ---help---
+ You'll have to say Y if your computer contains an NFC device that
+ you want to use under Linux.
+
+ You can say N here if you don't have any Near Field Communication
+ devices connected to your computer.
+
+if NFC_DEVICES
+
+config PN544_NFC
+ tristate "PN544 NFC driver"
+ depends on I2C
+ select CRC_CCITT
+ default n
+ ---help---
+ Say yes if you want PN544 Near Field Communication driver.
+ This is for i2c connected version. If unsure, say N here.
+
+ To compile this driver as a module, choose m here. The module will
+ be called pn544.
+
+
+endif # NFC_DEVICES
diff --git a/drivers/nfc/Makefile b/drivers/nfc/Makefile
new file mode 100644
index 000000000000..a4efb164ec49
--- /dev/null
+++ b/drivers/nfc/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for nfc devices
+#
+
+obj-$(CONFIG_PN544_NFC) += pn544.o
diff --git a/drivers/nfc/pn544.c b/drivers/nfc/pn544.c
index 5814477ad054..c895dc332fe9 100644
--- a/drivers/nfc/pn544.c
+++ b/drivers/nfc/pn544.c
@@ -34,7 +34,7 @@
#include <linux/gpio.h>
#include <linux/miscdevice.h>
#include <linux/spinlock.h>
-#include <linux/pn544.h>
+#include <linux/nfc/pn544.h>
#define MAX_BUFFER_SIZE 512
@@ -172,10 +172,11 @@ static int pn544_dev_open(struct inode *inode, struct file *filp)
return 0;
}
-static int pn544_dev_ioctl(struct inode *inode, struct file *filp,
- unsigned int cmd, unsigned long arg)
+static int pn544_dev_ioctl(struct file *filp, unsigned cmd,
+ unsigned long arg)
{
struct pn544_dev *pn544_dev = filp->private_data;
+ int ret=0;
switch (cmd) {
case PN544_SET_PWR:
@@ -183,27 +184,41 @@ static int pn544_dev_ioctl(struct inode *inode, struct file *filp,
/* power on with firmware download (requires hw reset)
*/
pr_info("%s power on with firmware\n", __func__);
- gpio_set_value(pn544_dev->ven_gpio, 1);
- gpio_set_value(pn544_dev->firm_gpio, 1);
+ if (pn544_dev->firm_gpio)
+ gpio_set_value(pn544_dev->firm_gpio, 1);
msleep(10);
- gpio_set_value(pn544_dev->ven_gpio, 0);
- msleep(10);
- gpio_set_value(pn544_dev->ven_gpio, 1);
+ ret = gpio_direction_output(pn544_dev->ven_gpio, 0);
+ if (ret < 0) {
+ pr_err("%s : could not set it to 0\n", __func__);
+ }
+ msleep(100);
+ ret = gpio_direction_input(pn544_dev->ven_gpio);
+ if (ret < 0) {
+ pr_err("%s : could not set in input direction\n", __func__);
+ }
msleep(10);
} else if (arg == 1) {
/* power on */
pr_info("%s power on\n", __func__);
- gpio_set_value(pn544_dev->firm_gpio, 0);
- gpio_set_value(pn544_dev->ven_gpio, 1);
- msleep(10);
+ if (pn544_dev->firm_gpio)
+ gpio_set_value(pn544_dev->firm_gpio, 0);
+ ret = gpio_direction_input(pn544_dev->ven_gpio);
+ if (ret < 0) {
+ pr_err("%s : could not set in input direction\n", __func__);
+ }
+ msleep(20);
} else if (arg == 0) {
/* power off */
pr_info("%s power off\n", __func__);
- gpio_set_value(pn544_dev->firm_gpio, 0);
- gpio_set_value(pn544_dev->ven_gpio, 0);
- msleep(10);
+ if (pn544_dev->firm_gpio)
+ gpio_set_value(pn544_dev->firm_gpio, 0);
+ ret = gpio_direction_output(pn544_dev->ven_gpio, 0);
+ if (ret < 0) {
+ pr_err("%s : could not set it to 0\n", __func__);
+ }
+ msleep(100);
} else {
- pr_err("%s bad arg %u\n", __func__, arg);
+ pr_err("%s bad arg %lu\n", __func__, arg);
return -EINVAL;
}
break;
@@ -221,7 +236,7 @@ static const struct file_operations pn544_dev_fops = {
.read = pn544_dev_read,
.write = pn544_dev_write,
.open = pn544_dev_open,
- .ioctl = pn544_dev_ioctl,
+ .unlocked_ioctl = pn544_dev_ioctl,
};
static int pn544_probe(struct i2c_client *client,
@@ -249,9 +264,11 @@ static int pn544_probe(struct i2c_client *client,
ret = gpio_request(platform_data->ven_gpio, "nfc_ven");
if (ret)
goto err_ven;
- ret = gpio_request(platform_data->firm_gpio, "nfc_firm");
- if (ret)
- goto err_firm;
+ if (platform_data->firm_gpio) {
+ ret = gpio_request(platform_data->firm_gpio, "nfc_firm");
+ if (ret)
+ goto err_firm;
+ }
pn544_dev = kzalloc(sizeof(*pn544_dev), GFP_KERNEL);
if (pn544_dev == NULL) {
@@ -266,6 +283,16 @@ static int pn544_probe(struct i2c_client *client,
pn544_dev->firm_gpio = platform_data->firm_gpio;
pn544_dev->client = client;
+ ret = gpio_direction_output(platform_data->ven_gpio, 0);
+ if (ret < 0) {
+ pr_err("%s : could not set it to 0\n", __func__);
+ }
+ msleep(100);
+ ret = gpio_direction_input(platform_data->ven_gpio);
+ if (ret < 0) {
+ pr_err("%s : could not set in input direction\n", __func__);
+ }
+
/* init mutex and queues */
init_waitqueue_head(&pn544_dev->read_wq);
mutex_init(&pn544_dev->read_mutex);
@@ -303,7 +330,8 @@ err_misc_register:
mutex_destroy(&pn544_dev->read_mutex);
kfree(pn544_dev);
err_exit:
- gpio_free(platform_data->firm_gpio);
+ if (pn544_dev->firm_gpio)
+ gpio_free(platform_data->firm_gpio);
err_firm:
gpio_free(platform_data->ven_gpio);
err_ven:
@@ -321,7 +349,8 @@ static int pn544_remove(struct i2c_client *client)
mutex_destroy(&pn544_dev->read_mutex);
gpio_free(pn544_dev->irq_gpio);
gpio_free(pn544_dev->ven_gpio);
- gpio_free(pn544_dev->firm_gpio);
+ if (pn544_dev->firm_gpio)
+ gpio_free(pn544_dev->firm_gpio);
kfree(pn544_dev);
return 0;