devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative
@ 2012-03-26  9:45 Viresh Kumar
  2012-03-26  9:45 ` [PATCH 2/2] Input: spear-keyboard: add device tree bindings Viresh Kumar
  2012-03-26 15:26 ` [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative Stephen Warren
  0 siblings, 2 replies; 7+ messages in thread
From: Viresh Kumar @ 2012-03-26  9:45 UTC (permalink / raw)
  To: dmitry.torokhov
  Cc: spear-devel, viresh.linux, swarren, rajeev-dlh.kumar, olof,
	devicetree-discuss, linux-input, Viresh Kumar

matrix_keyboard_of_fill_keymap() routines allocates memory using kzalloc()
routine. It is freed on call to matrix_keyboard_of_free_keymap() routine.

This patch converts these kzalloc() calls to devm_kzalloc() and thus we don't
require matrix_keyboard_of_free_keymap() anymore.

Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/input/keyboard/tegra-kbc.c  |   10 +++-------
 drivers/input/of_keymap.c           |   18 +++++-------------
 include/linux/input/matrix_keypad.h |   14 ++++----------
 3 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
index 21c42f8..40ee63f 100644
--- a/drivers/input/keyboard/tegra-kbc.c
+++ b/drivers/input/keyboard/tegra-kbc.c
@@ -659,7 +659,8 @@ tegra_kbc_dt_parse_pdata(struct platform_device *pdev)
 		pdata->pin_cfg[KBC_MAX_ROW + i].type = PIN_CFG_COL;
 	}
 
-	pdata->keymap_data = matrix_keyboard_of_fill_keymap(np, "linux,keymap");
+	pdata->keymap_data = matrix_keyboard_of_fill_keymap(&pdev->dev, np,
+			"linux,keymap");
 
 	/* FIXME: Add handling of linux,fn-keymap here */
 
@@ -798,9 +799,6 @@ static int __devinit tegra_kbc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, kbc);
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
 
-	if (!pdev->dev.platform_data)
-		matrix_keyboard_of_free_keymap(pdata->keymap_data);
-
 	return 0;
 
 err_free_irq:
@@ -815,10 +813,8 @@ err_free_mem:
 	input_free_device(input_dev);
 	kfree(kbc);
 err_free_pdata:
-	if (!pdev->dev.platform_data) {
-		matrix_keyboard_of_free_keymap(pdata->keymap_data);
+	if (!pdev->dev.platform_data)
 		kfree(pdata);
-	}
 
 	return err;
 }
diff --git a/drivers/input/of_keymap.c b/drivers/input/of_keymap.c
index 061493d..17eb27e 100644
--- a/drivers/input/of_keymap.c
+++ b/drivers/input/of_keymap.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/input.h>
@@ -27,7 +28,7 @@
 #include <linux/slab.h>
 
 struct matrix_keymap_data *
