linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support
@ 2012-06-08 10:52 Sourav Poddar
  2012-06-08 10:53 ` [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data Sourav Poddar
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sourav Poddar @ 2012-06-08 10:52 UTC (permalink / raw)
  To: devicetree-discuss
  Cc: linux-arm-kernel, linux-input, linux-kernel, sourav.poddar,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Dmitry Torokhov, Randy Dunlap

Update the Documentation with omap4 keypad device tree
binding information.
Add device tree support for omap4 keypad driver.

Tested on omap4430 sdp.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Benoit Cousson <b-cousson@ti.com>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
---
changes since v4:
- Developed it on top of dmitry's 'next' branch due to
dependency on generic "matrix_keypad_build_keymap" api 
patches queued in that branch
- Adapted the driver to fill "keymap" in device tree
using "matrix_keypad_build_keymap" api defined in
drivers/input/matrix-keymap.c
 .../devicetree/bindings/input/omap-keypad.txt      |   31 ++++++
 drivers/input/keyboard/omap4-keypad.c              |  108 +++++++++++++++-----
 2 files changed, 111 insertions(+), 28 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/omap-keypad.txt

diff --git a/Documentation/devicetree/bindings/input/omap-keypad.txt b/Documentation/devicetree/bindings/input/omap-keypad.txt
new file mode 100644
index 0000000..722425b
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/omap-keypad.txt
@@ -0,0 +1,31 @@
+* TI's Keypad Controller device tree bindings
+
+TI's Keypad controller is used to interface a SoC with a matrix-type
+keypad device. The keypad controller supports multiple row and column lines.
+A key can be placed at each intersection of a unique row and a unique column.
+The keypad controller can sense a key-press and key-release and report the
+event using a interrupt to the cpu.
+
+Required SoC Specific Properties:
+- compatible: should be one of the following
+   - "ti,omap4-keypad": For controllers compatible with omap4 keypad
+      controller.
+
+Required Board Specific Properties, in addition to those specified by
+the shared matrix-keyboard bindings:
+- keypad,num-rows: Number of row lines connected to the keypad
+  controller.
+
+- keypad,num-columns: Number of column lines connected to the
+  keypad controller.
+
+Optional Properties specific to linux:
+- linux,keypad-no-autorepeat: do no enable autorepeat feature.
+
+Example:
+        keypad@4ae1c000{
+                compatible = "ti,omap4-keypad";
+                keypad,num-rows = <2>;
+                keypad,num-columns = <8>;
+		linux,keypad-no-autorepeat;
+	};
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index aed5f69..d5a2d1a 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -27,6 +27,7 @@
 #include <linux/platform_device.h>
 #include <linux/errno.h>
 #include <linux/io.h>
+#include <linux/of.h>
 #include <linux/input.h>
 #include <linux/slab.h>
 #include <linux/pm_runtime.h>
@@ -75,6 +76,7 @@ enum {
 
 struct omap4_keypad {
 	struct input_dev *input;
+	struct matrix_keymap_data *keymap_data;
 
 	void __iomem *base;
 	unsigned int irq;
@@ -84,6 +86,7 @@ struct omap4_keypad {
 	u32 reg_offset;
 	u32 irqreg_offset;
 	unsigned int row_shift;
+	bool no_autorepeat;
 	unsigned char key_state[8];
 	unsigned short keymap[];
 };
@@ -208,25 +211,74 @@ static void omap4_keypad_close(struct input_dev *input)
 	pm_runtime_put_sync(input->dev.parent);
 }
 
+static struct omap4_keypad *omap_keypad_parse_dt(struct device *dev,
+				uint32_t rows, uint32_t cols,
+				struct input_dev *input_dev)
+{
+	struct device_node *np = dev->of_node;
+	struct platform_device *pdev = to_platform_device(dev);
+	struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
+	int error;
+
+	error = matrix_keypad_build_keymap(NULL, "linux,keymap",
+				rows, cols, keypad_data->keymap, input_dev);
+	if (error) {
+		dev_err(&pdev->dev, "failed to build keymap\n");
+		input_free_device(input_dev);
+	}
+
+	if (of_get_property(np, "linux,input-no-autorepeat", NULL))
+		keypad_data->no_autorepeat = true;
+
+	return keypad_data;
+}
+
 static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
 	const struct omap4_keypad_platform_data *pdata;
 	struct omap4_keypad *keypad_data;
 	struct input_dev *input_dev;
 	struct resource *res;
 	resource_size_t size;
-	unsigned int row_shift, max_keys;
+	unsigned int row_shift = 0, max_keys = 0;
+	uint32_t num_rows = 0, num_cols = 0;
 	int rev;
 	int irq;
 	int error;
 
 	/* platform data */
 	pdata = pdev->dev.platform_data;
-	if (!pdata) {
+	if (np) {
+		of_property_read_u32(np, "keypad,num-rows", &num_rows);
+		of_property_read_u32(np, "keypad,num-columns", &num_cols);
+		if (!num_rows || !num_cols) {
+			dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
+			return -EINVAL;
+		}
+	} else if (pdata) {
+		num_rows = pdata->rows;
+		num_cols = pdata->cols;
+	} else {
 		dev_err(&pdev->dev, "no platform data defined\n");
 		return -EINVAL;
 	}
 
+	row_shift = get_count_order(num_cols);
+	max_keys = num_rows << row_shift;
+
+	keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad) +
+			max_keys * sizeof(keypad_data->keymap[0]),
+				GFP_KERNEL);
+
+	if (!keypad_data) {
+		dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pdev, keypad_data);
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
 		dev_err(&pdev->dev, "no base address specified\n");
@@ -239,22 +291,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	if (!pdata->keymap_data) {
-		dev_err(&pdev->dev, "no keymap data defined\n");
-		return -EINVAL;
-	}
-
-	row_shift = get_count_order(pdata->cols);
-	max_keys = pdata->rows << row_shift;
-
-	keypad_data = kzalloc(sizeof(struct omap4_keypad) +
-				max_keys * sizeof(keypad_data->keymap[0]),
-			      GFP_KERNEL);
-	if (!keypad_data) {
-		dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
-		return -ENOMEM;
-	}
-
 	size = resource_size(res);
 
 	res = request_mem_region(res->start, size, pdev->name);
@@ -271,10 +307,10 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 		goto err_release_mem;
 	}
 
+	keypad_data->rows = num_rows;
+	keypad_data->cols = num_cols;
 	keypad_data->irq = irq;
 	keypad_data->row_shift = row_shift;
-	keypad_data->rows = pdata->rows;
-	keypad_data->cols = pdata->cols;
 
 	/*
 	* Enable clocks for the keypad module so that we can read
@@ -322,15 +358,25 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 	input_dev->open = omap4_keypad_open;
 	input_dev->close = omap4_keypad_close;
 
-	error = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
-					   pdata->rows, pdata->cols,
-					   keypad_data->keymap, input_dev);
-	if (error) {
-		dev_err(&pdev->dev, "failed to build keymap\n");
-		goto err_free_input;
+	if (np) {
+		keypad_data = omap_keypad_parse_dt(&pdev->dev,
+				keypad_data->rows, keypad_data->cols,
+				input_dev);
+	} else {
+		keypad_data->keymap_data =
+			(struct matrix_keymap_data *)pdata->keymap_data;
+		error = matrix_keypad_build_keymap(keypad_data->keymap_data,
+				NULL, keypad_data->rows, keypad_data->cols,
+				keypad_data->keymap, input_dev);
+		if (error) {
+			dev_err(&pdev->dev, "failed to build keymap\n");
+			goto err_free_input;
+		}
 	}
 
-	__set_bit(EV_REP, input_dev->evbit);
+	if (!keypad_data->no_autorepeat)
+		__set_bit(EV_REP, input_dev->evbit);
+
 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
 
 	input_set_drvdata(input_dev, keypad_data);
@@ -351,7 +397,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 		goto err_pm_disable;
 	}
 
-	platform_set_drvdata(pdev, keypad_data);
 	return 0;
 
 err_pm_disable:
@@ -392,12 +437,19 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id omap_keypad_dt_match[] = {
+	{ .compatible = "ti,omap4-keypad" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
+
 static struct platform_driver omap4_keypad_driver = {
 	.probe		= omap4_keypad_probe,
 	.remove		= __devexit_p(omap4_keypad_remove),
 	.driver		= {
 		.name	= "omap4-keypad",
 		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(omap_keypad_dt_match),
 	},
 };
 module_platform_driver(omap4_keypad_driver);
-- 
1.7.1


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

* [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data
  2012-06-08 10:52 [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Sourav Poddar
@ 2012-06-08 10:53 ` Sourav Poddar
  2012-06-15 14:58   ` Poddar, Sourav
  2012-06-19 14:27   ` Poddar, Sourav
  2012-06-19 14:25 ` [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Poddar, Sourav
  2012-07-10  6:13 ` Dmitry Torokhov
  2 siblings, 2 replies; 9+ messages in thread
From: Sourav Poddar @ 2012-06-08 10:53 UTC (permalink / raw)
  To: devicetree-discuss
  Cc: linux-arm-kernel, linux-input, linux-kernel, sourav.poddar,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Dmitry Torokhov

Add keypad data node in omap4 device tree file.
Also fill the device tree binding parameters
with the required value in "omap4-sdp" dts file.

