Skip to contentSkip to conversation

input: add mpr121 capacitive touchkey driver

PATCH In review Jiejing Zhang 4 participants 9 messages Apr 11, 2011 – Apr 13, 2011 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: add mpr121 capacitive touchkey driver

From: Zhang Jiejing <[email protected]>

This touchkey driver is based on Freescale mpr121 capacitive touch sensor controller.

It can support up to 12 keys, it use i2c interface.

The product infomation(data sheet, application notes) can be found under this link:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

---
 drivers/input/keyboard/Kconfig  |   12 ++
 drivers/input/keyboard/Makefile |    1 +
 drivers/input/keyboard/mpr121.c |  301 +++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/mpr.h         |   64 ++++++++
 4 files changed, 378 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/mpr121.c
 create mode 100644 include/linux/i2c/mpr.h
drivers/input/keyboard/Kconfig +12 -0
index b16bed0..0666e1e 100644
@@ -520,6 +520,18 @@ config KEYBOARD_XTKBD
 	  To compile this driver as a module, choose M here: the
 	  module will be called xtkbd.
 
+config KEYBOARD_MPR121
+	tristate "Freescale MPR121 Touchkey Driver"
+	depends on I2C
+	help
+	  Say Y here if you have the  touchkey Freescale mpr121 capacitive
+	  touch sensor controller in your system.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here
+endif
+
 config KEYBOARD_W90P910
 	tristate "W90P910 Matrix Keypad support"
 	depends on ARCH_W90X900
drivers/input/keyboard/Makefile +1 -0
index 878e6c2..b110ca8 100644
@@ -47,4 +47,5 @@ obj-$(CONFIG_KEYBOARD_TEGRA)		+= tegra-kbc.o
 obj-$(CONFIG_KEYBOARD_TNETV107X)	+= tnetv107x-keypad.o
 obj-$(CONFIG_KEYBOARD_TWL4030)		+= twl4030_keypad.o
 obj-$(CONFIG_KEYBOARD_XTKBD)		+= xtkbd.o
+obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121.o
 obj-$(CONFIG_KEYBOARD_W90P910)		+= w90p910_keypad.o
drivers/input/keyboard/mpr121.c new file +301 -0

301 lines not on this page · raw message

include/linux/i2c/mpr.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

Hi Zhang,

this is just a superficial review of your driver.

thanks,
Christoph

Quoted 6 lines · Jiejing Zhang

From: Zhang Jiejing <[email protected]>

This touchkey driver is based on Freescale mpr121 capacitive touch sensor controller.

It can support up to 12 keys, it use i2c interface.

typo

Quoted 20 lines

The product infomation(data sheet, application notes) can be found under this link:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

---
 drivers/input/keyboard/Kconfig  |   12 ++
 drivers/input/keyboard/Makefile |    1 +
 drivers/input/keyboard/mpr121.c |  301 +++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/mpr.h         |   64 ++++++++
 4 files changed, 378 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/mpr121.c
 create mode 100644 include/linux/i2c/mpr.h
drivers/input/keyboard/Kconfig +0 -0
index b16bed0..0666e1e 100644

drivers/input/keyboard/Kconfig config KEYBOARD_XTKBD · line 527

Quoted 8 lines
drivers/input/keyboard/Kconfig +5 -0
@@ -520,6 +520,18 @@ config KEYBOARD_XTKBD
 	  To compile this driver as a module, choose M here: the
 	  module will be called xtkbd.
 
+config KEYBOARD_MPR121
+	tristate "Freescale MPR121 Touchkey Driver"
+	depends on I2C
+	help
+	  Say Y here if you have the  touchkey Freescale mpr121 capacitive

typo: two spaces

drivers/input/keyboard/Kconfig config KEYBOARD_XTKBD · line 537

Quoted 10 lines
drivers/input/keyboard/Kconfig +7 -0
+	  touch sensor controller in your system.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here
+endif
+
 config KEYBOARD_W90P910
 	tristate "W90P910 Matrix Keypad support"
 	depends on ARCH_W90X900

- add: "To compile this driver as a module, choose M here: the module will be called mpr121."
- "endif" is wrong here, it breaks 'make config'
- maybe a more alphabetic approach in this list of drivers would be nice

drivers/input/keyboard/Makefile obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o · line 51

Quoted 10 lines
drivers/input/keyboard/Makefile +1 -0
index 878e6c2..b110ca8 100644
@@ -47,4 +47,5 @@ obj-$(CONFIG_KEYBOARD_TEGRA)		+= tegra-kbc.o
 obj-$(CONFIG_KEYBOARD_TNETV107X)	+= tnetv107x-keypad.o
 obj-$(CONFIG_KEYBOARD_TWL4030)		+= twl4030_keypad.o
 obj-$(CONFIG_KEYBOARD_XTKBD)		+= xtkbd.o
+obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121.o
 obj-$(CONFIG_KEYBOARD_W90P910)		+= w90p910_keypad.o

for better examination, please mind alphabetic order

Quoted 17 lines
drivers/input/keyboard/mpr121.c new file +11 -0
new file mode 100644
index 0000000..ee149a8
@@ -0,0 +1,301 @@
+/*
+ * Touchkey driver for Freescale MPR121 Controllor
+ *
+ * Copyright (C) 2011 Freescale Semiconductor, Inc.
+ * Author: Zhang Jiejing <[email protected]>
+ *
+ * Based on mcs_touchkey.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

drivers/input/keyboard/mpr121.c line 21

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/i2c/mpr.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/irq.h>

do not use irq.h directly

Quoted 45 lines
drivers/input/keyboard/mpr121.c new file +45 -0
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+
+struct mpr121_touchkey_data {
+	struct i2c_client	*client;
+	struct input_dev	*input_dev;
+	unsigned int		key_val;
+	int			statusbits;
+	int			keycount;
+	u16			keycodes[MPR121_MAX_KEY_COUNT];
+};
+
+struct mpr121_init_register {
+	int addr;
+	u8 val;
+};
+
+static struct mpr121_init_register init_reg_table[] = {
+	{MHD_RISING_ADDR,	0x1},
+	{NHD_RISING_ADDR,	0x1},
+	{MHD_FALLING_ADDR,	0x1},
+	{NHD_FALLING_ADDR,	0x1},
+	{NCL_FALLING_ADDR,	0xff},
+	{FDL_FALLING_ADDR,	0x02},
+	{FILTER_CONF_ADDR,	0x04},
+	{AFE_CONF_ADDR,		0x0b},
+	{AUTO_CONFIG_CTRL_ADDR, 0x0b},
+};
+
+static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
+{
+	struct mpr121_touchkey_data *data = dev_id;
+	struct i2c_client *client = data->client;
+	struct input_dev *input = data->input_dev;
+	unsigned int key_num, pressed;
+	int reg;
+
+	reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
+	if (reg < 0) {
+		dev_err(&client->dev, "i2c read error [%d]\n", reg);
+		goto out;
+	}
+
+	reg <<= 8;

drivers/input/keyboard/mpr121.c line 76

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+	reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
+	if (reg < 0) {
+		dev_err(&client->dev, "i2c read error [%d]\n", reg);
+		goto out;
+	}
+
+	reg &= TOUCH_STATUS_MASK;
+	/* use old press bit to figure out which bit changed */
+	key_num = ffs(reg ^ data->statusbits) - 1;
+	/* use the bit check the press status */

typo

Quoted 34 lines
drivers/input/keyboard/mpr121.c new file +34 -0
+	pressed = (reg & (1 << (key_num))) >> key_num;
+	data->statusbits = reg;
+	data->key_val = data->keycodes[key_num];
+
+	input_event(input, EV_MSC, MSC_SCAN, data->key_val);
+	input_report_key(input, data->key_val, pressed);
+	input_sync(input);
+
+	dev_dbg(&client->dev, "key %d %d %s\n", key_num, data->key_val,
+		pressed ? "pressed" : "released");
+
+out:
+	return IRQ_HANDLED;
+}
+
+static int mpr121_phys_init(struct mpr121_platform_data *pdata,
+			    struct mpr121_touchkey_data *data,
+			    struct i2c_client *client)
+{
+	struct mpr121_init_register *reg;
+	unsigned char usl, lsl, tl;
+	int i, t, vdd, ret;
+
+	/* setup touch/release threshold for ele0-ele11 */
+	for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
+		t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
+		ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
+		if (ret < 0)
+			goto err_i2c_write;
+		ret = i2c_smbus_write_byte_data(client, t + 1,
+						RELEASE_THRESHOLD);
+		if (ret < 0)
+			goto err_i2c_write;
+	}

drivers/input/keyboard/mpr121.c line 120

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+	/* setup init register */
+	for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
+		reg = &init_reg_table[i];
+		ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
+		if (ret < 0)
+			goto err_i2c_write;
+	}
+	/* setup auto-register by vdd,the formula please ref: AN3889
+	 * These register *must* set acrodding your VDD voltage supply
+	 * to the chip*/

typo

drivers/input/keyboard/mpr121.c line 133