-matrix_keyboard_of_fill_keymap(struct device_node *np,
+matrix_keyboard_of_fill_keymap(struct device *dev, struct device_node *np,
 			       const char *propname)
 {
 	struct matrix_keymap_data *kd;
@@ -46,16 +47,16 @@ matrix_keyboard_of_fill_keymap(struct device_node *np,
 		return NULL;
 
 	if (proplen % sizeof(u32)) {
-		pr_warn("Malformed keymap property %s in %s\n",
+		dev_warn(dev, "Malformed keymap property %s in %s\n",
 			propname, np->full_name);
 		return NULL;
 	}
 
-	kd = kzalloc(sizeof(*kd), GFP_KERNEL);
+	kd = devm_kzalloc(dev, sizeof(*kd), GFP_KERNEL);
 	if (!kd)
 		return NULL;
 
-	kd->keymap = keymap = kzalloc(proplen, GFP_KERNEL);
+	kd->keymap = keymap = devm_kzalloc(dev, proplen, GFP_KERNEL);
 	if (!kd->keymap) {
 		kfree(kd);
 		return NULL;
@@ -76,12 +77,3 @@ matrix_keyboard_of_fill_keymap(struct device_node *np,
 	return kd;
 }
 EXPORT_SYMBOL_GPL(matrix_keyboard_of_fill_keymap);
-
-void matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd)
-{
-	if (kd) {
-		kfree(kd->keymap);
-		kfree(kd);
-	}
-}
-EXPORT_SYMBOL_GPL(matrix_keyboard_of_free_keymap);
diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
index 6c07ced..fb2e578 100644
--- a/include/linux/input/matrix_keypad.h
+++ b/include/linux/input/matrix_keypad.h
@@ -109,20 +109,14 @@ matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
 
 #ifdef CONFIG_INPUT_OF_MATRIX_KEYMAP
 struct matrix_keymap_data *
-matrix_keyboard_of_fill_keymap(struct device_node *np, const char *propname);
-
-void matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd);
+matrix_keyboard_of_fill_keymap(struct device *dev, struct device_node *np,
+		const char *propname);
 #else
 static inline struct matrix_keymap_data *
-matrix_keyboard_of_fill_keymap(struct device_node *np, const char *propname)
+matrix_keyboard_of_fill_keymap(struct device *dev, struct device_node *np,
+		const char *propname)
 {
 	return NULL;
 }
-
-static inline void
-matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd)
-{
-}
 #endif
-
 #endif /* _MATRIX_KEYPAD_H */
-- 
1.7.10.rc2.10.gb47606


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

* [PATCH 2/2] Input: spear-keyboard: add device tree bindings
  2012-03-26  9:45 [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative Viresh Kumar
@ 2012-03-26  9:45 ` Viresh Kumar
  2012-03-26 15:30   ` Stephen Warren
  2012-03-26 15:26 ` [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative Stephen Warren
  1 sibling, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2012-03-26  9:45 UTC (permalink / raw)
  To: dmitry.torokhov
  Cc: spear-devel, viresh.linux, swarren, rajeev-dlh.kumar, olof,
	devicetree-discuss, linux-input, Viresh Kumar

This adds simple DT bindings for spear-keyboard controller.

Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 .../devicetree/bindings/input/spear-keyboard.txt   |   21 +++++++
 drivers/input/keyboard/Kconfig                     |    1 +
 drivers/input/keyboard/spear-keyboard.c            |   63 +++++++++++++++++++-
 3 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/input/spear-keyboard.txt

diff --git a/Documentation/devicetree/bindings/input/spear-keyboard.txt b/Documentation/devicetree/bindings/input/spear-keyboard.txt
new file mode 100644
index 0000000..3dc0103
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/spear-keyboard.txt
@@ -0,0 +1,21 @@
+* SPEAr keyboard controller
+
+Required properties:
+- compatible: "st,spear-kbd"
+
+Optional properties, in addition to those specified by the shared
+matrix-keyboard bindings:
+- autorepeat: bool: enables key autorepeat
+- mode: keyboard mode: 0 - 9x9, 1 - 6x6, 2 - 2x2
+
+Example:
+
+kbd@fc400000 {
+	compatible = "st,spear-kbd";
+	reg = <0xfc400000 0x100>;
+	linux,keymap = < 0x00030012
+			 0x0102003a >;
+	autorepeat;
+	mode = <0>;
+};
+
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index f354813..6da2b02 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -522,6 +522,7 @@ config KEYBOARD_OMAP4
 config KEYBOARD_SPEAR
 	tristate "ST SPEAR keyboard support"
 	depends on PLAT_SPEAR
+	select INPUT_OF_MATRIX_KEYMAP if USE_OF
 	help
 	  Say Y here if you want to use the SPEAR keyboard.
 
diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
index 3b6b528..2a16519 100644
--- a/drivers/input/keyboard/spear-keyboard.c
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -19,6 +19,7 @@
 #include <linux/irq.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_wakeup.h>
 #include <linux/slab.h>
@@ -136,9 +137,43 @@ static void spear_kbd_close(struct input_dev *dev)
 	kbd->last_key = KEY_RESERVED;
 }
 
+#ifdef CONFIG_OF
+static int __devinit spear_kbd_probe_dt(struct platform_device *pdev)
+{
+	struct kbd_platform_data *pdata = dev_get_platdata(&pdev->dev);
+	struct device_node *np = pdev->dev.of_node;
+	u32 val;
+
+	pdata->keymap = matrix_keyboard_of_fill_keymap(&pdev->dev, np,
+			"linux,keymap");
+	if (!pdata->keymap) {
+		dev_err(&pdev->dev, "DT: Invalid keymap array\n");
+		return -ENODEV;
+	}
+
+	if (of_property_read_bool(np, "autorepeat"))
+		pdata->rep = true;
+
+	if (!of_property_read_u32(np, "mode", &val)) {
+		pdata->mode = val;
+	} else {
+		dev_err(&pdev->dev, "DT: Invalid mode\n");
+		return -ENODEV;
+	}
+
+	return 0;
+}
+#else
+static int __devinit spear_kbd_probe_dt(struct platform_device *pdev)
+{
+	return -ENOSYS;
+}
+#endif
+
 static int __devinit spear_kbd_probe(struct platform_device *pdev)
 {
-	const struct kbd_platform_data *pdata = pdev->dev.platform_data;
+	struct kbd_platform_data *pdata;
+	struct device_node *np = pdev->dev.of_node;
 	const struct matrix_keymap_data *keymap;
 	struct spear_kbd *kbd;
 	struct input_dev *input_dev;
@@ -146,6 +181,23 @@ static int __devinit spear_kbd_probe(struct platform_device *pdev)
 	int irq;
 	int error;
 
+	if (np) {
+		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+		if (!pdata) {
+			dev_err(&pdev->dev, "DT: kzalloc failed\n");
+			return -ENOMEM;
+		}
+
+		pdev->dev.platform_data = pdata;
+		error = spear_kbd_probe_dt(pdev);
+		if (error) {
+			dev_err(&pdev->dev, "DT: no platform data\n");
+			return error;
+		}
+	} else {
+		pdata = dev_get_platdata(&pdev->dev);
+	}
+
 	if (!pdata) {
 		dev_err(&pdev->dev, "Invalid platform data\n");
 		return -EINVAL;
@@ -317,6 +369,14 @@ static int spear_kbd_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(spear_kbd_pm_ops, spear_kbd_suspend, spear_kbd_resume);
 
+#ifdef CONFIG_OF
+static const struct of_device_id spear_kbd_id_table[] = {
+	{ .compatible = "st,spear-kbd" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, spear_kbd_id_table);
+#endif
+
 static struct platform_driver spear_kbd_driver = {
 	.probe		= spear_kbd_probe,
 	.remove		= __devexit_p(spear_kbd_remove),
@@ -324,6 +384,7 @@ static struct platform_driver spear_kbd_driver = {
 		.name	= "keyboard",
 		.owner	= THIS_MODULE,
 		.pm	= &spear_kbd_pm_ops,
+		.of_match_table = of_match_ptr(spear_kbd_id_table),
 	},
 };
 module_platform_driver(spear_kbd_driver);
-- 
1.7.10.rc2.10.gb47606


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

* Re: [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative
  2012-03-26  9:45 [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative Viresh Kumar
  2012-03-26  9:45 ` [PATCH 2/2] Input: spear-keyboard: add device tree bindings Viresh Kumar
@ 2012-03-26 15:26 ` Stephen Warren
  2012-03-26 15:55   ` Dmitry Torokhov
  1 sibling, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2012-03-26 15:26 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: dmitry.torokhov, rajeev-dlh.kumar, devicetree-discuss,
	spear-devel, viresh.linux, linux-input

On 03/26/2012 03:45 AM, Viresh Kumar wrote:
> matrix_keyboard_of_fill_keymap() routines allocates memory using kzalloc()
> routine. It is freed on call to matrix_keyboard_of_free_keymap() routine.
> 
> This patch converts these kzalloc() calls to devm_kzalloc() and thus we don't
> require matrix_keyboard_of_free_keymap() anymore.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@st.com>

The Tegra-related parts,
Acked-by: Stephen Warren <swarren@wwwdotorg.org>

But that said, Dmitry specifically requested that the devm_* function
not be used during initial review of this code; IIRC he preferred just
doing the explicit frees. I can't find a link right now though.

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

* Re: [PATCH 2/2] Input: spear-keyboard: add device tree bindings
  2012-03-26  9:45 ` [PATCH 2/2] Input: spear-keyboard: add device tree bindings Viresh Kumar
@ 2012-03-26 15:30   ` Stephen Warren
       [not found]     ` <4F708B8F.10602-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2012-03-26 15:30 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: dmitry.torokhov, rajeev-dlh.kumar, devicetree-discuss,
	spear-devel, viresh.linux, linux-input

On 03/26/2012 03:45 AM, Viresh Kumar wrote:
> This adds simple DT bindings for spear-keyboard controller.
...
> diff --git a/Documentation/devicetree/bindings/input/spear-keyboard.txt b/Documentation/devicetree/bindings/input/spear-keyboard.txt
...
> +Required properties:
> +- compatible: "st,spear-kbd"

Should "spear" include some version number so that there's a clear path
if/when future SoCs need a different binding?

> +Optional properties, in addition to those specified by the shared
> +matrix-keyboard bindings:
> +- autorepeat: bool: enables key autorepeat
> +- mode: keyboard mode: 0 - 9x9, 1 - 6x6, 2 - 2x2

mode at least should be "st,mode". autorepeat is probably generic enough
that it doesn't need the vendor prefix.

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

* Re: [PATCH 2/2] Input: spear-keyboard: add device tree bindings
       [not found]     ` <4F708B8F.10602-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-03-26 15:35       ` viresh kumar
  0 siblings, 0 replies; 7+ messages in thread
From: viresh kumar @ 2012-03-26 15:35 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Viresh Kumar, dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	spear-devel-nkJGhpqTU55BDgjK7y7TUQ, rajeev-dlh.kumar-qxv4g6HH51o,
	linux-input-u79uwXL29TY76Z2rM5mHXA


[-- Attachment #1.1: Type: text/plain, Size: 483 bytes --]

On Mar 26, 2012 9:00 PM, "Stephen Warren" <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> wrote:
>
> > +- compatible: "st,spear-kbd"
>
> Should "spear" include some version number so that there's a clear path
> if/when future SoCs need a different binding?

Ya. I will name it spear300-kbd.

> > +- mode: keyboard mode: 0 - 9x9, 1 - 6x6, 2 - 2x2
>
> mode at least should be "st,mode". autorepeat is probably generic enough
> that it doesn't need the vendor prefix.

Ok.

--
Viresh

[-- Attachment #1.2: Type: text/html, Size: 711 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

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

* Re: [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative
  2012-03-26 15:26 ` [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative Stephen Warren
@ 2012-03-26 15:55   ` Dmitry Torokhov
  2012-03-27  4:18     ` spear devel
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2012-03-26 15:55 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Viresh Kumar, rajeev-dlh.kumar, devicetree-discuss, spear-devel,
	viresh.linux, linux-input

On Mon, Mar 26, 2012 at 09:26:01AM -0600, Stephen Warren wrote:
> On 03/26/2012 03:45 AM, Viresh Kumar wrote:
> > matrix_keyboard_of_fill_keymap() routines allocates memory using kzalloc()
> > routine. It is freed on call to matrix_keyboard_of_free_keymap() routine.
> > 
> > This patch converts these kzalloc() calls to devm_kzalloc() and thus we don't
> > require matrix_keyboard_of_free_keymap() anymore.
> > 
> > Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
> 
> The Tegra-related parts,
> Acked-by: Stephen Warren <swarren@wwwdotorg.org>
> 
> But that said, Dmitry specifically requested that the devm_* function
> not be used during initial review of this code; IIRC he preferred just
> doing the explicit frees. I can't find a link right now though.

Right, there is no need to haul allocated memory past the building of
the "real" keymap anyway.

Actually I want to change the interface so that we could do something
like:

	if (pdata->keymap) {
		matrix_keypad_build_keymap(...)
	} else {
		error = matrix_keypad_build_of_keymap();
		if (error)
			goto blah;
	}

So that one could override OF data with plaform data if needed and no
freeing of intermediate platform-like keymap structure is requited.
Or maybe encapsulate OF parsing directly into matrix_keypad_build_keymap
if passed keymap data is NULL...

Thanks.

-- 
Dmitry

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

* Re: [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative
  2012-03-26 15:55   ` Dmitry Torokhov
@ 2012-03-27  4:18     ` spear devel
  0 siblings, 0 replies; 7+ messages in thread
From: spear devel @ 2012-03-27  4:18 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Stephen Warren, Viresh Kumar, rajeev-dlh.kumar,
	devicetree-discuss, spear-devel, viresh.linux, linux-input

On 3/26/2012 9:25 PM, Dmitry Torokhov wrote:
> Actually I want to change the interface so that we could do something
> like:
> 
> 	if (pdata->keymap) {
> 		matrix_keypad_build_keymap(...)
> 	} else {
> 		error = matrix_keypad_build_of_keymap();
> 		if (error)
> 			goto blah;
> 	}

I would implement this and send V2.

--
viresh

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

end of thread, other threads:[~2012-03-27  4:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-26  9:45 [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative Viresh Kumar
2012-03-26  9:45 ` [PATCH 2/2] Input: spear-keyboard: add device tree bindings Viresh Kumar
2012-03-26 15:30   ` Stephen Warren
     [not found]     ` <4F708B8F.10602-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-26 15:35       ` viresh kumar
2012-03-26 15:26 ` [PATCH 1/2] input/of_keymap: Convert kzalloc to devm_kzalloc derivative Stephen Warren
2012-03-26 15:55   ` Dmitry Torokhov
2012-03-27  4:18     ` spear devel

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