Tested on omap4430 sdp with dmitry's 'next' branch.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Benoit Cousson <b-cousson@ti.com>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
---
 arch/arm/boot/dts/omap4-sdp.dts |   63 +++++++++++++++++++++++++++++++++++++++
 arch/arm/boot/dts/omap4.dtsi    |    5 +++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/omap4-sdp.dts b/arch/arm/boot/dts/omap4-sdp.dts
index 63c6b2b..0c9b3bf 100644
--- a/arch/arm/boot/dts/omap4-sdp.dts
+++ b/arch/arm/boot/dts/omap4-sdp.dts
@@ -17,4 +17,67 @@
 		device_type = "memory";
 		reg = <0x80000000 0x40000000>; /* 1 GB */
 	};
+
+	keypad@4ae1c000 {
+		keypad,num-rows = <8>;
+		keypad,num-columns = <8>;
+		linux,keymap = < 0x00000012
+			0x00010013
+			0x00020014
+			0x00030066
+			0x0004003f
+			0x00060017
+			0x0007002a
+			0x01000020
+			0x01010021
+			0x01020022
+			0x01030054
+			0x01040040
+			0x01060025
+			0x0107001c
+			0x0200002d
+			0x0201002e
+			0x0202002f
+			0x0203006b
+			0x02040041
+			0x02060034
+			0x0207003a
+			0x0300002c
+			0x0301004e
+			0x03020030
+			0x0303003b
+			0x03040042
+			0x03060018
+			0x03070039
+			0x04000011
+			0x04010015
+			0x04020016
+			0x0403003c
+			0x04040073
+			0x04060026
+			0x04070069
+			0x0500001f
+			0x05010023
+			0x05020024
+			0x0503003d
+			0x05040043
+			0x05050072
+			0x05060032
+			0x0507006a
+			0x06000010
+			0x0601001e
+			0x06020031
+			0x0603005c
+			0x0604000e
+			0x06060019
+			0x06070067
+			0x07000094
+			0x07010095
+			0x070200ca
+			0x070300cb
+			0x0704003e
+			0x07060160
+			0x0707006c >;
+		linux,input-no-autorepeat;
+	};
 };
diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
index 3d35559..e0f678a 100644
--- a/arch/arm/boot/dts/omap4.dtsi
+++ b/arch/arm/boot/dts/omap4.dtsi
@@ -156,4 +156,9 @@
 			ti,hwmods = "i2c4";
 		};
 	};
+
+	keypad@4ae1c000 {
+		compatible = "ti,omap4-keypad";
+		ti,hwmods = "kbd";
+	};
 };
-- 
1.7.1


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