Quoted 13 lines
drivers/input/keyboard/mpr121.c new file +13 -0
+	vdd = pdata->vdd_uv / 1000;
+	usl = ((vdd - 700) * 256) / vdd;
+	lsl = (usl * 65) / 100;
+	tl = (usl * 90) / 100;
+	ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
+	ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
+	ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
+	ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
+					data->keycount);
+	if (ret != 0)
+		goto err_i2c_write;
+
+	dev_info(&client->dev, "mpr121: config as enable %x of electrode.\n",

typo ?

Quoted 33 lines
drivers/input/keyboard/mpr121.c new file +33 -0
+		 data->keycount);
+
+	return 0;
+
+err_i2c_write:
+	dev_err(&client->dev, "i2c write error: %d\n", ret);
+	return ret;
+}
+
+static int __devinit mpr_touchkey_probe(struct i2c_client *client,
+					const struct i2c_device_id *id)
+{
+	struct mpr121_platform_data *pdata;
+	struct mpr121_touchkey_data *data;
+	struct input_dev *input_dev;
+	int error;
+	int i;
+
+	pdata = client->dev.platform_data;
+	if (!pdata) {
+		dev_err(&client->dev, "no platform data defined\n");
+		return -EINVAL;
+	}
+
+	if (!client->irq) {
+		dev_err(&client->dev, "The irq number should not be zero\n");
+		return -EINVAL;
+	}
+
+	data = kzalloc(sizeof(struct mpr121_touchkey_data), GFP_KERNEL);
+	input_dev = input_allocate_device();
+	if (!data || !input_dev) {
+		dev_err(&client->dev, "Falied to allocate memory\n");

drivers/input/keyboard/mpr121.c line 176

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+		error = -ENOMEM;
+		goto err_free_mem;
+	}
+
+	data->client = client;
+	data->input_dev = input_dev;
+	data->keycount = pdata->keycount;
+
+	if (data->keycount > MPR121_MAX_KEY_COUNT) {
+		dev_err(&client->dev, "Too many key defined\n");

typo

Quoted 93 lines
drivers/input/keyboard/mpr121.c new file +93 -0
+		error = -EINVAL;
+		goto err_free_mem;
+	}
+
+	error = mpr121_phys_init(pdata, data, client);
+	if (error) {
+		dev_err(&client->dev, "Failed to init register\n");
+		goto err_free_mem;
+	}
+
+	i2c_set_clientdata(client, data);
+
+	input_dev->name = "FSL MPR121 Touchkey";
+	input_dev->id.bustype = BUS_I2C;
+	input_dev->dev.parent = &client->dev;
+	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
+	input_dev->keycode = pdata->matrix;
+	input_dev->keycodesize = sizeof(pdata->matrix[0]);
+	input_dev->keycodemax = data->keycount;
+
+	for (i = 0; i < input_dev->keycodemax; i++) {
+		__set_bit(pdata->matrix[i], input_dev->keybit);
+		data->keycodes[i] = pdata->matrix[i];
+	}
+
+	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+	input_set_drvdata(input_dev, data);
+
+	error = request_threaded_irq(client->irq, NULL,
+				     mpr_touchkey_interrupt,
+				     IRQF_TRIGGER_FALLING,
+				     client->dev.driver->name, data);
+	if (error) {
+		dev_err(&client->dev, "Failed to register interrupt\n");
+		goto err_free_mem;
+	}
+
+	error = input_register_device(input_dev);
+	if (error)
+		goto err_free_irq;
+	i2c_set_clientdata(client, data);
+	device_init_wakeup(&client->dev, pdata->wakeup);
+	dev_info(&client->dev, "Mpr121 touch keyboard init success.\n");
+	return 0;
+
+err_free_irq:
+	free_irq(client->irq, data);
+err_free_mem:
+	input_free_device(input_dev);
+	kfree(data);
+	return error;
+}
+
+static int __devexit mpr_touchkey_remove(struct i2c_client *client)
+{
+	struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+	free_irq(client->irq, data);
+	input_unregister_device(data->input_dev);
+	kfree(data);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int mpr_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+
+	if (device_may_wakeup(&client->dev))
+		enable_irq_wake(client->irq);
+
+	i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
+
+	return 0;
+}
+
+static int mpr_resume(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+	if (device_may_wakeup(&client->dev))
+		disable_irq_wake(client->irq);
+
+	i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, data->keycount);
+
+	return 0;
+}
+#endif
+
+static const struct i2c_device_id mpr121_id[] = {
+	{"mpr121_touchkey", 0},

drivers/input/keyboard/mpr121.c line 279

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+	{ }
+};
+
+static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
+
+static struct i2c_driver mpr_touchkey_driver = {
+	.driver = {
+		.name	= "mpr121",
+		.owner	= THIS_MODULE,
+		.pm	= &mpr121_touchkey_pm_ops,

I would add a ifdef CONFIG_PM_SLEEP

Quoted 28 lines
drivers/input/keyboard/mpr121.c new file +22 -0
+	},
+	.id_table	= mpr121_id,
+	.probe		= mpr_touchkey_probe,
+	.remove		= __devexit_p(mpr_touchkey_remove),
+};
+
+static int __init mpr_touchkey_init(void)
+{
+	return i2c_add_driver(&mpr_touchkey_driver);
+}
+
+static void __exit mpr_touchkey_exit(void)
+{
+	i2c_del_driver(&mpr_touchkey_driver);
+}
+
+module_init(mpr_touchkey_init);
+module_exit(mpr_touchkey_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Zhang Jiejing <[email protected]>");
+MODULE_DESCRIPTION("Touch Key driver for FSL MPR121 Chip");
include/linux/i2c/mpr.h new file +0 -0
new file mode 100644
index 0000000..52d6e33

include/linux/i2c/mpr.h line 1

Quoted 1 line
include/linux/i2c/mpr.h new file +1 -0
@@ -0,0 +1,64 @@
+/* mpr.h - Header file for Freescale mpr121 capacitive touch sensor

no filename please

Quoted 9 lines
include/linux/i2c/mpr.h new file +9 -0
+ * controllor */
+
+#ifndef MPR_H
+#define MPR_H
+
+/* Register definitions */
+#define ELE_TOUCH_STATUS_0_ADDR	0x0
+#define ELE_TOUCH_STATUS_1_ADDR	0X1
+#define MHD_RISING_ADDR		0x2b

include/linux/i2c/mpr.h line 20

Quoted 10 lines
include/linux/i2c/mpr.h new file +10 -0
+#define NHD_RISING_ADDR		0x2c
+#define NCL_RISING_ADDR		0x2d
+#define FDL_RISING_ADDR		0x2e
+#define MHD_FALLING_ADDR	0x2f
+#define NHD_FALLING_ADDR	0x30
+#define NCL_FALLING_ADDR	0x31
+#define FDL_FALLING_ADDR	0x32
+#define ELE0_TOUCH_THRESHOLD_ADDR	0x41
+#define ELE0_RELEASE_THRESHOLD_ADDR	0x42
+/* ELE0...ELE11's threshold will set in a loop */

typo

include/linux/i2c/mpr.h line 28

Quoted 8 lines
include/linux/i2c/mpr.h new file +8 -0
+#define AFE_CONF_ADDR			0x5c
+#define FILTER_CONF_ADDR		0x5d
+
+/* ELECTRODE_CONF: this register is most important register, it
+ * control how many of electrode is enabled. If you set this register
+ * to 0x0, it make the sensor going to suspend mode. Other value(low
+ * bit is non-zero) will make the sensor into Run mode.  This register
+ * should be write at last.

typo

include/linux/i2c/mpr.h line 34

Quoted 6 lines
include/linux/i2c/mpr.h new file +6 -0
+ */
+#define ELECTRODE_CONF_ADDR		0x5e
+#define AUTO_CONFIG_CTRL_ADDR		0x7b
+/* AUTO_CONFIG_USL: Upper Limit for auto baseline search, this
+ * register is related to VDD supplied on your board, the value of
+ * this register is calc by EQ: `((VDD-0.7)/VDD) * 256`.

typo

include/linux/i2c/mpr.h line 37

Quoted 3 lines
include/linux/i2c/mpr.h new file +3 -0
+ * AUTO_CONFIG_LSL: Low Limit of auto baseline search. This is 65% of
+ * USL AUTO_CONFIG_TL: The Traget Level of auto baseline search, This
+ * is 90% of USL  */

typo

include/linux/i2c/mpr.h line 45

Quoted 8 lines
include/linux/i2c/mpr.h new file +8 -0
+#define AUTO_CONFIG_USL_ADDR		0x7d
+#define AUTO_CONFIG_LSL_ADDR		0x7e
+#define AUTO_CONFIG_TL_ADDR		0x7f
+
+/* Threshold of touch/release trigger */
+#define TOUCH_THRESHOLD			0x0f
+#define RELEASE_THRESHOLD		0x0a
+/* Mask Button bits of STATUS_0 & STATUS_1 register */

and or bit-and?

include/linux/i2c/mpr.h line 52

Quoted 7 lines
include/linux/i2c/mpr.h new file +7 -0
+#define TOUCH_STATUS_MASK		0xfff
+/* MPR121 have 12 electrodes */
+#define MPR121_MAX_KEY_COUNT		12
+
+
+/**
+ * @keycount: how many key maped

typo: "keys" ?

include/linux/i2c/mpr.h line 53

Quoted 1 line
include/linux/i2c/mpr.h new file +1 -0
+ * @vdd_uv: voltage of vdd supply the chip in uV

- typo
- uppercase for vdd

include/linux/i2c/mpr.h line 55

Quoted 2 lines
include/linux/i2c/mpr.h new file +2 -0
+ * @matrix: maxtrix of keys
+ * @wakeup: can key wake up system.

typo

Quoted 16 lines
include/linux/i2c/mpr.h new file +9 -0
+ */
+struct mpr121_platform_data {
+	u16 keycount;
+	u16 *matrix;
+	int wakeup;
+	int vdd_uv;
+};
+
+#endif
Signature · 5 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]

More majordomo info at http://vger.kernel.org/majordomo-info.htmln Tue, Apr 12, 2011 at 01:02:17AM +0800, Jiejing Zhang wrote:

maintainer
#2 lore raw
Quoted 12 lines · Christoph Fritz

drivers/input/keyboard/mpr121.c line 279

Quoted 8 lines · Jiejing Zhang
drivers/input/keyboard/mpr121.c new file +8 -0
+
+static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
+
+static struct i2c_driver mpr_touchkey_driver = {
+	.driver = {
+		.name	= "mpr121",
+		.owner	= THIS_MODULE,
+		.pm	= &mpr121_touchkey_pm_ops,

I would add a ifdef CONFIG_PM_SLEEP

No, since we could try supporting CONFIG_PM_RUNTIME for example (not necessarily in this driver, but in general case). dev_pm_ops structire is defined always but it contents change de3pending on CONFIG_PM_SLEEP. CONFIG_PM_RUNTILE and so forth. At a minium it is an empty structure, but it woudl still be defined.

Thanks.

Signature · 1 line
Dmitry
maintainer
#7 lore raw
In reply to Jiejing Zhang

Hi Jiejing,

Quoted 11 lines · Jiejing Zhang

From: Zhang Jiejing <[email protected]>

This touchkey driver is based on Freescale mpr121 capacitive touch sensor controller.

It can support up to 12 keys, it use i2c interface.

The product infomation(data sheet, application notes) can be found under this link:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

MOstly reasonable. In addition to Christoph's comments:

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static struct mpr121_init_register init_reg_table[] = {

const? And also __devinitconst?

Quoted 27 lines
drivers/input/keyboard/mpr121.c new file +27 -0
+	{MHD_RISING_ADDR,	0x1},
+	{NHD_RISING_ADDR,	0x1},
+	{MHD_FALLING_ADDR,	0x1},
+	{NHD_FALLING_ADDR,	0x1},
+	{NCL_FALLING_ADDR,	0xff},
+	{FDL_FALLING_ADDR,	0x02},
+	{FILTER_CONF_ADDR,	0x04},
+	{AFE_CONF_ADDR,		0x0b},
+	{AUTO_CONFIG_CTRL_ADDR, 0x0b},
+};
+
+static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
+{
+	struct mpr121_touchkey_data *data = dev_id;
+	struct i2c_client *client = data->client;
+	struct input_dev *input = data->input_dev;
+	unsigned int key_num, pressed;
+	int reg;
+
+	reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
+	if (reg < 0) {
+		dev_err(&client->dev, "i2c read error [%d]\n", reg);
+		goto out;
+	}
+
+	reg <<= 8;
+	reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);

drivers/input/keyboard/mpr121.c line 77

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+	if (reg < 0) {
+		dev_err(&client->dev, "i2c read error [%d]\n", reg);
+		goto out;
+	}
+
+	reg &= TOUCH_STATUS_MASK;
+	/* use old press bit to figure out which bit changed */
+	key_num = ffs(reg ^ data->statusbits) - 1;
+	/* use the bit check the press status */
+	pressed = (reg & (1 << (key_num))) >> key_num;

No need to shift by key_num, input_report_key normalizes to 'bool'.

drivers/input/keyboard/mpr121.c line 81

Quoted 4 lines
drivers/input/keyboard/mpr121.c new file +4 -0
+	data->statusbits = reg;
+	data->key_val = data->keycodes[key_num];
+
+	input_event(input, EV_MSC, MSC_SCAN, data->key_val);

sScancode is not data->key_val as it is KEY_XXX value but rather key_num.

drivers/input/keyboard/mpr121.c

Quoted 11 lines
drivers/input/keyboard/mpr121.c new file +11 -0
+	input_report_key(input, data->key_val, pressed);
+	input_sync(input);
+
+	dev_dbg(&client->dev, "key %d %d %s\n", key_num, data->key_val,
+		pressed ? "pressed" : "released");
+
+out:
+	return IRQ_HANDLED;
+}
+
+static int mpr121_phys_init(

__devinit

struct mpr121_platform_data *pdata,

pdata should be const.

Quoted 32 lines
drivers/input/keyboard/mpr121.c new file +32 -0
+			    struct mpr121_touchkey_data *data,
+			    struct i2c_client *client)
+{
+	struct mpr121_init_register *reg;
+	unsigned char usl, lsl, tl;
+	int i, t, vdd, ret;
+
+	/* setup touch/release threshold for ele0-ele11 */
+	for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
+		t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
+		ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
+		if (ret < 0)
+			goto err_i2c_write;
+		ret = i2c_smbus_write_byte_data(client, t + 1,
+						RELEASE_THRESHOLD);
+		if (ret < 0)
+			goto err_i2c_write;
+	}
+	/* setup init register */
+	for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
+		reg = &init_reg_table[i];
+		ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
+		if (ret < 0)
+			goto err_i2c_write;
+	}
+	/* setup auto-register by vdd,the formula please ref: AN3889
+	 * These register *must* set acrodding your VDD voltage supply
+	 * to the chip*/
+	vdd = pdata->vdd_uv / 1000;
+	usl = ((vdd - 700) * 256) / vdd;
+	lsl = (usl * 65) / 100;
+	tl = (usl * 90) / 100;

drivers/input/keyboard/mpr121.c line 134

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+	ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
+	ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
+	ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
+	ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
+					data->keycount);
+	if (ret != 0)
+		goto err_i2c_write;
+
+	dev_info(&client->dev, "mpr121: config as enable %x of electrode.\n",
+		 data->keycount);

Does it have to be dev_info? dev_dbg maybe?

drivers/input/keyboard/mpr121.c line 146

