Initial Contribution

msm-2.6.38: tag AU_LINUX_ANDROID_GINGERBREAD.02.03.04.00.142

Signed-off-by: Bryan Huntsman <bryanh@codeaurora.org>
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index b4dee9d..0822866 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -394,6 +394,24 @@
 	  To compile this driver as a module, choose M here; the
 	  module will be called opencores-kbd.
 
+config KEYBOARD_PM8058
+	bool "Qualcomm PM8058 Matrix Keypad support"
+	depends on PM8058
+	help
+	  Say Y here to enable the driver for the keypad matrix interface
+	  on the Qualcomm PM8058 power management I/C device.
+
+config KEYBOARD_PMIC8XXX
+	tristate "Qualcomm PMIC8XXX keypad support"
+	depends on MFD_PM8XXX
+	help
+	  Say Y here if you want to enable the driver for the PMIC8XXX
+	  keypad provided as a reference design from Qualcomm. This is intended
+	  to support upto 18x8 matrix based keypad design.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called pmic8xxx-keypad.
+
 config KEYBOARD_PXA27x
 	tristate "PXA27x/PXA3xx keypad support"
 	depends on PXA27x || PXA3xx || ARCH_MMP
@@ -553,6 +571,30 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called xtkbd.
 
+config KEYBOARD_QCIKBD
+   tristate "Quanta Computer Inc. keyboard"
+   depends on I2C
+   default n
+   help
+     Say Y here if you want to use the Quanta keyboard driver for ST 1.5
+     platform.
+
+config KEYBOARD_QCIKBD_REPEAT
+	bool "Enable Quanta Computer Inc. keyboard key repeat feature"
+	depends on KEYBOARD_QCIKBD
+	default n
+	help
+	  Say Y here if you want to enable Quanta keyboard driver's key repeat
+	  feature.
+
+config KEYBOARD_QCIKBD_LID
+	bool "Enable lid event for Quanta Computer Inc. keyboard"
+	depends on KEYBOARD_QCIKBD
+	default n
+	help
+	  Say Y here if you want to register lid event in Quanta keyboard
+	  driver.
+
 config KEYBOARD_W90P910
 	tristate "W90P910 Matrix Keypad support"
 	depends on ARCH_W90X900
@@ -563,4 +605,28 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called w90p910_keypad.
 
+config KEYBOARD_PMIC8058
+	tristate "Qualcomm PMIC8058 keypad"
+	depends on PMIC8058
+	default y
+	help
+	  Say Y here if you want to enable the driver for the PMIC8058
+	  keypad provided as a reference design from Qualcomm. This is intended
+	  to support upto 18x8 matrix based keypad design.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called pmic8058-keypad.
 endif
+config KEYBOARD_PMIC8058
+        tristate "Qualcomm PMIC8058 keypad"
+        depends on PMIC8058
+        default y
+        help
+          Say Y here if you want to enable the driver for the PMIC8058
+          keypad provided as a reference design from Qualcomm. This is intended
+          to support upto 18x8 matrix based keypad design.
+
+          To compile this driver as a module, choose M here: the module will
+          be called pmic8058-keypad.
+
+
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index ddde0fd..cf4c058 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -34,6 +34,7 @@
 obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
 obj-$(CONFIG_KEYBOARD_OMAP4)		+= omap4-keypad.o
 obj-$(CONFIG_KEYBOARD_OPENCORES)	+= opencores-kbd.o
+obj-$(CONFIG_KEYBOARD_PM8058)		+= pm8058-keypad.o
 obj-$(CONFIG_KEYBOARD_PMIC8XXX)		+= pmic8xxx-keypad.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keypad.o
 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY)	+= pxa930_rotary.o
@@ -50,4 +51,6 @@
 obj-$(CONFIG_KEYBOARD_TNETV107X)	+= tnetv107x-keypad.o
 obj-$(CONFIG_KEYBOARD_TWL4030)		+= twl4030_keypad.o
 obj-$(CONFIG_KEYBOARD_XTKBD)		+= xtkbd.o
+obj-$(CONFIG_KEYBOARD_QCIKBD)       += qci_kbd.o
 obj-$(CONFIG_KEYBOARD_W90P910)		+= w90p910_keypad.o
+obj-$(CONFIG_KEYBOARD_PMIC8058)		+= pmic8058-keypad.o
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index b02e426..c7aa2ce 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -334,20 +334,21 @@
 				matrix_keypad_interrupt,
 				pdata->clustered_irq_flags,
 				"matrix-keypad", keypad);