* Re: [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data
  2012-06-08 10:53 ` [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data Sourav Poddar
@ 2012-06-15 14:58   ` Poddar, Sourav
  2012-06-19 14:27   ` Poddar, Sourav
  1 sibling, 0 replies; 9+ messages in thread
From: Poddar, Sourav @ 2012-06-15 14:58 UTC (permalink / raw)
  To: devicetree-discuss, Dmitry Torokhov
  Cc: linux-arm-kernel, linux-input, linux-kernel, sourav.poddar,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi

Hi All,

On Fri, Jun 8, 2012 at 4:23 PM, Sourav Poddar <sourav.poddar@ti.com> wrote:
>
> Add keypad data node in omap4 device tree file.
> Also fill the device tree binding parameters
> with the required value in "omap4-sdp" dts file.
>
> Tested on omap4430 sdp with dmitry's 'next' branch.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Benoit Cousson <b-cousson@ti.com>
> Cc: Rob Herring <rob.herring@calxeda.com>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Dmitry Torokhov <dtor@mail.ru>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> ---
>  arch/arm/boot/dts/omap4-sdp.dts |   63
> +++++++++++++++++++++++++++++++++++++++
>  arch/arm/boot/dts/omap4.dtsi    |    5 +++
>  2 files changed, 68 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arm/boot/dts/omap4-sdp.dts
> b/arch/arm/boot/dts/omap4-sdp.dts
> index 63c6b2b..0c9b3bf 100644
> --- a/arch/arm/boot/dts/omap4-sdp.dts
> +++ b/arch/arm/boot/dts/omap4-sdp.dts
> @@ -17,4 +17,67 @@
>                device_type = "memory";
>                reg = <0x80000000 0x40000000>; /* 1 GB */
>        };
> +
> +       keypad@4ae1c000 {
> +               keypad,num-rows = <8>;
> +               keypad,num-columns = <8>;
> +               linux,keymap = < 0x00000012
> +                       0x00010013
> +                       0x00020014
> +                       0x00030066
> +                       0x0004003f
> +                       0x00060017
> +                       0x0007002a
> +                       0x01000020
> +                       0x01010021
> +                       0x01020022
> +                       0x01030054
> +                       0x01040040
> +                       0x01060025
> +                       0x0107001c
> +                       0x0200002d
> +                       0x0201002e
> +                       0x0202002f
> +                       0x0203006b
> +                       0x02040041
> +                       0x02060034
> +                       0x0207003a
> +                       0x0300002c
> +                       0x0301004e
> +                       0x03020030
> +                       0x0303003b
> +                       0x03040042
> +                       0x03060018
> +                       0x03070039
> +                       0x04000011
> +                       0x04010015
> +                       0x04020016
> +                       0x0403003c
> +                       0x04040073
> +                       0x04060026
> +                       0x04070069
> +                       0x0500001f
> +                       0x05010023
> +                       0x05020024
> +                       0x0503003d
> +                       0x05040043
> +                       0x05050072
> +                       0x05060032
> +                       0x0507006a
> +                       0x06000010
> +                       0x0601001e
> +                       0x06020031
> +                       0x0603005c
> +                       0x0604000e
> +                       0x06060019
> +                       0x06070067
> +                       0x07000094
> +                       0x07010095
> +                       0x070200ca
> +                       0x070300cb
> +                       0x0704003e
> +                       0x07060160
> +                       0x0707006c >;
> +               linux,input-no-autorepeat;
> +       };
>  };
> diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
> index 3d35559..e0f678a 100644
> --- a/arch/arm/boot/dts/omap4.dtsi
> +++ b/arch/arm/boot/dts/omap4.dtsi
> @@ -156,4 +156,9 @@
>                        ti,hwmods = "i2c4";
>                };
>        };
> +
> +       keypad@4ae1c000 {
> +               compatible = "ti,omap4-keypad";
> +               ti,hwmods = "kbd";
> +       };
>  };
> --
> 1.7.1
>
Gentle Ping on this..

~Sourav
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* Re: [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support
  2012-06-08 10:52 [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Sourav Poddar
  2012-06-08 10:53 ` [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data Sourav Poddar
@ 2012-06-19 14:25 ` Poddar, Sourav
  2012-07-05 14:07   ` Poddar, Sourav
  2012-07-10  6:13 ` Dmitry Torokhov
  2 siblings, 1 reply; 9+ messages in thread
From: Poddar, Sourav @ 2012-06-19 14:25 UTC (permalink / raw)
  To: devicetree-discuss
  Cc: linux-arm-kernel, linux-input, linux-kernel, sourav.poddar,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Dmitry Torokhov, Randy Dunlap, lo

+cc linux-omap

On Fri, Jun 8, 2012 at 4:22 PM, Sourav Poddar <sourav.poddar@ti.com> wrote:
> Update the Documentation with omap4 keypad device tree
> binding information.
> Add device tree support for omap4 keypad driver.
>
> Tested on omap4430 sdp.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Benoit Cousson <b-cousson@ti.com>
> Cc: Rob Herring <rob.herring@calxeda.com>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Dmitry Torokhov <dtor@mail.ru>
> Cc: Randy Dunlap <rdunlap@xenotime.net>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> ---
> changes since v4:
> - Developed it on top of dmitry's 'next' branch due to
> dependency on generic "matrix_keypad_build_keymap" api
> patches queued in that branch
> - Adapted the driver to fill "keymap" in device tree
> using "matrix_keypad_build_keymap" api defined in
> drivers/input/matrix-keymap.c
>  .../devicetree/bindings/input/omap-keypad.txt      |   31 ++++++
>  drivers/input/keyboard/omap4-keypad.c              |  108 +++++++++++++++-----
>  2 files changed, 111 insertions(+), 28 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/omap-keypad.txt
>
> diff --git a/Documentation/devicetree/bindings/input/omap-keypad.txt b/Documentation/devicetree/bindings/input/omap-keypad.txt
> new file mode 100644
> index 0000000..722425b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/omap-keypad.txt
> @@ -0,0 +1,31 @@
> +* TI's Keypad Controller device tree bindings
> +
> +TI's Keypad controller is used to interface a SoC with a matrix-type
> +keypad device. The keypad controller supports multiple row and column lines.
> +A key can be placed at each intersection of a unique row and a unique column.
> +The keypad controller can sense a key-press and key-release and report the
> +event using a interrupt to the cpu.
> +
> +Required SoC Specific Properties:
> +- compatible: should be one of the following
> +   - "ti,omap4-keypad": For controllers compatible with omap4 keypad
> +      controller.
> +
> +Required Board Specific Properties, in addition to those specified by
> +the shared matrix-keyboard bindings:
> +- keypad,num-rows: Number of row lines connected to the keypad
> +  controller.
> +
> +- keypad,num-columns: Number of column lines connected to the
> +  keypad controller.
> +
> +Optional Properties specific to linux:
> +- linux,keypad-no-autorepeat: do no enable autorepeat feature.
> +
> +Example:
> +        keypad@4ae1c000{
> +                compatible = "ti,omap4-keypad";
> +                keypad,num-rows = <2>;
> +                keypad,num-columns = <8>;
> +               linux,keypad-no-autorepeat;
> +       };
> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
> index aed5f69..d5a2d1a 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -27,6 +27,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/errno.h>
>  #include <linux/io.h>
> +#include <linux/of.h>
>  #include <linux/input.h>
>  #include <linux/slab.h>
>  #include <linux/pm_runtime.h>
> @@ -75,6 +76,7 @@ enum {
>
>  struct omap4_keypad {
>        struct input_dev *input;
> +       struct matrix_keymap_data *keymap_data;
>
>        void __iomem *base;
>        unsigned int irq;
> @@ -84,6 +86,7 @@ struct omap4_keypad {
>        u32 reg_offset;
>        u32 irqreg_offset;
>        unsigned int row_shift;
> +       bool no_autorepeat;
>        unsigned char key_state[8];
>        unsigned short keymap[];
>  };
> @@ -208,25 +211,74 @@ static void omap4_keypad_close(struct input_dev *input)
>        pm_runtime_put_sync(input->dev.parent);
>  }
>
> +static struct omap4_keypad *omap_keypad_parse_dt(struct device *dev,
> +                               uint32_t rows, uint32_t cols,
> +                               struct input_dev *input_dev)
> +{
> +       struct device_node *np = dev->of_node;
> +       struct platform_device *pdev = to_platform_device(dev);
> +       struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
> +       int error;
> +
> +       error = matrix_keypad_build_keymap(NULL, "linux,keymap",
> +                               rows, cols, keypad_data->keymap, input_dev);
> +       if (error) {
> +               dev_err(&pdev->dev, "failed to build keymap\n");
> +               input_free_device(input_dev);
> +       }
> +
> +       if (of_get_property(np, "linux,input-no-autorepeat", NULL))
> +               keypad_data->no_autorepeat = true;
> +
> +       return keypad_data;
> +}
> +
>  static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>  {
> +       struct device *dev = &pdev->dev;
> +       struct device_node *np = dev->of_node;
>        const struct omap4_keypad_platform_data *pdata;
>        struct omap4_keypad *keypad_data;
>        struct input_dev *input_dev;
>        struct resource *res;
>        resource_size_t size;
> -       unsigned int row_shift, max_keys;
> +       unsigned int row_shift = 0, max_keys = 0;
> +       uint32_t num_rows = 0, num_cols = 0;
>        int rev;
>        int irq;
>        int error;
>
>        /* platform data */
>        pdata = pdev->dev.platform_data;
> -       if (!pdata) {
> +       if (np) {
> +               of_property_read_u32(np, "keypad,num-rows", &num_rows);
> +               of_property_read_u32(np, "keypad,num-columns", &num_cols);
> +               if (!num_rows || !num_cols) {
> +                       dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
> +                       return -EINVAL;
> +               }
> +       } else if (pdata) {
> +               num_rows = pdata->rows;
> +               num_cols = pdata->cols;
> +       } else {
>                dev_err(&pdev->dev, "no platform data defined\n");
>                return -EINVAL;
>        }
>
> +       row_shift = get_count_order(num_cols);
> +       max_keys = num_rows << row_shift;
> +
> +       keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad) +
> +                       max_keys * sizeof(keypad_data->keymap[0]),
> +                               GFP_KERNEL);
> +
> +       if (!keypad_data) {
> +               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
> +               return -ENOMEM;
> +       }
> +
> +       platform_set_drvdata(pdev, keypad_data);
> +
>        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>        if (!res) {
>                dev_err(&pdev->dev, "no base address specified\n");
> @@ -239,22 +291,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>                return -EINVAL;
>        }
>
> -       if (!pdata->keymap_data) {
> -               dev_err(&pdev->dev, "no keymap data defined\n");
> -               return -EINVAL;
> -       }
> -
> -       row_shift = get_count_order(pdata->cols);
> -       max_keys = pdata->rows << row_shift;
> -
> -       keypad_data = kzalloc(sizeof(struct omap4_keypad) +
> -                               max_keys * sizeof(keypad_data->keymap[0]),
> -                             GFP_KERNEL);
> -       if (!keypad_data) {
> -               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
> -               return -ENOMEM;
> -       }
> -
>        size = resource_size(res);
>
>        res = request_mem_region(res->start, size, pdev->name);
> @@ -271,10 +307,10 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>                goto err_release_mem;
>        }
>
> +       keypad_data->rows = num_rows;
> +       keypad_data->cols = num_cols;
>        keypad_data->irq = irq;
>        keypad_data->row_shift = row_shift;
> -       keypad_data->rows = pdata->rows;
> -       keypad_data->cols = pdata->cols;
>
>        /*
>        * Enable clocks for the keypad module so that we can read
> @@ -322,15 +358,25 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>        input_dev->open = omap4_keypad_open;
>        input_dev->close = omap4_keypad_close;
>
> -       error = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
> -                                          pdata->rows, pdata->cols,
> -                                          keypad_data->keymap, input_dev);
> -       if (error) {
> -               dev_err(&pdev->dev, "failed to build keymap\n");
> -               goto err_free_input;
> +       if (np) {
> +               keypad_data = omap_keypad_parse_dt(&pdev->dev,
> +                               keypad_data->rows, keypad_data->cols,
> +                               input_dev);
> +       } else {
> +               keypad_data->keymap_data =
> +                       (struct matrix_keymap_data *)pdata->keymap_data;
> +               error = matrix_keypad_build_keymap(keypad_data->keymap_data,
> +                               NULL, keypad_data->rows, keypad_data->cols,
> +                               keypad_data->keymap, input_dev);
> +               if (error) {
> +                       dev_err(&pdev->dev, "failed to build keymap\n");
> +                       goto err_free_input;
> +               }
>        }
>
> -       __set_bit(EV_REP, input_dev->evbit);
> +       if (!keypad_data->no_autorepeat)
> +               __set_bit(EV_REP, input_dev->evbit);
> +
>        input_set_capability(input_dev, EV_MSC, MSC_SCAN);
>
>        input_set_drvdata(input_dev, keypad_data);
> @@ -351,7 +397,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>                goto err_pm_disable;
>        }
>
> -       platform_set_drvdata(pdev, keypad_data);
>        return 0;
>
>  err_pm_disable:
> @@ -392,12 +437,19 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
>        return 0;
>  }
>
> +static const struct of_device_id omap_keypad_dt_match[] = {
> +       { .compatible = "ti,omap4-keypad" },
> +       {},
> +};
> +MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
> +
>  static struct platform_driver omap4_keypad_driver = {
>        .probe          = omap4_keypad_probe,
>        .remove         = __devexit_p(omap4_keypad_remove),
>        .driver         = {
>                .name   = "omap4-keypad",
>                .owner  = THIS_MODULE,
> +               .of_match_table = of_match_ptr(omap_keypad_dt_match),
>        },
>  };
>  module_platform_driver(omap4_keypad_driver);
> --
> 1.7.1
>

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

* Re: [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data
  2012-06-08 10:53 ` [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data Sourav Poddar
  2012-06-15 14:58   ` Poddar, Sourav
@ 2012-06-19 14:27   ` Poddar, Sourav
  1 sibling, 0 replies; 9+ messages in thread
From: Poddar, Sourav @ 2012-06-19 14:27 UTC (permalink / raw)
  To: devicetree-discuss
  Cc: linux-arm-kernel, linux-input, linux-kernel, sourav.poddar,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Dmitry Torokhov, lo

+cc linux-omap

On Fri, Jun 8, 2012 at 4:23 PM, Sourav Poddar <sourav.poddar@ti.com> wrote:
> Add keypad data node in omap4 device tree file.
> Also fill the device tree binding parameters
> with the required value in "omap4-sdp" dts file.
>
> Tested on omap4430 sdp with dmitry's 'next' branch.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Benoit Cousson <b-cousson@ti.com>
> Cc: Rob Herring <rob.herring@calxeda.com>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Dmitry Torokhov <dtor@mail.ru>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> ---
>  arch/arm/boot/dts/omap4-sdp.dts |   63 +++++++++++++++++++++++++++++++++++++++
>  arch/arm/boot/dts/omap4.dtsi    |    5 +++
>  2 files changed, 68 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arm/boot/dts/omap4-sdp.dts b/arch/arm/boot/dts/omap4-sdp.dts
> index 63c6b2b..0c9b3bf 100644
> --- a/arch/arm/boot/dts/omap4-sdp.dts
> +++ b/arch/arm/boot/dts/omap4-sdp.dts
> @@ -17,4 +17,67 @@
>                device_type = "memory";
>                reg = <0x80000000 0x40000000>; /* 1 GB */
>        };
> +
> +       keypad@4ae1c000 {
> +               keypad,num-rows = <8>;
> +               keypad,num-columns = <8>;
> +               linux,keymap = < 0x00000012
> +                       0x00010013
> +                       0x00020014
> +                       0x00030066
> +                       0x0004003f
> +                       0x00060017
> +                       0x0007002a
> +                       0x01000020
> +                       0x01010021
> +                       0x01020022
> +                       0x01030054
> +                       0x01040040
> +                       0x01060025
> +                       0x0107001c
> +                       0x0200002d
> +                       0x0201002e
> +                       0x0202002f
> +                       0x0203006b
> +                       0x02040041
> +                       0x02060034
> +                       0x0207003a
> +                       0x0300002c
> +                       0x0301004e
> +                       0x03020030
> +                       0x0303003b
> +                       0x03040042
> +                       0x03060018
> +                       0x03070039
> +                       0x04000011
> +                       0x04010015
> +                       0x04020016
> +                       0x0403003c
> +                       0x04040073
> +                       0x04060026
> +                       0x04070069
> +                       0x0500001f
> +                       0x05010023
> +                       0x05020024
> +                       0x0503003d
> +                       0x05040043
> +                       0x05050072
> +                       0x05060032
> +                       0x0507006a
> +                       0x06000010
> +                       0x0601001e
> +                       0x06020031
> +                       0x0603005c
> +                       0x0604000e
> +                       0x06060019
> +                       0x06070067
> +                       0x07000094
> +                       0x07010095
> +                       0x070200ca
> +                       0x070300cb
> +                       0x0704003e
> +                       0x07060160
> +                       0x0707006c >;
> +               linux,input-no-autorepeat;
> +       };
>  };
> diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
> index 3d35559..e0f678a 100644
> --- a/arch/arm/boot/dts/omap4.dtsi
> +++ b/arch/arm/boot/dts/omap4.dtsi
> @@ -156,4 +156,9 @@
>                        ti,hwmods = "i2c4";
>                };
>        };
> +
> +       keypad@4ae1c000 {
> +               compatible = "ti,omap4-keypad";
> +               ti,hwmods = "kbd";
> +       };
>  };
> --
> 1.7.1
>
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* Re: [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support
  2012-06-19 14:25 ` [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Poddar, Sourav
@ 2012-07-05 14:07   ` Poddar, Sourav
  0 siblings, 0 replies; 9+ messages in thread
From: Poddar, Sourav @ 2012-07-05 14:07 UTC (permalink / raw)
  To: devicetree-discuss, Dmitry Torokhov
  Cc: linux-arm-kernel, linux-input, linux-kernel, sourav.poddar,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Randy Dunlap, lo

Hi Dmitry,
On Tue, Jun 19, 2012 at 7:55 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> +cc linux-omap
>
> On Fri, Jun 8, 2012 at 4:22 PM, Sourav Poddar <sourav.poddar@ti.com> wrote:
>> Update the Documentation with omap4 keypad device tree
>> binding information.
>> Add device tree support for omap4 keypad driver.
>>
>> Tested on omap4430 sdp.
>>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: Benoit Cousson <b-cousson@ti.com>
>> Cc: Rob Herring <rob.herring@calxeda.com>
>> Cc: Grant Likely <grant.likely@secretlab.ca>
>> Cc: Felipe Balbi <balbi@ti.com>
>> Cc: Dmitry Torokhov <dtor@mail.ru>
>> Cc: Randy Dunlap <rdunlap@xenotime.net>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> ---
>> changes since v4:
>> - Developed it on top of dmitry's 'next' branch due to
>> dependency on generic "matrix_keypad_build_keymap" api
>> patches queued in that branch
>> - Adapted the driver to fill "keymap" in device tree
>> using "matrix_keypad_build_keymap" api defined in
>> drivers/input/matrix-keymap.c
>>  .../devicetree/bindings/input/omap-keypad.txt      |   31 ++++++
>>  drivers/input/keyboard/omap4-keypad.c              |  108 +++++++++++++++-----
>>  2 files changed, 111 insertions(+), 28 deletions(-)
>>  create mode 100644 Documentation/devicetree/bindings/input/omap-keypad.txt
>>
>> diff --git a/Documentation/devicetree/bindings/input/omap-keypad.txt b/Documentation/devicetree/bindings/input/omap-keypad.txt
>> new file mode 100644
>> index 0000000..722425b
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/input/omap-keypad.txt
>> @@ -0,0 +1,31 @@
>> +* TI's Keypad Controller device tree bindings
>> +
>> +TI's Keypad controller is used to interface a SoC with a matrix-type
>> +keypad device. The keypad controller supports multiple row and column lines.
>> +A key can be placed at each intersection of a unique row and a unique column.
>> +The keypad controller can sense a key-press and key-release and report the
>> +event using a interrupt to the cpu.
>> +
>> +Required SoC Specific Properties:
>> +- compatible: should be one of the following
>> +   - "ti,omap4-keypad": For controllers compatible with omap4 keypad
>> +      controller.
>> +
>> +Required Board Specific Properties, in addition to those specified by
>> +the shared matrix-keyboard bindings:
>> +- keypad,num-rows: Number of row lines connected to the keypad
>> +  controller.
>> +
>> +- keypad,num-columns: Number of column lines connected to the
>> +  keypad controller.
>> +
>> +Optional Properties specific to linux:
>> +- linux,keypad-no-autorepeat: do no enable autorepeat feature.
>> +
>> +Example:
>> +        keypad@4ae1c000{
>> +                compatible = "ti,omap4-keypad";
>> +                keypad,num-rows = <2>;
>> +                keypad,num-columns = <8>;
>> +               linux,keypad-no-autorepeat;
>> +       };
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index aed5f69..d5a2d1a 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -27,6 +27,7 @@
>>  #include <linux/platform_device.h>
>>  #include <linux/errno.h>
>>  #include <linux/io.h>
>> +#include <linux/of.h>
>>  #include <linux/input.h>
>>  #include <linux/slab.h>
>>  #include <linux/pm_runtime.h>
>> @@ -75,6 +76,7 @@ enum {
>>
>>  struct omap4_keypad {
>>        struct input_dev *input;
>> +       struct matrix_keymap_data *keymap_data;
>>
>>        void __iomem *base;
>>        unsigned int irq;
>> @@ -84,6 +86,7 @@ struct omap4_keypad {
>>        u32 reg_offset;
>>        u32 irqreg_offset;
>>        unsigned int row_shift;
>> +       bool no_autorepeat;
>>        unsigned char key_state[8];
>>        unsigned short keymap[];
>>  };
>> @@ -208,25 +211,74 @@ static void omap4_keypad_close(struct input_dev *input)
>>        pm_runtime_put_sync(input->dev.parent);
>>  }
>>
>> +static struct omap4_keypad *omap_keypad_parse_dt(struct device *dev,
>> +                               uint32_t rows, uint32_t cols,
>> +                               struct input_dev *input_dev)
>> +{
>> +       struct device_node *np = dev->of_node;
>> +       struct platform_device *pdev = to_platform_device(dev);
>> +       struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
>> +       int error;
>> +
>> +       error = matrix_keypad_build_keymap(NULL, "linux,keymap",
>> +                               rows, cols, keypad_data->keymap, input_dev);
>> +       if (error) {
>> +               dev_err(&pdev->dev, "failed to build keymap\n");
>> +               input_free_device(input_dev);
>> +       }
>> +
>> +       if (of_get_property(np, "linux,input-no-autorepeat", NULL))
>> +               keypad_data->no_autorepeat = true;
>> +
>> +       return keypad_data;
>> +}
>> +
>>  static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>  {
>> +       struct device *dev = &pdev->dev;
>> +       struct device_node *np = dev->of_node;
>>        const struct omap4_keypad_platform_data *pdata;
>>        struct omap4_keypad *keypad_data;
>>        struct input_dev *input_dev;
>>        struct resource *res;
>>        resource_size_t size;
>> -       unsigned int row_shift, max_keys;
>> +       unsigned int row_shift = 0, max_keys = 0;
>> +       uint32_t num_rows = 0, num_cols = 0;
>>        int rev;
>>        int irq;
>>        int error;
>>
>>        /* platform data */
>>        pdata = pdev->dev.platform_data;
>> -       if (!pdata) {
>> +       if (np) {
>> +               of_property_read_u32(np, "keypad,num-rows", &num_rows);
>> +               of_property_read_u32(np, "keypad,num-columns", &num_cols);
>> +               if (!num_rows || !num_cols) {
>> +                       dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
>> +                       return -EINVAL;
>> +               }
>> +       } else if (pdata) {
>> +               num_rows = pdata->rows;
>> +               num_cols = pdata->cols;
>> +       } else {
>>                dev_err(&pdev->dev, "no platform data defined\n");
>>                return -EINVAL;
>>        }
>>
>> +       row_shift = get_count_order(num_cols);
>> +       max_keys = num_rows << row_shift;
>> +
>> +       keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad) +
>> +                       max_keys * sizeof(keypad_data->keymap[0]),
>> +                               GFP_KERNEL);
>> +
>> +       if (!keypad_data) {
>> +               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
>> +               return -ENOMEM;
>> +       }
>> +
>> +       platform_set_drvdata(pdev, keypad_data);
>> +
>>        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>        if (!res) {
>>                dev_err(&pdev->dev, "no base address specified\n");
>> @@ -239,22 +291,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>                return -EINVAL;
>>        }
>>
>> -       if (!pdata->keymap_data) {
>> -               dev_err(&pdev->dev, "no keymap data defined\n");
>> -               return -EINVAL;
>> -       }
>> -
>> -       row_shift = get_count_order(pdata->cols);
>> -       max_keys = pdata->rows << row_shift;
>> -
>> -       keypad_data = kzalloc(sizeof(struct omap4_keypad) +
>> -                               max_keys * sizeof(keypad_data->keymap[0]),
>> -                             GFP_KERNEL);
>> -       if (!keypad_data) {
>> -               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
>> -               return -ENOMEM;
>> -       }
>> -
>>        size = resource_size(res);
>>
>>        res = request_mem_region(res->start, size, pdev->name);
>> @@ -271,10 +307,10 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>                goto err_release_mem;
>>        }
>>
>> +       keypad_data->rows = num_rows;
>> +       keypad_data->cols = num_cols;
>>        keypad_data->irq = irq;
>>        keypad_data->row_shift = row_shift;
>> -       keypad_data->rows = pdata->rows;
>> -       keypad_data->cols = pdata->cols;
>>
>>        /*
>>        * Enable clocks for the keypad module so that we can read
>> @@ -322,15 +358,25 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>        input_dev->open = omap4_keypad_open;
>>        input_dev->close = omap4_keypad_close;
>>
>> -       error = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
>> -                                          pdata->rows, pdata->cols,
>> -                                          keypad_data->keymap, input_dev);
>> -       if (error) {
>> -               dev_err(&pdev->dev, "failed to build keymap\n");
>> -               goto err_free_input;
>> +       if (np) {
>> +               keypad_data = omap_keypad_parse_dt(&pdev->dev,
>> +                               keypad_data->rows, keypad_data->cols,
>> +                               input_dev);
>> +       } else {
>> +               keypad_data->keymap_data =
>> +                       (struct matrix_keymap_data *)pdata->keymap_data;
>> +               error = matrix_keypad_build_keymap(keypad_data->keymap_data,
>> +                               NULL, keypad_data->rows, keypad_data->cols,
>> +                               keypad_data->keymap, input_dev);
>> +               if (error) {
>> +                       dev_err(&pdev->dev, "failed to build keymap\n");
>> +                       goto err_free_input;
>> +               }
>>        }
>>
>> -       __set_bit(EV_REP, input_dev->evbit);
>> +       if (!keypad_data->no_autorepeat)
>> +               __set_bit(EV_REP, input_dev->evbit);
>> +
>>        input_set_capability(input_dev, EV_MSC, MSC_SCAN);
>>
>>        input_set_drvdata(input_dev, keypad_data);
>> @@ -351,7 +397,6 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>                goto err_pm_disable;
>>        }
>>
>> -       platform_set_drvdata(pdev, keypad_data);
>>        return 0;
>>
>>  err_pm_disable:
>> @@ -392,12 +437,19 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
>>        return 0;
>>  }
>>
>> +static const struct of_device_id omap_keypad_dt_match[] = {
>> +       { .compatible = "ti,omap4-keypad" },
>> +       {},
>> +};
>> +MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
>> +
>>  static struct platform_driver omap4_keypad_driver = {
>>        .probe          = omap4_keypad_probe,
>>        .remove         = __devexit_p(omap4_keypad_remove),
>>        .driver         = {
>>                .name   = "omap4-keypad",
>>                .owner  = THIS_MODULE,
>> +               .of_match_table = of_match_ptr(omap_keypad_dt_match),
>>        },
>>  };
>>  module_platform_driver(omap4_keypad_driver);
>> --
>> 1.7.1
>>
This patch is lying here for too long.
If there is no comment, can it be taken into your tree?

~Sourav

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

* Re: [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support
  2012-06-08 10:52 [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Sourav Poddar
  2012-06-08 10:53 ` [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data Sourav Poddar
  2012-06-19 14:25 ` [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Poddar, Sourav
@ 2012-07-10  6:13 ` Dmitry Torokhov
  2012-07-11  9:45   ` Poddar, Sourav
  2 siblings, 1 reply; 9+ messages in thread
From: Dmitry Torokhov @ 2012-07-10  6:13 UTC (permalink / raw)
  To: Sourav Poddar
  Cc: devicetree-discuss, linux-arm-kernel, linux-input, linux-kernel,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Randy Dunlap

Hi Sourav,

On Fri, Jun 08, 2012 at 04:22:59PM +0530, Sourav Poddar wrote:
> Update the Documentation with omap4 keypad device tree
> binding information.
> Add device tree support for omap4 keypad driver.
> 
> Tested on omap4430 sdp.
>

Sorry for the delay, I have a few comments:

>  
>  	/* platform data */
>  	pdata = pdev->dev.platform_data;
> -	if (!pdata) {
> +	if (np) {
> +		of_property_read_u32(np, "keypad,num-rows", &num_rows);
> +		of_property_read_u32(np, "keypad,num-columns", &num_cols);
> +		if (!num_rows || !num_cols) {
> +			dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
> +			return -EINVAL;
> +		}
> +	} else if (pdata) {
> +		num_rows = pdata->rows;
> +		num_cols = pdata->cols;
> +	} else {
>  		dev_err(&pdev->dev, "no platform data defined\n");
>  		return -EINVAL;
>  	}
>  

I believe drivers should use platform data if it is supplied and use DT
data if platform data is omitted. This way one can override firmware
data if needed.

Does the patch below (if applied on top of your) work for you?

Thanks.

-- 
Dmitry

Input: omap4-keypad - misc fixes

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/input/keyboard/omap4-keypad.c |  152 ++++++++++++++++-----------------
 1 file changed, 74 insertions(+), 78 deletions(-)


diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index d5a2d1a..033168e 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -76,7 +76,6 @@ enum {
 
 struct omap4_keypad {
 	struct input_dev *input;
-	struct matrix_keymap_data *keymap_data;
 
 	void __iomem *base;
 	unsigned int irq;
@@ -88,7 +87,7 @@ struct omap4_keypad {
 	unsigned int row_shift;
 	bool no_autorepeat;
 	unsigned char key_state[8];
-	unsigned short keymap[];
+	unsigned short *keymap;
 };
 
 static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
@@ -211,74 +210,52 @@ static void omap4_keypad_close(struct input_dev *input)
 	pm_runtime_put_sync(input->dev.parent);
 }
 
-static struct omap4_keypad *omap_keypad_parse_dt(struct device *dev,
-				uint32_t rows, uint32_t cols,
-				struct input_dev *input_dev)
+#ifdef CONFIG_OF
+static int __devinit omap4_keypad_parse_dt(struct device *dev,
+					   struct omap4_keypad *keypad_data)
 {
 	struct device_node *np = dev->of_node;
-	struct platform_device *pdev = to_platform_device(dev);
-	struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
 	int error;
 
-	error = matrix_keypad_build_keymap(NULL, "linux,keymap",
-				rows, cols, keypad_data->keymap, input_dev);
-	if (error) {
-		dev_err(&pdev->dev, "failed to build keymap\n");
-		input_free_device(input_dev);
+	if (!np) {
+		dev_err(dev, "missing DT data");
+		return -EINVAL;
+	}
+
+	of_property_read_u32(np, "keypad,num-rows", &keypad_data->rows);
+	of_property_read_u32(np, "keypad,num-columns", &keypad_data->cols);
+	if (!keypad_data->rows || !keypad_data->cols) {
+		dev_err(dev, "number of keypad rows/columns not specified\n");
+		return -EINVAL;
 	}
 
 	if (of_get_property(np, "linux,input-no-autorepeat", NULL))
 		keypad_data->no_autorepeat = true;
 
-	return keypad_data;
+	return 0;
+}
+#else
+static inline int omap4_keypad_parse_dt(struct device *dev,
+					struct omap4_keypad *keypad_data)
+{
+	return -ENOSYS;
 }
+#endif
 
 static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 {
-	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;
-	const struct omap4_keypad_platform_data *pdata;
+	const struct omap4_keypad_platform_data *pdata =
+				dev_get_platdata(&pdev->dev);
+	const struct matrix_keymap_data *keymap_data =
+				pdata ? pdata->keymap_data : NULL;
 	struct omap4_keypad *keypad_data;
 	struct input_dev *input_dev;
 	struct resource *res;
-	resource_size_t size;
-	unsigned int row_shift = 0, max_keys = 0;
-	uint32_t num_rows = 0, num_cols = 0;
+	unsigned int max_keys;
 	int rev;
 	int irq;
 	int error;
 
-	/* platform data */
-	pdata = pdev->dev.platform_data;
-	if (np) {
-		of_property_read_u32(np, "keypad,num-rows", &num_rows);
-		of_property_read_u32(np, "keypad,num-columns", &num_cols);
-		if (!num_rows || !num_cols) {
-			dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
-			return -EINVAL;
-		}
-	} else if (pdata) {
-		num_rows = pdata->rows;
-		num_cols = pdata->cols;
-	} else {
-		dev_err(&pdev->dev, "no platform data defined\n");
-		return -EINVAL;
-	}
-
-	row_shift = get_count_order(num_cols);
-	max_keys = num_rows << row_shift;
-
-	keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad) +
-			max_keys * sizeof(keypad_data->keymap[0]),
-				GFP_KERNEL);
-
-	if (!keypad_data) {
-		dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
-		return -ENOMEM;
-	}
-
-	platform_set_drvdata(pdev, keypad_data);
-
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
 		dev_err(&pdev->dev, "no base address specified\n");
@@ -291,9 +268,24 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	size = resource_size(res);
+	keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
+	if (!keypad_data) {
+		dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
+		return -ENOMEM;
+	}
+
+	keypad_data->irq = irq;
+
+	if (pdata) {
+		keypad_data->rows = pdata->rows;
+		keypad_data->cols = pdata->cols;
+	} else {
+		error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
+		if (error)
+			return error;
+	}
 
-	res = request_mem_region(res->start, size, pdev->name);
+	res = request_mem_region(res->start, resource_size(res), pdev->name);
 	if (!res) {
 		dev_err(&pdev->dev, "can't request mem region\n");
 		error = -EBUSY;
@@ -307,15 +299,11 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 		goto err_release_mem;
 	}
 
-	keypad_data->rows = num_rows;
-	keypad_data->cols = num_cols;
-	keypad_data->irq = irq;
-	keypad_data->row_shift = row_shift;
 
 	/*
-	* Enable clocks for the keypad module so that we can read
-	* revision register.
-	*/
+	 * Enable clocks for the keypad module so that we can read
+	 * revision register.
+	 */
 	pm_runtime_enable(&pdev->dev);
 	error = pm_runtime_get_sync(&pdev->dev);
 	if (error) {
@@ -358,29 +346,30 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 	input_dev->open = omap4_keypad_open;
 	input_dev->close = omap4_keypad_close;
 
-	if (np) {
-		keypad_data = omap_keypad_parse_dt(&pdev->dev,
-				keypad_data->rows, keypad_data->cols,
-				input_dev);
-	} else {
-		keypad_data->keymap_data =
-			(struct matrix_keymap_data *)pdata->keymap_data;
-		error = matrix_keypad_build_keymap(keypad_data->keymap_data,
-				NULL, keypad_data->rows, keypad_data->cols,
-				keypad_data->keymap, input_dev);
-		if (error) {
-			dev_err(&pdev->dev, "failed to build keymap\n");
-			goto err_free_input;
-		}
-	}
-
+	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
 	if (!keypad_data->no_autorepeat)
 		__set_bit(EV_REP, input_dev->evbit);
 
-	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
-
 	input_set_drvdata(input_dev, keypad_data);
 
+	keypad_data->row_shift = get_count_order(keypad_data->cols);
+	max_keys = keypad_data->rows << keypad_data->row_shift;
+	keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]),
+				      GFP_KERNEL);
+	if (!keypad_data->keymap) {
+		dev_err(&pdev->dev, "Not enough memory for keymap\n");
+		error = -ENOMEM;
+		goto err_free_input;
+	}
+
+	error = matrix_keypad_build_keymap(keymap_data, NULL,
+					   keypad_data->rows, keypad_data->cols,
+					   keypad_data->keymap, input_dev);
+	if (error) {
+		dev_err(&pdev->dev, "failed to build keymap\n");
+		goto err_free_keymap;
+	}
+
 	error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
 			     IRQF_TRIGGER_RISING,
 			     "omap4-keypad", keypad_data);
