mako: nfc: add new nfc broadcom driver

Change-Id: I3b06a3c77c8d935798fcbdb627a7fca983503d08
diff --git a/arch/arm/configs/mako_defconfig b/arch/arm/configs/mako_defconfig
index 9576e4a..607ff65 100644
--- a/arch/arm/configs/mako_defconfig
+++ b/arch/arm/configs/mako_defconfig
@@ -240,6 +240,7 @@
 CONFIG_CFG80211=y
 # CONFIG_CFG80211_WEXT is not set
 CONFIG_RFKILL=y
+CONFIG_BCM2079X=y
 CONFIG_GENLOCK=y
 CONFIG_GENLOCK_MISCDEVICE=y
 CONFIG_CONNECTOR=y
diff --git a/arch/arm/mach-msm/lge/mako/board-mako-gpiomux.c b/arch/arm/mach-msm/lge/mako/board-mako-gpiomux.c
index cf3cc3a..376cba8 100644
--- a/arch/arm/mach-msm/lge/mako/board-mako-gpiomux.c
+++ b/arch/arm/mach-msm/lge/mako/board-mako-gpiomux.c
@@ -765,6 +765,48 @@
 };
 #endif
 
+static struct gpiomux_setting nfc_bcm2079x_ven_cfg = { // NFC_WAKE
+	.func = GPIOMUX_FUNC_GPIO,
+	.drv = GPIOMUX_DRV_2MA,
+	.pull = GPIOMUX_PULL_NONE,
+	.dir = GPIOMUX_OUT_LOW,
+};
+
+static struct gpiomux_setting nfc_bcm2079x_irq_cfg = { // NFC_IRQ
+	.func = GPIOMUX_FUNC_GPIO,
+	.drv = GPIOMUX_DRV_2MA,
+	.pull = GPIOMUX_PULL_DOWN, // BCM2079X should be PULL_NONE? MDM to confirm.
+	.dir = GPIOMUX_IN,
+};
+
+static struct gpiomux_setting nfc_bcm2079x_firm_cfg = { // REG_PU
+	.func = GPIOMUX_FUNC_GPIO,
+	.drv = GPIOMUX_DRV_2MA,
+	.pull = GPIOMUX_PULL_NONE,
+	.dir = GPIOMUX_OUT_LOW,
+};
+
+static struct msm_gpiomux_config apq8064_bcm2079x_nfc_configs[] __initdata = {
+	{
+		.gpio = 37,
+		.settings = {
+			[GPIOMUX_SUSPENDED] = &nfc_bcm2079x_firm_cfg,
+		},
+	},
+	{
+		.gpio = 29,
+		.settings = {
+			[GPIOMUX_SUSPENDED] = &nfc_bcm2079x_irq_cfg,
+		},
+	},
+	{
+		.gpio = 55,
+		.settings = {
+			[GPIOMUX_SUSPENDED] = &nfc_bcm2079x_ven_cfg,
+		},
+	},
+};
+
 void __init apq8064_init_gpiomux(void)
 {
 	int rc;
@@ -809,6 +851,9 @@
 			ARRAY_SIZE(apq8064_nfc_configs));
 #endif
 
+	msm_gpiomux_install(apq8064_bcm2079x_nfc_configs,
+			ARRAY_SIZE(apq8064_bcm2079x_nfc_configs));
+
 	msm_gpiomux_install(apq8064_hdmi_configs,
 			ARRAY_SIZE(apq8064_hdmi_configs));
 }
diff --git a/arch/arm/mach-msm/lge/mako/board-mako-nfc.c b/arch/arm/mach-msm/lge/mako/board-mako-nfc.c
index ecccae3..e0a4c20 100644
--- a/arch/arm/mach-msm/lge/mako/board-mako-nfc.c
+++ b/arch/arm/mach-msm/lge/mako/board-mako-nfc.c
@@ -68,3 +68,36 @@
 	lge_add_i2c_nfc_devices();
 }
 #endif