-		if (err) {
+		if (err < 0) {
 			dev_err(&pdev->dev,
 				"Unable to acquire clustered interrupt\n");
 			goto err_free_rows;
 		}
 	} else {
 		for (i = 0; i < pdata->num_row_gpios; i++) {
-			err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
+			err = request_any_context_irq(
+					gpio_to_irq(pdata->row_gpios[i]),
 					matrix_keypad_interrupt,
 					IRQF_DISABLED |
 					IRQF_TRIGGER_RISING |
 					IRQF_TRIGGER_FALLING,
 					"matrix-keypad", keypad);
-			if (err) {
+			if (err < 0) {
 				dev_err(&pdev->dev,
 					"Unable to acquire interrupt "
 					"for GPIO line %i\n",
diff --git a/drivers/input/keyboard/pmic8058-keypad.c b/drivers/input/keyboard/pmic8058-keypad.c
new file mode 100644
index 0000000..9c7588e
--- /dev/null
+++ b/drivers/input/keyboard/pmic8058-keypad.c
@@ -0,0 +1,948 @@
+/* Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/bitops.h>
+#include <linux/mfd/pmic8058.h>
+#include <linux/delay.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/pm.h>
+#include <linux/pm_runtime.h>
+
+#include <linux/input/pmic8058-keypad.h>
+
+#define PM8058_MAX_ROWS		18
+#define PM8058_MAX_COLS		8
+#define PM8058_ROW_SHIFT	3
+#define PM8058_MATRIX_MAX_SIZE	(PM8058_MAX_ROWS * PM8058_MAX_COLS)
+
+#define PM8058_MIN_ROWS		5
+#define PM8058_MIN_COLS		5
+
+#define MAX_SCAN_DELAY		128
+#define MIN_SCAN_DELAY		1
+
+/* in nanoseconds */
+#define MAX_ROW_HOLD_DELAY	122000
+#define MIN_ROW_HOLD_DELAY	30500
+
+#define MAX_DEBOUNCE_B0_TIME	20
+#define MIN_DEBOUNCE_B0_TIME	5
+
+#define MAX_DEBOUNCE_A0_TIME	8
+#define MIN_DEBOUNCE_A0_TIME	1
+
+#define KEYP_CTRL			0x148
+
+#define KEYP_CTRL_EVNTS			BIT(0)
+#define KEYP_CTRL_EVNTS_MASK		0x3
+
+#define KEYP_CTRL_SCAN_COLS_SHIFT	5
+#define KEYP_CTRL_SCAN_COLS_MIN		5
+#define KEYP_CTRL_SCAN_COLS_BITS	0x3
+
+#define KEYP_CTRL_SCAN_ROWS_SHIFT	2
+#define KEYP_CTRL_SCAN_ROWS_MIN		5
+#define KEYP_CTRL_SCAN_ROWS_BITS	0x7
+
+#define KEYP_CTRL_KEYP_EN		BIT(7)
+
+#define KEYP_SCAN			0x149
+
+#define KEYP_SCAN_READ_STATE		BIT(0)
+#define KEYP_SCAN_DBOUNCE_SHIFT		1
+#define KEYP_SCAN_PAUSE_SHIFT		3
+#define KEYP_SCAN_ROW_HOLD_SHIFT	6
+
+#define KEYP_TEST			0x14A
+
+#define KEYP_TEST_CLEAR_RECENT_SCAN	BIT(6)
+#define KEYP_TEST_CLEAR_OLD_SCAN	BIT(5)
+#define KEYP_TEST_READ_RESET		BIT(4)
+#define KEYP_TEST_DTEST_EN		BIT(3)
+#define KEYP_TEST_ABORT_READ		BIT(0)
+
+#define KEYP_TEST_DBG_SELECT_SHIFT	1
+
+/* bits of these register represent
+ * '0' for key press
+ * '1' for key release
+ */
+#define KEYP_RECENT_DATA		0x14B
+#define KEYP_OLD_DATA			0x14C
+
+#define KEYP_CLOCK_FREQ			32768
+
+/* Internal flags */
+#define KEYF_FIX_LAST_ROW		0x01
+
+
+/* ---------------------------------------------------------------------*/
+struct pmic8058_kp {
+	const struct pmic8058_keypad_data *pdata;
+	struct input_dev *input;
+	int key_sense_irq;
+	int key_stuck_irq;
+
+	unsigned short *keycodes;
+
+	struct device *dev;
+	u16 keystate[PM8058_MAX_ROWS];
+	u16 stuckstate[PM8058_MAX_ROWS];
+
+	u32	flags;
+	struct pm8058_chip	*pm_chip;
+
+	/* protect read/write */
+	struct mutex		mutex;
+	bool			user_disabled;
+	u32			disable_depth;
+
+	u8			ctrl_reg;
+};
+
+static int pmic8058_kp_write_u8(struct pmic8058_kp *kp,
+				 u8 data, u16 reg)
+{
+	int rc;
+
+	rc = pm8058_write(kp->pm_chip, reg, &data, 1);
+	if (rc < 0)
+		dev_warn(kp->dev, "Error writing pmic8058: %X - ret %X\n",
+				reg, rc);
+	return rc;
+}
+
+static int pmic8058_kp_read(struct pmic8058_kp *kp,
+				 u8 *data, u16 reg, unsigned num_bytes)
+{
+	int rc;
+
+	rc = pm8058_read(kp->pm_chip, reg, data, num_bytes);
+	if (rc < 0)
+		dev_warn(kp->dev, "Error reading pmic8058: %X - ret %X\n",
+				reg, rc);
+
+	return rc;
+}
+
+static int pmic8058_kp_read_u8(struct pmic8058_kp *kp,
+				 u8 *data, u16 reg)
+{
+	int rc;
+
+	rc = pmic8058_kp_read(kp, data, reg, 1);
+	if (rc < 0)
+		dev_warn(kp->dev, "Error reading pmic8058: %X - ret %X\n",
+				reg, rc);
+	return rc;
+}
+
+static u8 pmic8058_col_state(struct pmic8058_kp *kp, u8 col)
+{
+	/* all keys pressed on that particular row? */
+	if (col == 0x00)
+		return 1 << kp->pdata->num_cols;
+	else
+		return col & ((1 << kp->pdata->num_cols) - 1);
+}
+/* REVISIT: just for debugging, will be removed in final working version */
+static void __dump_kp_regs(struct pmic8058_kp *kp, char *msg)
+{
+	u8 temp;
+
+	dev_dbg(kp->dev, "%s\n", msg);
+
+	pmic8058_kp_read_u8(kp, &temp, KEYP_CTRL);
+	dev_dbg(kp->dev, "KEYP_CTRL - %X\n", temp);
+	pmic8058_kp_read_u8(kp, &temp, KEYP_SCAN);
+	dev_dbg(kp->dev, "KEYP_SCAN - %X\n", temp);
+	pmic8058_kp_read_u8(kp, &temp, KEYP_TEST);
+	dev_dbg(kp->dev, "KEYP_TEST - %X\n", temp);
+}
+
+/* H/W constraint:
+ * One should read recent/old data registers equal to the
+ * number of columns programmed in the keyp_control register,
+ * otherwise h/w state machine may get stuck. In order to avoid this
+ * situation one should check readstate bit in keypad scan
+ * register to be '0' at the end of data read, to make sure
+ * the keypad state machine is not in READ state.
+ */
+static int pmic8058_chk_read_state(struct pmic8058_kp *kp, u16 data_reg)
+{
+	u8 temp, scan_val;
+	int retries = 10, rc;
+
+	do {
+		rc = pmic8058_kp_read_u8(kp, &scan_val, KEYP_SCAN);
+		if (scan_val & 0x1)
+			rc = pmic8058_kp_read_u8(kp, &temp, data_reg);
+	} while ((scan_val & 0x1) && (--retries > 0));
+
+	if (retries == 0)
+		dev_dbg(kp->dev, "Unable to clear read state bit\n");
+
+	return 0;
+}
+/*
+ * Synchronous read protocol for RevB0 onwards:
+ *
+ * 1. Write '1' to ReadState bit in KEYP_SCAN register
+ * 2. Wait 2*32KHz clocks, so that HW can successfully enter read mode
+ *    synchronously
+ * 3. Read rows in old array first if events are more than one
+ * 4. Read rows in recent array
+ * 5. Wait 4*32KHz clocks
+ * 6. Write '0' to ReadState bit of KEYP_SCAN register so that hw can
+ *    synchronously exit read mode.
+ */
+static int pmic8058_chk_sync_read(struct pmic8058_kp *kp)
+{
+	int rc;
+	u8 scan_val;
+
+	rc = pmic8058_kp_read_u8(kp, &scan_val, KEYP_SCAN);
+	scan_val |= 0x1;
+	rc = pmic8058_kp_write_u8(kp, scan_val, KEYP_SCAN);
+
+	/* 2 * 32KHz clocks */
+	udelay((2 * USEC_PER_SEC / KEYP_CLOCK_FREQ) + 1);
+
+	return rc;
+}
+
+static int pmic8058_kp_read_data(struct pmic8058_kp *kp, u16 *state,
+					u16 data_reg, int read_rows)
+{
+	int rc, row;
+	u8 new_data[PM8058_MAX_ROWS];
+
+	rc = pmic8058_kp_read(kp, new_data, data_reg, read_rows);
+
+	if (!rc) {
+		if (pm8058_rev(kp->pm_chip) == PM_8058_REV_1p0)
+			pmic8058_chk_read_state(kp, data_reg);
+		for (row = 0; row < kp->pdata->num_rows; row++) {
+			dev_dbg(kp->dev, "new_data[%d] = %d\n", row,
+						new_data[row]);
+			state[row] = pmic8058_col_state(kp, new_data[row]);
+		}
+	}
+
+	return rc;
+}
+
+static int pmic8058_kp_read_matrix(struct pmic8058_kp *kp, u16 *new_state,
+					 u16 *old_state)
+{
+	int rc, read_rows;
+	u8 scan_val;
+	static u8 rows[] = {
+		5, 6, 7, 8, 10, 10, 12, 12, 15, 15, 15, 18, 18, 18
+	};
+
+	if (kp->flags & KEYF_FIX_LAST_ROW &&
+			(kp->pdata->num_rows != PM8058_MAX_ROWS))
+		read_rows = rows[kp->pdata->num_rows - KEYP_CTRL_SCAN_ROWS_MIN
+					 + 1];
+	else
+		read_rows = kp->pdata->num_rows;
+
+	if (pm8058_rev(kp->pm_chip) > PM_8058_REV_1p0)
+		pmic8058_chk_sync_read(kp);
+
+	if (old_state)
+		rc = pmic8058_kp_read_data(kp, old_state, KEYP_OLD_DATA,
+						read_rows);
+
+	rc = pmic8058_kp_read_data(kp, new_state, KEYP_RECENT_DATA,
+					 read_rows);
+
+	if (pm8058_rev(kp->pm_chip) > PM_8058_REV_1p0) {
+		/* 4 * 32KHz clocks */
+		udelay((4 * USEC_PER_SEC / KEYP_CLOCK_FREQ) + 1);
+
+		rc = pmic8058_kp_read(kp, &scan_val, KEYP_SCAN, 1);
+		scan_val &= 0xFE;
+		rc = pmic8058_kp_write_u8(kp, scan_val, KEYP_SCAN);
+	}
+
+	return rc;
+}
+
+static int __pmic8058_kp_scan_matrix(struct pmic8058_kp *kp, u16 *new_state,
+					 u16 *old_state)
+{
+	int row, col, code;
+
+	for (row = 0; row < kp->pdata->num_rows; row++) {
+		int bits_changed = new_state[row] ^ old_state[row];
+
+		if (!bits_changed)
+			continue;
+
+		for (col = 0; col < kp->pdata->num_cols; col++) {
+			if (!(bits_changed & (1 << col)))
+				continue;
+
+			dev_dbg(kp->dev, "key [%d:%d] %s\n", row, col,
+					!(new_state[row] & (1 << col)) ?
+					"pressed" : "released");
+
+			code = MATRIX_SCAN_CODE(row, col, PM8058_ROW_SHIFT);
+			input_event(kp->input, EV_MSC, MSC_SCAN, code);
+			input_report_key(kp->input,
+					kp->keycodes[code],
+					!(new_state[row] & (1 << col)));
+
+			input_sync(kp->input);
+		}
+	}
+
+	return 0;
+}
+
+static int pmic8058_detect_ghost_keys(struct pmic8058_kp *kp, u16 *new_state)
+{
+	int row, found_first = -1;
+	u16 check, row_state;
+
+	check = 0;
+	for (row = 0; row < kp->pdata->num_rows; row++) {
+		row_state = (~new_state[row]) &
+				 ((1 << kp->pdata->num_cols) - 1);
+
+		if (hweight16(row_state) > 1) {
+			if (found_first == -1)
+				found_first = row;
+			if (check & row_state) {
+				dev_dbg(kp->dev, "detected ghost key on row[%d]"
+						 "row[%d]\n", found_first, row);
+				return 1;
+			}
+		}
+		check |= row_state;
+	}
+	return 0;
+}
+
+static int pmic8058_kp_scan_matrix(struct pmic8058_kp *kp, unsigned int events)
+{
+	u16 new_state[PM8058_MAX_ROWS];
+	u16 old_state[PM8058_MAX_ROWS];
+	int rc;
+
+	switch (events) {
+	case 0x1:
+		rc = pmic8058_kp_read_matrix(kp, new_state, NULL);
+		if (pmic8058_detect_ghost_keys(kp, new_state))
+			return -EINVAL;
+		__pmic8058_kp_scan_matrix(kp, new_state, kp->keystate);
+		memcpy(kp->keystate, new_state, sizeof(new_state));
+	break;
+	case 0x3: /* two events - eventcounter is gray-coded */
+		rc = pmic8058_kp_read_matrix(kp, new_state, old_state);
+		__pmic8058_kp_scan_matrix(kp, old_state, kp->keystate);
+		__pmic8058_kp_scan_matrix(kp, new_state, old_state);
+		memcpy(kp->keystate, new_state, sizeof(new_state));
+	break;
+	case 0x2:
+		dev_dbg(kp->dev, "Some key events are missed\n");
+		rc = pmic8058_kp_read_matrix(kp, new_state, old_state);
+		__pmic8058_kp_scan_matrix(kp, old_state, kp->keystate);
+		__pmic8058_kp_scan_matrix(kp, new_state, old_state);
+		memcpy(kp->keystate, new_state, sizeof(new_state));
+	break;
+	default:
+		rc = -1;
+	}
+	return rc;
+}
+
+static inline int pmic8058_kp_disabled(struct pmic8058_kp *kp)
+{
+	return kp->disable_depth != 0;
+}
+
+static void pmic8058_kp_enable(struct pmic8058_kp *kp)
+{
+	if (!pmic8058_kp_disabled(kp))
+		return;
+
+	if (--kp->disable_depth == 0) {
+
+		kp->ctrl_reg |= KEYP_CTRL_KEYP_EN;
+		pmic8058_kp_write_u8(kp, kp->ctrl_reg, KEYP_CTRL);
+
+		enable_irq(kp->key_sense_irq);
+		enable_irq(kp->key_stuck_irq);
+	}
+}
+
+static void pmic8058_kp_disable(struct pmic8058_kp *kp)
+{
+	if (kp->disable_depth++ == 0) {
+		disable_irq(kp->key_sense_irq);
+		disable_irq(kp->key_stuck_irq);
+
+		kp->ctrl_reg &= ~KEYP_CTRL_KEYP_EN;
+		pmic8058_kp_write_u8(kp, kp->ctrl_reg, KEYP_CTRL);
+	}
+}
+
+static ssize_t pmic8058_kp_disable_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct pmic8058_kp *kp = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", pmic8058_kp_disabled(kp));
+}
+
+static ssize_t pmic8058_kp_disable_store(struct device *dev,
+					struct device_attribute *attr,
+					const char *buf, size_t count)
+{
+	struct pmic8058_kp *kp = dev_get_drvdata(dev);
+	long i = 0;
+	int rc;
+
+	rc = strict_strtoul(buf, 10, &i);
+	if (rc)
+		return -EINVAL;
+
+	i = !!i;
+
+	mutex_lock(&kp->mutex);
+	if (i == kp->user_disabled) {
+		mutex_unlock(&kp->mutex);
+		return count;
+	}
+
+	kp->user_disabled = i;
+
+	if (i)
+		pmic8058_kp_disable(kp);
+	else
+		pmic8058_kp_enable(kp);
+	mutex_unlock(&kp->mutex);
+
+	return count;
+}
+
+static DEVICE_ATTR(disable_kp, 0664, pmic8058_kp_disable_show,
+			pmic8058_kp_disable_store);
+
+
+/*
+ * NOTE: We are reading recent and old data registers blindly
+ * whenever key-stuck interrupt happens, because events counter doesn't
+ * get updated when this interrupt happens due to key stuck doesn't get
+ * considered as key state change.
+ *
+ * We are not using old data register contents after they are being read
+ * because it might report the key which was pressed before the key being stuck
+ * as stuck key because it's pressed status is stored in the old data
+ * register.
+ */
+static irqreturn_t pmic8058_kp_stuck_irq(int irq, void *data)
+{
+	u16 new_state[PM8058_MAX_ROWS];
+	u16 old_state[PM8058_MAX_ROWS];
+	int rc;
+	struct pmic8058_kp *kp = data;
+
+	rc = pmic8058_kp_read_matrix(kp, new_state, old_state);
+	__pmic8058_kp_scan_matrix(kp, new_state, kp->stuckstate);
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * NOTE: Any row multiple interrupt issue - PMIC4 Rev A0
+ *
+ * If the S/W responds to the key-event interrupt too early and reads the
+ * recent data, the keypad FSM will mistakenly go to the IDLE state, instead
+ * of the scan pause state as it is supposed too. Since the key is still
+ * pressed, the keypad scanner will go through the debounce, scan, and generate
+ * another key event interrupt. The workaround for this issue is to add delay
+ * of 1ms between servicing the key event interrupt and reading the recent data.
+ */
+static irqreturn_t pmic8058_kp_irq(int irq, void *data)
+{
+	struct pmic8058_kp *kp = data;
+	u8 ctrl_val, events;
+	int rc;
+
+	if (pm8058_rev(kp->pm_chip) == PM_8058_REV_1p0)
+		mdelay(1);
+
+	dev_dbg(kp->dev, "key sense irq\n");
+	__dump_kp_regs(kp, "pmic8058_kp_irq");
+
+	rc = pmic8058_kp_read(kp, &ctrl_val, KEYP_CTRL, 1);
+	events = ctrl_val & KEYP_CTRL_EVNTS_MASK;
+
+	rc = pmic8058_kp_scan_matrix(kp, events);
+
+	return IRQ_HANDLED;
+}
+/*
+ * NOTE: Last row multi-interrupt issue
+ *
+ * In PMIC Rev A0, if any key in the last row of the keypad matrix
+ * is pressed and held, the H/W keeps on generating interrupts.
+ * Software work-arounds it by programming the keypad controller next level
+ * up rows (for 8x12 matrix it is 15 rows) so the keypad controller
+ * thinks of more-rows than the actual ones, so the actual last-row
+ * in the matrix won't generate multiple interrupts.
+ */
+static int pmic8058_kpd_init(struct pmic8058_kp *kp)
+{
+	int bits, rc, cycles;
+	u8 scan_val = 0, ctrl_val = 0;
+	static u8 row_bits[] = {
+		0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7,
+	};
+
+	/* Find column bits */
+	if (kp->pdata->num_cols < KEYP_CTRL_SCAN_COLS_MIN)
+		bits = 0;
+	else
+		bits = kp->pdata->num_cols - KEYP_CTRL_SCAN_COLS_MIN;
+	ctrl_val = (bits & KEYP_CTRL_SCAN_COLS_BITS) <<
+		KEYP_CTRL_SCAN_COLS_SHIFT;
+
+	/* Find row bits */
+	if (kp->pdata->num_rows < KEYP_CTRL_SCAN_ROWS_MIN)
+		bits = 0;
+	else if (kp->pdata->num_rows > PM8058_MAX_ROWS)
+		bits = KEYP_CTRL_SCAN_ROWS_BITS;
+	else
+		bits = row_bits[kp->pdata->num_rows - KEYP_CTRL_SCAN_ROWS_MIN];
+
+	/* Use max rows to fix last row problem if actual rows are less */
+	if (kp->flags & KEYF_FIX_LAST_ROW &&
+			 (kp->pdata->num_rows != PM8058_MAX_ROWS))
+		bits = row_bits[kp->pdata->num_rows - KEYP_CTRL_SCAN_ROWS_MIN
+					 + 1];
+
+	ctrl_val |= (bits << KEYP_CTRL_SCAN_ROWS_SHIFT);
+
+	rc = pmic8058_kp_write_u8(kp, ctrl_val, KEYP_CTRL);
+
+	if (pm8058_rev(kp->pm_chip) == PM_8058_REV_1p0)
+		bits = fls(kp->pdata->debounce_ms[0]) - 1;
+	else
+		bits = (kp->pdata->debounce_ms[1] / 5) - 1;
+
+	scan_val |= (bits << KEYP_SCAN_DBOUNCE_SHIFT);
+
+	bits = fls(kp->pdata->scan_delay_ms) - 1;
+	scan_val |= (bits << KEYP_SCAN_PAUSE_SHIFT);
+
+	/* Row hold time is a multiple of 32KHz cycles. */
+	cycles = (kp->pdata->row_hold_ns * KEYP_CLOCK_FREQ) / NSEC_PER_SEC;
+
+	scan_val |= (cycles << KEYP_SCAN_ROW_HOLD_SHIFT);
+
+	rc = pmic8058_kp_write_u8(kp, scan_val, KEYP_SCAN);
+
+	return rc;
+}
+
+static int pm8058_kp_config_drv(int gpio_start, int num_gpios)
+{
+	int	rc;
+	struct pm8058_gpio kypd_drv = {
+		.direction	= PM_GPIO_DIR_OUT,
+		.output_buffer	= PM_GPIO_OUT_BUF_OPEN_DRAIN,
+		.output_value	= 0,
+		.pull		= PM_GPIO_PULL_NO,
+		.vin_sel	= 2,
+		.out_strength	= PM_GPIO_STRENGTH_LOW,
+		.function	= PM_GPIO_FUNC_1,
+		.inv_int_pol	= 1,
+	};
+
+	if (gpio_start < 0 || num_gpios < 0 || num_gpios > PM8058_GPIOS)
+		return -EINVAL;
+
+	while (num_gpios--) {
+		rc = pm8058_gpio_config(gpio_start++, &kypd_drv);
+		if (rc) {
+			pr_err("%s: FAIL pm8058_gpio_config(): rc=%d.\n",
+				__func__, rc);
+			return rc;
+		}
+	}
+
+	return 0;
+}
+
+static int pm8058_kp_config_sns(int gpio_start, int num_gpios)
+{
+	int	rc;
+	struct pm8058_gpio kypd_sns = {
+		.direction	= PM_GPIO_DIR_IN,
+		.pull		= PM_GPIO_PULL_UP_31P5,
+		.vin_sel	= 2,
+		.out_strength	= PM_GPIO_STRENGTH_NO,
+		.function	= PM_GPIO_FUNC_NORMAL,
+		.inv_int_pol	= 1,
+	};
+
+	if (gpio_start < 0 || num_gpios < 0 || num_gpios > PM8058_GPIOS)
+		return -EINVAL;
+
+	while (num_gpios--) {
+		rc = pm8058_gpio_config(gpio_start++, &kypd_sns);
+		if (rc) {
+			pr_err("%s: FAIL pm8058_gpio_config(): rc=%d.\n",
+				__func__, rc);
+			return rc;
+		}
+	}
+
+	return 0;
+}
+
+/*
+ * keypad controller should be initialized in the following sequence
+ * only, otherwise it might get into FSM stuck state.
+ *
+ * - Initialize keypad control parameters, like no. of rows, columns,
+ *   timing values etc.,
+ * - configure rows and column gpios pull up/down.
+ * - set irq edge type.
+ * - enable the keypad controller.
+ */
+static int __devinit pmic8058_kp_probe(struct platform_device *pdev)
+{
+	struct pmic8058_keypad_data *pdata = pdev->dev.platform_data;
+	const struct matrix_keymap_data *keymap_data;
+	struct pmic8058_kp *kp;
+	int rc;
+	unsigned short *keycodes;
+	u8 ctrl_val;
+	struct pm8058_chip	*pm_chip;
+
+	pm_chip = dev_get_drvdata(pdev->dev.parent);
+	if (pm_chip == NULL) {
+		dev_err(&pdev->dev, "no parent data passed in\n");
+		return -EFAULT;
+	}
+
+	if (!pdata || !pdata->num_cols || !pdata->num_rows ||
+		pdata->num_cols > PM8058_MAX_COLS ||
+		pdata->num_rows > PM8058_MAX_ROWS ||
+		pdata->num_cols < PM8058_MIN_COLS ||
+		pdata->num_rows < PM8058_MIN_ROWS) {
+		dev_err(&pdev->dev, "invalid platform data\n");
+		return -EINVAL;
+	}
+
+	if (pdata->rows_gpio_start < 0 || pdata->cols_gpio_start < 0) {
+		dev_err(&pdev->dev, "invalid gpio_start platform data\n");
+		return -EINVAL;
+	}
+
+	if (!pdata->scan_delay_ms || pdata->scan_delay_ms > MAX_SCAN_DELAY
+		|| pdata->scan_delay_ms < MIN_SCAN_DELAY ||
+		!is_power_of_2(pdata->scan_delay_ms)) {
+		dev_err(&pdev->dev, "invalid keypad scan time supplied\n");
+		return -EINVAL;
+	}
+
+	if (!pdata->row_hold_ns || pdata->row_hold_ns > MAX_ROW_HOLD_DELAY
+		|| pdata->row_hold_ns < MIN_ROW_HOLD_DELAY ||
+		((pdata->row_hold_ns % MIN_ROW_HOLD_DELAY) != 0)) {
+		dev_err(&pdev->dev, "invalid keypad row hold time supplied\n");
+		return -EINVAL;
+	}
+
+	if (pm8058_rev(pm_chip) == PM_8058_REV_1p0) {
+		if (!pdata->debounce_ms
+			|| !is_power_of_2(pdata->debounce_ms[0])
+			|| pdata->debounce_ms[0] > MAX_DEBOUNCE_A0_TIME
+			|| pdata->debounce_ms[0] < MIN_DEBOUNCE_A0_TIME) {
+			dev_err(&pdev->dev, "invalid debounce time supplied\n");
+			return -EINVAL;
+		}
+	} else {
+		if (!pdata->debounce_ms
+			|| ((pdata->debounce_ms[1] % 5) != 0)
+			|| pdata->debounce_ms[1] > MAX_DEBOUNCE_B0_TIME
+			|| pdata->debounce_ms[1] < MIN_DEBOUNCE_B0_TIME) {
+			dev_err(&pdev->dev, "invalid debounce time supplied\n");
+			return -EINVAL;
+		}
+	}
+
+	keymap_data = pdata->keymap_data;
+	if (!keymap_data) {
+		dev_err(&pdev->dev, "no keymap data supplied\n");
+		return -EINVAL;
+	}
+
+	kp = kzalloc(sizeof(*kp), GFP_KERNEL);
+	if (!kp)
+		return -ENOMEM;
+
+	keycodes = kzalloc(PM8058_MATRIX_MAX_SIZE * sizeof(*keycodes),
+				 GFP_KERNEL);
+	if (!keycodes) {
+		rc = -ENOMEM;
+		goto err_alloc_mem;
+	}
+
+	platform_set_drvdata(pdev, kp);
+	mutex_init(&kp->mutex);
+
+	kp->pdata	= pdata;
+	kp->dev		= &pdev->dev;
+	kp->keycodes	= keycodes;
+	kp->pm_chip	= pm_chip;
+
+	if (pm8058_rev(pm_chip) == PM_8058_REV_1p0)
+		kp->flags |= KEYF_FIX_LAST_ROW;
+
+	kp->input = input_allocate_device();
+	if (!kp->input) {
+		dev_err(&pdev->dev, "unable to allocate input device\n");
+		rc = -ENOMEM;
+		goto err_alloc_device;
+	}
+
+	/* Enable runtime PM ops, start in ACTIVE mode */
+	rc = pm_runtime_set_active(&pdev->dev);
+	if (rc < 0)
+		dev_dbg(&pdev->dev, "unable to set runtime pm state\n");
+	pm_runtime_enable(&pdev->dev);
+
+	kp->key_sense_irq = platform_get_irq(pdev, 0);
+	if (kp->key_sense_irq < 0) {
+		dev_err(&pdev->dev, "unable to get keypad sense irq\n");
+		rc = -ENXIO;
+		goto err_get_irq;
+	}
+
+	kp->key_stuck_irq = platform_get_irq(pdev, 1);
+	if (kp->key_stuck_irq < 0) {
+		dev_err(&pdev->dev, "unable to get keypad stuck irq\n");
+		rc = -ENXIO;
+		goto err_get_irq;
+	}
+
+	if (pdata->input_name)
+		kp->input->name = pdata->input_name;
+	else
+		kp->input->name = "PMIC8058 keypad";
+
+	if (pdata->input_phys_device)
+		kp->input->phys = pdata->input_phys_device;
+	else
+		kp->input->phys = "pmic8058_keypad/input0";
+
+	kp->input->dev.parent	= &pdev->dev;
+
+	kp->input->id.bustype	= BUS_HOST;
+	kp->input->id.version	= 0x0001;
+	kp->input->id.product	= 0x0001;
+	kp->input->id.vendor	= 0x0001;
+
+	kp->input->evbit[0]	= BIT_MASK(EV_KEY);
+
+	if (pdata->rep)
+		__set_bit(EV_REP, kp->input->evbit);
+
+	kp->input->keycode	= keycodes;
+	kp->input->keycodemax	= PM8058_MATRIX_MAX_SIZE;
+	kp->input->keycodesize	= sizeof(*keycodes);
+
+	matrix_keypad_build_keymap(keymap_data, PM8058_ROW_SHIFT,
+					kp->input->keycode, kp->input->keybit);
+
+	input_set_capability(kp->input, EV_MSC, MSC_SCAN);
+	input_set_drvdata(kp->input, kp);
+
+	rc = input_register_device(kp->input);
+	if (rc < 0) {
+		dev_err(&pdev->dev, "unable to register keypad input device\n");
+		goto err_get_irq;
+	}
+
+	/* initialize keypad state */
+	memset(kp->keystate, 0xff, sizeof(kp->keystate));
+	memset(kp->stuckstate, 0xff, sizeof(kp->stuckstate));
+
+	rc = pmic8058_kpd_init(kp);
+	if (rc < 0) {
+		dev_err(&pdev->dev, "unable to initialize keypad controller\n");
+		goto err_kpd_init;
+	}
+
+	rc = pm8058_kp_config_sns(pdata->cols_gpio_start,
+			pdata->num_cols);
+	if (rc < 0) {
+		dev_err(&pdev->dev, "unable to configure keypad sense lines\n");
+		goto err_gpio_config;
+	}
+
+	rc = pm8058_kp_config_drv(pdata->rows_gpio_start,
+			pdata->num_rows);
+	if (rc < 0) {
+		dev_err(&pdev->dev, "unable to configure keypad drive lines\n");
+		goto err_gpio_config;
+	}
+
+	rc = request_threaded_irq(kp->key_sense_irq, NULL, pmic8058_kp_irq,
+				 IRQF_TRIGGER_RISING, "pmic-keypad", kp);
+	if (rc < 0) {
+		dev_err(&pdev->dev, "failed to request keypad sense irq\n");
+		goto err_req_sense_irq;
+	}
+
+	rc = request_threaded_irq(kp->key_stuck_irq, NULL,
+				 pmic8058_kp_stuck_irq, IRQF_TRIGGER_RISING,
+				 "pmic-keypad-stuck", kp);
+	if (rc < 0) {
+		dev_err(&pdev->dev, "failed to request keypad stuck irq\n");
+		goto err_req_stuck_irq;
+	}
+
+	rc = pmic8058_kp_read_u8(kp, &ctrl_val, KEYP_CTRL);
+	ctrl_val |= KEYP_CTRL_KEYP_EN;
+	rc = pmic8058_kp_write_u8(kp, ctrl_val, KEYP_CTRL);
+
+	kp->ctrl_reg = ctrl_val;
+
+	__dump_kp_regs(kp, "probe");
+
+	rc = device_create_file(&pdev->dev, &dev_attr_disable_kp);
+	if (rc < 0)
+		goto err_create_file;
+
+	device_init_wakeup(&pdev->dev, pdata->wakeup);
+
+	return 0;
+
+err_create_file:
+	free_irq(kp->key_stuck_irq, NULL);
+err_req_stuck_irq:
+	free_irq(kp->key_sense_irq, NULL);
+err_req_sense_irq:
+err_gpio_config:
+err_kpd_init:
+	input_unregister_device(kp->input);
+	kp->input = NULL;
+err_get_irq:
+	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	input_free_device(kp->input);
+err_alloc_device:
+	kfree(keycodes);
+err_alloc_mem:
+	kfree(kp);
+	return rc;
+}
+
+static int __devexit pmic8058_kp_remove(struct platform_device *pdev)
+{
+	struct pmic8058_kp *kp = platform_get_drvdata(pdev);
+
+	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	device_remove_file(&pdev->dev, &dev_attr_disable_kp);
+	device_init_wakeup(&pdev->dev, 0);
+	free_irq(kp->key_stuck_irq, NULL);
+	free_irq(kp->key_sense_irq, NULL);
+	input_unregister_device(kp->input);
+	platform_set_drvdata(pdev, NULL);
+	kfree(kp->input->keycode);
+	kfree(kp);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int pmic8058_kp_suspend(struct device *dev)
+{
+	struct pmic8058_kp *kp = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev) && !pmic8058_kp_disabled(kp)) {
+		enable_irq_wake(kp->key_sense_irq);
+	} else {
+		mutex_lock(&kp->mutex);
+		pmic8058_kp_disable(kp);
+		mutex_unlock(&kp->mutex);
+	}
+
+	return 0;
+}
+
+static int pmic8058_kp_resume(struct device *dev)
+{
+	struct pmic8058_kp *kp = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev) && !pmic8058_kp_disabled(kp)) {
+		disable_irq_wake(kp->key_sense_irq);
+	} else {
+		mutex_lock(&kp->mutex);
+		pmic8058_kp_enable(kp);
+		mutex_unlock(&kp->mutex);
+	}
+
+	return 0;
+}
+
+static struct dev_pm_ops pm8058_kp_pm_ops = {
+	.suspend	= pmic8058_kp_suspend,
+	.resume		= pmic8058_kp_resume,
+};
+#endif
+
+static struct platform_driver pmic8058_kp_driver = {
+	.probe		= pmic8058_kp_probe,
+	.remove		= __devexit_p(pmic8058_kp_remove),
+	.driver		= {
+		.name = "pm8058-keypad",
+		.owner = THIS_MODULE,
+#ifdef CONFIG_PM
+		.pm = &pm8058_kp_pm_ops,
+#endif
+	},
+};
+
+static int __init pmic8058_kp_init(void)
+{
+	return platform_driver_register(&pmic8058_kp_driver);
+}
+module_init(pmic8058_kp_init);
+
+static void __exit pmic8058_kp_exit(void)
+{
+	platform_driver_unregister(&pmic8058_kp_driver);
+}
+module_exit(pmic8058_kp_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("PMIC8058 keypad driver");
+MODULE_VERSION("1.0");
+MODULE_ALIAS("platform:pmic8058_keypad");
diff --git a/drivers/input/keyboard/pmic8xxx-keypad.c b/drivers/input/keyboard/pmic8xxx-keypad.c
index 6229c3e..f0629ce 100644
--- a/drivers/input/keyboard/pmic8xxx-keypad.c
+++ b/drivers/input/keyboard/pmic8xxx-keypad.c
@@ -116,6 +116,9 @@
 	int rc;
 
 	rc = pm8xxx_writeb(kp->dev->parent, reg, data);
+	if (rc < 0)
+		dev_warn(kp->dev, "Error writing pmic8xxx: %X - ret %X\n",
+				reg, rc);
 	return rc;
 }
 
@@ -125,6 +128,10 @@
 	int rc;
 
 	rc = pm8xxx_read_buf(kp->dev->parent, reg, data, num_bytes);
+	if (rc < 0)
+		dev_warn(kp->dev, "Error reading pmic8xxx: %X - ret %X\n",
+				reg, rc);
+
 	return rc;
 }
 
@@ -134,6 +141,9 @@
 	int rc;
 
 	rc = pmic8xxx_kp_read(kp, data, reg, 1);
+	if (rc < 0)
+		dev_warn(kp->dev, "Error reading pmic8xxx: %X - ret %X\n",
+				reg, rc);
 	return rc;
 }
 
