diff options
author | Anita Kar <akar@nvidia.com> | 2013-01-17 13:27:29 +0530 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2013-09-14 12:57:57 -0700 |
commit | e247ae87d0f9e1987032d9a33759220dbc811bcd (patch) | |
tree | 417689f3b6f48dfe6f8c4214ec3222a926f4f7f1 /drivers/nfc | |
parent | 66dd351d282759e5ff06ffc37d4f75929b6ff9a3 (diff) |
nfc: implement i2c shutdown for Broadcom nfc
Implementation of i2c shutdown for bcm2079x nfc module
to discard any i2c communication after shutdown.
Bug 1203783
Change-Id: I10ac641629d5c6ab8d0adb229588a89d77ab99ae
Signed-off-by: Anita Kar <akar@nvidia.com>
Reviewed-on: http://git-master/r/191939
GVS: Gerrit_Virtual_Submit
(cherry picked from commit 3777260ddec2fe578e7985dbec401cfce887d01f)
Signed-off-by: Richard Zhao <rizhao@nvidia.com>
Reviewed-on: http://git-master/r/201642
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Rakesh Goyal <rgoyal@nvidia.com>
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Diffstat (limited to 'drivers/nfc')
-rw-r--r-- | drivers/nfc/bcm2079x-i2c.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/drivers/nfc/bcm2079x-i2c.c b/drivers/nfc/bcm2079x-i2c.c index 076cf98e651a..0cc3a8b8486b 100644 --- a/drivers/nfc/bcm2079x-i2c.c +++ b/drivers/nfc/bcm2079x-i2c.c @@ -36,7 +36,6 @@ #include <linux/spinlock.h> #include <linux/poll.h> #include <linux/version.h> - #include <linux/nfc/bcm2079x.h> #define TRUE 1 @@ -70,7 +69,8 @@ struct bcm2079x_dev { unsigned int error_read; unsigned int count_read; unsigned int count_irq; - int original_address; + int original_address; + bool shutdown_complete; }; static void bcm2079x_init_stat(struct bcm2079x_dev *bcm2079x_dev) @@ -156,8 +156,17 @@ static void change_client_addr(struct bcm2079x_dev *bcm2079x_dev, int addr) "%04x, addr_data[%d] = %02x\n", client->addr, client->flags, sizeof(addr_data) - 1, addr_data[sizeof(addr_data) - 1]); + + mutex_lock(&bcm2079x_dev->read_mutex); + if (bcm2079x_dev && (bcm2079x_dev->shutdown_complete == true)) { + dev_info(&client->dev, "%s: discarding as " \ + "NFC in shutdown state\n", __func__); + mutex_unlock(&bcm2079x_dev->read_mutex); + } ret = i2c_master_send(client, addr_data+offset, sizeof(addr_data)-offset); + mutex_unlock(&bcm2079x_dev->read_mutex); + client->addr = addr_data[5]; dev_info(&client->dev, "change_client_addr to (0x%04X) flag = %04x, ret = %d\n", @@ -211,6 +220,14 @@ static ssize_t bcm2079x_dev_read(struct file *filp, char __user *buf, mutex_lock(&bcm2079x_dev->read_mutex); + /*Check for shutdown condition*/ + if (bcm2079x_dev && (bcm2079x_dev->shutdown_complete == true)) { + dev_info(&bcm2079x_dev->client->dev, "%s: discarding read " \ + "as NFC in shutdown state\n", __func__); + mutex_unlock(&bcm2079x_dev->read_mutex); + return -ENODEV; + } + /** Read the first 4 bytes to include the length of the NCI or HCI packet.**/ ret = i2c_master_recv(bcm2079x_dev->client, tmp, 4); @@ -284,6 +301,15 @@ static ssize_t bcm2079x_dev_write(struct file *filp, const char __user *buf, } mutex_lock(&bcm2079x_dev->read_mutex); + + /*Check for shutdown condition*/ + if (bcm2079x_dev && (bcm2079x_dev->shutdown_complete == true)) { + dev_info(&bcm2079x_dev->client->dev, "%s: discarding write " \ + "as NFC in shutdown state\n", __func__); + mutex_unlock(&bcm2079x_dev->read_mutex); + return -ENODEV; + } + /* Write data */ ret = i2c_master_send(bcm2079x_dev->client, tmp, count); @@ -499,6 +525,20 @@ static int bcm2079x_remove(struct i2c_client *client) return 0; } +static void bcm2079x_shutdown(struct i2c_client *client) +{ + struct bcm2079x_dev *bcm2079x_data = i2c_get_clientdata(client); + + mutex_lock(&bcm2079x_data->read_mutex); + if (client->irq) + disable_irq(client->irq); + bcm2079x_data->shutdown_complete = true; + mutex_unlock(&bcm2079x_data->read_mutex); + + dev_info(&bcm2079x_data->client->dev, + "%s: NFC shutting down\n", __func__); +} + static const struct i2c_device_id bcm2079x_id[] = { {"bcm2079x-i2c", 0}, {} @@ -508,6 +548,7 @@ static struct i2c_driver bcm2079x_driver = { .id_table = bcm2079x_id, .probe = bcm2079x_probe, .remove = bcm2079x_remove, + .shutdown = bcm2079x_shutdown, .driver = { .owner = THIS_MODULE, .name = "bcm2079x-i2c", |