@@ -397,11 +386,14 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
 		goto err_pm_disable;
 	}
 
+	platform_set_drvdata(pdev, keypad_data);
 	return 0;
 
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
 	free_irq(keypad_data->irq, keypad_data);
+err_free_keymap:
+	kfree(keypad_data->keymap);
 err_free_input:
 	input_free_device(input_dev);
 err_pm_put_sync:
@@ -409,7 +401,7 @@ err_pm_put_sync:
 err_unmap:
 	iounmap(keypad_data->base);
 err_release_mem:
-	release_mem_region(res->start, size);
+	release_mem_region(res->start, resource_size(res));
 err_free_keypad:
 	kfree(keypad_data);
 	return error;
@@ -431,17 +423,21 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	release_mem_region(res->start, resource_size(res));
 
+	kfree(keypad_data->keymap);
 	kfree(keypad_data);
+
 	platform_set_drvdata(pdev, NULL);
 
 	return 0;
 }
 
+#ifdef CONFIG_OF
 static const struct of_device_id omap_keypad_dt_match[] = {
 	{ .compatible = "ti,omap4-keypad" },
 	{},
 };
 MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
+#endif
 
 static struct platform_driver omap4_keypad_driver = {
 	.probe		= omap4_keypad_probe,

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

* Re: [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support
  2012-07-10  6:13 ` Dmitry Torokhov
@ 2012-07-11  9:45   ` Poddar, Sourav
  2012-07-11 11:20     ` Poddar, Sourav
  0 siblings, 1 reply; 9+ messages in thread
From: Poddar, Sourav @ 2012-07-11  9:45 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: devicetree-discuss, linux-arm-kernel, linux-input, linux-kernel,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Randy Dunlap

Hi Dmitry,

On Tue, Jul 10, 2012 at 11:43 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> Hi Sourav,
>
> On Fri, Jun 08, 2012 at 04:22:59PM +0530, Sourav Poddar wrote:
>> Update the Documentation with omap4 keypad device tree
>> binding information.
>> Add device tree support for omap4 keypad driver.
>>
>> Tested on omap4430 sdp.
>>
>
> Sorry for the delay, I have a few comments:
>
>>
>>       /* platform data */
>>       pdata = pdev->dev.platform_data;
>> -     if (!pdata) {
>> +     if (np) {
>> +             of_property_read_u32(np, "keypad,num-rows", &num_rows);
>> +             of_property_read_u32(np, "keypad,num-columns", &num_cols);
>> +             if (!num_rows || !num_cols) {
>> +                     dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
>> +                     return -EINVAL;
>> +             }
>> +     } else if (pdata) {
>> +             num_rows = pdata->rows;
>> +             num_cols = pdata->cols;
>> +     } else {
>>               dev_err(&pdev->dev, "no platform data defined\n");
>>               return -EINVAL;
>>       }
>>
>
> I believe drivers should use platform data if it is supplied and use DT
> data if platform data is omitted. This way one can override firmware
> data if needed.
>
> Does the patch below (if applied on top of your) work for you?
>
Yes, the above patch works fine for me.
Acked-by: Sourav Poddar <sourav.poddar@ti.com>

Note, I did some mux setting changes in the bootloader for DT case.

Thanks,
Sourav
> Thanks.
>
> --
> Dmitry
>
> Input: omap4-keypad - misc fixes
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>
>  drivers/input/keyboard/omap4-keypad.c |  152 ++++++++++++++++-----------------
>  1 file changed, 74 insertions(+), 78 deletions(-)
>
>
> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
> index d5a2d1a..033168e 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -76,7 +76,6 @@ enum {
>
>  struct omap4_keypad {
>         struct input_dev *input;
> -       struct matrix_keymap_data *keymap_data;
>
>         void __iomem *base;
>         unsigned int irq;
> @@ -88,7 +87,7 @@ struct omap4_keypad {
>         unsigned int row_shift;
>         bool no_autorepeat;
>         unsigned char key_state[8];
> -       unsigned short keymap[];
> +       unsigned short *keymap;
>  };
>
>  static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> @@ -211,74 +210,52 @@ static void omap4_keypad_close(struct input_dev *input)
>         pm_runtime_put_sync(input->dev.parent);
>  }
>
> -static struct omap4_keypad *omap_keypad_parse_dt(struct device *dev,
> -                               uint32_t rows, uint32_t cols,
> -                               struct input_dev *input_dev)
> +#ifdef CONFIG_OF
> +static int __devinit omap4_keypad_parse_dt(struct device *dev,
> +                                          struct omap4_keypad *keypad_data)
>  {
>         struct device_node *np = dev->of_node;
> -       struct platform_device *pdev = to_platform_device(dev);
> -       struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
>         int error;
>
> -       error = matrix_keypad_build_keymap(NULL, "linux,keymap",
> -                               rows, cols, keypad_data->keymap, input_dev);
> -       if (error) {
> -               dev_err(&pdev->dev, "failed to build keymap\n");
> -               input_free_device(input_dev);
> +       if (!np) {
> +               dev_err(dev, "missing DT data");
> +               return -EINVAL;
> +       }
> +
> +       of_property_read_u32(np, "keypad,num-rows", &keypad_data->rows);
> +       of_property_read_u32(np, "keypad,num-columns", &keypad_data->cols);
> +       if (!keypad_data->rows || !keypad_data->cols) {
> +               dev_err(dev, "number of keypad rows/columns not specified\n");
> +               return -EINVAL;
>         }
>
>         if (of_get_property(np, "linux,input-no-autorepeat", NULL))
>                 keypad_data->no_autorepeat = true;
>
> -       return keypad_data;
> +       return 0;
> +}
> +#else
> +static inline int omap4_keypad_parse_dt(struct device *dev,
> +                                       struct omap4_keypad *keypad_data)
> +{
> +       return -ENOSYS;
>  }
> +#endif
>
>  static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>  {
> -       struct device *dev = &pdev->dev;
> -       struct device_node *np = dev->of_node;
> -       const struct omap4_keypad_platform_data *pdata;
> +       const struct omap4_keypad_platform_data *pdata =
> +                               dev_get_platdata(&pdev->dev);
> +       const struct matrix_keymap_data *keymap_data =
> +                               pdata ? pdata->keymap_data : NULL;
>         struct omap4_keypad *keypad_data;
>         struct input_dev *input_dev;
>         struct resource *res;
> -       resource_size_t size;
> -       unsigned int row_shift = 0, max_keys = 0;
> -       uint32_t num_rows = 0, num_cols = 0;
> +       unsigned int max_keys;
>         int rev;
>         int irq;
>         int error;
>
> -       /* platform data */
> -       pdata = pdev->dev.platform_data;
> -       if (np) {
> -               of_property_read_u32(np, "keypad,num-rows", &num_rows);
> -               of_property_read_u32(np, "keypad,num-columns", &num_cols);
> -               if (!num_rows || !num_cols) {
> -                       dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
> -                       return -EINVAL;
> -               }
> -       } else if (pdata) {
> -               num_rows = pdata->rows;
> -               num_cols = pdata->cols;
> -       } else {
> -               dev_err(&pdev->dev, "no platform data defined\n");
> -               return -EINVAL;
> -       }
> -
> -       row_shift = get_count_order(num_cols);
> -       max_keys = num_rows << row_shift;
> -
> -       keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad) +
> -                       max_keys * sizeof(keypad_data->keymap[0]),
> -                               GFP_KERNEL);
> -
> -       if (!keypad_data) {
> -               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
> -               return -ENOMEM;
> -       }
> -
> -       platform_set_drvdata(pdev, keypad_data);
> -
>         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>         if (!res) {
>                 dev_err(&pdev->dev, "no base address specified\n");
> @@ -291,9 +268,24 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>                 return -EINVAL;
>         }
>
> -       size = resource_size(res);
> +       keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
> +       if (!keypad_data) {
> +               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
> +               return -ENOMEM;
> +       }
> +
> +       keypad_data->irq = irq;
> +
> +       if (pdata) {
> +               keypad_data->rows = pdata->rows;
> +               keypad_data->cols = pdata->cols;
> +       } else {
> +               error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
> +               if (error)
> +                       return error;
> +       }
>
> -       res = request_mem_region(res->start, size, pdev->name);
> +       res = request_mem_region(res->start, resource_size(res), pdev->name);
>         if (!res) {
>                 dev_err(&pdev->dev, "can't request mem region\n");
>                 error = -EBUSY;
> @@ -307,15 +299,11 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>                 goto err_release_mem;
>         }
>
> -       keypad_data->rows = num_rows;
> -       keypad_data->cols = num_cols;
> -       keypad_data->irq = irq;
> -       keypad_data->row_shift = row_shift;
>
>         /*
> -       * Enable clocks for the keypad module so that we can read
> -       * revision register.
> -       */
> +        * Enable clocks for the keypad module so that we can read
> +        * revision register.
> +        */
>         pm_runtime_enable(&pdev->dev);
>         error = pm_runtime_get_sync(&pdev->dev);
>         if (error) {
> @@ -358,29 +346,30 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>         input_dev->open = omap4_keypad_open;
>         input_dev->close = omap4_keypad_close;
>
> -       if (np) {
> -               keypad_data = omap_keypad_parse_dt(&pdev->dev,
> -                               keypad_data->rows, keypad_data->cols,
> -                               input_dev);
> -       } else {
> -               keypad_data->keymap_data =
> -                       (struct matrix_keymap_data *)pdata->keymap_data;
> -               error = matrix_keypad_build_keymap(keypad_data->keymap_data,
> -                               NULL, keypad_data->rows, keypad_data->cols,
> -                               keypad_data->keymap, input_dev);
> -               if (error) {
> -                       dev_err(&pdev->dev, "failed to build keymap\n");
> -                       goto err_free_input;
> -               }
> -       }
> -
> +       input_set_capability(input_dev, EV_MSC, MSC_SCAN);
>         if (!keypad_data->no_autorepeat)
>                 __set_bit(EV_REP, input_dev->evbit);
>
> -       input_set_capability(input_dev, EV_MSC, MSC_SCAN);
> -
>         input_set_drvdata(input_dev, keypad_data);
>
> +       keypad_data->row_shift = get_count_order(keypad_data->cols);
> +       max_keys = keypad_data->rows << keypad_data->row_shift;
> +       keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]),
> +                                     GFP_KERNEL);
> +       if (!keypad_data->keymap) {
> +               dev_err(&pdev->dev, "Not enough memory for keymap\n");
> +               error = -ENOMEM;
> +               goto err_free_input;
> +       }
> +
> +       error = matrix_keypad_build_keymap(keymap_data, NULL,
> +                                          keypad_data->rows, keypad_data->cols,
> +                                          keypad_data->keymap, input_dev);
> +       if (error) {
> +               dev_err(&pdev->dev, "failed to build keymap\n");
> +               goto err_free_keymap;
> +       }
> +
>         error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
>                              IRQF_TRIGGER_RISING,
>                              "omap4-keypad", keypad_data);
> @@ -397,11 +386,14 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>                 goto err_pm_disable;
>         }
>
> +       platform_set_drvdata(pdev, keypad_data);
>         return 0;
>
>  err_pm_disable:
>         pm_runtime_disable(&pdev->dev);
>         free_irq(keypad_data->irq, keypad_data);
> +err_free_keymap:
> +       kfree(keypad_data->keymap);
>  err_free_input:
>         input_free_device(input_dev);
>  err_pm_put_sync:
> @@ -409,7 +401,7 @@ err_pm_put_sync:
>  err_unmap:
>         iounmap(keypad_data->base);
>  err_release_mem:
> -       release_mem_region(res->start, size);
> +       release_mem_region(res->start, resource_size(res));
>  err_free_keypad:
>         kfree(keypad_data);
>         return error;
> @@ -431,17 +423,21 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
>         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>         release_mem_region(res->start, resource_size(res));
>
> +       kfree(keypad_data->keymap);
>         kfree(keypad_data);
> +
>         platform_set_drvdata(pdev, NULL);
>
>         return 0;
>  }
>
> +#ifdef CONFIG_OF
>  static const struct of_device_id omap_keypad_dt_match[] = {
>         { .compatible = "ti,omap4-keypad" },
>         {},
>  };
>  MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
> +#endif
>
>  static struct platform_driver omap4_keypad_driver = {
>         .probe          = omap4_keypad_probe,

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

* Re: [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support
  2012-07-11  9:45   ` Poddar, Sourav
@ 2012-07-11 11:20     ` Poddar, Sourav
  0 siblings, 0 replies; 9+ messages in thread
From: Poddar, Sourav @ 2012-07-11 11:20 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: devicetree-discuss, linux-arm-kernel, linux-input, linux-kernel,
	Andrew Morton, Benoit Cousson, Rob Herring, Grant Likely,
	Felipe Balbi, Randy Dunlap

Hi Dmitry,

On Wed, Jul 11, 2012 at 3:15 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> On Tue, Jul 10, 2012 at 11:43 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>> Hi Sourav,
>>
>> On Fri, Jun 08, 2012 at 04:22:59PM +0530, Sourav Poddar wrote:
>>> Update the Documentation with omap4 keypad device tree
>>> binding information.
>>> Add device tree support for omap4 keypad driver.
>>>
>>> Tested on omap4430 sdp.
>>>
>>
>> Sorry for the delay, I have a few comments:
>>
>>>
>>>       /* platform data */
>>>       pdata = pdev->dev.platform_data;
>>> -     if (!pdata) {
>>> +     if (np) {
>>> +             of_property_read_u32(np, "keypad,num-rows", &num_rows);
>>> +             of_property_read_u32(np, "keypad,num-columns", &num_cols);
>>> +             if (!num_rows || !num_cols) {
>>> +                     dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
>>> +                     return -EINVAL;
>>> +             }
>>> +     } else if (pdata) {
>>> +             num_rows = pdata->rows;
>>> +             num_cols = pdata->cols;
>>> +     } else {
>>>               dev_err(&pdev->dev, "no platform data defined\n");
>>>               return -EINVAL;
>>>       }
>>>
>>
>> I believe drivers should use platform data if it is supplied and use DT
>> data if platform data is omitted. This way one can override firmware
>> data if needed.
>>
>> Does the patch below (if applied on top of your) work for you?
>>
> Yes, the above patch works fine for me.
> Acked-by: Sourav Poddar <sourav.poddar@ti.com>
>
> Note, I did some mux setting changes in the bootloader for DT case.
>
To be explicit, these was done throughout for testing. Nothing specific to your
incremental patch.
> Thanks,
> Sourav
>> Thanks.
>>
>> --
>> Dmitry
>>
>> Input: omap4-keypad - misc fixes
>>
>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> ---
>>
>>  drivers/input/keyboard/omap4-keypad.c |  152 ++++++++++++++++-----------------
>>  1 file changed, 74 insertions(+), 78 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index d5a2d1a..033168e 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -76,7 +76,6 @@ enum {
>>
>>  struct omap4_keypad {
>>         struct input_dev *input;
>> -       struct matrix_keymap_data *keymap_data;
>>
>>         void __iomem *base;
>>         unsigned int irq;
>> @@ -88,7 +87,7 @@ struct omap4_keypad {
>>         unsigned int row_shift;
>>         bool no_autorepeat;
>>         unsigned char key_state[8];
>> -       unsigned short keymap[];
>> +       unsigned short *keymap;
>>  };
>>
>>  static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> @@ -211,74 +210,52 @@ static void omap4_keypad_close(struct input_dev *input)
>>         pm_runtime_put_sync(input->dev.parent);
>>  }
>>
>> -static struct omap4_keypad *omap_keypad_parse_dt(struct device *dev,
>> -                               uint32_t rows, uint32_t cols,
>> -                               struct input_dev *input_dev)
>> +#ifdef CONFIG_OF
>> +static int __devinit omap4_keypad_parse_dt(struct device *dev,
>> +                                          struct omap4_keypad *keypad_data)
>>  {
>>         struct device_node *np = dev->of_node;
>> -       struct platform_device *pdev = to_platform_device(dev);
>> -       struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
>>         int error;
>>
>> -       error = matrix_keypad_build_keymap(NULL, "linux,keymap",
>> -                               rows, cols, keypad_data->keymap, input_dev);
>> -       if (error) {
>> -               dev_err(&pdev->dev, "failed to build keymap\n");
>> -               input_free_device(input_dev);
>> +       if (!np) {
>> +               dev_err(dev, "missing DT data");
>> +               return -EINVAL;
>> +       }
>> +
>> +       of_property_read_u32(np, "keypad,num-rows", &keypad_data->rows);
>> +       of_property_read_u32(np, "keypad,num-columns", &keypad_data->cols);
>> +       if (!keypad_data->rows || !keypad_data->cols) {
>> +               dev_err(dev, "number of keypad rows/columns not specified\n");
>> +               return -EINVAL;
>>         }
>>
>>         if (of_get_property(np, "linux,input-no-autorepeat", NULL))
>>                 keypad_data->no_autorepeat = true;
>>
>> -       return keypad_data;
>> +       return 0;
>> +}
>> +#else
>> +static inline int omap4_keypad_parse_dt(struct device *dev,
>> +                                       struct omap4_keypad *keypad_data)
>> +{
>> +       return -ENOSYS;
>>  }
>> +#endif
>>
>>  static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>  {
>> -       struct device *dev = &pdev->dev;
>> -       struct device_node *np = dev->of_node;
>> -       const struct omap4_keypad_platform_data *pdata;
>> +       const struct omap4_keypad_platform_data *pdata =
>> +                               dev_get_platdata(&pdev->dev);
>> +       const struct matrix_keymap_data *keymap_data =
>> +                               pdata ? pdata->keymap_data : NULL;
>>         struct omap4_keypad *keypad_data;
>>         struct input_dev *input_dev;
>>         struct resource *res;
>> -       resource_size_t size;
>> -       unsigned int row_shift = 0, max_keys = 0;
>> -       uint32_t num_rows = 0, num_cols = 0;
>> +       unsigned int max_keys;
>>         int rev;
>>         int irq;
>>         int error;
>>
>> -       /* platform data */
>> -       pdata = pdev->dev.platform_data;
>> -       if (np) {
>> -               of_property_read_u32(np, "keypad,num-rows", &num_rows);
>> -               of_property_read_u32(np, "keypad,num-columns", &num_cols);
>> -               if (!num_rows || !num_cols) {
>> -                       dev_err(&pdev->dev, "number of keypad rows/columns not specified\n");
>> -                       return -EINVAL;
>> -               }
>> -       } else if (pdata) {
>> -               num_rows = pdata->rows;
>> -               num_cols = pdata->cols;
>> -       } else {
>> -               dev_err(&pdev->dev, "no platform data defined\n");
>> -               return -EINVAL;
>> -       }
>> -
>> -       row_shift = get_count_order(num_cols);
>> -       max_keys = num_rows << row_shift;
>> -
>> -       keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad) +
>> -                       max_keys * sizeof(keypad_data->keymap[0]),
>> -                               GFP_KERNEL);
>> -
>> -       if (!keypad_data) {
>> -               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
>> -               return -ENOMEM;
>> -       }
>> -
>> -       platform_set_drvdata(pdev, keypad_data);
>> -
>>         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>         if (!res) {
>>                 dev_err(&pdev->dev, "no base address specified\n");
>> @@ -291,9 +268,24 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>                 return -EINVAL;
>>         }
>>
>> -       size = resource_size(res);
>> +       keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
>> +       if (!keypad_data) {
>> +               dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
>> +               return -ENOMEM;
>> +       }
>> +
>> +       keypad_data->irq = irq;
>> +
>> +       if (pdata) {
>> +               keypad_data->rows = pdata->rows;
>> +               keypad_data->cols = pdata->cols;
>> +       } else {
>> +               error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
>> +               if (error)
>> +                       return error;
>> +       }
>>
>> -       res = request_mem_region(res->start, size, pdev->name);
>> +       res = request_mem_region(res->start, resource_size(res), pdev->name);
>>         if (!res) {
>>                 dev_err(&pdev->dev, "can't request mem region\n");
>>                 error = -EBUSY;
>> @@ -307,15 +299,11 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>                 goto err_release_mem;
>>         }
>>
>> -       keypad_data->rows = num_rows;
>> -       keypad_data->cols = num_cols;
>> -       keypad_data->irq = irq;
>> -       keypad_data->row_shift = row_shift;
>>
>>         /*
>> -       * Enable clocks for the keypad module so that we can read
>> -       * revision register.
>> -       */
>> +        * Enable clocks for the keypad module so that we can read
>> +        * revision register.
>> +        */
>>         pm_runtime_enable(&pdev->dev);
>>         error = pm_runtime_get_sync(&pdev->dev);
>>         if (error) {
>> @@ -358,29 +346,30 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>         input_dev->open = omap4_keypad_open;
>>         input_dev->close = omap4_keypad_close;
>>
>> -       if (np) {
>> -               keypad_data = omap_keypad_parse_dt(&pdev->dev,
>> -                               keypad_data->rows, keypad_data->cols,
>> -                               input_dev);
>> -       } else {
>> -               keypad_data->keymap_data =
>> -                       (struct matrix_keymap_data *)pdata->keymap_data;
>> -               error = matrix_keypad_build_keymap(keypad_data->keymap_data,
>> -                               NULL, keypad_data->rows, keypad_data->cols,
>> -                               keypad_data->keymap, input_dev);
>> -               if (error) {
>> -                       dev_err(&pdev->dev, "failed to build keymap\n");
>> -                       goto err_free_input;
>> -               }
>> -       }
>> -
>> +       input_set_capability(input_dev, EV_MSC, MSC_SCAN);
>>         if (!keypad_data->no_autorepeat)
>>                 __set_bit(EV_REP, input_dev->evbit);
>>
>> -       input_set_capability(input_dev, EV_MSC, MSC_SCAN);
>> -
>>         input_set_drvdata(input_dev, keypad_data);
>>
>> +       keypad_data->row_shift = get_count_order(keypad_data->cols);
>> +       max_keys = keypad_data->rows << keypad_data->row_shift;
>> +       keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]),
>> +                                     GFP_KERNEL);
>> +       if (!keypad_data->keymap) {
>> +               dev_err(&pdev->dev, "Not enough memory for keymap\n");
>> +               error = -ENOMEM;
>> +               goto err_free_input;
>> +       }
>> +
>> +       error = matrix_keypad_build_keymap(keymap_data, NULL,
>> +                                          keypad_data->rows, keypad_data->cols,
>> +                                          keypad_data->keymap, input_dev);
>> +       if (error) {
>> +               dev_err(&pdev->dev, "failed to build keymap\n");
>> +               goto err_free_keymap;
>> +       }
>> +
>>         error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
>>                              IRQF_TRIGGER_RISING,
>>                              "omap4-keypad", keypad_data);
>> @@ -397,11 +386,14 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>>                 goto err_pm_disable;
>>         }
>>
>> +       platform_set_drvdata(pdev, keypad_data);
>>         return 0;
>>
>>  err_pm_disable:
>>         pm_runtime_disable(&pdev->dev);
>>         free_irq(keypad_data->irq, keypad_data);
>> +err_free_keymap:
>> +       kfree(keypad_data->keymap);
>>  err_free_input:
>>         input_free_device(input_dev);
>>  err_pm_put_sync:
>> @@ -409,7 +401,7 @@ err_pm_put_sync:
>>  err_unmap:
>>         iounmap(keypad_data->base);
>>  err_release_mem:
>> -       release_mem_region(res->start, size);
>> +       release_mem_region(res->start, resource_size(res));
>>  err_free_keypad:
>>         kfree(keypad_data);
>>         return error;
>> @@ -431,17 +423,21 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
>>         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>         release_mem_region(res->start, resource_size(res));
>>
>> +       kfree(keypad_data->keymap);
>>         kfree(keypad_data);
>> +
>>         platform_set_drvdata(pdev, NULL);
>>
>>         return 0;
>>  }
>>
>> +#ifdef CONFIG_OF
>>  static const struct of_device_id omap_keypad_dt_match[] = {
>>         { .compatible = "ti,omap4-keypad" },
>>         {},
>>  };
>>  MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
>> +#endif
>>
>>  static struct platform_driver omap4_keypad_driver = {
>>         .probe          = omap4_keypad_probe,

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

end of thread, other threads:[~2012-07-11 11:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-08 10:52 [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Sourav Poddar
2012-06-08 10:53 ` [RESEND/PATCHv5 2/2] arm/dts: omap4-sdp: Add keypad data Sourav Poddar
2012-06-15 14:58   ` Poddar, Sourav
2012-06-19 14:27   ` Poddar, Sourav
2012-06-19 14:25 ` [RESEND/PATCHv5 1/2] drivers: input: keypad: Add device tree support Poddar, Sourav
2012-07-05 14:07   ` Poddar, Sourav
2012-07-10  6:13 ` Dmitry Torokhov
2012-07-11  9:45   ` Poddar, Sourav
2012-07-11 11:20     ` Poddar, Sourav

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).