linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support
@ 2013-05-06  3:04 Chao Xie
  2013-05-06  3:04 ` [PATCH V2 1/5] input: pxa27x-keypad: use matrix_keymap for matrix keyes Chao Xie
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Chao Xie @ 2013-05-06  3:04 UTC (permalink / raw)
  To: linux-kernel, linux-input, dmitry.torokhov, haojian.zhuang,
	xiechao.mail
  Cc: Chao Xie

The patches include 2 parts
1. use matrix_keypad for matrix keyes support
2. add device tree support for pxa27x-keypad

V2->V1:
Do not copy the members from pdata. For device tree support,
directly allocate the pdata structure.

Chao Xie (5):
  input: pxa27x-keypad: use matrix_keymap for matrix keyes
  arm: mmp: use matrix_keymap for aspenite
  arm: mmp: use matrix_keymap for teton_bga
  input: pxa27x-keypad: remove the unused members at platform data
  input: pxa27x-keypad: add device tree support

 .../devicetree/bindings/input/pxa27x-keypad.txt    |   60 +++++
 arch/arm/mach-mmp/aspenite.c                       |   10 +-
 arch/arm/mach-mmp/teton_bga.c                      |    8 +-
 drivers/input/keyboard/Kconfig                     |    1 +
 drivers/input/keyboard/pxa27x_keypad.c             |  266 ++++++++++++++++++--
 include/linux/platform_data/keypad-pxa27x.h        |    3 +-
 6 files changed, 325 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/pxa27x-keypad.txt

-- 
1.7.4.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH V2 1/5] input: pxa27x-keypad: use matrix_keymap for matrix keyes
  2013-05-06  3:04 [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support Chao Xie
@ 2013-05-06  3:04 ` Chao Xie
  2013-05-06  3:04 ` [PATCH V2 2/5] arm: mmp: use matrix_keymap for aspenite Chao Xie
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Chao Xie @ 2013-05-06  3:04 UTC (permalink / raw)
  To: linux-kernel, linux-input, dmitry.torokhov, haojian.zhuang,
	xiechao.mail
  Cc: Chao Xie

pxa27x-keypad includes matrix keyes. Make use of matrix_keymap
for the matrix keyes.

Signed-off-by: Chao Xie <chao.xie@marvell.com>
---
 drivers/input/keyboard/Kconfig              |    1 +
 drivers/input/keyboard/pxa27x_keypad.c      |   36 +++++++++++++++++---------
 include/linux/platform_data/keypad-pxa27x.h |    1 +
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index ac05006..fff3751 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -441,6 +441,7 @@ config KEYBOARD_OPENCORES
 config KEYBOARD_PXA27x
 	tristate "PXA27x/PXA3xx keypad support"
 	depends on PXA27x || PXA3xx || ARCH_MMP
+	select INPUT_MATRIXKMAP
 	help
 	  Enable support for PXA27x/PXA3xx keypad controller.
 
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index 5330d8f..c9f212a 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -118,25 +118,29 @@ struct pxa27x_keypad {
 	unsigned int direct_key_mask;
 };
 
-static void pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad)
+static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad)
 {
 	struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
 	struct input_dev *input_dev = keypad->input_dev;
 	unsigned short keycode;
-	int i;
+	int ret, i;
+	const struct matrix_keymap_data *keymap_data =
+				pdata ? pdata->matrix_keymap_data : NULL;
 
-	for (i = 0; i < pdata->matrix_key_map_size; i++) {
-		unsigned int key = pdata->matrix_key_map[i];
-		unsigned int row = KEY_ROW(key);
-		unsigned int col = KEY_COL(key);
-		unsigned int scancode = MATRIX_SCAN_CODE(row, col,
-							 MATRIX_ROW_SHIFT);
+	ret = matrix_keypad_build_keymap(keymap_data, NULL,
+					 pdata->matrix_key_rows,
+					 pdata->matrix_key_cols,
+					 keypad->keycodes, input_dev);
+	if (ret)
+		return ret;
 
-		keycode = KEY_VAL(key);
-		keypad->keycodes[scancode] = keycode;
-		__set_bit(keycode, input_dev->keybit);
-	}
+	/*
+	 * The keycodes may not only includes matrix key but also the direct
+	 * key or rotary key.
+	 */
+	input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes);
 
+	/* For direct key. */
 	for (i = 0; i < pdata->direct_key_num; i++) {
 		keycode = pdata->direct_key_map[i];
 		keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = keycode;
@@ -178,6 +182,8 @@ static void pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad)
 	}
 
 	__clear_bit(KEY_RESERVED, input_dev->keybit);
+
+	return 0;
 }
 
 static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad)
@@ -555,7 +561,11 @@ static int pxa27x_keypad_probe(struct platform_device *pdev)
 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
 
-	pxa27x_keypad_build_keycode(keypad);
+	error  = pxa27x_keypad_build_keycode(keypad);
+	if (error) {
+		dev_err(&pdev->dev, "failed to build keycode\n");
+		goto failed_put_clk;
+	}
 
 	if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) ||
 	    (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) {
diff --git a/include/linux/platform_data/keypad-pxa27x.h b/include/linux/platform_data/keypad-pxa27x.h
index 5ce8d5e6..0db423b 100644
--- a/include/linux/platform_data/keypad-pxa27x.h
+++ b/include/linux/platform_data/keypad-pxa27x.h
@@ -36,6 +36,7 @@
 struct pxa27x_keypad_platform_data {
 
 	/* code map for the matrix keys */
+	const struct matrix_keymap_data *matrix_keymap_data;
 	unsigned int	matrix_key_rows;
 	unsigned int	matrix_key_cols;
 	unsigned int	*matrix_key_map;
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH V2 2/5] arm: mmp: use matrix_keymap for aspenite
  2013-05-06  3:04 [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support Chao Xie
  2013-05-06  3:04 ` [PATCH V2 1/5] input: pxa27x-keypad: use matrix_keymap for matrix keyes Chao Xie