@@ -463,7 +473,7 @@
 					__func__, gpio_start + i, rc);
 			return rc;
 		}
-	 }
+	}
 
 	return 0;
 }
@@ -532,7 +542,7 @@
 		.output_buffer	= PM_GPIO_OUT_BUF_OPEN_DRAIN,
 		.output_value	= 0,
 		.pull		= PM_GPIO_PULL_NO,
-		.vin_sel	= PM_GPIO_VIN_S3,
+		.vin_sel	= PM_GPIO_VIN_S4,
 		.out_strength	= PM_GPIO_STRENGTH_LOW,
 		.function	= PM_GPIO_FUNC_1,
 		.inv_int_pol	= 1,
@@ -541,7 +551,7 @@
 	struct pm_gpio kypd_sns = {
 		.direction	= PM_GPIO_DIR_IN,
 		.pull		= PM_GPIO_PULL_UP_31P5,
-		.vin_sel	= PM_GPIO_VIN_S3,
+		.vin_sel	= PM_GPIO_VIN_S4,
 		.out_strength	= PM_GPIO_STRENGTH_NO,
 		.function	= PM_GPIO_FUNC_NORMAL,
 		.inv_int_pol	= 1,
diff --git a/drivers/input/keyboard/qci_kbd.c b/drivers/input/keyboard/qci_kbd.c
new file mode 100644
index 0000000..d735012
--- /dev/null
+++ b/drivers/input/keyboard/qci_kbd.c
@@ -0,0 +1,721 @@
+/* Quanta I2C Keyboard Driver
+ *
+ * Copyright (C) 2009 Quanta Computer Inc.
+ * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+ * Author: Hsin Wu <hsin.wu@quantatw.com>
+ * Author: Austin Lai <austin.lai@quantatw.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+ /*
+ *
+ *  The Driver with I/O communications via the I2C Interface for ON2 of AP BU.
+ *  And it is only working on the nuvoTon WPCE775x Embedded Controller.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/mutex.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/keyboard.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+
+#include <linux/input/qci_kbd.h>
+
+/* Keyboard special scancode */
+#define RC_KEY_FN          0x70
+#define RC_KEY_BREAK       0x80
+#define KEY_ACK_FA         0xFA
+#define SCAN_EMUL0         0xE0
+#define SCAN_EMUL1         0xE1
+#define SCAN_PAUSE1        0x1D
+#define SCAN_PAUSE2        0x45
+#define SCAN_LIDSW_OPEN    0x70
+#define SCAN_LIDSW_CLOSE   0x71
+
+/* Keyboard keycodes */
+#define NOKEY           KEY_RESERVED
+#define KEY_LEFTWIN     KEY_LEFTMETA
+#define KEY_RIGHTWIN    KEY_RIGHTMETA
+#define KEY_APPS        KEY_COMPOSE
+#define KEY_PRINTSCR    KEY_SYSRQ
+
+#define KEYBOARD_ID_NAME          "qci-i2ckbd"
+#define KEYBOARD_NAME                "Quanta Keyboard"
+#define KEYBOARD_DEVICE             "/i2c/input0"
+#define KEYBOARD_CMD_ENABLE             0xF4
+#define KEYBOARD_CMD_SET_LED            0xED
+
+/*-----------------------------------------------------------------------------
+ * Keyboard scancode to linux keycode translation table
+ *---------------------------------------------------------------------------*/
+
+static const unsigned char on2_keycode[256] = {
+	[0]   = NOKEY,
+	[1]   = NOKEY,
+	[2]   = NOKEY,
+	[3]   = KEY_5,
+	[4]   = KEY_7,
+	[5]   = KEY_9,
+	[6]   = KEY_MINUS,
+	[7]   = NOKEY,
+	[8]   = NOKEY,
+	[9]   = NOKEY,
+	[10]  = NOKEY,
+	[11]  = KEY_LEFTBRACE,
+	[12]  = KEY_F10,
+	[13]  = KEY_INSERT,
+	[14]  = KEY_F11,
+	[15]  = KEY_ESC,
+	[16]  = NOKEY,
+	[17]  = NOKEY,
+	[18]  = NOKEY,
+	[19]  = KEY_4,
+	[20]  = KEY_6,
+	[21]  = KEY_8,
+	[22]  = KEY_0,
+	[23]  = KEY_EQUAL,
+	[24]  = NOKEY,
+	[25]  = NOKEY,
+	[26]  = NOKEY,
+	[27]  = KEY_P,
+	[28]  = KEY_F9,
+	[29]  = KEY_DELETE,
+	[30]  = KEY_F12,
+	[31]  = KEY_GRAVE,
+	[32]  = KEY_W,
+	[33]  = NOKEY,
+	[34]  = NOKEY,
+	[35]  = KEY_R,
+	[36]  = KEY_T,
+	[37]  = KEY_U,
+	[38]  = KEY_O,
+	[39]  = KEY_RIGHTBRACE,
+	[40]  = NOKEY,
+	[41]  = NOKEY,
+	[42]  = NOKEY,
+	[43]  = KEY_APOSTROPHE,
+	[44]  = KEY_BACKSPACE,
+	[45]  = NOKEY,
+	[46]  = KEY_F8,
+	[47]  = KEY_F5,
+	[48]  = KEY_S,
+	[49]  = NOKEY,
+	[50]  = NOKEY,
+	[51]  = KEY_E,
+	[52]  = KEY_H,
+	[53]  = KEY_Y,
+	[54]  = KEY_I,
+	[55]  = KEY_ENTER,
+	[56]  = NOKEY,
+	[57]  = NOKEY,
+	[58]  = NOKEY,
+	[59]  = KEY_SEMICOLON,
+	[60]  = KEY_3,
+	[61]  = KEY_PAGEUP,
+	[62]  = KEY_Q,
+	[63]  = KEY_TAB,
+	[64]  = KEY_A,
+	[65]  = NOKEY,
+	[66]  = NOKEY,
+	[67]  = KEY_F,
+	[68]  = KEY_G,
+	[69]  = KEY_J,
+	[70]  = KEY_L,
+	[71]  = NOKEY,
+	[72]  = KEY_RIGHTSHIFT,
+	[73]  = NOKEY,
+	[74]  = NOKEY,
+	[75]  = KEY_SLASH,
+	[76]  = KEY_2,
+	[77]  = KEY_PAGEDOWN,
+	[78]  = KEY_F4,
+	[79]  = KEY_F1,
+	[80]  = KEY_Z,
+	[81]  = NOKEY,
+	[82]  = NOKEY,
+	[83]  = KEY_D,
+	[84]  = KEY_V,
+	[85]  = KEY_N,
+	[86]  = KEY_K,
+	[87]  = NOKEY,
+	[88]  = KEY_LEFTSHIFT,
+	[89]  = KEY_RIGHTCTRL,
+	[90]  = NOKEY,
+	[91]  = KEY_DOT,
+	[92]  = KEY_UP,
+	[93]  = KEY_RIGHT,
+	[94]  = KEY_F3,
+	[95]  = KEY_F2,
+	[96]  = NOKEY,
+	[97]  = NOKEY,
+	[98]  = KEY_RIGHTALT,
+	[99]  = KEY_X,
+	[100] = KEY_C,
+	[101] = KEY_B,
+	[102] = KEY_COMMA,
+	[103] = NOKEY,
+	[104] = NOKEY,
+	[105] = NOKEY,
+	[106] = NOKEY,
+	[107] = NOKEY,
+	[108] = KEY_PRINTSCR,
+	[109] = KEY_DOWN,
+	[110] = KEY_1,
+	[111] = KEY_CAPSLOCK,
+	[112] = KEY_F24,
+	[113] = KEY_HOME,
+	[114] = KEY_LEFTALT,
+	[115] = NOKEY,
+	[116] = KEY_SPACE,
+	[117] = KEY_BACKSLASH,
+	[118] = KEY_M,
+	[119] = KEY_COMPOSE,
+	[120] = NOKEY,
+	[121] = KEY_LEFTCTRL,
+	[122] = NOKEY,
+	[123] = NOKEY,
+	[124] = KEY_PAUSE,
+	[125] = KEY_LEFT,
+	[126] = KEY_F7,
+	[127] = KEY_F6,
+	[128] = NOKEY,
+	[129] = NOKEY,
+	[130] = NOKEY,
+	[131] = NOKEY,
+	[132] = NOKEY,
+	[133] = NOKEY,
+	[134] = NOKEY,
+	[135] = NOKEY,
+	[136] = NOKEY,
+	[137] = NOKEY,
+	[138] = NOKEY,
+	[139] = NOKEY,
+	[140] = NOKEY,
+	[141] = NOKEY,
+	[142] = NOKEY,
+	[143] = NOKEY,
+	[144] = NOKEY,
+	[145] = NOKEY,
+	[146] = NOKEY,
+	[147] = NOKEY,
+	[148] = NOKEY,
+	[149] = NOKEY,
+	[150] = NOKEY,
+	[151] = NOKEY,
+	[152] = NOKEY,
+	[153] = NOKEY,
+	[154] = NOKEY,
+	[155] = NOKEY,
+	[156] = NOKEY,
+	[157] = NOKEY,
+	[158] = NOKEY,
+	[159] = NOKEY,
+	[160] = NOKEY,
+	[161] = NOKEY,
+	[162] = NOKEY,
+	[163] = NOKEY,
+	[164] = NOKEY,
+	[165] = NOKEY,
+	[166] = NOKEY,
+	[167] = NOKEY,
+	[168] = NOKEY,
+	[169] = NOKEY,
+	[170] = NOKEY,
+	[171] = NOKEY,
+	[172] = NOKEY,
+	[173] = NOKEY,
+	[174] = NOKEY,
+	[175] = NOKEY,
+	[176] = NOKEY,
+	[177] = NOKEY,
+	[178] = NOKEY,
+	[179] = NOKEY,
+	[180] = NOKEY,
+	[181] = NOKEY,
+	[182] = NOKEY,
+	[183] = NOKEY,
+	[184] = NOKEY,
+	[185] = NOKEY,
+	[186] = NOKEY,
+	[187] = NOKEY,
+	[188] = NOKEY,
+	[189] = KEY_HOME,
+	[190] = NOKEY,
+	[191] = NOKEY,
+	[192] = NOKEY,
+	[193] = NOKEY,
+	[194] = NOKEY,
+	[195] = NOKEY,
+	[196] = NOKEY,
+	[197] = NOKEY,
+	[198] = NOKEY,
+	[199] = NOKEY,
+	[200] = NOKEY,
+	[201] = NOKEY,
+	[202] = NOKEY,
+	[203] = NOKEY,
+	[204] = NOKEY,
+	[205] = KEY_END,
+	[206] = NOKEY,
+	[207] = NOKEY,
+	[208] = NOKEY,
+	[209] = NOKEY,
+	[210] = NOKEY,
+	[211] = NOKEY,
+	[212] = NOKEY,
+	[213] = NOKEY,
+	[214] = NOKEY,
+	[215] = NOKEY,
+	[216] = NOKEY,
+	[217] = NOKEY,
+	[218] = NOKEY,
+	[219] = NOKEY,
+	[220] = KEY_VOLUMEUP,
+	[221] = KEY_BRIGHTNESSUP,
+	[222] = NOKEY,
+	[223] = NOKEY,
+	[224] = NOKEY,
+	[225] = NOKEY,
+	[226] = NOKEY,
+	[227] = NOKEY,
+	[228] = NOKEY,
+	[229] = NOKEY,
+	[230] = NOKEY,
+	[231] = NOKEY,
+	[232] = NOKEY,
+	[233] = NOKEY,
+	[234] = NOKEY,
+	[235] = NOKEY,
+	[236] = NOKEY,
+	[237] = KEY_VOLUMEDOWN,
+	[238] = NOKEY,
+	[239] = NOKEY,
+	[240] = NOKEY,
+	[241] = NOKEY,
+	[242] = NOKEY,
+	[243] = NOKEY,
+	[244] = NOKEY,
+	[245] = NOKEY,
+	[246] = NOKEY,
+	[247] = NOKEY,
+	[248] = NOKEY,
+	[249] = NOKEY,
+	[250] = NOKEY,
+	[251] = NOKEY,
+	[252] = NOKEY,
+	[253] = KEY_BRIGHTNESSDOWN,
+	[254] = NOKEY,
+	[255] = NOKEY,
+};
+
+static const u8 emul0_map[128] = {
+	  0,   0,   0,  0,  0,  0,  0,   0,   0,   0,  0,   0,  0,   0,  0,   0,
+	  0,   0,   0,  0,  0,  0,  0,   0,   0,   0,  0,   0, 96,  97,  0,   0,
+	113,   0,   0,  0,  0,  0,  0,   0,   0,   0,  0,   0,  0,   0, 114,  0,
+	115,   0,   0,  0,  0, 98,  0,  99, 100,   0,  0,   0,  0,   0,  0,   0,
+	  0,   0,   0,  0,  0,  0,  0, 102, 103, 104,  0, 105,  0, 106,  0, 107,
+	108, 109, 110, 111, 0,  0,  0,   0,   0,   0,  0, 139,  0, 150,  0,   0,
+	  0,   0,   0,  0,  0,  0,  0,   0,   0,   0,  0,   0,  0,   0,  0,   0,
+	  0,   0,   0,  0,  0,  0,  0,   0,   0,   0,  0,   0,  0,   0,  0,   0,
+};
+
+/*-----------------------------------------------------------------------------
+ * Global variables
+ *---------------------------------------------------------------------------*/
+
+struct input_dev *g_qci_keyboard_dev;
+
+/* General structure to hold the driver data */
+struct i2ckbd_drv_data {
+	struct i2c_client *ki2c_client;
+	struct work_struct work;
+	struct input_dev *qcikbd_dev;
+	struct mutex kb_mutex;
+	unsigned int qcikbd_gpio; /* GPIO used for interrupt */
+	unsigned int qcikbd_irq;
+	unsigned int key_down;
+	unsigned int escape;
+	unsigned int pause_seq;
+	unsigned int fn;
+	unsigned char led_status;
+	bool standard_scancodes;
+	bool kb_leds;
+	bool event_led;
+	bool emul0;
+	bool emul1;
+	bool pause1;
+};
+#ifdef CONFIG_PM
+static int qcikbd_suspend(struct device *dev)
+{
+	struct i2ckbd_drv_data *context = input_get_drvdata(g_qci_keyboard_dev);
+
+	enable_irq_wake(context->qcikbd_irq);
+	return 0;
+}
+
+static int qcikbd_resume(struct device *dev)
+{
+	struct i2ckbd_drv_data *context = input_get_drvdata(g_qci_keyboard_dev);
+	struct i2c_client *ikbdclient = context->ki2c_client;
+
+	disable_irq_wake(context->qcikbd_irq);
+
+	/* consume any keypress generated while suspended */
+	i2c_smbus_read_byte(ikbdclient);
+	return 0;
+}
+#endif
+static int __devinit qcikbd_probe(struct i2c_client *client,
+	const struct i2c_device_id *id);
+static int __devexit qcikbd_remove(struct i2c_client *kbd);
+
+static const struct i2c_device_id qcikbd_idtable[] = {
+	{ KEYBOARD_ID_NAME, 0 },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(i2c, qcikbd_idtable);
+
+#ifdef CONFIG_PM
+static struct dev_pm_ops qcikbd_pm_ops = {
+	.suspend  = qcikbd_suspend,
+	.resume   = qcikbd_resume,
+};
+#endif
+static struct i2c_driver i2ckbd_driver = {
+	.driver = {
+		.owner = THIS_MODULE,
+		.name  = KEYBOARD_ID_NAME,
+#ifdef CONFIG_PM
+		.pm = &qcikbd_pm_ops,
+#endif
+	},
+	.probe	  = qcikbd_probe,
+	.remove = __devexit_p(qcikbd_remove),
+	.id_table = qcikbd_idtable,
+};
+
+/*-----------------------------------------------------------------------------
+ * Driver functions
+ *---------------------------------------------------------------------------*/
+
+#ifdef CONFIG_KEYBOARD_QCIKBD_LID
+static void process_lid(struct input_dev *ikbdev, unsigned char scancode)
+{
+	if (scancode == SCAN_LIDSW_OPEN)
+		input_report_switch(ikbdev, SW_LID, 0);
+	else if (scancode == SCAN_LIDSW_CLOSE)
+		input_report_switch(ikbdev, SW_LID, 1);
+	else
+		return;
+	input_sync(ikbdev);
+}
+#endif
+
+static irqreturn_t qcikbd_interrupt(int irq, void *dev_id)
+{
+	struct i2ckbd_drv_data *ikbd_drv_data = dev_id;
+	schedule_work(&ikbd_drv_data->work);
+	return IRQ_HANDLED;
+}
+
+static void qcikbd_work_handler(struct work_struct *_work)
+{
+	unsigned char scancode;
+	unsigned char scancode_only;
+	unsigned int  keycode;
+
+	struct i2ckbd_drv_data *ikbd_drv_data =
+		container_of(_work, struct i2ckbd_drv_data, work);
+
+	struct i2c_client *ikbdclient = ikbd_drv_data->ki2c_client;
+	struct input_dev *ikbdev = ikbd_drv_data->qcikbd_dev;
+
+	mutex_lock(&ikbd_drv_data->kb_mutex);
+
+	if ((ikbd_drv_data->kb_leds) && (ikbd_drv_data->event_led)) {
+		i2c_smbus_write_byte(ikbdclient, KEYBOARD_CMD_SET_LED);
+		i2c_smbus_write_byte(ikbdclient, ikbd_drv_data->led_status);
+		ikbd_drv_data->event_led = 0;
+		goto work_exit;
+	}
+
+	scancode = i2c_smbus_read_byte(ikbdclient);
+
+	if (scancode == KEY_ACK_FA)
+		goto work_exit;
+
+	if (ikbd_drv_data->standard_scancodes) {
+		/* pause key is E1 1D 45 */
+		if (scancode == SCAN_EMUL1) {
+			ikbd_drv_data->emul1 = 1;
+			goto work_exit;
+		}
+		if (ikbd_drv_data->emul1) {
+			ikbd_drv_data->emul1 = 0;
+			if ((scancode & 0x7f) == SCAN_PAUSE1)
+				ikbd_drv_data->pause1 = 1;
+			goto work_exit;
+		}
+		if (ikbd_drv_data->pause1) {
+			ikbd_drv_data->pause1 = 0;
+			if ((scancode & 0x7f) == SCAN_PAUSE2) {
+				input_report_key(ikbdev, KEY_PAUSE,
+						 !(scancode & 0x80));
+				input_sync(ikbdev);
+			}
+			goto work_exit;
+		}
+
+		if (scancode == SCAN_EMUL0) {
+			ikbd_drv_data->emul0 = 1;
+			goto work_exit;
+		}
+		if (ikbd_drv_data->emul0) {
+			ikbd_drv_data->emul0 = 0;
+			scancode_only = scancode & 0x7f;
+#ifdef CONFIG_KEYBOARD_QCIKBD_LID
+			if ((scancode_only == SCAN_LIDSW_OPEN) ||
+			    (scancode_only == SCAN_LIDSW_CLOSE)) {
+				process_lid(ikbdev, scancode);
+				goto work_exit;
+			}
+#endif
+			keycode = emul0_map[scancode_only];
+			if (!keycode) {
+				dev_err(&ikbdev->dev,
+					"Unrecognized scancode %02x %02x\n",
+					SCAN_EMUL0, scancode);
+				goto work_exit;
+			}
+		} else {
+			keycode = scancode & 0x7f;
+		}
+		/* MS bit of scancode indicates direction of keypress */
+		ikbd_drv_data->key_down = !(scancode & 0x80);
+		if (keycode) {
+			input_event(ikbdev, EV_MSC, MSC_SCAN, scancode);
+			input_report_key(ikbdev, keycode,
+					 ikbd_drv_data->key_down);
+			input_sync(ikbdev);
+		}
+		goto work_exit;
+	}
+
+	mutex_unlock(&ikbd_drv_data->kb_mutex);
+
+	if (scancode == RC_KEY_FN) {
+		ikbd_drv_data->fn = 0x80;     /* select keycode table  > 0x7F */
+	} else {
+		ikbd_drv_data->key_down = 1;
+		if (scancode & RC_KEY_BREAK) {
+			ikbd_drv_data->key_down = 0;
+			if ((scancode & 0x7F) == RC_KEY_FN)
+				ikbd_drv_data->fn = 0;
+		}
+		keycode = on2_keycode[(scancode & 0x7F) | ikbd_drv_data->fn];
+		if (keycode != NOKEY) {
+			input_report_key(ikbdev,
+					 keycode,
+					 ikbd_drv_data->key_down);
+			input_sync(ikbdev);
+		}
+	}
+	return;
+
+work_exit:
+	mutex_unlock(&ikbd_drv_data->kb_mutex);
+}
+
+static int qcikbd_input_event(struct input_dev *dev, unsigned int type,
+			      unsigned int code, int value)
+{
+	struct i2ckbd_drv_data *ikbd_drv_data = input_get_drvdata(dev);
+	struct input_dev *ikbdev = ikbd_drv_data->qcikbd_dev;
+
+	if (type != EV_LED)
+		return -EINVAL;
+
+	ikbd_drv_data->led_status =
+		(test_bit(LED_SCROLLL, ikbdev->led) ? 1 : 0) |
+		(test_bit(LED_NUML, ikbdev->led) ? 2 : 0) |
+		(test_bit(LED_CAPSL, ikbdev->led) ? 4 : 0);
+	ikbd_drv_data->event_led = 1;
+
+	schedule_work(&ikbd_drv_data->work);
+	return 0;
+}
+
+static int qcikbd_open(struct input_dev *dev)
+{
+	struct i2ckbd_drv_data *ikbd_drv_data = input_get_drvdata(dev);
+	struct i2c_client *ikbdclient = ikbd_drv_data->ki2c_client;
+
+	/* Send F4h - enable keyboard */
+	i2c_smbus_write_byte(ikbdclient, KEYBOARD_CMD_ENABLE);
+	return 0;
+}
+
+static int __devinit qcikbd_probe(struct i2c_client *client,
+				    const struct i2c_device_id *id)
+{
+	int err;
+	int i;
+	struct i2ckbd_drv_data *context;
+	struct qci_kbd_platform_data *pdata = client->dev.platform_data;
+
+	if (!pdata) {
+		pr_err("[KBD] platform data not supplied\n");
+		return -EINVAL;
+	}
+
+	context = kzalloc(sizeof(struct i2ckbd_drv_data), GFP_KERNEL);
+	if (!context)
+		return -ENOMEM;
+	i2c_set_clientdata(client, context);
+	context->ki2c_client = client;
+	context->qcikbd_gpio = client->irq;
+	client->driver = &i2ckbd_driver;
+
+	INIT_WORK(&context->work, qcikbd_work_handler);
+	mutex_init(&context->kb_mutex);
+
+	err = gpio_request(context->qcikbd_gpio, "qci-kbd");
+	if (err) {
+		pr_err("[KBD] err gpio request\n");
+		goto gpio_request_fail;
+	}
+
+	context->qcikbd_irq = gpio_to_irq(context->qcikbd_gpio);
+	err = request_irq(context->qcikbd_irq,
+			  qcikbd_interrupt,
+			  IRQF_TRIGGER_FALLING,
+			  KEYBOARD_ID_NAME,
+			  context);
+	if (err) {
+		pr_err("[KBD] err unable to get IRQ\n");
+		goto request_irq_fail;
+	}
+
+	context->standard_scancodes = pdata->standard_scancodes;
+	context->kb_leds = pdata->kb_leds;
+	context->qcikbd_dev = input_allocate_device();
+	if (!context->qcikbd_dev) {
+		pr_err("[KBD]allocting memory err\n");
+		err = -ENOMEM;
+		goto allocate_fail;
+	}
+
+	context->qcikbd_dev->name       = KEYBOARD_NAME;
+	context->qcikbd_dev->phys       = KEYBOARD_DEVICE;
+	context->qcikbd_dev->id.bustype = BUS_I2C;
+	context->qcikbd_dev->id.vendor  = 0x1050;
+	context->qcikbd_dev->id.product = 0x0006;
+	context->qcikbd_dev->id.version = 0x0004;
+	context->qcikbd_dev->open       = qcikbd_open;
+	set_bit(EV_KEY, context->qcikbd_dev->evbit);
+	__set_bit(MSC_SCAN, context->qcikbd_dev->mscbit);
+
+	if (pdata->repeat)
+		set_bit(EV_REP, context->qcikbd_dev->evbit);
+
+	/* Enable all supported keys */
+	for (i = 1; i < ARRAY_SIZE(on2_keycode) ; i++)
+		set_bit(on2_keycode[i], context->qcikbd_dev->keybit);
+
+	set_bit(KEY_POWER, context->qcikbd_dev->keybit);
+	set_bit(KEY_END, context->qcikbd_dev->keybit);
+	set_bit(KEY_VOLUMEUP, context->qcikbd_dev->keybit);
+	set_bit(KEY_VOLUMEDOWN, context->qcikbd_dev->keybit);
+	set_bit(KEY_ZOOMIN, context->qcikbd_dev->keybit);
+	set_bit(KEY_ZOOMOUT, context->qcikbd_dev->keybit);
+
+#ifdef CONFIG_KEYBOARD_QCIKBD_LID
+	set_bit(EV_SW, context->qcikbd_dev->evbit);
+	set_bit(SW_LID, context->qcikbd_dev->swbit);
+#endif
+
+	if (context->kb_leds) {
+		context->qcikbd_dev->event = qcikbd_input_event;
+		__set_bit(EV_LED, context->qcikbd_dev->evbit);
+		__set_bit(LED_NUML, context->qcikbd_dev->ledbit);
+		__set_bit(LED_CAPSL, context->qcikbd_dev->ledbit);
+		__set_bit(LED_SCROLLL, context->qcikbd_dev->ledbit);
+	}
+
+	input_set_drvdata(context->qcikbd_dev, context);
+	err = input_register_device(context->qcikbd_dev);
+	if (err) {
+		pr_err("[KBD] err input register device\n");
+		goto register_fail;
+	}
+	g_qci_keyboard_dev = context->qcikbd_dev;
+	return 0;
+register_fail:
+	input_free_device(context->qcikbd_dev);
+
+allocate_fail:
+	free_irq(context->qcikbd_irq, context);
+
+request_irq_fail:
+	gpio_free(context->qcikbd_gpio);
+
+gpio_request_fail:
+	i2c_set_clientdata(client, NULL);
+	kfree(context);
+	return err;
+}
+
+static int __devexit qcikbd_remove(struct i2c_client *dev)
+{
+	struct i2ckbd_drv_data *context = i2c_get_clientdata(dev);
+
+	free_irq(context->qcikbd_irq, context);
+	gpio_free(context->qcikbd_gpio);
+	input_free_device(context->qcikbd_dev);
+	input_unregister_device(context->qcikbd_dev);
+	kfree(context);
+
+	return 0;
+}
+
+static int __init qcikbd_init(void)
+{
+	return i2c_add_driver(&i2ckbd_driver);
+}
+
+static void __exit qcikbd_exit(void)
+{
+	i2c_del_driver(&i2ckbd_driver);
+}
+
+struct input_dev *nkbc_keypad_get_input_dev(void)
+{
+	return g_qci_keyboard_dev;
+}
+EXPORT_SYMBOL(nkbc_keypad_get_input_dev);
+module_init(qcikbd_init);
+module_exit(qcikbd_exit);
+
+MODULE_AUTHOR("Quanta Computer Inc.");
+MODULE_DESCRIPTION("Quanta Embedded Controller I2C Keyboard Driver");
+MODULE_LICENSE("GPL v2");
+