RE: [PATCH 2/2] Input: matrix-keypad - Add device tree support

2012-10-30 Thread AnilKumar, Chimata
Hi Rob,

Thanks for the comments.

On Fri, Oct 19, 2012 at 18:27:21, Rob Herring wrote:
> On 10/19/2012 02:06 AM, AnilKumar Ch wrote:
> > Add device tree support to matrix keypad driver and usage details
> > are added to device tree documentation. Driver was tested on AM335x
> > EVM.
> > 
> > Signed-off-by: AnilKumar Ch 
> > ---
> >  .../devicetree/bindings/input/matrix-keypad.txt|   52 ++
> >  drivers/input/keyboard/matrix_keypad.c |  104 
> > +++-
> >  2 files changed, 155 insertions(+), 1 deletion(-)
> >  create mode 100644 
> > Documentation/devicetree/bindings/input/matrix-keypad.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/input/matrix-keypad.txt 
> > b/Documentation/devicetree/bindings/input/matrix-keypad.txt
> > new file mode 100644
> > index 000..50aaa6e
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/input/matrix-keypad.txt
> > @@ -0,0 +1,52 @@
> > +* GPIO driven matrix keypad device tree bindings
> > +
> > +GPIO driven matrix keypad is used to interface a SoC with a matrix keypad.
> > +The matrix keypad supports multiple row and column lines, a key can be
> > +placed at each intersection of a unique row and a unique column. The matrix
> > +keypad can sense a key-press and key-release by means of GPIO lines and
> > +report the event using GPIO interrupts to the cpu.
> > +
> > +Required Properties:
> > +- compatible:  Should be "matix-keypad"
> 
> How about gpio-matrix-keypad?

More meaningful, changed

> 
> > +- keypad,num-row-gpios:Number of row lines connected to the keypad
> > +   controller.
> > +- keypad,num-col-gpios:Number of column lines connected to the keypad
> > +   controller.
> 
> Isn't the number of gpios just the count of gpios listed below? So you
> don't need these props.

Removed

> 
> > +- row-gpios:   List of gpios used as row lines. The gpio 
> > specifier
> > +   for this property depends on the gpio controller to
> > +   which these row lines are connected.
> > +- col-gpios:   List of gpios used as column lines. The gpio 
> > specifier
> > +   for this property depends on the gpio controller to
> > +   which these column lines are connected.
> > +
> > +Optional Properties:
> > +- linux,no-autorepeat: do no enable autorepeat feature.
> > +- linux,wakeup:use any event on keypad as wakeup event.
> > +- debounce-delay-ms:   debounce interval in milliseconds
> > +- col-scan-delay-us:   delay, measured in microseconds, that is needed
> > +   before we can scan keypad after activating column gpio
> > +- clustered-irq:   have clustered irq number
> > +- clustered-irq-flags: have clustered irq flags
> 
> It's not clear what clustered means here. If I have to go read Linux
> code to understand, you are doing it wrong. Describe the h/w, not Linux
> data structs.

I have added based on pdata of the driver, I am not using these
parameters because AM335x-EVM have different interrupts for all
gpio pins.

clustered-irq: combined irq source for the whole matrix keypad,
like all gpio keys are connected to a gpio expander