@ 2013-05-06  3:04 ` Chao Xie
  2013-05-06  3:04 ` [PATCH V2 3/5] arm: mmp: use matrix_keymap for teton_bga Chao Xie
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Chao Xie @ 2013-05-06  3:04 UTC (permalink / raw)
  To: linux-kernel, linux-input, dmitry.torokhov, haojian.zhuang,
	xiechao.mail
  Cc: Chao Xie

Signed-off-by: Chao Xie <chao.xie@marvell.com>
---
 arch/arm/mach-mmp/aspenite.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mmp/aspenite.c b/arch/arm/mach-mmp/aspenite.c
index 9f64d56..1e23346 100644
--- a/arch/arm/mach-mmp/aspenite.c
+++ b/arch/arm/mach-mmp/aspenite.c
@@ -205,7 +205,7 @@ struct pxa168fb_mach_info aspenite_lcd_info = {
 	.invert_pixclock	= 0,
 };
 
-static unsigned int aspenite_matrix_key_map[] = {
+static const unsigned int aspenite_matrix_key_map[] = {
 	KEY(0, 6, KEY_UP),	/* SW 4 */
 	KEY(0, 7, KEY_DOWN),	/* SW 5 */
 	KEY(1, 6, KEY_LEFT),	/* SW 6 */
@@ -214,11 +214,15 @@ static unsigned int aspenite_matrix_key_map[] = {
 	KEY(4, 7, KEY_ESC),	/* SW 9 */
 };
 
+static struct matrix_keymap_data aspenite_matrix_keymap_data = {
+	.keymap			= aspenite_matrix_key_map,
+	.keymap_size		= ARRAY_SIZE(aspenite_matrix_key_map),
+};
+
 static struct pxa27x_keypad_platform_data aspenite_keypad_info __initdata = {
 	.matrix_key_rows	= 5,
 	.matrix_key_cols	= 8,
-	.matrix_key_map		= aspenite_matrix_key_map,
-	.matrix_key_map_size	= ARRAY_SIZE(aspenite_matrix_key_map),
+	.matrix_keymap_data	= &aspenite_matrix_keymap_data,
 	.debounce_interval	= 30,
 };
 
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH V2 3/5] arm: mmp: use matrix_keymap for teton_bga
  2013-05-06  3:04 [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support Chao Xie
  2013-05-06  3:04 ` [PATCH V2 1/5] input: pxa27x-keypad: use matrix_keymap for matrix keyes Chao Xie
  2013-05-06  3:04 ` [PATCH V2 2/5] arm: mmp: use matrix_keymap for aspenite Chao Xie
@ 2013-05-06  3:04 ` Chao Xie
  2013-05-06  3:04 ` [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data Chao Xie
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Chao Xie @ 2013-05-06  3:04 UTC (permalink / raw)
  To: linux-kernel, linux-input, dmitry.torokhov, haojian.zhuang,
	xiechao.mail
  Cc: Chao Xie

Signed-off-by: Chao Xie <chao.xie@marvell.com>
---
 arch/arm/mach-mmp/teton_bga.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mmp/teton_bga.c b/arch/arm/mach-mmp/teton_bga.c
index 8609967..d8967fa 100644
--- a/arch/arm/mach-mmp/teton_bga.c
+++ b/arch/arm/mach-mmp/teton_bga.c
@@ -56,11 +56,15 @@ static unsigned int teton_bga_matrix_key_map[] = {
 	KEY(1, 7, KEY_RIGHT),
 };
 
+static struct matrix_keymap_data teton_bga_matrix_keymap_data = {
+	.keymap			= teton_bga_matrix_key_map,
+	.keymap_size		= ARRAY_SIZE(teton_bga_matrix_key_map),
+};
+
 static struct pxa27x_keypad_platform_data teton_bga_keypad_info __initdata = {
 	.matrix_key_rows        = 2,
 	.matrix_key_cols        = 8,
-	.matrix_key_map         = teton_bga_matrix_key_map,
-	.matrix_key_map_size    = ARRAY_SIZE(teton_bga_matrix_key_map),
+	.matrix_keymap_data	= &teton_bga_matrix_keymap_data,
 	.debounce_interval      = 30,
 };
 
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data
  2013-05-06  3:04 [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support Chao Xie
                   ` (2 preceding siblings ...)
  2013-05-06  3:04 ` [PATCH V2 3/5] arm: mmp: use matrix_keymap for teton_bga Chao Xie
@ 2013-05-06  3:04 ` Chao Xie
  2013-06-17 13:10   ` Arnd Bergmann
  2013-05-06  3:04 ` [PATCH V2 5/5] input: pxa27x-keypad: add device tree support Chao Xie
  2013-05-13  8:02 ` [PATCH V2 0/5] input: pxa27x-keypad: enhancement and " Chao Xie
  5 siblings, 1 reply; 12+ messages in thread
From: Chao Xie @ 2013-05-06  3:04 UTC (permalink / raw)
  To: linux-kernel, linux-input, dmitry.torokhov, haojian.zhuang,
	xiechao.mail
  Cc: Chao Xie

Now pxa27x-keypad make use matrix_keymap for matrix keyes, so
remove the unused members in platform data.

Signed-off-by: Chao Xie <chao.xie@marvell.com>
---
 include/linux/platform_data/keypad-pxa27x.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/include/linux/platform_data/keypad-pxa27x.h b/include/linux/platform_data/keypad-pxa27x.h
index 0db423b..2462556 100644
--- a/include/linux/platform_data/keypad-pxa27x.h
+++ b/include/linux/platform_data/keypad-pxa27x.h
@@ -39,8 +39,6 @@ struct pxa27x_keypad_platform_data {
 	const struct matrix_keymap_data *matrix_keymap_data;
 	unsigned int	matrix_key_rows;
 	unsigned int	matrix_key_cols;
-	unsigned int	*matrix_key_map;
-	int		matrix_key_map_size;
 
 	/* direct keys */
 	int		direct_key_num;
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH V2 5/5] input: pxa27x-keypad: add device tree support
  2013-05-06  3:04 [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support Chao Xie
                   ` (3 preceding siblings ...)
  2013-05-06  3:04 ` [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data Chao Xie
@ 2013-05-06  3:04 ` Chao Xie
  2013-05-13  8:02 ` [PATCH V2 0/5] input: pxa27x-keypad: enhancement and " Chao Xie
  5 siblings, 0 replies; 12+ messages in thread
From: Chao Xie @ 2013-05-06  3:04 UTC (permalink / raw)
  To: linux-kernel, linux-input, dmitry.torokhov, haojian.zhuang,
	xiechao.mail
  Cc: Chao Xie

Signed-off-by: Chao Xie <chao.xie@marvell.com>
---
 .../devicetree/bindings/input/pxa27x-keypad.txt    |   60 +++++
 drivers/input/keyboard/pxa27x_keypad.c             |  232 +++++++++++++++++++-
 2 files changed, 288 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/pxa27x-keypad.txt

diff --git a/Documentation/devicetree/bindings/input/pxa27x-keypad.txt b/Documentation/devicetree/bindings/input/pxa27x-keypad.txt
new file mode 100644
index 0000000..f8674f7
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/pxa27x-keypad.txt
@@ -0,0 +1,60 @@
+* Marvell PXA Keypad controller
+
+Required Properties
+- compatible : should be "marvell,pxa27x-keypad"
+- reg : Address and length of the register set for the device
+- interrupts : The interrupt for the keypad controller
+- marvell,debounce-interval : How long time the key will be
+  recognized when it is pressed. It is a u32 value, and bit[31:16]
+  is debounce interval for direct key and bit[15:0] is debounce
+  interval for matrix key. The value is in binary number of 2ms
+
+Optional Properties For Matrix Keyes
+Please refer to matrix-keymap.txt
+
+Optional Properties for Direct Keyes
+- marvell,direct-key-count : How many direct keyes are used.
+- marvell,direct-key-mask : The mask indicates which keyes
+  are used. If bit[X] of the mask is set, the direct key X
+  is used.
+- marvell,direct-key-low-active : Direct key status register
+  tells the level of pins that connects to the direct keyes.
+  When this property is set, it means that when the pin level
+  is low, the key is pressed(active).
+- marvell,direct-key-map : It is a u16 array. Each item indicates
+  the linux key-code for the direct key.
+
+Optional Properties For Rotary
+- marvell,rotary0 : It is a u32 value. Bit[31:16] is the
+  linux key-code for rotary up. Bit[15:0] is the linux key-code
+  for rotary down. It is for rotary 0.
+- marvell,rotary1 : Same as marvell,rotary0. It is for rotary 1.
+- marvell,rotary-rel-key : When rotary is used for relative axes
+  in the device, the value indicates the key-code for relative
+  axes measurement in the device. It is a u32 value. Bit[31:16]
+  is for rotary 1, and Bit[15:0] is for rotary 0.
+
+Examples:
+	keypad: keypad@d4012000 {
+		keypad,num-rows = <3>;
+		keypad,num-columns = <5>;
+		linux,keymap = <0x0000000e	/* KEY_BACKSPACE */
+				0x0001006b	/* KEY_END */
+				0x00020061	/* KEY_RIGHTCTRL */
+				0x0003000b	/* KEY_0 */
+				0x00040002	/* KEY_1 */
+				0x0100008b	/* KEY_MENU */
+				0x01010066	/* KEY_HOME */
+				0x010200e7	/* KEY_SEND */
+				0x01030009	/* KEY_8 */
+				0x0104000a	/* KEY_9 */
+				0x02000160	/* KEY_OK */
+				0x02010003	/* KEY_2 */
+				0x02020004	/* KEY_3 */
+				0x02030005	/* KEY_4 */
+				0x02040006>;	/* KEY_5 */
+		marvell,rotary0 = <0x006c0067>;	/* KEY_UP & KEY_DOWN */
+		marvell,direct-key-count = <1>;
+		marvell,direct-key-map = <0x001c>;
+		marvell,debounce-interval = <0x001e001e>;
+	};
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index c9f212a..3b63a12 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -118,6 +118,217 @@ struct pxa27x_keypad {
 	unsigned int direct_key_mask;
 };
 
+static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad)
+{
+	int ret;
+	u32 rows, cols;
+	struct input_dev *input_dev = keypad->input_dev;
+	struct device *dev = input_dev->dev.parent;
+	struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
+
+	ret = matrix_keypad_parse_of_params(dev, &rows, &cols);
+	if (ret)
+		return ret;
+
+	if (rows > MAX_MATRIX_KEY_ROWS || cols > MAX_MATRIX_KEY_COLS) {
+		dev_err(dev, "rows or cols exceeds maximum value\n");
+		return -EINVAL;
+	}
+
+	pdata->matrix_key_rows = rows;
+	pdata->matrix_key_cols = cols;
+
+	ret = matrix_keypad_build_keymap(NULL, NULL,
+					 pdata->matrix_key_rows,
+					 pdata->matrix_key_cols,
+					 keypad->keycodes, input_dev);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad)
+{
+	const __be16 *prop;
+	unsigned short code;
+	int i, ret;
+	unsigned int proplen, size;
+	struct input_dev *input_dev = keypad->input_dev;
+	struct device *dev = input_dev->dev.parent;
+	struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
+	struct device_node *np = dev->of_node;
+
+	ret = of_property_read_u32(np, "marvell,direct-key-count",
+				   &pdata->direct_key_num);
+	if (ret) {
+		/*
+		 * If do not have marvel,direct-key-count defined,
+		 * it means direct key is not supported.
+		 */
+		if (ret == -EINVAL)
+			return 0;
+		return ret;
+	}
+	ret = of_property_read_u32(np, "marvell,direct-key-mask",
+				   &pdata->direct_key_mask);
+	if (ret && ret != -EINVAL)
+		return ret;
+	/*
+	 * If marvell,direct-key-mask is not defined, driver will use
+	 * default value. Default value is set when configure the keypad.
+	 */
+	else if (ret == -EINVAL)
+		pdata->direct_key_mask = 0;
+
+	pdata->direct_key_low_active = of_property_read_bool(np,
+					"marvell,direct-key-low-active");
+
+	prop = of_get_property(np, "marvell,direct-key-map", &proplen);
+	if (!prop)
+		return -EINVAL;
+
+	if (proplen % sizeof(u16))
+		return -EINVAL;
+
+	size = proplen / sizeof(u16);
+
+	/* Only MAX_DIRECT_KEY_NUM is accepted.*/
+	if (size > MAX_DIRECT_KEY_NUM)
+		return -EINVAL;
+
+	for (i = 0; i < size; i++) {
+		code = be16_to_cpup(prop + i);
+		keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code;
+		__set_bit(code, input_dev->keybit);
+	}
+
+	return 0;
+}
+
+static int pxa27x_keypad_rotary_parse_dt(struct pxa27x_keypad *keypad)
+{
+	const __be32 *prop;
+	int i, relkey_ret;
+	unsigned int code, proplen;
+	const char *rotaryname[2] = {
+			"marvell,rotary0", "marvell,rotary1"};
+	const char relkeyname[] = {"marvell,rotary-rel-key"};
+	struct input_dev *input_dev = keypad->input_dev;
+	struct device *dev = input_dev->dev.parent;
+	struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
+	struct device_node *np = dev->of_node;
+
+	relkey_ret = of_property_read_u32(np, relkeyname, &code);
+	/* if can read correct rotary key-code, we do not need this. */
+	if (relkey_ret == 0) {
+		unsigned short relcode;
+
+		/* rotary0 taks lower half, rotary1 taks upper half. */
+		relcode = code & 0xffff;
+		pdata->rotary0_rel_code = (code & 0xffff);
+		__set_bit(relcode, input_dev->relbit);
+
+		relcode = code >> 16;
+		pdata->rotary1_rel_code = relcode;
+		__set_bit(relcode, input_dev->relbit);
+	}
+
+	for (i = 0; i < 2; i++) {
+		prop = of_get_property(np, rotaryname[i], &proplen);
+		/*
+		 * If the prop is not set, it means keypad does not need
+		 * initialize the rotaryX.
+		 */
+		if (!prop)
+			continue;
+
+		code = be32_to_cpup(prop);
+		/*
+		 * Not all up/down key code are valid.
+		 * Now we depends on direct-rel-code.
+		 */
+		if ((!(code & 0xffff) || !(code >> 16)) && relkey_ret) {
+			return relkey_ret;
+		} else {
+			unsigned int n = MAX_MATRIX_KEY_NUM + (i << 1);
+			unsigned short keycode;
+
+			keycode = code & 0xffff;
+			keypad->keycodes[n] = keycode;
+			__set_bit(keycode, input_dev->keybit);
+
+			keycode = code >> 16;
+			keypad->keycodes[n + 1] = keycode;
+			__set_bit(keycode, input_dev->keybit);
+
+			if (i == 0)
+				pdata->rotary0_rel_code = -1;
+			else
+				pdata->rotary1_rel_code = -1;
+		}
+		if (i == 0)
+			pdata->enable_rotary0 = 1;
+		else
+			pdata->enable_rotary1 = 1;
+	}
+
+	keypad->rotary_rel_code[0] = pdata->rotary0_rel_code;
+	keypad->rotary_rel_code[1] = pdata->rotary1_rel_code;
+
+	return 0;
+}
+
+static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad)
+{
+	int ret;
+	struct input_dev *input_dev = keypad->input_dev;
+	struct device *dev = input_dev->dev.parent;
+	struct device_node *np = dev->of_node;
+
+	if (!keypad->pdata) {
+		keypad->pdata = devm_kzalloc(dev, sizeof(*keypad->pdata),
+					     GFP_KERNEL);
+		if (!keypad->pdata) {
+			dev_err(dev, "failed to allocate memory for pdata\n");
+			return -ENOMEM;
+		}
+	}
+
+	ret = pxa27x_keypad_matrix_key_parse_dt(keypad);
+	if (ret) {
+		dev_err(dev, "failed to parse matrix key\n");
+		return ret;
+	}
+
+	ret = pxa27x_keypad_direct_key_parse_dt(keypad);
+	if (ret) {
+		dev_err(dev, "failed to parse direct key\n");
+		return ret;
+	}
+
+	ret = pxa27x_keypad_rotary_parse_dt(keypad);
+	if (ret) {
+		dev_err(dev, "failed to parse rotary key\n");
+		return ret;
+	}
+
+	ret = of_property_read_u32(np, "marvell,debounce-interval",
+				   &keypad->pdata->debounce_interval);
+	if (ret) {
+		dev_err(dev, "failed to parse debpunce-interval\n");
+		return ret;
+	}
+
+	/*
+	 * The keycodes may not only includes matrix key but also the direct
+	 * key or rotary key.
+	 */
+	input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes);
+
+	return 0;
+}
+
 static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad)
 {
 	struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
@@ -491,15 +702,15 @@ static const struct dev_pm_ops pxa27x_keypad_pm_ops = {
 static int pxa27x_keypad_probe(struct platform_device *pdev)
 {
 	struct pxa27x_keypad_platform_data *pdata = pdev->dev.platform_data;
+	struct device_node *np = pdev->dev.of_node;
 	struct pxa27x_keypad *keypad;
 	struct input_dev *input_dev;
 	struct resource *res;
 	int irq, error;
 
-	if (pdata == NULL) {
-		dev_err(&pdev->dev, "no platform data defined\n");
+	/* Driver need build keycode from device tree or pdata */
+	if (!np && !pdata)
 		return -EINVAL;
-	}
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
@@ -561,12 +772,18 @@ static int pxa27x_keypad_probe(struct platform_device *pdev)
 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
 
-	error  = pxa27x_keypad_build_keycode(keypad);
+	if (np)
+		error = pxa27x_keypad_build_keycode_from_dt(keypad);
+	else
+		error  = pxa27x_keypad_build_keycode(keypad);
 	if (error) {
 		dev_err(&pdev->dev, "failed to build keycode\n");
 		goto failed_put_clk;
 	}
 
+	/* If device tree is supported, pdata will be allocated. */
+	pdata = keypad->pdata;
+
 	if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) ||
 	    (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) {
 		input_dev->evbit[0] |= BIT_MASK(EV_REL);
@@ -628,11 +845,18 @@ static int pxa27x_keypad_remove(struct platform_device *pdev)
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:pxa27x-keypad");
 
+static const struct of_device_id pxa27x_keypad_dt_match[] = {
+	{ .compatible = "marvell,pxa27x-keypad" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, pxa27x_keypad_dt_match);
+
 static struct platform_driver pxa27x_keypad_driver = {
 	.probe		= pxa27x_keypad_probe,
 	.remove		= pxa27x_keypad_remove,
 	.driver		= {
 		.name	= "pxa27x-keypad",
+		.of_match_table = of_match_ptr(pxa27x_keypad_dt_match),
 		.owner	= THIS_MODULE,
 #ifdef CONFIG_PM
 		.pm	= &pxa27x_keypad_pm_ops,
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support
  2013-05-06  3:04 [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support Chao Xie
                   ` (4 preceding siblings ...)
  2013-05-06  3:04 ` [PATCH V2 5/5] input: pxa27x-keypad: add device tree support Chao Xie
@ 2013-05-13  8:02 ` Chao Xie
  2013-05-15  6:40   ` Dmitry Torokhov
  5 siblings, 1 reply; 12+ messages in thread
From: Chao Xie @ 2013-05-13  8:02 UTC (permalink / raw)
  To: Chao Xie
  Cc: linux-kernel@vger.kernel.org, linux-input, dmitry.torokhov,
	Haojian Zhuang

hi, dmitry
What is your idea about these patches?
Do i need add someone else to review them?

On Mon, May 6, 2013 at 11:04 AM, Chao Xie <chao.xie@marvell.com> wrote:
> The patches include 2 parts
> 1. use matrix_keypad for matrix keyes support
> 2. add device tree support for pxa27x-keypad
>
> V2->V1:
> Do not copy the members from pdata. For device tree support,
> directly allocate the pdata structure.
>
> Chao Xie (5):
>   input: pxa27x-keypad: use matrix_keymap for matrix keyes
>   arm: mmp: use matrix_keymap for aspenite
>   arm: mmp: use matrix_keymap for teton_bga
>   input: pxa27x-keypad: remove the unused members at platform data
>   input: pxa27x-keypad: add device tree support
>
>  .../devicetree/bindings/input/pxa27x-keypad.txt    |   60 +++++
>  arch/arm/mach-mmp/aspenite.c                       |   10 +-
>  arch/arm/mach-mmp/teton_bga.c                      |    8 +-
>  drivers/input/keyboard/Kconfig                     |    1 +
>  drivers/input/keyboard/pxa27x_keypad.c             |  266 ++++++++++++++++++--
>  include/linux/platform_data/keypad-pxa27x.h        |    3 +-
>  6 files changed, 325 insertions(+), 23 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/pxa27x-keypad.txt
>
> --
> 1.7.4.1
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support
  2013-05-13  8:02 ` [PATCH V2 0/5] input: pxa27x-keypad: enhancement and " Chao Xie
@ 2013-05-15  6:40   ` Dmitry Torokhov
  2013-06-13  2:47     ` Chao Xie
  0 siblings, 1 reply; 12+ messages in thread
From: Dmitry Torokhov @ 2013-05-15  6:40 UTC (permalink / raw)
  To: Chao Xie
  Cc: Chao Xie, linux-kernel@vger.kernel.org, linux-input,
	Haojian Zhuang

Hi Chao,

On Mon, May 13, 2013 at 04:02:07PM +0800, Chao Xie wrote:
> hi, dmitry
> What is your idea about these patches?
> Do i need add someone else to review them?
> 

No, they look good, give me a couple more days but I should apply them.
I am going to fold the first 4 into one patch though.

> On Mon, May 6, 2013 at 11:04 AM, Chao Xie <chao.xie@marvell.com> wrote:
> > The patches include 2 parts
> > 1. use matrix_keypad for matrix keyes support
> > 2. add device tree support for pxa27x-keypad
> >
> > V2->V1:
> > Do not copy the members from pdata. For device tree support,
> > directly allocate the pdata structure.
> >
> > Chao Xie (5):
> >   input: pxa27x-keypad: use matrix_keymap for matrix keyes
> >   arm: mmp: use matrix_keymap for aspenite
> >   arm: mmp: use matrix_keymap for teton_bga
> >   input: pxa27x-keypad: remove the unused members at platform data
> >   input: pxa27x-keypad: add device tree support
> >
> >  .../devicetree/bindings/input/pxa27x-keypad.txt    |   60 +++++
> >  arch/arm/mach-mmp/aspenite.c                       |   10 +-
> >  arch/arm/mach-mmp/teton_bga.c                      |    8 +-
> >  drivers/input/keyboard/Kconfig                     |    1 +
> >  drivers/input/keyboard/pxa27x_keypad.c             |  266 ++++++++++++++++++--
> >  include/linux/platform_data/keypad-pxa27x.h        |    3 +-
> >  6 files changed, 325 insertions(+), 23 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/input/pxa27x-keypad.txt
> >
> > --
> > 1.7.4.1
> >

-- 
Dmitry

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support
  2013-05-15  6:40   ` Dmitry Torokhov
@ 2013-06-13  2:47     ` Chao Xie
  0 siblings, 0 replies; 12+ messages in thread
From: Chao Xie @ 2013-06-13  2:47 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Chao Xie, linux-kernel@vger.kernel.org, linux-input,
	Haojian Zhuang

hi, Dmitry
What are the status for these patches? Thanks.

On Wed, May 15, 2013 at 2:40 PM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> Hi Chao,
>
> On Mon, May 13, 2013 at 04:02:07PM +0800, Chao Xie wrote:
>> hi, dmitry
>> What is your idea about these patches?
>> Do i need add someone else to review them?
>>
>
> No, they look good, give me a couple more days but I should apply them.
> I am going to fold the first 4 into one patch though.
>
>> On Mon, May 6, 2013 at 11:04 AM, Chao Xie <chao.xie@marvell.com> wrote:
>> > The patches include 2 parts
>> > 1. use matrix_keypad for matrix keyes support
>> > 2. add device tree support for pxa27x-keypad
>> >
>> > V2->V1:
>> > Do not copy the members from pdata. For device tree support,
>> > directly allocate the pdata structure.
>> >
>> > Chao Xie (5):
>> >   input: pxa27x-keypad: use matrix_keymap for matrix keyes
>> >   arm: mmp: use matrix_keymap for aspenite
>> >   arm: mmp: use matrix_keymap for teton_bga
>> >   input: pxa27x-keypad: remove the unused members at platform data
>> >   input: pxa27x-keypad: add device tree support
>> >
>> >  .../devicetree/bindings/input/pxa27x-keypad.txt    |   60 +++++
>> >  arch/arm/mach-mmp/aspenite.c                       |   10 +-
>> >  arch/arm/mach-mmp/teton_bga.c                      |    8 +-
>> >  drivers/input/keyboard/Kconfig                     |    1 +
>> >  drivers/input/keyboard/pxa27x_keypad.c             |  266 ++++++++++++++++++--
>> >  include/linux/platform_data/keypad-pxa27x.h        |    3 +-
>> >  6 files changed, 325 insertions(+), 23 deletions(-)
>> >  create mode 100644 Documentation/devicetree/bindings/input/pxa27x-keypad.txt
>> >
>> > --
>> > 1.7.4.1
>> >
>
> --
> Dmitry

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data
  2013-05-06  3:04 ` [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data Chao Xie
@ 2013-06-17 13:10   ` Arnd Bergmann
  2013-06-17 17:07     ` Dmitry Torokhov
  0 siblings, 1 reply; 12+ messages in thread
From: Arnd Bergmann @ 2013-06-17 13:10 UTC (permalink / raw)
  To: Chao Xie
  Cc: linux-kernel, linux-input, dmitry.torokhov, haojian.zhuang,
	xiechao.mail

On Sunday 05 May 2013 23:04:07 Chao Xie wrote:
> Now pxa27x-keypad make use matrix_keymap for matrix keyes, so
> remove the unused members in platform data.
> 
> Signed-off-by: Chao Xie <chao.xie@marvell.com>
> ---
>  include/linux/platform_data/keypad-pxa27x.h |    2 --
>  1 files changed, 0 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/platform_data/keypad-pxa27x.h b/include/linux/platform_data/keypad-pxa27x.h
> index 0db423b..2462556 100644
> --- a/include/linux/platform_data/keypad-pxa27x.h
> +++ b/include/linux/platform_data/keypad-pxa27x.h
> @@ -39,8 +39,6 @@ struct pxa27x_keypad_platform_data {
>         const struct matrix_keymap_data *matrix_keymap_data;
>         unsigned int    matrix_key_rows;
>         unsigned int    matrix_key_cols;
> -       unsigned int    *matrix_key_map;
> -       int             matrix_key_map_size;
>  
>         /* direct keys */
>         int             direct_key_num;


This just broke a number of configurations:

em_x270_defconfig
ezx_defconfig
palmz72_defconfig
pxa3xx_defconfig

You have to make sure that all these board files get converted:

arch/arm/mach-pxa/em-x270.c
arch/arm/mach-pxa/ezx.c
arch/arm/mach-pxa/littleton.c
arch/arm/mach-pxa/mainstone.c
arch/arm/mach-pxa/mioa701.c
arch/arm/mach-pxa/palmld.c
arch/arm/mach-pxa/palmt5.c
arch/arm/mach-pxa/palmtreo.c
arch/arm/mach-pxa/palmtx.c
arch/arm/mach-pxa/palmz72.c
arch/arm/mach-pxa/tavorevb.c
arch/arm/mach-pxa/z2.c
arch/arm/mach-pxa/zylonite.c

or leave the code to interpret that platform data in place.

	Arnd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data
  2013-06-17 13:10   ` Arnd Bergmann
@ 2013-06-17 17:07     ` Dmitry Torokhov
  2013-06-18  1:10       ` Chao Xie
  0 siblings, 1 reply; 12+ messages in thread
From: Dmitry Torokhov @ 2013-06-17 17:07 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Chao Xie, linux-kernel, linux-input, haojian.zhuang, xiechao.mail

On Monday, June 17, 2013 03:10:27 PM Arnd Bergmann wrote:
> On Sunday 05 May 2013 23:04:07 Chao Xie wrote:
> > Now pxa27x-keypad make use matrix_keymap for matrix keyes, so
> > remove the unused members in platform data.
> > 
> > Signed-off-by: Chao Xie <chao.xie@marvell.com>
> > ---
> > 
> >  include/linux/platform_data/keypad-pxa27x.h |    2 --
> >  1 files changed, 0 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/linux/platform_data/keypad-pxa27x.h
> > b/include/linux/platform_data/keypad-pxa27x.h index 0db423b..2462556
> > 100644
> > --- a/include/linux/platform_data/keypad-pxa27x.h
> > +++ b/include/linux/platform_data/keypad-pxa27x.h
> > @@ -39,8 +39,6 @@ struct pxa27x_keypad_platform_data {
> > 
> >         const struct matrix_keymap_data *matrix_keymap_data;
> >         unsigned int    matrix_key_rows;
> >         unsigned int    matrix_key_cols;
> > 
> > -       unsigned int    *matrix_key_map;
> > -       int             matrix_key_map_size;
> > 
> >         /* direct keys */
> >         int             direct_key_num;
> 
> This just broke a number of configurations:
> 
> em_x270_defconfig
> ezx_defconfig
> palmz72_defconfig
> pxa3xx_defconfig
> 
> You have to make sure that all these board files get converted:
> 
> arch/arm/mach-pxa/em-x270.c
> arch/arm/mach-pxa/ezx.c
> arch/arm/mach-pxa/littleton.c
> arch/arm/mach-pxa/mainstone.c
> arch/arm/mach-pxa/mioa701.c
> arch/arm/mach-pxa/palmld.c
> arch/arm/mach-pxa/palmt5.c
> arch/arm/mach-pxa/palmtreo.c
> arch/arm/mach-pxa/palmtx.c
> arch/arm/mach-pxa/palmz72.c
> arch/arm/mach-pxa/tavorevb.c
> arch/arm/mach-pxa/z2.c
> arch/arm/mach-pxa/zylonite.c
> 
> or leave the code to interpret that platform data in place.

Sorry about this, I'll drop the patch until it gets sorted out.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data
  2013-06-17 17:07     ` Dmitry Torokhov
@ 2013-06-18  1:10       ` Chao Xie
  0 siblings, 0 replies; 12+ messages in thread
From: Chao Xie @ 2013-06-18  1:10 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Arnd Bergmann, Chao Xie, linux-kernel@vger.kernel.org,
	linux-input, Haojian Zhuang

On Tue, Jun 18, 2013 at 1:07 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Monday, June 17, 2013 03:10:27 PM Arnd Bergmann wrote:
>> On Sunday 05 May 2013 23:04:07 Chao Xie wrote:
>> > Now pxa27x-keypad make use matrix_keymap for matrix keyes, so
>> > remove the unused members in platform data.
>> >
>> > Signed-off-by: Chao Xie <chao.xie@marvell.com>
>> > ---
>> >
>> >  include/linux/platform_data/keypad-pxa27x.h |    2 --
>> >  1 files changed, 0 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/include/linux/platform_data/keypad-pxa27x.h
>> > b/include/linux/platform_data/keypad-pxa27x.h index 0db423b..2462556
>> > 100644
>> > --- a/include/linux/platform_data/keypad-pxa27x.h
>> > +++ b/include/linux/platform_data/keypad-pxa27x.h
>> > @@ -39,8 +39,6 @@ struct pxa27x_keypad_platform_data {
>> >
>> >         const struct matrix_keymap_data *matrix_keymap_data;
>> >         unsigned int    matrix_key_rows;
>> >         unsigned int    matrix_key_cols;
>> >
>> > -       unsigned int    *matrix_key_map;
>> > -       int             matrix_key_map_size;
>> >
>> >         /* direct keys */
>> >         int             direct_key_num;
>>
>> This just broke a number of configurations:
>>
>> em_x270_defconfig
>> ezx_defconfig
>> palmz72_defconfig
>> pxa3xx_defconfig
>>
>> You have to make sure that all these board files get converted:
>>
>> arch/arm/mach-pxa/em-x270.c
>> arch/arm/mach-pxa/ezx.c
>> arch/arm/mach-pxa/littleton.c
>> arch/arm/mach-pxa/mainstone.c
>> arch/arm/mach-pxa/mioa701.c
>> arch/arm/mach-pxa/palmld.c
>> arch/arm/mach-pxa/palmt5.c
>> arch/arm/mach-pxa/palmtreo.c
>> arch/arm/mach-pxa/palmtx.c
>> arch/arm/mach-pxa/palmz72.c
>> arch/arm/mach-pxa/tavorevb.c
>> arch/arm/mach-pxa/z2.c
>> arch/arm/mach-pxa/zylonite.c
>>
>> or leave the code to interpret that platform data in place.
>
> Sorry about this, I'll drop the patch until it gets sorted out.
>
> Thanks.
>
I am sorry that i forget mach-pxa, i only changes mach-mmp.
I will do the samething for mach-pxa, and reset the patch.

> --
> Dmitry

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-06-18  1:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-06  3:04 [PATCH V2 0/5] input: pxa27x-keypad: enhancement and device tree support Chao Xie
2013-05-06  3:04 ` [PATCH V2 1/5] input: pxa27x-keypad: use matrix_keymap for matrix keyes Chao Xie
2013-05-06  3:04 ` [PATCH V2 2/5] arm: mmp: use matrix_keymap for aspenite Chao Xie
2013-05-06  3:04 ` [PATCH V2 3/5] arm: mmp: use matrix_keymap for teton_bga Chao Xie
2013-05-06  3:04 ` [PATCH V2 4/5] input: pxa27x-keypad: remove the unused members at platform data Chao Xie
2013-06-17 13:10   ` Arnd Bergmann
2013-06-17 17:07     ` Dmitry Torokhov
2013-06-18  1:10       ` Chao Xie
2013-05-06  3:04 ` [PATCH V2 5/5] input: pxa27x-keypad: add device tree support Chao Xie
2013-05-13  8:02 ` [PATCH V2 0/5] input: pxa27x-keypad: enhancement and " Chao Xie
2013-05-15  6:40   ` Dmitry Torokhov
2013-06-13  2:47     ` Chao Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).