+
+#include <linux/nfc/bcm2079x.h>
+
+#define NFC_GPIO_VEN            55
+#define NFC_GPIO_IRQ            29
+#define NFC_GPIO_FIRM           37
+
+static struct bcm2079x_platform_data bcm2079x_pdata = {
+	.irq_gpio = NFC_GPIO_IRQ,
+	.en_gpio = NFC_GPIO_VEN,
+	.wake_gpio= NFC_GPIO_FIRM,
+};
+
+static struct i2c_board_info i2c_bcm2079x[] __initdata = {
+	{
+		I2C_BOARD_INFO("bcm2079x-i2c", 0x1FA),
+		.flags = I2C_CLIENT_TEN,
+		.irq = MSM_GPIO_TO_INT(NFC_GPIO_IRQ),
+		.platform_data = &bcm2079x_pdata,
+	},
+};
+
+static void __init lge_add_i2c_bcm2079x_device(void)
+{
+	i2c_register_board_info(APQ_8064_GSBI1_QUP_I2C_BUS_ID,
+			       i2c_bcm2079x,
+			       ARRAY_SIZE(i2c_bcm2079x));
+}
+
+void __init lge_add_bcm2079x_device(void)
+{
+	lge_add_i2c_bcm2079x_device();
+}
diff --git a/arch/arm/mach-msm/lge/mako/board-mako.c b/arch/arm/mach-msm/lge/mako/board-mako.c
index 9778fe8..1ebfbd3 100644
--- a/arch/arm/mach-msm/lge/mako/board-mako.c
+++ b/arch/arm/mach-msm/lge/mako/board-mako.c
@@ -2077,6 +2077,7 @@
 #if defined(CONFIG_LGE_NFC_PN544)
 	lge_add_nfc_devices();
 #endif
+	lge_add_bcm2079x_device();
 	lge_add_persistent_ram();
 	lge_add_ramconsole_devices();
 	lge_add_panic_handler_devices();
diff --git a/arch/arm/mach-msm/lge/mako/board-mako.h b/arch/arm/mach-msm/lge/mako/board-mako.h
index 31dcdfd..8d132d6 100644
--- a/arch/arm/mach-msm/lge/mako/board-mako.h
+++ b/arch/arm/mach-msm/lge/mako/board-mako.h
@@ -70,6 +70,7 @@
 		struct mmc_platform_data *plat);
 extern void __init lge_add_sound_devices(void);
 extern void __init lge_add_backlight_devices(void);
+void __init lge_add_bcm2079x_device(void);
 void apq8064_init_mmc(void);
 void apq8064_init_gpiomux(void);
 void apq8064_init_pmic(void);
diff --git a/drivers/nfc/Kconfig b/drivers/nfc/Kconfig
index 5af95927..8fd48d4 100644
--- a/drivers/nfc/Kconfig
+++ b/drivers/nfc/Kconfig
@@ -39,3 +39,10 @@
 	  into the kernel or say M to compile it as module.
 
 endmenu
+
+config BCM2079X
+	bool "Broadcom 2079X NFC Controller Driver"
+	depends on I2C
+	select CRC_CCITT
+	help
+	  Broadcom 2079X Near Field Communication controller support.
diff --git a/drivers/nfc/Makefile b/drivers/nfc/Makefile
index ab99e85..c05b26b 100644
--- a/drivers/nfc/Makefile
+++ b/drivers/nfc/Makefile
@@ -5,5 +5,6 @@
 obj-$(CONFIG_PN544_NFC)		+= pn544.o
 obj-$(CONFIG_NFC_PN533)		+= pn533.o
 obj-$(CONFIG_NFC_WILINK)	+= nfcwilink.o
+obj-$(CONFIG_BCM2079X)		+= bcm2079x-i2c.o
 
 ccflags-$(CONFIG_NFC_DEBUG) := -DDEBUG