> 
> > +
> > +Example:
> > +   matrix-keypad {
> > +   compatible = "matrix-keypad";
> > +   keypad,num-row-gpios = <3>;
> > +   keypad,num-col-gpios = <2>;
> > +   debounce-delay-ms = <5>;
> > +   col-scan-delay-us = <2>;
> > +
> > +   row-gpios = < 25 0
> > + 26 0
> > + 27 0>;
> > +
> > +   col-gpios = < 21 0
> > + 22 0>;
> > +
> > +   linux,keymap = <0x008B
> > +   0x019E
> > +   0x0269
> > +   0x0001006A
> > +   0x0101001C
> > +   0x0201006C>;
> > +   };
> > diff --git a/drivers/input/keyboard/matrix_keypad.c 
> > b/drivers/input/keyboard/matrix_keypad.c
> > index 18b7237..39e480d 100644
> > --- a/drivers/input/keyboard/matrix_keypad.c
> > +++ b/drivers/input/keyboard/matrix_keypad.c
> > @@ -23,6 +23,9 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> >  
> >  struct matrix_keypad {
> > const struct matrix_keypad_platform_data *pdata;
> > @@ -394,6 +397,91 @@ static void matrix_keypad_free_gpio(struct 
> > matrix_keypad *keypad)
> > gpio_free(pdata->col_gpios[i]);
> >  }
> >  
> > +#ifdef CONFIG_OF
> > +static
> > +struct matrix_keypad_platform_data *matrix_keypad_parse_dt(struct device 
> > *dev)
> > +{
> > +   struct matrix_keypad_platform_data *pdata;
> > +   struct matrix_keymap_data *keymap_data;
> > +   struct device_node *np = dev->of_node;
> > +   struct property *prop;
> > +   int key_count = 0, length, row, col;
> > +   uint32_t *keymap;
> > +
> > +   pdata = devm_kzalloc(dev, 

RE: [PATCH 2/2] Input: matrix-keypad - Add device tree support

2012-10-30 Thread AnilKumar, Chimata
Hi Rob,

Thanks for the comments.

On Fri, Oct 19, 2012 at 18:27:21, Rob Herring wrote:
 On 10/19/2012 02:06 AM, AnilKumar Ch wrote:
  Add device tree support to matrix keypad driver and usage details
  are added to device tree documentation. Driver was tested on AM335x
  EVM.
  
  Signed-off-by: AnilKumar Ch anilku...@ti.com
  ---
   .../devicetree/bindings/input/matrix-keypad.txt|   52 ++
   drivers/input/keyboard/matrix_keypad.c |  104 
  +++-
   2 files changed, 155 insertions(+), 1 deletion(-)
   create mode 100644 
  Documentation/devicetree/bindings/input/matrix-keypad.txt
  
  diff --git a/Documentation/devicetree/bindings/input/matrix-keypad.txt 
  b/Documentation/devicetree/bindings/input/matrix-keypad.txt
  new file mode 100644
  index 000..50aaa6e
  --- /dev/null
  +++ b/Documentation/devicetree/bindings/input/matrix-keypad.txt
  @@ -0,0 +1,52 @@
  +* GPIO driven matrix keypad device tree bindings
  +
  +GPIO driven matrix keypad is used to interface a SoC with a matrix keypad.
  +The matrix keypad supports multiple row and column lines, a key can be
  +placed at each intersection of a unique row and a unique column. The matrix
  +keypad can sense a key-press and key-release by means of GPIO lines and
  +report the event using GPIO interrupts to the cpu.
  +
  +Required Properties:
  +- compatible:  Should be matix-keypad
 
 How about gpio-matrix-keypad?

More meaningful, changed

 
  +- keypad,num-row-gpios:Number of row lines connected to the keypad
  +   controller.
  +- keypad,num-col-gpios:Number of column lines connected to the keypad
  +   controller.
 
 Isn't the number of gpios just the count of gpios listed below? So you
 don't need these props.

Removed

 
  +- row-gpios:   List of gpios used as row lines. The gpio 
  specifier
  +   for this property depends on the gpio controller to
  +   which these row lines are connected.
  +- col-gpios:   List of gpios used as column lines. The gpio 
  specifier
  +   for this property depends on the gpio controller to
  +   which these column lines are connected.
  +
  +Optional Properties:
  +- linux,no-autorepeat: do no enable autorepeat feature.
  +- linux,wakeup:use any event on keypad as wakeup event.
  +- debounce-delay-ms:   debounce interval in milliseconds
  +- col-scan-delay-us:   delay, measured in microseconds, that is needed
  +   before we can scan keypad after activating column gpio
  +- clustered-irq:   have clustered irq number
  +- clustered-irq-flags: have clustered irq flags
 
 It's not clear what clustered means here. If I have to go read Linux
 code to understand, you are doing it wrong. Describe the h/w, not Linux
 data structs.

I have added based on pdata of the driver, I am not using these
parameters because AM335x-EVM have different interrupts for all
gpio pins.

clustered-irq: combined irq source for the whole matrix keypad,
like all gpio keys are connected to a gpio expander

 
  +
  +Example:
  +   matrix-keypad {
  +   compatible = matrix-keypad;
  +   keypad,num-row-gpios = 3;
  +   keypad,num-col-gpios = 2;
  +   debounce-delay-ms = 5;
  +   col-scan-delay-us = 2;
  +
  +   row-gpios = gpio2 25 0
  +gpio2 26 0
  +gpio2 27 0;
  +
  +   col-gpios = gpio2 21 0
  +gpio2 22 0;
  +
  +   linux,keymap = 0x008B
  +   0x019E
  +   0x0269
  +   0x0001006A
  +   0x0101001C
  +   0x0201006C;
  +   };
  diff --git a/drivers/input/keyboard/matrix_keypad.c 
  b/drivers/input/keyboard/matrix_keypad.c
  index 18b7237..39e480d 100644
  --- a/drivers/input/keyboard/matrix_keypad.c
  +++ b/drivers/input/keyboard/matrix_keypad.c
  @@ -23,6 +23,9 @@
   #include linux/gpio.h
   #include linux/input/matrix_keypad.h
   #include linux/slab.h
  +#include linux/of.h
  +#include linux/of_gpio.h
  +#include linux/of_platform.h
   
   struct matrix_keypad {
  const struct matrix_keypad_platform_data *pdata;
  @@ -394,6 +397,91 @@ static void matrix_keypad_free_gpio(struct 
  matrix_keypad *keypad)
  gpio_free(pdata-col_gpios[i]);
   }
   
  +#ifdef CONFIG_OF
  +static
  +struct matrix_keypad_platform_data *matrix_keypad_parse_dt(struct device 
  *dev)
  +{
  +   struct matrix_keypad_platform_data *pdata;
  +   struct matrix_keymap_data *keymap_data;
  +   struct device_node *np = dev-of_node;
  +   struct property *prop;
  +   int key_count = 0, length, row, col;
  +   uint32_t *keymap;
  +
  +   pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  +   if (!pdata) {
  +   dev_err(dev, could not allocate memory for platform 

Re: [PATCH 2/2] Input: matrix-keypad - Add device tree support

2012-10-19 Thread Rob Herring
On 10/19/2012 02:06 AM, AnilKumar Ch wrote:
> Add device tree support to matrix keypad driver and usage details
> are added to device tree documentation. Driver was tested on AM335x
> EVM.
> 
> Signed-off-by: AnilKumar Ch 
> ---
>  .../devicetree/bindings/input/matrix-keypad.txt|   52 ++
>  drivers/input/keyboard/matrix_keypad.c |  104 
> +++-
>  2 files changed, 155 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/devicetree/bindings/input/matrix-keypad.txt
> 
> diff --git a/Documentation/devicetree/bindings/input/matrix-keypad.txt 
> b/Documentation/devicetree/bindings/input/matrix-keypad.txt
> new file mode 100644
> index 000..50aaa6e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/matrix-keypad.txt
> @@ -0,0 +1,52 @@
> +* GPIO driven matrix keypad device tree bindings
> +
> +GPIO driven matrix keypad is used to interface a SoC with a matrix keypad.
> +The matrix keypad supports multiple row and column lines, a key can be
> +placed at each intersection of a unique row and a unique column. The matrix
> +keypad can sense a key-press and key-release by means of GPIO lines and
> +report the event using GPIO interrupts to the cpu.
> +
> +Required Properties:
> +- compatible:Should be "matix-keypad"

How about gpio-matrix-keypad?

> +- keypad,num-row-gpios:  Number of row lines connected to the keypad
> + controller.
> +- keypad,num-col-gpios:  Number of column lines connected to the keypad
> + controller.

Isn't the number of gpios just the count of gpios listed below? So you
don't need these props.

> +- row-gpios: List of gpios used as row lines. The gpio specifier
> + for this property depends on the gpio controller to
> + which these row lines are connected.
> +- col-gpios: List of gpios used as column lines. The gpio specifier
> + for this property depends on the gpio controller to
> + which these column lines are connected.
> +
> +Optional Properties:
> +- linux,no-autorepeat:   do no enable autorepeat feature.
> +- linux,wakeup:  use any event on keypad as wakeup event.
> +- debounce-delay-ms: debounce interval in milliseconds
> +- col-scan-delay-us: delay, measured in microseconds, that is needed
> + before we can scan keypad after activating column gpio
> +- clustered-irq: have clustered irq number
> +- clustered-irq-flags:   have clustered irq flags

It's not clear what clustered means here. If I have to go read Linux
code to understand, you are doing it wrong. Describe the h/w, not Linux
data structs.

> +
> +Example:
> + matrix-keypad {
> + compatible = "matrix-keypad";
> + keypad,num-row-gpios = <3>;
> + keypad,num-col-gpios = <2>;
> + debounce-delay-ms = <5>;
> + col-scan-delay-us = <2>;
> +
> + row-gpios = < 25 0
> +   26 0
> +   27 0>;
> +
> + col-gpios = < 21 0
> +   22 0>;
> +
> + linux,keymap = <0x008B
> + 0x019E
> + 0x0269
> + 0x0001006A
> + 0x0101001C
> + 0x0201006C>;
> + };
> diff --git a/drivers/input/keyboard/matrix_keypad.c 
> b/drivers/input/keyboard/matrix_keypad.c
> index 18b7237..39e480d 100644
> --- a/drivers/input/keyboard/matrix_keypad.c
> +++ b/drivers/input/keyboard/matrix_keypad.c
> @@ -23,6 +23,9 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> +#include 
>  
>  struct matrix_keypad {
>   const struct matrix_keypad_platform_data *pdata;
> @@ -394,6 +397,91 @@ static void matrix_keypad_free_gpio(struct matrix_keypad 
> *keypad)
>   gpio_free(pdata->col_gpios[i]);
>  }
>  
> +#ifdef CONFIG_OF
> +static
> +struct matrix_keypad_platform_data *matrix_keypad_parse_dt(struct device 
> *dev)
> +{
> + struct matrix_keypad_platform_data *pdata;
> + struct matrix_keymap_data *keymap_data;
> + struct device_node *np = dev->of_node;
> + struct property *prop;
> + int key_count = 0, length, row, col;
> + uint32_t *keymap;
> +
> + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> + if (!pdata) {
> + dev_err(dev, "could not allocate memory for platform data\n");
> + return NULL;
> + }
> +
> + of_property_read_u32(np, "keypad,num-row-gpios", >num_row_gpios);
> + of_property_read_u32(np, "keypad,num-col-gpios", >num_col_gpios);
> + if (!pdata->num_row_gpios || !pdata->num_col_gpios) {
> + dev_err(dev, "number of keypad rows/columns not specified\n");
> + return NULL;
> + }
> +
> + keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
> 

[PATCH 2/2] Input: matrix-keypad - Add device tree support

2012-10-19 Thread AnilKumar Ch
Add device tree support to matrix keypad driver and usage details
are added to device tree documentation. Driver was tested on AM335x
EVM.

Signed-off-by: AnilKumar Ch 
---
 .../devicetree/bindings/input/matrix-keypad.txt|   52 ++
 drivers/input/keyboard/matrix_keypad.c |  104 +++-
 2 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/input/matrix-keypad.txt

diff --git a/Documentation/devicetree/bindings/input/matrix-keypad.txt 
b/Documentation/devicetree/bindings/input/matrix-keypad.txt
new file mode 100644
index 000..50aaa6e
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/matrix-keypad.txt
@@ -0,0 +1,52 @@
+* GPIO driven matrix keypad device tree bindings
+
+GPIO driven matrix keypad is used to interface a SoC with a matrix keypad.
+The matrix keypad supports multiple row and column lines, a key can be
+placed at each intersection of a unique row and a unique column. The matrix
+keypad can sense a key-press and key-release by means of GPIO lines and
+report the event using GPIO interrupts to the cpu.
+
+Required Properties:
+- compatible:  Should be "matix-keypad"
+- keypad,num-row-gpios:Number of row lines connected to the keypad
+   controller.
+- keypad,num-col-gpios:Number of column lines connected to the keypad
+   controller.
+- row-gpios:   List of gpios used as row lines. The gpio specifier
+   for this property depends on the gpio controller to
+   which these row lines are connected.
+- col-gpios:   List of gpios used as column lines. The gpio specifier
+   for this property depends on the gpio controller to
+   which these column lines are connected.
+
+Optional Properties:
+- linux,no-autorepeat: do no enable autorepeat feature.
+- linux,wakeup:use any event on keypad as wakeup event.
+- debounce-delay-ms:   debounce interval in milliseconds
+- col-scan-delay-us:   delay, measured in microseconds, that is needed
+   before we can scan keypad after activating column gpio
+- clustered-irq:   have clustered irq number
+- clustered-irq-flags: have clustered irq flags
+
+Example:
+   matrix-keypad {
+   compatible = "matrix-keypad";
+   keypad,num-row-gpios = <3>;
+   keypad,num-col-gpios = <2>;
+   debounce-delay-ms = <5>;
+   col-scan-delay-us = <2>;
+
+   row-gpios = < 25 0
+ 26 0
+ 27 0>;
+
+   col-gpios = < 21 0
+ 22 0>;
+
+   linux,keymap = <0x008B
+   0x019E
+   0x0269
+   0x0001006A
+   0x0101001C
+   0x0201006C>;
+   };
diff --git a/drivers/input/keyboard/matrix_keypad.c 
b/drivers/input/keyboard/matrix_keypad.c
index 18b7237..39e480d 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -23,6 +23,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 struct matrix_keypad {
const struct matrix_keypad_platform_data *pdata;
@@ -394,6 +397,91 @@ static void matrix_keypad_free_gpio(struct matrix_keypad 
*keypad)
gpio_free(pdata->col_gpios[i]);
 }
 
+#ifdef CONFIG_OF
+static
+struct matrix_keypad_platform_data *matrix_keypad_parse_dt(struct device *dev)
+{
+   struct matrix_keypad_platform_data *pdata;
+   struct matrix_keymap_data *keymap_data;
+   struct device_node *np = dev->of_node;
+   struct property *prop;
+   int key_count = 0, length, row, col;
+   uint32_t *keymap;
+
+   pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   dev_err(dev, "could not allocate memory for platform data\n");
+   return NULL;
+   }
+
+   of_property_read_u32(np, "keypad,num-row-gpios", >num_row_gpios);
+   of_property_read_u32(np, "keypad,num-col-gpios", >num_col_gpios);
+   if (!pdata->num_row_gpios || !pdata->num_col_gpios) {
+   dev_err(dev, "number of keypad rows/columns not specified\n");
+   return NULL;
+   }
+
+   keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
+   if (!keymap_data) {
+   dev_err(dev, "could not allocate memory for keymap data\n");
+   return NULL;
+   }
+   pdata->keymap_data = keymap_data;
+
+   prop = of_find_property(np, "linux,keymap", );
+   if (!prop)
+   return NULL;
+
+   key_count = length / sizeof(u32);
+   keymap_data->keymap_size = key_count;
+   keymap = devm_kzalloc(dev, sizeof(uint32_t) * key_count, GFP_KERNEL);
+   if (!keymap) 

[PATCH 2/2] Input: matrix-keypad - Add device tree support

2012-10-19 Thread AnilKumar Ch
Add device tree support to matrix keypad driver and usage details
are added to device tree documentation. Driver was tested on AM335x
EVM.

Signed-off-by: AnilKumar Ch anilku...@ti.com
---
 .../devicetree/bindings/input/matrix-keypad.txt|   52 ++
 drivers/input/keyboard/matrix_keypad.c |  104 +++-
 2 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/input/matrix-keypad.txt

diff --git a/Documentation/devicetree/bindings/input/matrix-keypad.txt 
b/Documentation/devicetree/bindings/input/matrix-keypad.txt
new file mode 100644
index 000..50aaa6e
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/matrix-keypad.txt
@@ -0,0 +1,52 @@
+* GPIO driven matrix keypad device tree bindings
+
+GPIO driven matrix keypad is used to interface a SoC with a matrix keypad.
+The matrix keypad supports multiple row and column lines, a key can be
+placed at each intersection of a unique row and a unique column. The matrix
+keypad can sense a key-press and key-release by means of GPIO lines and
+report the event using GPIO interrupts to the cpu.
+
+Required Properties:
+- compatible:  Should be matix-keypad
+- keypad,num-row-gpios:Number of row lines connected to the keypad
+   controller.
+- keypad,num-col-gpios:Number of column lines connected to the keypad
+   controller.
+- row-gpios:   List of gpios used as row lines. The gpio specifier
+   for this property depends on the gpio controller to
+   which these row lines are connected.
+- col-gpios:   List of gpios used as column lines. The gpio specifier
+   for this property depends on the gpio controller to
+   which these column lines are connected.
+
+Optional Properties:
+- linux,no-autorepeat: do no enable autorepeat feature.
+- linux,wakeup:use any event on keypad as wakeup event.
+- debounce-delay-ms:   debounce interval in milliseconds
+- col-scan-delay-us:   delay, measured in microseconds, that is needed
+   before we can scan keypad after activating column gpio
+- clustered-irq:   have clustered irq number
+- clustered-irq-flags: have clustered irq flags
+
+Example:
+   matrix-keypad {
+   compatible = matrix-keypad;
+   keypad,num-row-gpios = 3;
+   keypad,num-col-gpios = 2;
+   debounce-delay-ms = 5;
+   col-scan-delay-us = 2;
+
+   row-gpios = gpio2 25 0
+gpio2 26 0
+gpio2 27 0;
+
+   col-gpios = gpio2 21 0
+gpio2 22 0;
+
+   linux,keymap = 0x008B
+   0x019E
+   0x0269
+   0x0001006A
+   0x0101001C
+   0x0201006C;
+   };
diff --git a/drivers/input/keyboard/matrix_keypad.c 
b/drivers/input/keyboard/matrix_keypad.c
index 18b7237..39e480d 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -23,6 +23,9 @@
 #include linux/gpio.h
 #include linux/input/matrix_keypad.h
 #include linux/slab.h
+#include linux/of.h
+#include linux/of_gpio.h
+#include linux/of_platform.h
 
 struct matrix_keypad {
const struct matrix_keypad_platform_data *pdata;
@@ -394,6 +397,91 @@ static void matrix_keypad_free_gpio(struct matrix_keypad 
*keypad)
gpio_free(pdata-col_gpios[i]);
 }
 
+#ifdef CONFIG_OF
+static
+struct matrix_keypad_platform_data *matrix_keypad_parse_dt(struct device *dev)
+{
+   struct matrix_keypad_platform_data *pdata;
+   struct matrix_keymap_data *keymap_data;
+   struct device_node *np = dev-of_node;
+   struct property *prop;
+   int key_count = 0, length, row, col;
+   uint32_t *keymap;
+
+   pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   dev_err(dev, could not allocate memory for platform data\n);
+   return NULL;
+   }
+
+   of_property_read_u32(np, keypad,num-row-gpios, pdata-num_row_gpios);
+   of_property_read_u32(np, keypad,num-col-gpios, pdata-num_col_gpios);
+   if (!pdata-num_row_gpios || !pdata-num_col_gpios) {
+   dev_err(dev, number of keypad rows/columns not specified\n);
+   return NULL;
+   }
+
+   keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
+   if (!keymap_data) {
+   dev_err(dev, could not allocate memory for keymap data\n);
+   return NULL;
+   }
+   pdata-keymap_data = keymap_data;
+
+   prop = of_find_property(np, linux,keymap, length);
+   if (!prop)
+   return NULL;
+
+   key_count = length / sizeof(u32);
+   

Re: [PATCH 2/2] Input: matrix-keypad - Add device tree support

2012-10-19 Thread Rob Herring
On 10/19/2012 02:06 AM, AnilKumar Ch wrote:
 Add device tree support to matrix keypad driver and usage details
 are added to device tree documentation. Driver was tested on AM335x
 EVM.
 
 Signed-off-by: AnilKumar Ch anilku...@ti.com
 ---
  .../devicetree/bindings/input/matrix-keypad.txt|   52 ++
  drivers/input/keyboard/matrix_keypad.c |  104 
 +++-
  2 files changed, 155 insertions(+), 1 deletion(-)
  create mode 100644 Documentation/devicetree/bindings/input/matrix-keypad.txt
 
 diff --git a/Documentation/devicetree/bindings/input/matrix-keypad.txt 
 b/Documentation/devicetree/bindings/input/matrix-keypad.txt
 new file mode 100644
 index 000..50aaa6e
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/input/matrix-keypad.txt
 @@ -0,0 +1,52 @@
 +* GPIO driven matrix keypad device tree bindings
 +
 +GPIO driven matrix keypad is used to interface a SoC with a matrix keypad.
 +The matrix keypad supports multiple row and column lines, a key can be
 +placed at each intersection of a unique row and a unique column. The matrix
 +keypad can sense a key-press and key-release by means of GPIO lines and
 +report the event using GPIO interrupts to the cpu.
 +
 +Required Properties:
 +- compatible:Should be matix-keypad

How about gpio-matrix-keypad?

 +- keypad,num-row-gpios:  Number of row lines connected to the keypad
 + controller.
 +- keypad,num-col-gpios:  Number of column lines connected to the keypad
 + controller.

Isn't the number of gpios just the count of gpios listed below? So you
don't need these props.

 +- row-gpios: List of gpios used as row lines. The gpio specifier
 + for this property depends on the gpio controller to
 + which these row lines are connected.
 +- col-gpios: List of gpios used as column lines. The gpio specifier
 + for this property depends on the gpio controller to
 + which these column lines are connected.
 +
 +Optional Properties:
 +- linux,no-autorepeat:   do no enable autorepeat feature.
 +- linux,wakeup:  use any event on keypad as wakeup event.
 +- debounce-delay-ms: debounce interval in milliseconds
 +- col-scan-delay-us: delay, measured in microseconds, that is needed
 + before we can scan keypad after activating column gpio
 +- clustered-irq: have clustered irq number
 +- clustered-irq-flags:   have clustered irq flags

It's not clear what clustered means here. If I have to go read Linux
code to understand, you are doing it wrong. Describe the h/w, not Linux
data structs.

 +
 +Example:
 + matrix-keypad {
 + compatible = matrix-keypad;
 + keypad,num-row-gpios = 3;
 + keypad,num-col-gpios = 2;
 + debounce-delay-ms = 5;
 + col-scan-delay-us = 2;
 +
 + row-gpios = gpio2 25 0
 +  gpio2 26 0
 +  gpio2 27 0;
 +
 + col-gpios = gpio2 21 0
 +  gpio2 22 0;
 +
 + linux,keymap = 0x008B
 + 0x019E
 + 0x0269
 + 0x0001006A
 + 0x0101001C
 + 0x0201006C;
 + };
 diff --git a/drivers/input/keyboard/matrix_keypad.c 
 b/drivers/input/keyboard/matrix_keypad.c
 index 18b7237..39e480d 100644
 --- a/drivers/input/keyboard/matrix_keypad.c
 +++ b/drivers/input/keyboard/matrix_keypad.c
 @@ -23,6 +23,9 @@
  #include linux/gpio.h
  #include linux/input/matrix_keypad.h
  #include linux/slab.h
 +#include linux/of.h
 +#include linux/of_gpio.h
 +#include linux/of_platform.h
  
  struct matrix_keypad {
   const struct matrix_keypad_platform_data *pdata;
 @@ -394,6 +397,91 @@ static void matrix_keypad_free_gpio(struct matrix_keypad 
 *keypad)
   gpio_free(pdata-col_gpios[i]);
  }
  
 +#ifdef CONFIG_OF
 +static
 +struct matrix_keypad_platform_data *matrix_keypad_parse_dt(struct device 
 *dev)
 +{
 + struct matrix_keypad_platform_data *pdata;
 + struct matrix_keymap_data *keymap_data;
 + struct device_node *np = dev-of_node;
 + struct property *prop;
 + int key_count = 0, length, row, col;
 + uint32_t *keymap;
 +
 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
 + if (!pdata) {
 + dev_err(dev, could not allocate memory for platform data\n);
 + return NULL;
 + }
 +
 + of_property_read_u32(np, keypad,num-row-gpios, pdata-num_row_gpios);
 + of_property_read_u32(np, keypad,num-col-gpios, pdata-num_col_gpios);
 + if (!pdata-num_row_gpios || !pdata-num_col_gpios) {
 + dev_err(dev, number of keypad rows/columns not specified\n);
 + return NULL;
 + }
 +
 + keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
 +