Quoted 12 lines
drivers/input/keyboard/mpr121.c new file +12 -0
+
+	return 0;
+
+err_i2c_write:
+	dev_err(&client->dev, "i2c write error: %d\n", ret);
+	return ret;
+}
+
+static int __devinit mpr_touchkey_probe(struct i2c_client *client,
+					const struct i2c_device_id *id)
+{
+	struct mpr121_platform_data *pdata;

const.

Quoted 31 lines
drivers/input/keyboard/mpr121.c new file +31 -0
+	struct mpr121_touchkey_data *data;
+	struct input_dev *input_dev;
+	int error;
+	int i;
+
+	pdata = client->dev.platform_data;
+	if (!pdata) {
+		dev_err(&client->dev, "no platform data defined\n");
+		return -EINVAL;
+	}
+
+	if (!client->irq) {
+		dev_err(&client->dev, "The irq number should not be zero\n");
+		return -EINVAL;
+	}
+
+	data = kzalloc(sizeof(struct mpr121_touchkey_data), GFP_KERNEL);
+	input_dev = input_allocate_device();
+	if (!data || !input_dev) {
+		dev_err(&client->dev, "Falied to allocate memory\n");
+		error = -ENOMEM;
+		goto err_free_mem;
+	}
+
+	data->client = client;
+	data->input_dev = input_dev;
+	data->keycount = pdata->keycount;
+
+	if (data->keycount > MPR121_MAX_KEY_COUNT) {
+		dev_err(&client->dev, "Too many key defined\n");
+		error = -EINVAL;

drivers/input/keyboard/mpr121.c line 187

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+		goto err_free_mem;
+	}
+
+	error = mpr121_phys_init(pdata, data, client);
+	if (error) {
+		dev_err(&client->dev, "Failed to init register\n");
+		goto err_free_mem;
+	}
+
+	i2c_set_clientdata(client, data);

You should do this at the very end, before returning success (0). Actually, you do do this, so just remove this instance.

drivers/input/keyboard/mpr121.c line 193

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+
+	input_dev->name = "FSL MPR121 Touchkey";
+	input_dev->id.bustype = BUS_I2C;
+	input_dev->dev.parent = &client->dev;
+	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
+	input_dev->keycode = pdata->matrix;

No, you are assigning pointer to the platform data, instead of pointer to the data in device structure. That is why I'd rather you renamed 'struct mpr121_touchkey_data' to 'struct mpr121_touchkey' and 'data' to 'mpr121' so as to avoid confusion with platform data.

Quoted 16 lines
drivers/input/keyboard/mpr121.c new file +16 -0
+	input_dev->keycodesize = sizeof(pdata->matrix[0]);
+	input_dev->keycodemax = data->keycount;
+
+	for (i = 0; i < input_dev->keycodemax; i++) {
+		__set_bit(pdata->matrix[i], input_dev->keybit);
+		data->keycodes[i] = pdata->matrix[i];
+	}
+
+	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+	input_set_drvdata(input_dev, data);
+
+	error = request_threaded_irq(client->irq, NULL,
+				     mpr_touchkey_interrupt,
+				     IRQF_TRIGGER_FALLING,
+				     client->dev.driver->name, data);
+	if (error) {

drivers/input/keyboard/mpr121.c line 219

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+		dev_err(&client->dev, "Failed to register interrupt\n");
+		goto err_free_mem;
+	}
+
+	error = input_register_device(input_dev);
+	if (error)
+		goto err_free_irq;
+	i2c_set_clientdata(client, data);
+	device_init_wakeup(&client->dev, pdata->wakeup);
+	dev_info(&client->dev, "Mpr121 touch keyboard init success.\n");

No need for having this message. You can see the device bound to the driver in sysfs. The boot is noisy enough.

Quoted 106 lines
drivers/input/keyboard/mpr121.c new file +82 -0
+	return 0;
+
+err_free_irq:
+	free_irq(client->irq, data);
+err_free_mem:
+	input_free_device(input_dev);
+	kfree(data);
+	return error;
+}
+
+static int __devexit mpr_touchkey_remove(struct i2c_client *client)
+{
+	struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+	free_irq(client->irq, data);
+	input_unregister_device(data->input_dev);
+	kfree(data);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int mpr_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+
+	if (device_may_wakeup(&client->dev))
+		enable_irq_wake(client->irq);
+
+	i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
+
+	return 0;
+}
+
+static int mpr_resume(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+	if (device_may_wakeup(&client->dev))
+		disable_irq_wake(client->irq);
+
+	i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, data->keycount);
+
+	return 0;
+}
+#endif
+
+static const struct i2c_device_id mpr121_id[] = {
+	{"mpr121_touchkey", 0},
+	{ }
+};
+
+static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
+
+static struct i2c_driver mpr_touchkey_driver = {
+	.driver = {
+		.name	= "mpr121",
+		.owner	= THIS_MODULE,
+		.pm	= &mpr121_touchkey_pm_ops,
+	},
+	.id_table	= mpr121_id,
+	.probe		= mpr_touchkey_probe,
+	.remove		= __devexit_p(mpr_touchkey_remove),
+};
+
+static int __init mpr_touchkey_init(void)
+{
+	return i2c_add_driver(&mpr_touchkey_driver);
+}
+
+static void __exit mpr_touchkey_exit(void)
+{
+	i2c_del_driver(&mpr_touchkey_driver);
+}
+
+module_init(mpr_touchkey_init);
+module_exit(mpr_touchkey_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Zhang Jiejing <[email protected]>");
+MODULE_DESCRIPTION("Touch Key driver for FSL MPR121 Chip");
include/linux/i2c/mpr.h new file +18 -0
new file mode 100644
index 0000000..52d6e33
@@ -0,0 +1,64 @@
+/* mpr.h - Header file for Freescale mpr121 capacitive touch sensor
+ * controllor */
+
+#ifndef MPR_H
+#define MPR_H
+
+/* Register definitions */
+#define ELE_TOUCH_STATUS_0_ADDR	0x0
+#define ELE_TOUCH_STATUS_1_ADDR	0X1
+#define MHD_RISING_ADDR		0x2b
+#define NHD_RISING_ADDR		0x2c
+#define NCL_RISING_ADDR		0x2d
+#define FDL_RISING_ADDR		0x2e
+#define MHD_FALLING_ADDR	0x2f
+#define NHD_FALLING_ADDR	0x30
+#define NCL_FALLING_ADDR	0x31
+#define FDL_FALLING_ADDR	0x32
+#define ELE0_TOUCH_THRESHOLD_ADDR	0x41

include/linux/i2c/mpr.h line 28

Quoted 10 lines
include/linux/i2c/mpr.h new file +10 -0
+#define ELE0_RELEASE_THRESHOLD_ADDR	0x42
+/* ELE0...ELE11's threshold will set in a loop */
+#define AFE_CONF_ADDR			0x5c
+#define FILTER_CONF_ADDR		0x5d
+
+/* ELECTRODE_CONF: this register is most important register, it
+ * control how many of electrode is enabled. If you set this register
+ * to 0x0, it make the sensor going to suspend mode. Other value(low
+ * bit is non-zero) will make the sensor into Run mode.  This register
+ * should be write at last.

Hmm, most of the comments require proper grammar. If you need help with it - let the list know, we'll try to help.

Quoted 21 lines
include/linux/i2c/mpr.h new file +21 -0
+ */
+#define ELECTRODE_CONF_ADDR		0x5e
+#define AUTO_CONFIG_CTRL_ADDR		0x7b
+/* AUTO_CONFIG_USL: Upper Limit for auto baseline search, this
+ * register is related to VDD supplied on your board, the value of
+ * this register is calc by EQ: `((VDD-0.7)/VDD) * 256`.
+ * AUTO_CONFIG_LSL: Low Limit of auto baseline search. This is 65% of
+ * USL AUTO_CONFIG_TL: The Traget Level of auto baseline search, This
+ * is 90% of USL  */
+#define AUTO_CONFIG_USL_ADDR		0x7d
+#define AUTO_CONFIG_LSL_ADDR		0x7e
+#define AUTO_CONFIG_TL_ADDR		0x7f
+
+/* Threshold of touch/release trigger */
+#define TOUCH_THRESHOLD			0x0f
+#define RELEASE_THRESHOLD		0x0a
+/* Mask Button bits of STATUS_0 & STATUS_1 register */
+#define TOUCH_STATUS_MASK		0xfff
+/* MPR121 have 12 electrodes */
+#define MPR121_MAX_KEY_COUNT		12
+

include/linux/i2c/mpr.h line 59

Quoted 10 lines
include/linux/i2c/mpr.h new file +10 -0
+
+/**
+ * @keycount: how many key maped
+ * @vdd_uv: voltage of vdd supply the chip in uV
+ * @matrix: maxtrix of keys
+ * @wakeup: can key wake up system.
+ */
+struct mpr121_platform_data {
+	u16 keycount;
+	u16 *matrix;

If this device is indeed organized as a matrix (lookslike this) maybe you should look at definitions provided by include/linux/input/matrix_keypad.h

include/linux/i2c/mpr.h line 60

Quoted 1 line
include/linux/i2c/mpr.h new file +1 -0
+	int wakeup;

bool?

include/linux/i2c/mpr.h line 64

Quoted 4 lines
include/linux/i2c/mpr.h new file +4 -0
+	int vdd_uv;
+};
+
+#endif

Thanks.

Signature · 1 line
Dmitry
#4 lore raw
In reply to a message not in the archive

Hi Christoph,

I'm sorry for my poor English grammar.
I'll try to fix these typo, If still have error, please point me out.

2011/4/12 Christoph Fritz <[email protected]>

Quoted 9 lines

Hi Zhang,

 this is just a superficial review of your driver.

thanks,
 Christoph

On Tue, Apr 12, 2011 at 01:02:17AM +0800, Jiejing Zhang wrote:

Quoted 8 lines
Quoted 6 lines

From: Zhang Jiejing <[email protected]>

This touchkey driver is based on Freescale mpr121 capacitive touch sensor controller.

It can support up to 12 keys, it use i2c interface.

typo

-> It can supports up to 12 electrodes, and using i2c interface.

Quoted 24 lines
Quoted 24 lines

The product infomation(data sheet, application notes) can be found under this link:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

---
 drivers/input/keyboard/Kconfig  |   12 ++ drivers/input/keyboard/Makefile |    1 + drivers/input/keyboard/mpr121.c |  301 +++++++++++++++++++++++++++++++++++++++ include/linux/i2c/mpr.h         |   64 ++++++++

 4 files changed, 378 insertions(+), 0 deletions(-)

 create mode 100644 drivers/input/keyboard/mpr121.c create mode 100644 include/linux/i2c/mpr.h

drivers/input/keyboard/Kconfig +0 -0
index b16bed0..0666e1e 100644
@@ -520,6 +520,18 @@ config KEYBOARD_XTKBD

        To compile this driver as a module, choose M here: the module will be called xtkbd.

Quoted 7 lines
Quoted 5 lines

+config KEYBOARD_MPR121
+     tristate "Freescale MPR121 Touchkey Driver"
+     depends on I2C
+     help
+       Say Y here if you have the  touchkey Freescale mpr121 capacitive

typo: two spaces

will fix.

Quoted 17 lines
Quoted 11 lines

+       touch sensor controller in your system.

drivers/input/keyboard/Kconfig +6 -0
+
+       If unsure, say N.
+
+       To compile this driver as a module, choose M here
+endif
+

 config KEYBOARD_W90P910
      tristate "W90P910 Matrix Keypad support"
      depends on ARCH_W90X900

- add: "To compile this driver as a module, choose M here: the module will be called mpr121."
- "endif" is wrong here, it breaks 'make config'
- maybe a more alphabetic approach in this list of drivers would be nice

yes. I will.

Quoted 13 lines
Quoted 11 lines
drivers/input/keyboard/Makefile +0 -0
index 878e6c2..b110ca8 100644
@@ -47,4 +47,5 @@ obj-$(CONFIG_KEYBOARD_TEGRA)                += tegra-kbc.o

 obj-$(CONFIG_KEYBOARD_TNETV107X)     += tnetv107x-keypad.o obj-$(CONFIG_KEYBOARD_TWL4030)               += twl4030_keypad.o obj-$(CONFIG_KEYBOARD_XTKBD)         += xtkbd.o +obj-$(CONFIG_KEYBOARD_MPR121)                += mpr121.o obj-$(CONFIG_KEYBOARD_W90P910)               += w90p910_keypad.o

for better examination, please mind alphabetic order

will do.

Quoted 22 lines
Quoted 22 lines
drivers/input/keyboard/mpr121.c new file +15 -0
new file mode 100644
index 0000000..ee149a8
@@ -0,0 +1,301 @@
+/*
+ * Touchkey driver for Freescale MPR121 Controllor
+ *
+ * Copyright (C) 2011 Freescale Semiconductor, Inc.
+ * Author: Zhang Jiejing <[email protected]>
+ *
+ * Based on mcs_touchkey.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 21

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/i2c/mpr.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/irq.h>

do not use irq.h directly

ok.

Quoted 50 lines
Quoted 50 lines
drivers/input/keyboard/mpr121.c new file +49 -0
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+
+struct mpr121_touchkey_data {
+     struct i2c_client       *client;
+     struct input_dev        *input_dev;
+     unsigned int            key_val;
+     int                     statusbits;
+     int                     keycount;
+     u16                     keycodes[MPR121_MAX_KEY_COUNT];
+};
+
+struct mpr121_init_register {
+     int addr;
+     u8 val;
+};
+
+static struct mpr121_init_register init_reg_table[] = {
+     {MHD_RISING_ADDR,       0x1},
+     {NHD_RISING_ADDR,       0x1},
+     {MHD_FALLING_ADDR,      0x1},
+     {NHD_FALLING_ADDR,      0x1},
+     {NCL_FALLING_ADDR,      0xff},
+     {FDL_FALLING_ADDR,      0x02},
+     {FILTER_CONF_ADDR,      0x04},
+     {AFE_CONF_ADDR,         0x0b},
+     {AUTO_CONFIG_CTRL_ADDR, 0x0b},
+};
+
+static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
+{
+     struct mpr121_touchkey_data *data = dev_id;
+     struct i2c_client *client = data->client;
+     struct input_dev *input = data->input_dev;
+     unsigned int key_num, pressed;
+     int reg;
+
+     reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
+     }
+
+     reg <<= 8;
+     reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 76

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+     }
+
+     reg &= TOUCH_STATUS_MASK;
+     /* use old press bit to figure out which bit changed */
+     key_num = ffs(reg ^ data->statusbits) - 1;
+     /* use the bit check the press status */

typo

this comment will remove.

Quoted 39 lines
Quoted 39 lines
drivers/input/keyboard/mpr121.c new file +38 -0
+     pressed = (reg & (1 << (key_num))) >> key_num;
+     data->statusbits = reg;
+     data->key_val = data->keycodes[key_num];
+
+     input_event(input, EV_MSC, MSC_SCAN, data->key_val);
+     input_report_key(input, data->key_val, pressed);
+     input_sync(input);
+
+     dev_dbg(&client->dev, "key %d %d %s\n", key_num, data->key_val,
+             pressed ? "pressed" : "released");
+
+out:
+     return IRQ_HANDLED;
+}
+
+static int mpr121_phys_init(struct mpr121_platform_data *pdata,
+                         struct mpr121_touchkey_data *data,
+                         struct i2c_client *client)
+{
+     struct mpr121_init_register *reg;
+     unsigned char usl, lsl, tl;
+     int i, t, vdd, ret;
+
+     /* setup touch/release threshold for ele0-ele11 */
+     for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
+             t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
+             ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+             ret = i2c_smbus_write_byte_data(client, t + 1,
+                                             RELEASE_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup init register */
+     for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
+             reg = &init_reg_table[i];
+             ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 120

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup auto-register by vdd,the formula please ref: AN3889
+      * These register *must* set acrodding your VDD voltage supply
+      * to the chip*/

typo

is this right?
    /* setup Auto Config Registers by VDD.
     * The formula was written in AN3889.
     * These registers *must* be set by VDD voltage. */

Quoted 15 lines
Quoted 4 lines
drivers/input/keyboard/mpr121.c new file +3 -0
+     vdd = pdata->vdd_uv / 1000;
+     usl = ((vdd - 700) * 256) / vdd;
+     lsl = (usl * 65) / 100;

drivers/input/keyboard/mpr121.c line 133

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+     tl = (usl * 90) / 100;
+     ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
+     ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
+                                     data->keycount);
+     if (ret != 0)
+             goto err_i2c_write;
+
+     dev_info(&client->dev, "mpr121: config as enable %x of electrode.\n",
Quoted 1 line

typo ?

-> dev_dbg(&client->dev, "mpr121: setup with %x electrodes.\n",

Quoted 38 lines
Quoted 38 lines
drivers/input/keyboard/mpr121.c new file +37 -0
+              data->keycount);
+
+     return 0;
+
+err_i2c_write:
+     dev_err(&client->dev, "i2c write error: %d\n", ret);
+     return ret;
+}
+
+static int __devinit mpr_touchkey_probe(struct i2c_client *client,
+                                     const struct i2c_device_id *id)
+{
+     struct mpr121_platform_data *pdata;
+     struct mpr121_touchkey_data *data;
+     struct input_dev *input_dev;
+     int error;
+     int i;
+
+     pdata = client->dev.platform_data;
+     if (!pdata) {
+             dev_err(&client->dev, "no platform data defined\n");
+             return -EINVAL;
+     }
+
+     if (!client->irq) {
+             dev_err(&client->dev, "The irq number should not be zero\n");
+             return -EINVAL;
+     }
+
+     data = kzalloc(sizeof(struct mpr121_touchkey_data), GFP_KERNEL);
+     input_dev = input_allocate_device();
+     if (!data || !input_dev) {
+             dev_err(&client->dev, "Falied to allocate memory\n");
+             error = -ENOMEM;
+             goto err_free_mem;
+     }
+
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 176

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+     data->client = client;
+     data->input_dev = input_dev;
+     data->keycount = pdata->keycount;
+
+     if (data->keycount > MPR121_MAX_KEY_COUNT) {
+             dev_err(&client->dev, "Too many key defined\n");

typo

-> dev_err(&client->dev, "too much keys defined\n");

Quoted 130 lines
Quoted 94 lines
drivers/input/keyboard/mpr121.c new file +93 -0
+             error = -EINVAL;
+             goto err_free_mem;
+     }
+
+     error = mpr121_phys_init(pdata, data, client);
+     if (error) {
+             dev_err(&client->dev, "Failed to init register\n");
+             goto err_free_mem;
+     }
+
+     i2c_set_clientdata(client, data);
+
+     input_dev->name = "FSL MPR121 Touchkey";
+     input_dev->id.bustype = BUS_I2C;
+     input_dev->dev.parent = &client->dev;
+     input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
+     input_dev->keycode = pdata->matrix;
+     input_dev->keycodesize = sizeof(pdata->matrix[0]);
+     input_dev->keycodemax = data->keycount;
+
+     for (i = 0; i < input_dev->keycodemax; i++) {
+             __set_bit(pdata->matrix[i], input_dev->keybit);
+             data->keycodes[i] = pdata->matrix[i];
+     }
+
+     input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+     input_set_drvdata(input_dev, data);
+
+     error = request_threaded_irq(client->irq, NULL,
+                                  mpr_touchkey_interrupt,
+                                  IRQF_TRIGGER_FALLING,
+                                  client->dev.driver->name, data);
+     if (error) {
+             dev_err(&client->dev, "Failed to register interrupt\n");
+             goto err_free_mem;
+     }
+
+     error = input_register_device(input_dev);
+     if (error)
+             goto err_free_irq;
+     i2c_set_clientdata(client, data);
+     device_init_wakeup(&client->dev, pdata->wakeup);
+     dev_info(&client->dev, "Mpr121 touch keyboard init success.\n");
+     return 0;
+
+err_free_irq:
+     free_irq(client->irq, data);
+err_free_mem:
+     input_free_device(input_dev);
+     kfree(data);
+     return error;
+}
+
+static int __devexit mpr_touchkey_remove(struct i2c_client *client)
+{
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     free_irq(client->irq, data);
+     input_unregister_device(data->input_dev);
+     kfree(data);
+
+     return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int mpr_suspend(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+
+     if (device_may_wakeup(&client->dev))
+             enable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
+
+     return 0;
+}
+
+static int mpr_resume(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     if (device_may_wakeup(&client->dev))
+             disable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, data->keycount);
+
+     return 0;
+}
+#endif
+
+static const struct i2c_device_id mpr121_id[] = {
+     {"mpr121_touchkey", 0},

drivers/input/keyboard/mpr121.c line 279

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+     { }
+};
+
+static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
+
+static struct i2c_driver mpr_touchkey_driver = {
+     .driver = {
+             .name   = "mpr121",
+             .owner  = THIS_MODULE,
+             .pm     = &mpr121_touchkey_pm_ops,

I would add a ifdef CONFIG_PM_SLEEP

Quoted 23 lines
drivers/input/keyboard/mpr121.c new file +22 -0
+     },
+     .id_table       = mpr121_id,
+     .probe          = mpr_touchkey_probe,
+     .remove         = __devexit_p(mpr_touchkey_remove),
+};
+
+static int __init mpr_touchkey_init(void)
+{
+     return i2c_add_driver(&mpr_touchkey_driver);
+}
+
+static void __exit mpr_touchkey_exit(void)
+{
+     i2c_del_driver(&mpr_touchkey_driver);
+}
+
+module_init(mpr_touchkey_init);
+module_exit(mpr_touchkey_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Zhang Jiejing <[email protected]>");
+MODULE_DESCRIPTION("Touch Key driver for FSL MPR121 Chip");
include/linux/i2c/mpr.h +0 -0
Quoted 8 lines

include/linux/i2c/mpr.h line 1

Quoted 6 lines

new file mode 100644
index 0000000..52d6e33

include/linux/i2c/mpr.h new file +1 -0
@@ -0,0 +1,64 @@
+/* mpr.h - Header file for Freescale mpr121 capacitive touch sensor

no filename please

will do.

Quoted 14 lines
Quoted 14 lines
include/linux/i2c/mpr.h new file +13 -0
+ * controllor */
+
+#ifndef MPR_H
+#define MPR_H
+
+/* Register definitions */
+#define ELE_TOUCH_STATUS_0_ADDR      0x0
+#define ELE_TOUCH_STATUS_1_ADDR      0X1
+#define MHD_RISING_ADDR              0x2b
+#define NHD_RISING_ADDR              0x2c
+#define NCL_RISING_ADDR              0x2d
+#define FDL_RISING_ADDR              0x2e
+#define MHD_FALLING_ADDR     0x2f
Quoted 8 lines

include/linux/i2c/mpr.h line 20

Quoted 6 lines
include/linux/i2c/mpr.h new file +6 -0
+#define NHD_FALLING_ADDR     0x30
+#define NCL_FALLING_ADDR     0x31
+#define FDL_FALLING_ADDR     0x32
+#define ELE0_TOUCH_THRESHOLD_ADDR    0x41
+#define ELE0_RELEASE_THRESHOLD_ADDR  0x42
+/* ELE0...ELE11's threshold will set in a loop */

typo

-> /* ELE0...ELE11's threshold will be set in a loop */

Quoted 11 lines

include/linux/i2c/mpr.h line 28

Quoted 9 lines
include/linux/i2c/mpr.h new file +8 -0
+#define AFE_CONF_ADDR                        0x5c
+#define FILTER_CONF_ADDR             0x5d
+
+/* ELECTRODE_CONF: this register is most important register, it
+ * control how many of electrode is enabled. If you set this register
+ * to 0x0, it make the sensor going to suspend mode. Other value(low
+ * bit is non-zero) will make the sensor into Run mode.  This register
+ * should be write at last.

typo

->  * should be written in the end.

Quoted 9 lines

include/linux/i2c/mpr.h line 34

Quoted 7 lines
include/linux/i2c/mpr.h new file +6 -0
+ */
+#define ELECTRODE_CONF_ADDR          0x5e
+#define AUTO_CONFIG_CTRL_ADDR                0x7b
+/* AUTO_CONFIG_USL: Upper Limit for auto baseline search, this
+ * register is related to VDD supplied on your board, the value of
+ * this register is calc by EQ: `((VDD-0.7)/VDD) * 256`.

typo

->  * this register is calculated by EQ: ((VDD-0.7)/VDD) * 256.

Quoted 6 lines

include/linux/i2c/mpr.h line 37

Quoted 4 lines
include/linux/i2c/mpr.h new file +3 -0
+ * AUTO_CONFIG_LSL: Low Limit of auto baseline search. This is 65% of
+ * USL AUTO_CONFIG_TL: The Traget Level of auto baseline search, This
+ * is 90% of USL  */

typo

->  * USL AUTO_CONFIG_TL: The traget level of auto baseline search, it is ->  * 90% of USL */

Quoted 11 lines

include/linux/i2c/mpr.h line 45

Quoted 9 lines
include/linux/i2c/mpr.h new file +8 -0
+#define AUTO_CONFIG_USL_ADDR         0x7d
+#define AUTO_CONFIG_LSL_ADDR         0x7e
+#define AUTO_CONFIG_TL_ADDR          0x7f
+
+/* Threshold of touch/release trigger */
+#define TOUCH_THRESHOLD                      0x0f
+#define RELEASE_THRESHOLD            0x0a
+/* Mask Button bits of STATUS_0 & STATUS_1 register */

and or bit-and?

don't need and or bit-and, it just means low 12 bits of status register is touch key's status.
-> /* low 12 bits of status register is touch key's status */

Quoted 10 lines

include/linux/i2c/mpr.h line 52

Quoted 8 lines
include/linux/i2c/mpr.h new file +7 -0
+#define TOUCH_STATUS_MASK            0xfff
+/* MPR121 have 12 electrodes */
+#define MPR121_MAX_KEY_COUNT         12
+
+
+/**
+ * @keycount: how many key maped

typo: "keys" ?

->  * @keycount: how many keys mapped

Quoted 5 lines

include/linux/i2c/mpr.h line 53

Quoted 2 lines
include/linux/i2c/mpr.h new file +1 -0
+ * @vdd_uv: voltage of vdd supply the chip in uV

- typo
- uppercase for vdd

->  * @vdd_uv: VDD voltage in uV

Quoted 5 lines

include/linux/i2c/mpr.h line 55

Quoted 3 lines
include/linux/i2c/mpr.h new file +2 -0
+ * @matrix: maxtrix of keys
+ * @wakeup: can key wake up system.

typo

->  * @wakeup: can wake up system or not

Quoted 13 lines
Quoted 13 lines
include/linux/i2c/mpr.h new file +9 -1
+ */
+struct mpr121_platform_data {
+     u16 keycount;
+     u16 *matrix;
+     int wakeup;
+     int vdd_uv;
+};
+
+#endif
--

1.7.1

Quoted 4 lines
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.htmln Tue, Apr 12, 2011 at 01:02:17AM +0800, Jiejing Zhang wrote:

:-(
sorry again for my horrible grammar.

Jiejing
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 3 lines · Jiejing.Zhang

Hi Christoph,

I'm sorry for my poor English grammar.

I suppose the list can help. Here is my input:

Quoted 14 lines

I'll try to fix these typo, If still have error, please point me out.

2011/4/12 Christoph Fritz <[email protected]>

Quoted 11 lines

Hi Zhang,

this is just a superficial review of your driver.

thanks,
Christoph

Quoted 2 lines · Jiejing Zhang

From: Zhang Jiejing <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This touchkey driver is based on Freescale mpr121 capacitive touch sensor controller.

It can support up to 12 keys, it use i2c interface.

typo

-> It can supports up to 12 electrodes, and using i2c interface.

This patch adds basic support for Freescale MPR121 capacitive touch sensor.
It's an i2c controller with up to 12 capacitance sensing inputs.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The product infomation(data sheet, application notes) can be found under this link:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

Product information (data sheet, application notes) can be found here:

Quoted 202 lines
Quoted 19 lines
Quoted 19 lines
---
 drivers/input/keyboard/Kconfig  |   12 ++
 drivers/input/keyboard/Makefile |    1 +
 drivers/input/keyboard/mpr121.c |  301 +++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/mpr.h         |   64 ++++++++
 4 files changed, 378 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/mpr121.c
 create mode 100644 include/linux/i2c/mpr.h
drivers/input/keyboard/Kconfig +0 -0
index b16bed0..0666e1e 100644
@@ -520,6 +520,18 @@ config KEYBOARD_XTKBD
        To compile this driver as a module, choose M here: the
        module will be called xtkbd.
 
Quoted 7 lines

drivers/input/keyboard/Kconfig config KEYBOARD_XTKBD · line 527

Quoted 5 lines
drivers/input/keyboard/Kconfig +5 -0
+config KEYBOARD_MPR121
+     tristate "Freescale MPR121 Touchkey Driver"
+     depends on I2C
+     help
+       Say Y here if you have the  touchkey Freescale mpr121 capacitive

typo: two spaces

will fix.

Quoted 17 lines

drivers/input/keyboard/Kconfig config KEYBOARD_XTKBD · line 537

Quoted 11 lines
drivers/input/keyboard/Kconfig +7 -0
+       touch sensor controller in your system.
+
+       If unsure, say N.
+
+       To compile this driver as a module, choose M here
+endif
+
 config KEYBOARD_W90P910
      tristate "W90P910 Matrix Keypad support"
      depends on ARCH_W90X900

- add: "To compile this driver as a module, choose M here: the module will be called mpr121."
- "endif" is wrong here, it breaks 'make config'
- maybe a more alphabetic approach in this list of drivers would be nice

yes. I will.

Quoted 13 lines

drivers/input/keyboard/Makefile obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o · line 51

Quoted 11 lines
drivers/input/keyboard/Makefile +1 -0
index 878e6c2..b110ca8 100644
@@ -47,4 +47,5 @@ obj-$(CONFIG_KEYBOARD_TEGRA)                += tegra-kbc.o
 obj-$(CONFIG_KEYBOARD_TNETV107X)     += tnetv107x-keypad.o
 obj-$(CONFIG_KEYBOARD_TWL4030)               += twl4030_keypad.o
 obj-$(CONFIG_KEYBOARD_XTKBD)         += xtkbd.o
+obj-$(CONFIG_KEYBOARD_MPR121)                += mpr121.o
 obj-$(CONFIG_KEYBOARD_W90P910)               += w90p910_keypad.o

for better examination, please mind alphabetic order

will do.

Quoted 22 lines
Quoted 22 lines
drivers/input/keyboard/mpr121.c new file +15 -0
new file mode 100644
index 0000000..ee149a8
@@ -0,0 +1,301 @@
+/*
+ * Touchkey driver for Freescale MPR121 Controllor
+ *
+ * Copyright (C) 2011 Freescale Semiconductor, Inc.
+ * Author: Zhang Jiejing <[email protected]>
+ *
+ * Based on mcs_touchkey.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 21

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/i2c/mpr.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/irq.h>

do not use irq.h directly

ok.

Quoted 50 lines
Quoted 50 lines
drivers/input/keyboard/mpr121.c new file +49 -0
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+
+struct mpr121_touchkey_data {
+     struct i2c_client       *client;
+     struct input_dev        *input_dev;
+     unsigned int            key_val;
+     int                     statusbits;
+     int                     keycount;
+     u16                     keycodes[MPR121_MAX_KEY_COUNT];
+};
+
+struct mpr121_init_register {
+     int addr;
+     u8 val;
+};
+
+static struct mpr121_init_register init_reg_table[] = {
+     {MHD_RISING_ADDR,       0x1},
+     {NHD_RISING_ADDR,       0x1},
+     {MHD_FALLING_ADDR,      0x1},
+     {NHD_FALLING_ADDR,      0x1},
+     {NCL_FALLING_ADDR,      0xff},
+     {FDL_FALLING_ADDR,      0x02},
+     {FILTER_CONF_ADDR,      0x04},
+     {AFE_CONF_ADDR,         0x0b},
+     {AUTO_CONFIG_CTRL_ADDR, 0x0b},
+};
+
+static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
+{
+     struct mpr121_touchkey_data *data = dev_id;
+     struct i2c_client *client = data->client;
+     struct input_dev *input = data->input_dev;
+     unsigned int key_num, pressed;
+     int reg;
+
+     reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
+     }
+
+     reg <<= 8;
+     reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 76

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+     }
+
+     reg &= TOUCH_STATUS_MASK;
+     /* use old press bit to figure out which bit changed */
+     key_num = ffs(reg ^ data->statusbits) - 1;
+     /* use the bit check the press status */

typo

this comment will remove.

Quoted 39 lines
Quoted 39 lines
drivers/input/keyboard/mpr121.c new file +38 -0
+     pressed = (reg & (1 << (key_num))) >> key_num;
+     data->statusbits = reg;
+     data->key_val = data->keycodes[key_num];
+
+     input_event(input, EV_MSC, MSC_SCAN, data->key_val);
+     input_report_key(input, data->key_val, pressed);
+     input_sync(input);
+
+     dev_dbg(&client->dev, "key %d %d %s\n", key_num, data->key_val,
+             pressed ? "pressed" : "released");
+
+out:
+     return IRQ_HANDLED;
+}
+
+static int mpr121_phys_init(struct mpr121_platform_data *pdata,
+                         struct mpr121_touchkey_data *data,
+                         struct i2c_client *client)
+{
+     struct mpr121_init_register *reg;
+     unsigned char usl, lsl, tl;
+     int i, t, vdd, ret;
+
+     /* setup touch/release threshold for ele0-ele11 */
+     for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
+             t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
+             ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+             ret = i2c_smbus_write_byte_data(client, t + 1,
+                                             RELEASE_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup init register */
+     for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
+             reg = &init_reg_table[i];
+             ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 120

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup auto-register by vdd,the formula please ref: AN3889
+      * These register *must* set acrodding your VDD voltage supply
+      * to the chip*/

typo

Quoted 5 lines

is this right?
/* setup Auto Config Registers by VDD.
* The formula was written in AN3889.
* These registers *must* be set by VDD voltage. */

Capacitance on sensing input varies and needs to be compensated. The internal MPR121-auto-configuration can do this if it's registers are set properly (based on pdata->vdd_uv).

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/input/keyboard/mpr121.c new file +13 -0
+     vdd = pdata->vdd_uv / 1000;
+     usl = ((vdd - 700) * 256) / vdd;
+     lsl = (usl * 65) / 100;
+     tl = (usl * 90) / 100;
+     ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
+     ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
+                                     data->keycount);
+     if (ret != 0)
+             goto err_i2c_write;
+
+     dev_info(&client->dev, "mpr121: config as enable %x of electrode.\n",
Quoted 3 lines
Quoted 1 line

typo ?

-> dev_dbg(&client->dev, "mpr121: setup with %x electrodes.\n",

Do you mean keys or "capacitance sensing inputs"?

Quoted 47 lines
Quoted 38 lines
Quoted 38 lines
drivers/input/keyboard/mpr121.c new file +37 -0
+              data->keycount);
+
+     return 0;
+
+err_i2c_write:
+     dev_err(&client->dev, "i2c write error: %d\n", ret);
+     return ret;
+}
+
+static int __devinit mpr_touchkey_probe(struct i2c_client *client,
+                                     const struct i2c_device_id *id)
+{
+     struct mpr121_platform_data *pdata;
+     struct mpr121_touchkey_data *data;
+     struct input_dev *input_dev;
+     int error;
+     int i;
+
+     pdata = client->dev.platform_data;
+     if (!pdata) {
+             dev_err(&client->dev, "no platform data defined\n");
+             return -EINVAL;
+     }
+
+     if (!client->irq) {
+             dev_err(&client->dev, "The irq number should not be zero\n");
+             return -EINVAL;
+     }
+
+     data = kzalloc(sizeof(struct mpr121_touchkey_data), GFP_KERNEL);
+     input_dev = input_allocate_device();
+     if (!data || !input_dev) {
+             dev_err(&client->dev, "Falied to allocate memory\n");
+             error = -ENOMEM;
+             goto err_free_mem;
+     }
+
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 176

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+     data->client = client;
+     data->input_dev = input_dev;
+     data->keycount = pdata->keycount;
+
+     if (data->keycount > MPR121_MAX_KEY_COUNT) {
+             dev_err(&client->dev, "Too many key defined\n");

typo

Quoted 1 line

-> dev_err(&client->dev, "too much keys defined\n");

"too many keys defined"

Quoted 176 lines
Quoted 130 lines
Quoted 94 lines
drivers/input/keyboard/mpr121.c new file +93 -0
+             error = -EINVAL;
+             goto err_free_mem;
+     }
+
+     error = mpr121_phys_init(pdata, data, client);
+     if (error) {
+             dev_err(&client->dev, "Failed to init register\n");
+             goto err_free_mem;
+     }
+
+     i2c_set_clientdata(client, data);
+
+     input_dev->name = "FSL MPR121 Touchkey";
+     input_dev->id.bustype = BUS_I2C;
+     input_dev->dev.parent = &client->dev;
+     input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
+     input_dev->keycode = pdata->matrix;
+     input_dev->keycodesize = sizeof(pdata->matrix[0]);
+     input_dev->keycodemax = data->keycount;
+
+     for (i = 0; i < input_dev->keycodemax; i++) {
+             __set_bit(pdata->matrix[i], input_dev->keybit);
+             data->keycodes[i] = pdata->matrix[i];
+     }
+
+     input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+     input_set_drvdata(input_dev, data);
+
+     error = request_threaded_irq(client->irq, NULL,
+                                  mpr_touchkey_interrupt,
+                                  IRQF_TRIGGER_FALLING,
+                                  client->dev.driver->name, data);
+     if (error) {
+             dev_err(&client->dev, "Failed to register interrupt\n");
+             goto err_free_mem;
+     }
+
+     error = input_register_device(input_dev);
+     if (error)
+             goto err_free_irq;
+     i2c_set_clientdata(client, data);
+     device_init_wakeup(&client->dev, pdata->wakeup);
+     dev_info(&client->dev, "Mpr121 touch keyboard init success.\n");
+     return 0;
+
+err_free_irq:
+     free_irq(client->irq, data);
+err_free_mem:
+     input_free_device(input_dev);
+     kfree(data);
+     return error;
+}
+
+static int __devexit mpr_touchkey_remove(struct i2c_client *client)
+{
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     free_irq(client->irq, data);
+     input_unregister_device(data->input_dev);
+     kfree(data);
+
+     return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int mpr_suspend(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+
+     if (device_may_wakeup(&client->dev))
+             enable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
+
+     return 0;
+}
+
+static int mpr_resume(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     if (device_may_wakeup(&client->dev))
+             disable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, data->keycount);
+
+     return 0;
+}
+#endif
+
+static const struct i2c_device_id mpr121_id[] = {
+     {"mpr121_touchkey", 0},

drivers/input/keyboard/mpr121.c line 279

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+     { }
+};
+
+static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
+
+static struct i2c_driver mpr_touchkey_driver = {
+     .driver = {
+             .name   = "mpr121",
+             .owner  = THIS_MODULE,
+             .pm     = &mpr121_touchkey_pm_ops,

I would add a ifdef CONFIG_PM_SLEEP

Quoted 23 lines
drivers/input/keyboard/mpr121.c new file +22 -0
+     },
+     .id_table       = mpr121_id,
+     .probe          = mpr_touchkey_probe,
+     .remove         = __devexit_p(mpr_touchkey_remove),
+};
+
+static int __init mpr_touchkey_init(void)
+{
+     return i2c_add_driver(&mpr_touchkey_driver);
+}
+
+static void __exit mpr_touchkey_exit(void)
+{
+     i2c_del_driver(&mpr_touchkey_driver);
+}
+
+module_init(mpr_touchkey_init);
+module_exit(mpr_touchkey_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Zhang Jiejing <[email protected]>");
+MODULE_DESCRIPTION("Touch Key driver for FSL MPR121 Chip");
include/linux/i2c/mpr.h +0 -0
Quoted 8 lines

include/linux/i2c/mpr.h line 1

Quoted 6 lines

new file mode 100644
index 0000000..52d6e33

include/linux/i2c/mpr.h new file +1 -0
@@ -0,0 +1,64 @@
+/* mpr.h - Header file for Freescale mpr121 capacitive touch sensor

no filename please

will do.

Quoted 14 lines
Quoted 14 lines
include/linux/i2c/mpr.h new file +13 -0
+ * controllor */
+
+#ifndef MPR_H
+#define MPR_H
+
+/* Register definitions */
+#define ELE_TOUCH_STATUS_0_ADDR      0x0
+#define ELE_TOUCH_STATUS_1_ADDR      0X1
+#define MHD_RISING_ADDR              0x2b
+#define NHD_RISING_ADDR              0x2c
+#define NCL_RISING_ADDR              0x2d
+#define FDL_RISING_ADDR              0x2e
+#define MHD_FALLING_ADDR     0x2f
Quoted 8 lines

include/linux/i2c/mpr.h line 20

Quoted 6 lines
include/linux/i2c/mpr.h new file +6 -0
+#define NHD_FALLING_ADDR     0x30
+#define NCL_FALLING_ADDR     0x31
+#define FDL_FALLING_ADDR     0x32
+#define ELE0_TOUCH_THRESHOLD_ADDR    0x41
+#define ELE0_RELEASE_THRESHOLD_ADDR  0x42
+/* ELE0...ELE11's threshold will set in a loop */

typo

-> /* ELE0...ELE11's threshold will be set in a loop */

Quoted 11 lines

include/linux/i2c/mpr.h line 28

Quoted 9 lines
include/linux/i2c/mpr.h new file +8 -0
+#define AFE_CONF_ADDR                        0x5c
+#define FILTER_CONF_ADDR             0x5d
+
+/* ELECTRODE_CONF: this register is most important register, it
+ * control how many of electrode is enabled. If you set this register
+ * to 0x0, it make the sensor going to suspend mode. Other value(low
+ * bit is non-zero) will make the sensor into Run mode.  This register
+ * should be write at last.

typo

Quoted 1 line

-> * should be written in the end.

ELECTRODE_CONF: This register mainly configures the number of enabled capacitance sensing inputs and its run/suspend mode.

Quoted 11 lines
Quoted 10 lines

include/linux/i2c/mpr.h line 34

Quoted 8 lines
include/linux/i2c/mpr.h new file +6 -0
+ */
+#define ELECTRODE_CONF_ADDR          0x5e
+#define AUTO_CONFIG_CTRL_ADDR                0x7b
+/* AUTO_CONFIG_USL: Upper Limit for auto baseline search, this
+ * register is related to VDD supplied on your board, the value of
+ * this register is calc by EQ: `((VDD-0.7)/VDD) * 256`.

typo

Quoted 1 line

-> * this register is calculated by EQ: ((VDD-0.7)/VDD) * 256.

It's in the source how it gets calculated, so I don't think you need to document it here.

Quoted 10 lines
Quoted 7 lines

include/linux/i2c/mpr.h line 37

Quoted 5 lines
include/linux/i2c/mpr.h new file +3 -0
+ * AUTO_CONFIG_LSL: Low Limit of auto baseline search. This is 65% of
+ * USL AUTO_CONFIG_TL: The Traget Level of auto baseline search, This
+ * is 90% of USL  */

typo

-> * USL AUTO_CONFIG_TL: The traget level of auto baseline search, it is -> * 90% of USL */

just remove 'is', typo in target

Quoted 5 lines
Quoted 5 lines

include/linux/i2c/mpr.h line 40

Quoted 5 lines
include/linux/i2c/mpr.h new file +3 -0
+#define AUTO_CONFIG_USL_ADDR         0x7d
+#define AUTO_CONFIG_LSL_ADDR         0x7e
+#define AUTO_CONFIG_TL_ADDR          0x7f

Why do they need to be in the header file?
Couldn't be a lot of defines get moved into the actual driver?

Quoted 11 lines
Quoted 7 lines

include/linux/i2c/mpr.h line 45

Quoted 5 lines
include/linux/i2c/mpr.h new file +5 -0
+
+/* Threshold of touch/release trigger */
+#define TOUCH_THRESHOLD                      0x0f
+#define RELEASE_THRESHOLD            0x0a
+/* Mask Button bits of STATUS_0 & STATUS_1 register */

and or bit-and?

don't need and or bit-and, it just means low 12 bits of status register is touch key's status.
-> /* low 12 bits of status register is touch key's status */

/* Masks for touch and release triggers */

should be enough

Quoted 11 lines
Quoted 10 lines

include/linux/i2c/mpr.h line 52

Quoted 8 lines
include/linux/i2c/mpr.h new file +7 -0
+#define TOUCH_STATUS_MASK            0xfff
+/* MPR121 have 12 electrodes */
+#define MPR121_MAX_KEY_COUNT         12
+
+
+/**
+ * @keycount: how many key maped

typo: "keys" ?

Quoted 1 line

-> * @keycount: how many keys mapped

Do you mean "keys" or "capacitance sensing inputs"?

Quoted 9 lines
Quoted 5 lines

include/linux/i2c/mpr.h line 53

Quoted 2 lines
include/linux/i2c/mpr.h new file +1 -0
+ * @vdd_uv: voltage of vdd supply the chip in uV

- typo
- uppercase for vdd

-> * @vdd_uv: VDD voltage in uV

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

include/linux/i2c/mpr.h line 55

Quoted 2 lines
include/linux/i2c/mpr.h new file +2 -0
+ * @matrix: maxtrix of keys
+ * @wakeup: can key wake up system.

typo

-> * @wakeup: can wake up system or not

"enable wakeup"

Just out of curiosity, why does platform data need to enable/disable wakeup?

Quoted 8 lines
Quoted 8 lines

include/linux/i2c/mpr.h line 62

Quoted 8 lines
include/linux/i2c/mpr.h new file +7 -0
+ */
+struct mpr121_platform_data {
+     u16 keycount;
+     u16 *matrix;
+     int wakeup;
+     int vdd_uv;
+};

Please make the order of comments equal to this struct.

Quoted 14 lines
Quoted 9 lines
Quoted 9 lines
include/linux/i2c/mpr.h new file +2 -1
+
+#endif
--

1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmln Tue, Apr 12, 2011 at 01:02:17AM +0800, Jiejing Zhang wrote:

:-(
sorry again for my horrible grammar.

Jiejing

#8 lore raw
In reply to Dmitry Torokhov

Hi Dmitry,

2011/4/12 Dmitry Torokhov <[email protected]>:

Quoted 15 lines

Hi Jiejing,

Quoted 11 lines · Jiejing Zhang

From: Zhang Jiejing <[email protected]>

This touchkey driver is based on Freescale mpr121 capacitive touch sensor controller.

It can support up to 12 keys, it use i2c interface.

The product infomation(data sheet, application notes) can be found under this link:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

Quoted 6 lines

MOstly reasonable. In addition to Christoph's comments:

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static struct mpr121_init_register init_reg_table[] = {

const? And also __devinitconst?

will do.

Quoted 32 lines
Quoted 32 lines

+     {MHD_RISING_ADDR,       0x1},
+     {NHD_RISING_ADDR,       0x1},
+     {MHD_FALLING_ADDR,      0x1},
+     {NHD_FALLING_ADDR,      0x1},
+     {NCL_FALLING_ADDR,      0xff},
+     {FDL_FALLING_ADDR,      0x02},
+     {FILTER_CONF_ADDR,      0x04},
+     {AFE_CONF_ADDR,         0x0b},
+     {AUTO_CONFIG_CTRL_ADDR, 0x0b},

drivers/input/keyboard/mpr121.c new file +22 -0
+};
+
+static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
+{
+     struct mpr121_touchkey_data *data = dev_id;
+     struct i2c_client *client = data->client;
+     struct input_dev *input = data->input_dev;
+     unsigned int key_num, pressed;
+     int reg;
+
+     reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
+     }
+
+     reg <<= 8;
+     reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
+     }
Quoted 9 lines
Quoted 6 lines

+
+     reg &= TOUCH_STATUS_MASK;
+     /* use old press bit to figure out which bit changed */
+     key_num = ffs(reg ^ data->statusbits) - 1;
+     /* use the bit check the press status */
+     pressed = (reg & (1 << (key_num))) >> key_num;

No need to shift by key_num, input_report_key normalizes to 'bool'.

yes, will change.

Quoted 7 lines
Quoted 4 lines

+     data->statusbits = reg;
+     data->key_val = data->keycodes[key_num];
+
+     input_event(input, EV_MSC, MSC_SCAN, data->key_val);

sScancode is not data->key_val as it is KEY_XXX value but rather key_num.

thanks for point out, will change to key_num.

Quoted 5 lines
Quoted 5 lines

+     input_report_key(input, data->key_val, pressed);
+     input_sync(input);
+
+     dev_dbg(&client->dev, "key %d %d %s\n", key_num, data->key_val,
+             pressed ? "pressed" : "released");

Quoted 8 lines

drivers/input/keyboard/mpr121.c

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+
+out:
+     return IRQ_HANDLED;
+}
+
+static int mpr121_phys_init(

__devinit

will do.

Quoted 41 lines

                           struct mpr121_platform_data *pdata,

pdata should be const.

Quoted 36 lines

+                         struct mpr121_touchkey_data *data,
+                         struct i2c_client *client)

drivers/input/keyboard/mpr121.c new file +34 -0
+{
+     struct mpr121_init_register *reg;
+     unsigned char usl, lsl, tl;
+     int i, t, vdd, ret;
+
+     /* setup touch/release threshold for ele0-ele11 */
+     for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
+             t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
+             ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+             ret = i2c_smbus_write_byte_data(client, t + 1,
+                                             RELEASE_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup init register */
+     for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
+             reg = &init_reg_table[i];
+             ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup auto-register by vdd,the formula please ref: AN3889
+      * These register *must* set acrodding your VDD voltage supply
+      * to the chip*/
+     vdd = pdata->vdd_uv / 1000;
+     usl = ((vdd - 700) * 256) / vdd;
+     lsl = (usl * 65) / 100;
+     tl = (usl * 90) / 100;
+     ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
+     ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
Quoted 9 lines
Quoted 6 lines

+                                     data->keycount);
+     if (ret != 0)
+             goto err_i2c_write;
+
+     dev_info(&client->dev, "mpr121: config as enable %x of electrode.\n",
+              data->keycount);

Does it have to be dev_info? dev_dbg maybe?

will change to dev_dbg.

Quoted 6 lines
Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+
+     return 0;
+
+err_i2c_write:
+     dev_err(&client->dev, "i2c write error: %d\n", ret);
+     return ret;
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 146

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+}
+
+static int __devinit mpr_touchkey_probe(struct i2c_client *client,
+                                     const struct i2c_device_id *id)
+{
+     struct mpr121_platform_data *pdata;

const.

will do.

Quoted 37 lines
Quoted 37 lines

+     struct mpr121_touchkey_data *data;
+     struct input_dev *input_dev;
+     int error;
+     int i;

drivers/input/keyboard/mpr121.c new file +32 -0
+
+     pdata = client->dev.platform_data;
+     if (!pdata) {
+             dev_err(&client->dev, "no platform data defined\n");
+             return -EINVAL;
+     }
+
+     if (!client->irq) {
+             dev_err(&client->dev, "The irq number should not be zero\n");
+             return -EINVAL;
+     }
+
+     data = kzalloc(sizeof(struct mpr121_touchkey_data), GFP_KERNEL);
+     input_dev = input_allocate_device();
+     if (!data || !input_dev) {
+             dev_err(&client->dev, "Falied to allocate memory\n");
+             error = -ENOMEM;
+             goto err_free_mem;
+     }
+
+     data->client = client;
+     data->input_dev = input_dev;
+     data->keycount = pdata->keycount;
+
+     if (data->keycount > MPR121_MAX_KEY_COUNT) {
+             dev_err(&client->dev, "Too many key defined\n");
+             error = -EINVAL;
+             goto err_free_mem;
+     }
+
+     error = mpr121_phys_init(pdata, data, client);
+     if (error) {
Quoted 9 lines
Quoted 5 lines

+             dev_err(&client->dev, "Failed to init register\n");
+             goto err_free_mem;
+     }
+
+     i2c_set_clientdata(client, data);

You should do this at the very end, before returning success (0). Actually, you do do this, so just remove this instance.

will remove.

Quoted 7 lines
Quoted 6 lines

+
+     input_dev->name = "FSL MPR121 Touchkey";
+     input_dev->id.bustype = BUS_I2C;
+     input_dev->dev.parent = &client->dev;
+     input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
+     input_dev->keycode = pdata->matrix;

Quoted 5 lines

No, you are assigning pointer to the platform data, instead of pointer to the data in device structure. That is why I'd rather you renamed 'struct mpr121_touchkey_data' to 'struct mpr121_touchkey' and 'data' to 'mpr121' so as to avoid confusion with platform data.

I've changed all struct mpr121_touchkey_data to struct mpr121_touchkey. and change the "data" to mpr121.

I'm truly confuse with platform data.

Quoted 21 lines
Quoted 21 lines

+     input_dev->keycodesize = sizeof(pdata->matrix[0]);
+     input_dev->keycodemax = data->keycount;

drivers/input/keyboard/mpr121.c new file +19 -0
+
+     for (i = 0; i < input_dev->keycodemax; i++) {
+             __set_bit(pdata->matrix[i], input_dev->keybit);
+             data->keycodes[i] = pdata->matrix[i];
+     }
+
+     input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+     input_set_drvdata(input_dev, data);
+
+     error = request_threaded_irq(client->irq, NULL,
+                                  mpr_touchkey_interrupt,
+                                  IRQF_TRIGGER_FALLING,
+                                  client->dev.driver->name, data);
+     if (error) {
+             dev_err(&client->dev, "Failed to register interrupt\n");
+             goto err_free_mem;
+     }
+
+     error = input_register_device(input_dev);
Quoted 8 lines
Quoted 5 lines

+     if (error)
+             goto err_free_irq;
+     i2c_set_clientdata(client, data);
+     device_init_wakeup(&client->dev, pdata->wakeup);
+     dev_info(&client->dev, "Mpr121 touch keyboard init success.\n");

No need for having this message. You can see the device bound to the driver in sysfs. The boot is noisy enough.

ok, will do.

Quoted 148 lines
Quoted 107 lines

+     return 0;

drivers/input/keyboard/mpr121.c new file +81 -0
+
+err_free_irq:
+     free_irq(client->irq, data);
+err_free_mem:
+     input_free_device(input_dev);
+     kfree(data);
+     return error;
+}
+
+static int __devexit mpr_touchkey_remove(struct i2c_client *client)
+{
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     free_irq(client->irq, data);
+     input_unregister_device(data->input_dev);
+     kfree(data);
+
+     return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int mpr_suspend(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+
+     if (device_may_wakeup(&client->dev))
+             enable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
+
+     return 0;
+}
+
+static int mpr_resume(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     if (device_may_wakeup(&client->dev))
+             disable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, data->keycount);
+
+     return 0;
+}
+#endif
+
+static const struct i2c_device_id mpr121_id[] = {
+     {"mpr121_touchkey", 0},
+     { }
+};
+
+static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
+
+static struct i2c_driver mpr_touchkey_driver = {
+     .driver = {
+             .name   = "mpr121",
+             .owner  = THIS_MODULE,
+             .pm     = &mpr121_touchkey_pm_ops,
+     },
+     .id_table       = mpr121_id,
+     .probe          = mpr_touchkey_probe,
+     .remove         = __devexit_p(mpr_touchkey_remove),
+};
+
+static int __init mpr_touchkey_init(void)
+{
+     return i2c_add_driver(&mpr_touchkey_driver);
+}
+
+static void __exit mpr_touchkey_exit(void)
+{
+     i2c_del_driver(&mpr_touchkey_driver);
+}
+
+module_init(mpr_touchkey_init);
+module_exit(mpr_touchkey_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Zhang Jiejing <[email protected]>");
+MODULE_DESCRIPTION("Touch Key driver for FSL MPR121 Chip");
include/linux/i2c/mpr.h new file +18 -0
new file mode 100644
index 0000000..52d6e33
@@ -0,0 +1,64 @@
+/* mpr.h - Header file for Freescale mpr121 capacitive touch sensor
+ * controllor */
+
+#ifndef MPR_H
+#define MPR_H
+
+/* Register definitions */
+#define ELE_TOUCH_STATUS_0_ADDR      0x0
+#define ELE_TOUCH_STATUS_1_ADDR      0X1
+#define MHD_RISING_ADDR              0x2b
+#define NHD_RISING_ADDR              0x2c
+#define NCL_RISING_ADDR              0x2d
+#define FDL_RISING_ADDR              0x2e
+#define MHD_FALLING_ADDR     0x2f
+#define NHD_FALLING_ADDR     0x30
+#define NCL_FALLING_ADDR     0x31
+#define FDL_FALLING_ADDR     0x32
+#define ELE0_TOUCH_THRESHOLD_ADDR    0x41

include/linux/i2c/mpr.h line 28

Quoted 10 lines
include/linux/i2c/mpr.h new file +10 -0
+#define ELE0_RELEASE_THRESHOLD_ADDR  0x42
+/* ELE0...ELE11's threshold will set in a loop */
+#define AFE_CONF_ADDR                        0x5c
+#define FILTER_CONF_ADDR             0x5d
+
+/* ELECTRODE_CONF: this register is most important register, it
+ * control how many of electrode is enabled. If you set this register
+ * to 0x0, it make the sensor going to suspend mode. Other value(low
+ * bit is non-zero) will make the sensor into Run mode.  This register
+ * should be write at last.

Hmm, most of the comments require proper grammar. If you need help with it - let the list know, we'll try to help.

Quoted 27 lines
include/linux/i2c/mpr.h new file +27 -0
+ */
+#define ELECTRODE_CONF_ADDR          0x5e
+#define AUTO_CONFIG_CTRL_ADDR                0x7b
+/* AUTO_CONFIG_USL: Upper Limit for auto baseline search, this
+ * register is related to VDD supplied on your board, the value of
+ * this register is calc by EQ: `((VDD-0.7)/VDD) * 256`.
+ * AUTO_CONFIG_LSL: Low Limit of auto baseline search. This is 65% of
+ * USL AUTO_CONFIG_TL: The Traget Level of auto baseline search, This
+ * is 90% of USL  */
+#define AUTO_CONFIG_USL_ADDR         0x7d
+#define AUTO_CONFIG_LSL_ADDR         0x7e
+#define AUTO_CONFIG_TL_ADDR          0x7f
+
+/* Threshold of touch/release trigger */
+#define TOUCH_THRESHOLD                      0x0f
+#define RELEASE_THRESHOLD            0x0a
+/* Mask Button bits of STATUS_0 & STATUS_1 register */
+#define TOUCH_STATUS_MASK            0xfff
+/* MPR121 have 12 electrodes */
+#define MPR121_MAX_KEY_COUNT         12
+
+
+/**
+ * @keycount: how many key maped
+ * @vdd_uv: voltage of vdd supply the chip in uV
+ * @matrix: maxtrix of keys
+ * @wakeup: can key wake up system.
Quoted 8 lines

include/linux/i2c/mpr.h line 59

Quoted 4 lines
include/linux/i2c/mpr.h new file +4 -0
+ */
+struct mpr121_platform_data {
+     u16 keycount;
+     u16 *matrix;

If this device is indeed organized as a matrix (lookslike this) maybe you should look at definitions provided by include/linux/input/matrix_keypad.h

OK, will change platform data to use matrix_keypad_data structure, I will convert them into an array into struct mpr121_touchkey: u16 keycodes[12]. The reason is it's will more similar to controller's register map.

Quoted 4 lines

include/linux/i2c/mpr.h line 60

Quoted 2 lines
include/linux/i2c/mpr.h new file +1 -0
+     int wakeup;

bool?

wiil do.

Quoted 11 lines

include/linux/i2c/mpr.h line 64

Quoted 5 lines
include/linux/i2c/mpr.h new file +4 -0
+     int vdd_uv;
+};
+
+#endif

Thanks.

--
Dmitry

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to Christoph Fritz

Hi Christonph,

Thanks a lot for your input, I will use them, they are better.:-)

2011/4/12 Christoph Fritz <[email protected]>:

Quoted 572 lines · Jiejing.Zhang
Quoted 3 lines

Hi Christoph,

I'm sorry for my poor English grammar.

I suppose the list can help. Here is my input:

Quoted 14 lines

I'll try to fix these typo, If still have error, please point me out.

2011/4/12 Christoph Fritz <[email protected]>

Quoted 11 lines

Hi Zhang,

 this is just a superficial review of your driver.

thanks,
 Christoph

Quoted 2 lines · Jiejing Zhang

From: Zhang Jiejing <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This touchkey driver is based on Freescale mpr121 capacitive touch sensor controller.

It can support up to 12 keys, it use i2c interface.

typo

-> It can supports up to 12 electrodes, and using i2c interface.

This patch adds basic support for Freescale MPR121 capacitive touch sensor.
It's an i2c controller with up to 12 capacitance sensing inputs.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The product infomation(data sheet, application notes) can be found under this link:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

Product information (data sheet, application notes) can be found here:

Quoted 202 lines
Quoted 19 lines
Quoted 19 lines

---
 drivers/input/keyboard/Kconfig  |   12 ++ drivers/input/keyboard/Makefile |    1 + drivers/input/keyboard/mpr121.c |  301 +++++++++++++++++++++++++++++++++++++++ include/linux/i2c/mpr.h         |   64 ++++++++

 4 files changed, 378 insertions(+), 0 deletions(-)

 create mode 100644 drivers/input/keyboard/mpr121.c create mode 100644 include/linux/i2c/mpr.h

drivers/input/keyboard/Kconfig +0 -0
index b16bed0..0666e1e 100644
@@ -520,6 +520,18 @@ config KEYBOARD_XTKBD

        To compile this driver as a module, choose M here: the module will be called xtkbd.

Quoted 7 lines
Quoted 5 lines

+config KEYBOARD_MPR121
+     tristate "Freescale MPR121 Touchkey Driver"
+     depends on I2C
+     help
+       Say Y here if you have the  touchkey Freescale mpr121 capacitive

typo: two spaces

will fix.

Quoted 17 lines
Quoted 11 lines

+       touch sensor controller in your system.

drivers/input/keyboard/Kconfig +6 -0
+
+       If unsure, say N.
+
+       To compile this driver as a module, choose M here
+endif
+

 config KEYBOARD_W90P910
      tristate "W90P910 Matrix Keypad support"
      depends on ARCH_W90X900

- add: "To compile this driver as a module, choose M here: the module will be called mpr121."
- "endif" is wrong here, it breaks 'make config'
- maybe a more alphabetic approach in this list of drivers would be nice

yes. I will.

Quoted 13 lines
Quoted 11 lines
drivers/input/keyboard/Makefile +0 -0
index 878e6c2..b110ca8 100644
@@ -47,4 +47,5 @@ obj-$(CONFIG_KEYBOARD_TEGRA)                += tegra-kbc.o

 obj-$(CONFIG_KEYBOARD_TNETV107X)     += tnetv107x-keypad.o obj-$(CONFIG_KEYBOARD_TWL4030)               += twl4030_keypad.o obj-$(CONFIG_KEYBOARD_XTKBD)         += xtkbd.o +obj-$(CONFIG_KEYBOARD_MPR121)                += mpr121.o obj-$(CONFIG_KEYBOARD_W90P910)               += w90p910_keypad.o

for better examination, please mind alphabetic order

will do.

Quoted 22 lines
Quoted 22 lines
drivers/input/keyboard/mpr121.c new file +15 -0
new file mode 100644
index 0000000..ee149a8
@@ -0,0 +1,301 @@
+/*
+ * Touchkey driver for Freescale MPR121 Controllor
+ *
+ * Copyright (C) 2011 Freescale Semiconductor, Inc.
+ * Author: Zhang Jiejing <[email protected]>
+ *
+ * Based on mcs_touchkey.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 21

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/i2c/mpr.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/irq.h>

do not use irq.h directly

ok.

Quoted 50 lines
Quoted 50 lines
drivers/input/keyboard/mpr121.c new file +49 -0
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+
+struct mpr121_touchkey_data {
+     struct i2c_client       *client;
+     struct input_dev        *input_dev;
+     unsigned int            key_val;
+     int                     statusbits;
+     int                     keycount;
+     u16                     keycodes[MPR121_MAX_KEY_COUNT];
+};
+
+struct mpr121_init_register {
+     int addr;
+     u8 val;
+};
+
+static struct mpr121_init_register init_reg_table[] = {
+     {MHD_RISING_ADDR,       0x1},
+     {NHD_RISING_ADDR,       0x1},
+     {MHD_FALLING_ADDR,      0x1},
+     {NHD_FALLING_ADDR,      0x1},
+     {NCL_FALLING_ADDR,      0xff},
+     {FDL_FALLING_ADDR,      0x02},
+     {FILTER_CONF_ADDR,      0x04},
+     {AFE_CONF_ADDR,         0x0b},
+     {AUTO_CONFIG_CTRL_ADDR, 0x0b},
+};
+
+static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
+{
+     struct mpr121_touchkey_data *data = dev_id;
+     struct i2c_client *client = data->client;
+     struct input_dev *input = data->input_dev;
+     unsigned int key_num, pressed;
+     int reg;
+
+     reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
+     }
+
+     reg <<= 8;
+     reg |= i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_0_ADDR);
+     if (reg < 0) {
+             dev_err(&client->dev, "i2c read error [%d]\n", reg);
+             goto out;
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 76

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+     }
+
+     reg &= TOUCH_STATUS_MASK;
+     /* use old press bit to figure out which bit changed */
+     key_num = ffs(reg ^ data->statusbits) - 1;
+     /* use the bit check the press status */

typo

this comment will remove.

Quoted 39 lines
Quoted 39 lines
drivers/input/keyboard/mpr121.c new file +38 -0
+     pressed = (reg & (1 << (key_num))) >> key_num;
+     data->statusbits = reg;
+     data->key_val = data->keycodes[key_num];
+
+     input_event(input, EV_MSC, MSC_SCAN, data->key_val);
+     input_report_key(input, data->key_val, pressed);
+     input_sync(input);
+
+     dev_dbg(&client->dev, "key %d %d %s\n", key_num, data->key_val,
+             pressed ? "pressed" : "released");
+
+out:
+     return IRQ_HANDLED;
+}
+
+static int mpr121_phys_init(struct mpr121_platform_data *pdata,
+                         struct mpr121_touchkey_data *data,
+                         struct i2c_client *client)
+{
+     struct mpr121_init_register *reg;
+     unsigned char usl, lsl, tl;
+     int i, t, vdd, ret;
+
+     /* setup touch/release threshold for ele0-ele11 */
+     for (i = 0; i <= MPR121_MAX_KEY_COUNT; i++) {
+             t = ELE0_TOUCH_THRESHOLD_ADDR + (i * 2);
+             ret = i2c_smbus_write_byte_data(client, t, TOUCH_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+             ret = i2c_smbus_write_byte_data(client, t + 1,
+                                             RELEASE_THRESHOLD);
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup init register */
+     for (i = 0; i < ARRAY_SIZE(init_reg_table); i++) {
+             reg = &init_reg_table[i];
+             ret = i2c_smbus_write_byte_data(client, reg->addr, reg->val);
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 120

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+             if (ret < 0)
+                     goto err_i2c_write;
+     }
+     /* setup auto-register by vdd,the formula please ref: AN3889
+      * These register *must* set acrodding your VDD voltage supply
+      * to the chip*/

typo

Quoted 5 lines

is this right?
    /* setup Auto Config Registers by VDD.
     * The formula was written in AN3889.
     * These registers *must* be set by VDD voltage. */

Capacitance on sensing input varies and needs to be compensated. The internal MPR121-auto-configuration can do this if it's registers are set properly (based on pdata->vdd_uv).

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/input/keyboard/mpr121.c new file +13 -0
+     vdd = pdata->vdd_uv / 1000;
+     usl = ((vdd - 700) * 256) / vdd;
+     lsl = (usl * 65) / 100;
+     tl = (usl * 90) / 100;
+     ret = i2c_smbus_write_byte_data(client, AUTO_CONFIG_USL_ADDR, usl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_LSL_ADDR, lsl);
+     ret |= i2c_smbus_write_byte_data(client, AUTO_CONFIG_TL_ADDR, tl);
+     ret |= i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR,
+                                     data->keycount);
+     if (ret != 0)
+             goto err_i2c_write;
+
+     dev_info(&client->dev, "mpr121: config as enable %x of electrode.\n",
Quoted 3 lines
Quoted 1 line

typo ?

-> dev_dbg(&client->dev, "mpr121: setup with %x electrodes.\n",

Do you mean keys or "capacitance sensing inputs"?

Quoted 47 lines
Quoted 38 lines
Quoted 38 lines
drivers/input/keyboard/mpr121.c new file +37 -0
+              data->keycount);
+
+     return 0;
+
+err_i2c_write:
+     dev_err(&client->dev, "i2c write error: %d\n", ret);
+     return ret;
+}
+
+static int __devinit mpr_touchkey_probe(struct i2c_client *client,
+                                     const struct i2c_device_id *id)
+{
+     struct mpr121_platform_data *pdata;
+     struct mpr121_touchkey_data *data;
+     struct input_dev *input_dev;
+     int error;
+     int i;
+
+     pdata = client->dev.platform_data;
+     if (!pdata) {
+             dev_err(&client->dev, "no platform data defined\n");
+             return -EINVAL;
+     }
+
+     if (!client->irq) {
+             dev_err(&client->dev, "The irq number should not be zero\n");
+             return -EINVAL;
+     }
+
+     data = kzalloc(sizeof(struct mpr121_touchkey_data), GFP_KERNEL);
+     input_dev = input_allocate_device();
+     if (!data || !input_dev) {
+             dev_err(&client->dev, "Falied to allocate memory\n");
+             error = -ENOMEM;
+             goto err_free_mem;
+     }
+
Quoted 8 lines

drivers/input/keyboard/mpr121.c line 176

Quoted 6 lines
drivers/input/keyboard/mpr121.c new file +6 -0
+     data->client = client;
+     data->input_dev = input_dev;
+     data->keycount = pdata->keycount;
+
+     if (data->keycount > MPR121_MAX_KEY_COUNT) {
+             dev_err(&client->dev, "Too many key defined\n");

typo

Quoted 1 line

-> dev_err(&client->dev, "too much keys defined\n");

"too many keys defined"

Quoted 176 lines
Quoted 130 lines
Quoted 94 lines
drivers/input/keyboard/mpr121.c new file +93 -0
+             error = -EINVAL;
+             goto err_free_mem;
+     }
+
+     error = mpr121_phys_init(pdata, data, client);
+     if (error) {
+             dev_err(&client->dev, "Failed to init register\n");
+             goto err_free_mem;
+     }
+
+     i2c_set_clientdata(client, data);
+
+     input_dev->name = "FSL MPR121 Touchkey";
+     input_dev->id.bustype = BUS_I2C;
+     input_dev->dev.parent = &client->dev;
+     input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
+     input_dev->keycode = pdata->matrix;
+     input_dev->keycodesize = sizeof(pdata->matrix[0]);
+     input_dev->keycodemax = data->keycount;
+
+     for (i = 0; i < input_dev->keycodemax; i++) {
+             __set_bit(pdata->matrix[i], input_dev->keybit);
+             data->keycodes[i] = pdata->matrix[i];
+     }
+
+     input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+     input_set_drvdata(input_dev, data);
+
+     error = request_threaded_irq(client->irq, NULL,
+                                  mpr_touchkey_interrupt,
+                                  IRQF_TRIGGER_FALLING,
+                                  client->dev.driver->name, data);
+     if (error) {
+             dev_err(&client->dev, "Failed to register interrupt\n");
+             goto err_free_mem;
+     }
+
+     error = input_register_device(input_dev);
+     if (error)
+             goto err_free_irq;
+     i2c_set_clientdata(client, data);
+     device_init_wakeup(&client->dev, pdata->wakeup);
+     dev_info(&client->dev, "Mpr121 touch keyboard init success.\n");
+     return 0;
+
+err_free_irq:
+     free_irq(client->irq, data);
+err_free_mem:
+     input_free_device(input_dev);
+     kfree(data);
+     return error;
+}
+
+static int __devexit mpr_touchkey_remove(struct i2c_client *client)
+{
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     free_irq(client->irq, data);
+     input_unregister_device(data->input_dev);
+     kfree(data);
+
+     return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int mpr_suspend(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+
+     if (device_may_wakeup(&client->dev))
+             enable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00);
+
+     return 0;
+}
+
+static int mpr_resume(struct device *dev)
+{
+     struct i2c_client *client = to_i2c_client(dev);
+     struct mpr121_touchkey_data *data = i2c_get_clientdata(client);
+
+     if (device_may_wakeup(&client->dev))
+             disable_irq_wake(client->irq);
+
+     i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, data->keycount);
+
+     return 0;
+}
+#endif
+
+static const struct i2c_device_id mpr121_id[] = {
+     {"mpr121_touchkey", 0},

drivers/input/keyboard/mpr121.c line 279

Quoted 10 lines
drivers/input/keyboard/mpr121.c new file +10 -0
+     { }
+};
+
+static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume);
+
+static struct i2c_driver mpr_touchkey_driver = {
+     .driver = {
+             .name   = "mpr121",
+             .owner  = THIS_MODULE,
+             .pm     = &mpr121_touchkey_pm_ops,

I would add a ifdef CONFIG_PM_SLEEP

Quoted 23 lines
drivers/input/keyboard/mpr121.c new file +22 -0
+     },
+     .id_table       = mpr121_id,
+     .probe          = mpr_touchkey_probe,
+     .remove         = __devexit_p(mpr_touchkey_remove),
+};
+
+static int __init mpr_touchkey_init(void)
+{
+     return i2c_add_driver(&mpr_touchkey_driver);
+}
+
+static void __exit mpr_touchkey_exit(void)
+{
+     i2c_del_driver(&mpr_touchkey_driver);
+}
+
+module_init(mpr_touchkey_init);
+module_exit(mpr_touchkey_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Zhang Jiejing <[email protected]>");
+MODULE_DESCRIPTION("Touch Key driver for FSL MPR121 Chip");
include/linux/i2c/mpr.h +0 -0
Quoted 8 lines

include/linux/i2c/mpr.h line 1

Quoted 6 lines

new file mode 100644
index 0000000..52d6e33

include/linux/i2c/mpr.h new file +1 -0
@@ -0,0 +1,64 @@
+/* mpr.h - Header file for Freescale mpr121 capacitive touch sensor

no filename please

will do.

Quoted 14 lines
Quoted 14 lines
include/linux/i2c/mpr.h new file +13 -0
+ * controllor */
+
+#ifndef MPR_H
+#define MPR_H
+
+/* Register definitions */
+#define ELE_TOUCH_STATUS_0_ADDR      0x0
+#define ELE_TOUCH_STATUS_1_ADDR      0X1
+#define MHD_RISING_ADDR              0x2b
+#define NHD_RISING_ADDR              0x2c
+#define NCL_RISING_ADDR              0x2d
+#define FDL_RISING_ADDR              0x2e
+#define MHD_FALLING_ADDR     0x2f
Quoted 8 lines

include/linux/i2c/mpr.h line 20

Quoted 6 lines
include/linux/i2c/mpr.h new file +6 -0
+#define NHD_FALLING_ADDR     0x30
+#define NCL_FALLING_ADDR     0x31
+#define FDL_FALLING_ADDR     0x32
+#define ELE0_TOUCH_THRESHOLD_ADDR    0x41
+#define ELE0_RELEASE_THRESHOLD_ADDR  0x42
+/* ELE0...ELE11's threshold will set in a loop */

typo

-> /* ELE0...ELE11's threshold will be set in a loop */

Quoted 11 lines

include/linux/i2c/mpr.h line 28

Quoted 9 lines
include/linux/i2c/mpr.h new file +8 -0
+#define AFE_CONF_ADDR                        0x5c
+#define FILTER_CONF_ADDR             0x5d
+
+/* ELECTRODE_CONF: this register is most important register, it
+ * control how many of electrode is enabled. If you set this register
+ * to 0x0, it make the sensor going to suspend mode. Other value(low
+ * bit is non-zero) will make the sensor into Run mode.  This register
+ * should be write at last.

typo

Quoted 1 line

->  * should be written in the end.

ELECTRODE_CONF: This register mainly configures the number of enabled capacitance sensing inputs and its run/suspend mode.

Quoted 11 lines
Quoted 10 lines

include/linux/i2c/mpr.h line 34

Quoted 8 lines
include/linux/i2c/mpr.h new file +6 -0
+ */
+#define ELECTRODE_CONF_ADDR          0x5e
+#define AUTO_CONFIG_CTRL_ADDR                0x7b
+/* AUTO_CONFIG_USL: Upper Limit for auto baseline search, this
+ * register is related to VDD supplied on your board, the value of
+ * this register is calc by EQ: `((VDD-0.7)/VDD) * 256`.

typo

Quoted 1 line

->  * this register is calculated by EQ: ((VDD-0.7)/VDD) * 256.

It's in the source how it gets calculated, so I don't think you need to document it here.

Quoted 10 lines
Quoted 7 lines

include/linux/i2c/mpr.h line 37

Quoted 5 lines
include/linux/i2c/mpr.h new file +3 -0
+ * AUTO_CONFIG_LSL: Low Limit of auto baseline search. This is 65% of
+ * USL AUTO_CONFIG_TL: The Traget Level of auto baseline search, This
+ * is 90% of USL  */

typo

->  * USL AUTO_CONFIG_TL: The traget level of auto baseline search, it is ->  * 90% of USL */

just remove 'is', typo in target

Quoted 5 lines
Quoted 5 lines

include/linux/i2c/mpr.h line 40

Quoted 5 lines
include/linux/i2c/mpr.h new file +3 -0
+#define AUTO_CONFIG_USL_ADDR         0x7d
+#define AUTO_CONFIG_LSL_ADDR         0x7e
+#define AUTO_CONFIG_TL_ADDR          0x7f

Why do they need to be in the header file?
Couldn't be a lot of defines get moved into the actual driver?

Quoted 11 lines
Quoted 7 lines

include/linux/i2c/mpr.h line 45

Quoted 5 lines
include/linux/i2c/mpr.h new file +5 -0
+
+/* Threshold of touch/release trigger */
+#define TOUCH_THRESHOLD                      0x0f
+#define RELEASE_THRESHOLD            0x0a
+/* Mask Button bits of STATUS_0 & STATUS_1 register */

and or bit-and?

don't need and or bit-and, it just means low 12 bits of status register is touch key's status.
-> /* low 12 bits of status register is touch key's status */

/* Masks for touch and release triggers */

should be enough

Quoted 11 lines
Quoted 10 lines

include/linux/i2c/mpr.h line 52

Quoted 8 lines
include/linux/i2c/mpr.h new file +7 -0
+#define TOUCH_STATUS_MASK            0xfff
+/* MPR121 have 12 electrodes */
+#define MPR121_MAX_KEY_COUNT         12
+
+
+/**
+ * @keycount: how many key maped

typo: "keys" ?

Quoted 3 lines
Quoted 1 line

->  * @keycount: how many keys mapped

Do you mean "keys" or "capacitance sensing inputs"?

I will change keys, and keycount to a const struct matrix_keymap_data *matrix; to resue the struct already in kernel.
the comments will change to @matrix: pointer to &matrix_keymap_data.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

include/linux/i2c/mpr.h line 53

Quoted 2 lines
include/linux/i2c/mpr.h new file +1 -0
+ * @vdd_uv: voltage of vdd supply the chip in uV

- typo
- uppercase for vdd

->  * @vdd_uv: VDD voltage in uV

Quoted 4 lines
Quoted 3 lines
include/linux/i2c/mpr.h new file +2 -0
+ * @matrix: maxtrix of keys
+ * @wakeup: can key wake up system.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

typo

->  * @wakeup: can wake up system or not

"enable wakeup"

Just out of curiosity, why does platform data need to enable/disable wakeup?

It's should be configure the button as a wake-up source.

I think better defined in platform_data, like linux/input/gpio_keys.h struct gpio_keys_button.

Quoted 30 lines
Quoted 9 lines
Quoted 9 lines

include/linux/i2c/mpr.h line 62

Quoted 9 lines
include/linux/i2c/mpr.h new file +7 -0
+ */
+struct mpr121_platform_data {
+     u16 keycount;
+     u16 *matrix;
+     int wakeup;
+     int vdd_uv;
+};

Please make the order of comments equal to this struct.

Quoted 14 lines
Quoted 9 lines
Quoted 9 lines
include/linux/i2c/mpr.h new file +2 -1
+
+#endif
--

1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.htmln Tue, Apr 12, 2011 at 01:02:17AM +0800, Jiejing Zhang wrote:

:-(
sorry again for my horrible grammar.

Jiejing

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

PATCH v2 1/1 input: keyboard: FSL MPR121 capacitive touch button.

In reply to Dmitry Torokhov

This patch adds basic support for Freescale MPR121 capacitive touch sensor.
It's an i2c controller with up to 12 capacitance sensing inputs.

Product information (data sheet, application notes) can be found here:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121

---
Changes since v1:
1. change files name from mpr121.c to mpr121_touchkey.c
2. lots of typo fix, thanks to Christoph Fritz
3. correct data declear function.
4. fix report MSC_SCAN to report key_num
5. remove print
6. use matrix_keypad_data in platform_data
7. move register define into .c file rather than header file.

---
 drivers/input/keyboard/Kconfig           |   15 ++-
 drivers/input/keyboard/Makefile          |    1 +
 drivers/input/keyboard/mpr121_touchkey.c |  330 ++++++++++++++++++++++++++++++
 include/linux/i2c/mpr.h                  |   19 ++
 4 files changed, 363 insertions(+), 2 deletions(-)
 create mode 100644 drivers/input/keyboard/mpr121_touchkey.c
 create mode 100644 include/linux/i2c/mpr.h
drivers/input/keyboard/Kconfig +13 -2
index c7a9202..58670d7 100644
@@ -315,6 +315,19 @@ config KEYBOARD_MCS
 	  To compile this driver as a module, choose M here: the
 	  module will be called mcs_touchkey.
 
+config KEYBOARD_MPR121
+	tristate "Freescale MPR121 Touchkey"
+	depends on I2C
+	help
+	  Say Y here if you have Freescale MPR121 touchkey controller
+	  chip in your system.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mpr121_touchkey
+endif
+
 config KEYBOARD_IMX
 	tristate "IMX keypad support"
 	depends on ARCH_MXC
@@ -519,5 +532,3 @@ config KEYBOARD_W90P910
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called w90p910_keypad.
-
-endif
drivers/input/keyboard/Makefile +1 -0
index 468c627..37fa96b 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
 obj-$(CONFIG_KEYBOARD_MCS)		+= mcs_touchkey.o
+obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
 obj-$(CONFIG_KEYBOARD_NEWTON)		+= newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NOMADIK)		+= nomadik-ske-keypad.o
 obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
drivers/input/keyboard/mpr121_touchkey.c new file +330 -0

330 lines not on this page · raw message

include/linux/i2c/mpr.h new file +19 -0
new file mode 100644
index 0000000..f15abe7
@@ -0,0 +1,19 @@
+/* Header file for Freescale MPR121 Capacitive Touch Sensor Controllor */
+
+#ifndef MPR_H
+#define MPR_H
+
+struct matrix_keymap_data;
+
+/**
+ * @matrix: pointer to &matrix_keymap_data.
+ * @wakeup: configure the button as a wake-up source
+ * @vdd_uv: VDD voltage in uV
+ */
+struct mpr121_platform_data {
+	const struct matrix_keymap_data *matrix;
+	bool wakeup;
+	int vdd_uv;
+};
+
+#endif
Signature · 1 line
1.7.0.4