diff --git a/drivers/nfc/bcm2079x-i2c.c b/drivers/nfc/bcm2079x-i2c.c
new file mode 100644
index 0000000..d719409
--- /dev/null
+++ b/drivers/nfc/bcm2079x-i2c.c
@@ -0,0 +1,472 @@
+/*
+ * Copyright (C) 2012 Broadcom Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/jiffies.h>
+#include <linux/uaccess.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/miscdevice.h>
+#include <linux/spinlock.h>
+#include <linux/poll.h>
+#include <linux/version.h>
+
+#include <linux/nfc/bcm2079x.h>
+
+/* do not change below */
+#define MAX_BUFFER_SIZE		780
+
+/* Read data */
+#define PACKET_HEADER_SIZE_NCI	(4)
+#define PACKET_HEADER_SIZE_HCI	(3)
+#define PACKET_TYPE_NCI		(16)
+#define PACKET_TYPE_HCIEV	(4)
+#define MAX_PACKET_SIZE		(PACKET_HEADER_SIZE_NCI + 255)
+
+struct bcm2079x_dev {
+	wait_queue_head_t read_wq;
+	struct mutex read_mutex;
+	struct i2c_client *client;
+	struct miscdevice bcm2079x_device;
+	unsigned int wake_gpio;
+	unsigned int en_gpio;
+	unsigned int irq_gpio;
+	bool irq_enabled;
+	spinlock_t irq_enabled_lock;
+	unsigned int count_irq;
+};
+
+static void bcm2079x_init_stat(struct bcm2079x_dev *bcm2079x_dev)
+{
+	bcm2079x_dev->count_irq = 0;
+}
+
+static void bcm2079x_disable_irq(struct bcm2079x_dev *bcm2079x_dev)
+{
+	unsigned long flags;
+	spin_lock_irqsave(&bcm2079x_dev->irq_enabled_lock, flags);
+	if (bcm2079x_dev->irq_enabled) {
+		disable_irq_nosync(bcm2079x_dev->client->irq);
+		bcm2079x_dev->irq_enabled = false;
+	}
+	spin_unlock_irqrestore(&bcm2079x_dev->irq_enabled_lock, flags);
+}
+
+static void bcm2079x_enable_irq(struct bcm2079x_dev *bcm2079x_dev)
+{
+	unsigned long flags;
+	spin_lock_irqsave(&bcm2079x_dev->irq_enabled_lock, flags);
+	if (!bcm2079x_dev->irq_enabled) {
+		bcm2079x_dev->irq_enabled = true;
+		enable_irq(bcm2079x_dev->client->irq);
+	}
+	spin_unlock_irqrestore(&bcm2079x_dev->irq_enabled_lock, flags);
+}
+
+/*
+ The alias address 0x79, when sent as a 7-bit address from the host processor
+ will match the first byte (highest 2 bits) of the default client address
+ (0x1FA) that is programmed in bcm20791.
+ When used together with the first byte (0xFA) of the byte sequence below,
+ it can be used to address the bcm20791 in a system that does not support
+ 10-bit address and change the default address to 0x38.
+ the new address can be changed by changing the CLIENT_ADDRESS below if 0x38
+ conflicts with other device on the same i2c bus.
+ */
+#define ALIAS_ADDRESS	  0x79
+
+static void change_client_addr(struct bcm2079x_dev *bcm2079x_dev, int addr)
+{
+	struct i2c_client *client;
+	int ret;
+	int i;
+	int offset = 0;
+	char addr_data[] = {
+		0xFA, 0xF2, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x2A
+	};
+
+	client = bcm2079x_dev->client;
+	client->addr = ALIAS_ADDRESS;
+	client->flags &= ~I2C_CLIENT_TEN;
+	offset = 0;
+
+	addr_data[5] = addr & 0xFF;
+	ret = 0;
+	for (i = 1; i < sizeof(addr_data) - 1; ++i)
+		ret += addr_data[i];
+	addr_data[sizeof(addr_data) - 1] = (ret & 0xFF);
+	dev_info(&client->dev,
+		 "Change client device from (0x%04X) flag = "\
+		 "%04x, addr_data[%d] = %02x\n",
+		 client->addr, client->flags, sizeof(addr_data) - 1,
+		 addr_data[sizeof(addr_data) - 1]);
+	ret = i2c_master_send(client, addr_data+offset, sizeof(addr_data)-offset);
+	if (ret != sizeof(addr_data)-offset) {
+		client->addr = ALIAS_ADDRESS;
+		client->flags &= ~I2C_CLIENT_TEN;
+		dev_info(&client->dev,
+			 "Change client device from (0x%04X) flag = "\
+			 "%04x, addr_data[%d] = %02x\n",
+			 client->addr, client->flags, sizeof(addr_data) - 1,
+			 addr_data[sizeof(addr_data) - 1]);
+		ret = i2c_master_send(client, addr_data, sizeof(addr_data));
+	}
+	client->addr = addr_data[5];
+
+	dev_info(&client->dev,
+		 "Change client device changed to (0x%04X) flag = %04x, ret = %d\n",
+		 client->addr, client->flags, ret);
+}
+
+static irqreturn_t bcm2079x_dev_irq_handler(int irq, void *dev_id)
+{
+	struct bcm2079x_dev *bcm2079x_dev = dev_id;
+	unsigned long flags;
+
+	spin_lock_irqsave(&bcm2079x_dev->irq_enabled_lock, flags);
+	bcm2079x_dev->count_irq++;
+	spin_unlock_irqrestore(&bcm2079x_dev->irq_enabled_lock, flags);
+	wake_up(&bcm2079x_dev->read_wq);
+
+	return IRQ_HANDLED;
+}
+
+static unsigned int bcm2079x_dev_poll(struct file *filp, poll_table *wait)
+{
+	struct bcm2079x_dev *bcm2079x_dev = filp->private_data;
+	unsigned int mask = 0;
+	unsigned long flags;
+
+	poll_wait(filp, &bcm2079x_dev->read_wq, wait);
+
+	spin_lock_irqsave(&bcm2079x_dev->irq_enabled_lock, flags);
+	if (bcm2079x_dev->count_irq > 0)
+	{
+		bcm2079x_dev->count_irq--;
+		mask |= POLLIN | POLLRDNORM;
+	}
+	spin_unlock_irqrestore(&bcm2079x_dev->irq_enabled_lock, flags);
+
+	return mask;
+}
+
+static ssize_t bcm2079x_dev_read(struct file *filp, char __user *buf,
+				  size_t count, loff_t *offset)
+{
+	struct bcm2079x_dev *bcm2079x_dev = filp->private_data;
+	unsigned char tmp[MAX_BUFFER_SIZE];
+	int total, len, ret;
+
+	total = 0;
+	len = 0;
+
+	if (count > MAX_BUFFER_SIZE)
+		count = MAX_BUFFER_SIZE;
+
+	mutex_lock(&bcm2079x_dev->read_mutex);
+
+	/** Read the first 4 bytes to include the length of the NCI or HCI packet.
+	**/
+	ret = i2c_master_recv(bcm2079x_dev->client, tmp, 4);
+	if (ret == 4) {
+		total = ret;
+		/** First byte is the packet type
+		**/
+		switch(tmp[0]) {
+			case PACKET_TYPE_NCI:
+				len = tmp[PACKET_HEADER_SIZE_NCI-1];
+				break;
+
+			case PACKET_TYPE_HCIEV:
+				len = tmp[PACKET_HEADER_SIZE_HCI-1];
+				if (len == 0)
+					total--;/*Since payload is 0, decrement total size (from 4 to 3) */
+				else
+					len--;/*First byte of payload is in tmp[3] already */
+				break;
+
+			default:
+				len = 0;/*Unknown packet byte */
+				break;
+		} /* switch*/
+
+		/** make sure full packet fits in the buffer
+		**/
+		if (len > 0 && (len + total) <= count) {
+			/** read the remainder of the packet.
+			**/
+			ret = i2c_master_recv(bcm2079x_dev->client, tmp+total, len);
+			if (ret == len)
+				total += len;
+		} /* if */
+	} /* if */
+
+	mutex_unlock(&bcm2079x_dev->read_mutex);
+
+	if (total > count || copy_to_user(buf, tmp, total)) {
+		dev_err(&bcm2079x_dev->client->dev,
+			"failed to copy to user space, total = %d\n", total);
+		total = -EFAULT;
+	}
+
+	return total;
+}
+
+static ssize_t bcm2079x_dev_write(struct file *filp, const char __user *buf,
+				   size_t count, loff_t *offset)
+{
+	struct bcm2079x_dev *bcm2079x_dev = filp->private_data;
+	char tmp[MAX_BUFFER_SIZE];
+	int ret;
+
+	if (count > MAX_BUFFER_SIZE) {
+		dev_err(&bcm2079x_dev->client->dev, "out of memory\n");
+		return -ENOMEM;
+	}
+
+	if (copy_from_user(tmp, buf, count)) {
+		dev_err(&bcm2079x_dev->client->dev,
+			"failed to copy from user space\n");
+		return -EFAULT;
+	}
+
+	mutex_lock(&bcm2079x_dev->read_mutex);
+	/* Write data */
+
+	ret = i2c_master_send(bcm2079x_dev->client, tmp, count);
+	if (ret != count) {
+		dev_err(&bcm2079x_dev->client->dev,
+			"failed to write %d\n", ret);
+		ret = -EIO;
+	}
+	mutex_unlock(&bcm2079x_dev->read_mutex);
+
+	return ret;
+}
+
+static int bcm2079x_dev_open(struct inode *inode, struct file *filp)
+{
+	int ret = 0;
+
+	struct bcm2079x_dev *bcm2079x_dev = container_of(filp->private_data,
+							   struct bcm2079x_dev,
+							   bcm2079x_device);
+	filp->private_data = bcm2079x_dev;
+	bcm2079x_init_stat(bcm2079x_dev);
+	bcm2079x_enable_irq(bcm2079x_dev);
+	dev_info(&bcm2079x_dev->client->dev,
+		 "%d,%d\n", imajor(inode), iminor(inode));
+
+	return ret;
+}
+
+static long bcm2079x_dev_unlocked_ioctl(struct file *filp,
+					 unsigned int cmd, unsigned long arg)
+{
+	struct bcm2079x_dev *bcm2079x_dev = filp->private_data;
+
+	switch (cmd) {
+	case BCMNFC_READ_FULL_PACKET:
+		break;
+	case BCMNFC_READ_MULTI_PACKETS:
+		break;
+	case BCMNFC_CHANGE_ADDR:
+		dev_info(&bcm2079x_dev->client->dev,
+			 "%s, BCMNFC_CHANGE_ADDR (%x, %lx):\n", __func__, cmd,
+			 arg);
+		change_client_addr(bcm2079x_dev, arg);
+		break;
+	case BCMNFC_POWER_CTL:
+		gpio_set_value(bcm2079x_dev->en_gpio, arg);
+		break;
+	case BCMNFC_WAKE_CTL:
+		gpio_set_value(bcm2079x_dev->wake_gpio, arg);
+		break;
+	default:
+		dev_err(&bcm2079x_dev->client->dev,
+			"%s, unknown cmd (%x, %lx)\n", __func__, cmd, arg);
+		return 0;
+	}
+
+	return 0;
+}
+
+static const struct file_operations bcm2079x_dev_fops = {
+	.owner = THIS_MODULE,
+	.llseek = no_llseek,
+	.poll = bcm2079x_dev_poll,
+	.read = bcm2079x_dev_read,
+	.write = bcm2079x_dev_write,
+	.open = bcm2079x_dev_open,
+	.unlocked_ioctl = bcm2079x_dev_unlocked_ioctl
+};
+
+static int bcm2079x_probe(struct i2c_client *client,
+			   const struct i2c_device_id *id)
+{
+	int ret;
+	struct bcm2079x_platform_data *platform_data;
+	struct bcm2079x_dev *bcm2079x_dev;
+
+	platform_data = client->dev.platform_data;
+
+	dev_info(&client->dev, "%s, probing bcm2079x driver flags = %x\n", __func__, client->flags);
+	if (platform_data == NULL) {
+		dev_err(&client->dev, "nfc probe fail\n");
+		return -ENODEV;
+	}
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+		dev_err(&client->dev, "need I2C_FUNC_I2C\n");
+		return -ENODEV;
+	}
+
+	ret = gpio_request_one(platform_data->irq_gpio, GPIOF_IN, "nfc_int");
+	if (ret)
+		return -ENODEV;
+	ret = gpio_request_one(platform_data->en_gpio, GPIOF_OUT_INIT_LOW, "nfc_ven");
+	if (ret)
+		goto err_en;
+	ret = gpio_request_one(platform_data->wake_gpio, GPIOF_OUT_INIT_LOW,"nfc_firm");
+	if (ret)
+		goto err_firm;
+
+	gpio_set_value(platform_data->en_gpio, 0);
+	gpio_set_value(platform_data->wake_gpio, 0);
+
+	bcm2079x_dev = kzalloc(sizeof(*bcm2079x_dev), GFP_KERNEL);
+	if (bcm2079x_dev == NULL) {
+		dev_err(&client->dev,
+			"failed to allocate memory for module data\n");
+		ret = -ENOMEM;
+		goto err_exit;
+	}
+
+	bcm2079x_dev->wake_gpio = platform_data->wake_gpio;
+	bcm2079x_dev->irq_gpio = platform_data->irq_gpio;
+	bcm2079x_dev->en_gpio = platform_data->en_gpio;
+	bcm2079x_dev->client = client;
+
+	/* init mutex and queues */
+	init_waitqueue_head(&bcm2079x_dev->read_wq);
+	mutex_init(&bcm2079x_dev->read_mutex);
+	spin_lock_init(&bcm2079x_dev->irq_enabled_lock);
+
+	bcm2079x_dev->bcm2079x_device.minor = MISC_DYNAMIC_MINOR;
+	bcm2079x_dev->bcm2079x_device.name = "bcm2079x-i2c";
+	bcm2079x_dev->bcm2079x_device.fops = &bcm2079x_dev_fops;
+
+	ret = misc_register(&bcm2079x_dev->bcm2079x_device);
+	if (ret) {
+		dev_err(&client->dev, "misc_register failed\n");
+		goto err_misc_register;
+	}
+
+	/* request irq.  the irq is set whenever the chip has data available
+	 * for reading.  it is cleared when all data has been read.
+	 */
+	dev_info(&client->dev, "requesting IRQ %d\n", client->irq);
+	bcm2079x_dev->irq_enabled = true;
+	ret = request_irq(client->irq, bcm2079x_dev_irq_handler,
+			  IRQF_TRIGGER_RISING, client->name, bcm2079x_dev);
+	if (ret) {
+		dev_err(&client->dev, "request_irq failed\n");
+		goto err_request_irq_failed;
+	}
+	bcm2079x_disable_irq(bcm2079x_dev);
+	i2c_set_clientdata(client, bcm2079x_dev);
+	dev_info(&client->dev,
+		 "%s, probing bcm2079x driver exited successfully\n",
+		 __func__);
+	return 0;
+
+err_request_irq_failed:
+	misc_deregister(&bcm2079x_dev->bcm2079x_device);
+err_misc_register:
+	mutex_destroy(&bcm2079x_dev->read_mutex);
+	kfree(bcm2079x_dev);
+err_exit:
+	gpio_free(platform_data->wake_gpio);
+err_firm:
+	gpio_free(platform_data->en_gpio);
+err_en:
+	gpio_free(platform_data->irq_gpio);
+	return ret;
+}
+
+static int bcm2079x_remove(struct i2c_client *client)
+{
+	struct bcm2079x_dev *bcm2079x_dev;
+
+	bcm2079x_dev = i2c_get_clientdata(client);
+	free_irq(client->irq, bcm2079x_dev);
+	misc_deregister(&bcm2079x_dev->bcm2079x_device);
+	mutex_destroy(&bcm2079x_dev->read_mutex);
+	gpio_free(bcm2079x_dev->irq_gpio);
+	gpio_free(bcm2079x_dev->en_gpio);
+	gpio_free(bcm2079x_dev->wake_gpio);
+	kfree(bcm2079x_dev);
+
+	return 0;
+}
+
+static const struct i2c_device_id bcm2079x_id[] = {
+	{"bcm2079x-i2c", 0},
+	{}
+};
+
+static struct i2c_driver bcm2079x_driver = {
+	.id_table = bcm2079x_id,
+	.probe = bcm2079x_probe,
+	.remove = bcm2079x_remove,
+	.driver = {
+		.owner = THIS_MODULE,
+		.name = "bcm2079x-i2c",
+	},
+};
+
+/*
+ * module load/unload record keeping
+ */
+
+static int __init bcm2079x_dev_init(void)
+{
+	return i2c_add_driver(&bcm2079x_driver);
+}
+module_init(bcm2079x_dev_init);
+
+static void __exit bcm2079x_dev_exit(void)
+{
+	i2c_del_driver(&bcm2079x_driver);
+}
+module_exit(bcm2079x_dev_exit);
+
+MODULE_AUTHOR("Broadcom");
+MODULE_DESCRIPTION("NFC bcm2079x driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/nfc/bcm2079x.h b/include/linux/nfc/bcm2079x.h
new file mode 100644
index 0000000..359a008
--- /dev/null
+++ b/include/linux/nfc/bcm2079x.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 Broadcom Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _BCM2079X_H
+#define _BCM2079X_H
+
+#define BCMNFC_MAGIC	0xFA
+
+/*
+ * BCMNFC power control via ioctl
+ * BCMNFC_POWER_CTL(0): power off
+ * BCMNFC_POWER_CTL(1): power on
+ * BCMNFC_WAKE_CTL(0): wake off
+ * BCMNFC_WAKE_CTL(1): wake on
+ */
+#define BCMNFC_POWER_CTL		_IO(BCMNFC_MAGIC, 0x01)
+#define BCMNFC_CHANGE_ADDR		_IO(BCMNFC_MAGIC, 0x02)
+#define BCMNFC_READ_FULL_PACKET		_IO(BCMNFC_MAGIC, 0x03)
+#define BCMNFC_SET_WAKE_ACTIVE_STATE	_IO(BCMNFC_MAGIC, 0x04)
+#define BCMNFC_WAKE_CTL			_IO(BCMNFC_MAGIC, 0x05)
+#define BCMNFC_READ_MULTI_PACKETS	_IO(BCMNFC_MAGIC, 0x06)
+
+struct bcm2079x_platform_data {
+	unsigned int irq_gpio;
+	unsigned int en_gpio;
+	int wake_gpio;
+};
+
+#endif