diff mbox

[4/5] Input: Enable STMPE keypad driver for Device Tree

Message ID 1352900837-20759-5-git-send-email-lee.jones@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Lee Jones Nov. 14, 2012, 1:47 p.m. UTC
This patch allows the STMPE driver to be successfully probed and
initialised when Device Tree support is enabled. Besides the usual
platform data changes, we also separate the process of filling in
the 'in use' pin bitmap, as we have to extract the information from
Device Tree in the DT boot case.

Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/input/keyboard/stmpe-keypad.c |   67 ++++++++++++++++++++++++++++-----
 drivers/mfd/stmpe.c                   |    1 +
 2 files changed, 59 insertions(+), 9 deletions(-)

Comments

Lee Jones Nov. 23, 2012, 3:53 p.m. UTC | #1
On Wed, 14 Nov 2012, Lee Jones wrote:

> This patch allows the STMPE driver to be successfully probed and
> initialised when Device Tree support is enabled. Besides the usual
> platform data changes, we also separate the process of filling in
> the 'in use' pin bitmap, as we have to extract the information from
> Device Tree in the DT boot case.
> 
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: linux-input@vger.kernel.org
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Acked-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/input/keyboard/stmpe-keypad.c |   67 ++++++++++++++++++++++++++++-----
>  drivers/mfd/stmpe.c                   |    1 +
>  2 files changed, 59 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
> index 470a877..4ae01d5 100644
> --- a/drivers/input/keyboard/stmpe-keypad.c
> +++ b/drivers/input/keyboard/stmpe-keypad.c
> @@ -257,19 +257,73 @@ static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
>  			      (plat->debounce_ms << 1));
>  }
>  
> +static int stmpe_keypad_fill_used_pins(struct platform_device *pdev,
> +				struct stmpe_keypad *keypad,
> +				struct stmpe_keypad_platform_data *plat)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	unsigned int proplen;
> +	const __be32 *prop;
> +	int i;
> +
> +	if (np) {
> +		prop = of_get_property(np, "linux,keymap", &proplen);
> +		if (!prop) {
> +			dev_err(&pdev->dev,
> +				"linux,keymap property not defined\n");
> +			return -EINVAL;
> +		}
> +
> +		for (i = 0; i < proplen / sizeof(u32); i++) {
> +			unsigned int key = be32_to_cpup(prop + i);
> +
> +			keypad->cols |= 1 << KEY_COL(key);
> +			keypad->rows |= 1 << KEY_ROW(key);
> +		}
> +	} else {
> +		for (i = 0; i < plat->keymap_data->keymap_size; i++) {
> +			unsigned int key = plat->keymap_data->keymap[i];
> +
> +			keypad->cols |= 1 << KEY_COL(key);
> +			keypad->rows |= 1 << KEY_ROW(key);
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static void __devinit stmpe_keypad_of_probe(struct device_node *np,
> +				struct stmpe_keypad_platform_data *plat)
> +{
> +	of_property_read_u32(np, "debounce-interval", &plat->debounce_ms);
> +	of_property_read_u32(np, "st,scan-count", &plat->scan_count);
> +
> +	if (of_get_property(np, "st,no-autorepeat", NULL))
> +		plat->no_autorepeat = true;
> +}
> +
>  static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
>  {
>  	struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
>  	struct stmpe_keypad_platform_data *plat;
> +	struct device_node *np = pdev->dev.of_node;
>  	struct stmpe_keypad *keypad;
>  	struct input_dev *input;
>  	int ret;
>  	int irq;
> -	int i;
>  
>  	plat = stmpe->pdata->keypad;
> -	if (!plat)
> -		return -ENODEV;
> +	if (!plat) {
> +		if (np) {
> +			plat = devm_kzalloc(&pdev->dev,
> +					sizeof(*plat), GFP_KERNEL);
> +			if (!plat)
> +				return -ENOMEM;
> +
> +			stmpe_keypad_of_probe(np, plat);
> +		} else
> +			return -ENODEV;
> +	}
>  
>  	irq = platform_get_irq(pdev, 0);
>  	if (irq < 0)
> @@ -300,12 +354,7 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
>  	if (!plat->no_autorepeat)
>  		__set_bit(EV_REP, input->evbit);
>  
> -	for (i = 0; i < plat->keymap_data->keymap_size; i++) {
> -		unsigned int key = plat->keymap_data->keymap[i];
> -
> -		keypad->cols |= 1 << KEY_COL(key);
> -		keypad->rows |= 1 << KEY_ROW(key);
> -	}
> +	stmpe_keypad_fill_used_pins(pdev, keypad, plat);
>  
>  	keypad->stmpe = stmpe;
>  	keypad->plat = plat;
> diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
> index ba157d4..b03cc64 100644
> --- a/drivers/mfd/stmpe.c
> +++ b/drivers/mfd/stmpe.c
> @@ -321,6 +321,7 @@ static struct resource stmpe_keypad_resources[] = {
>  
>  static struct mfd_cell stmpe_keypad_cell = {
>  	.name		= "stmpe-keypad",
> +	.of_compatible  = "st,stmpe-keypad",
>  	.resources	= stmpe_keypad_resources,
>  	.num_resources	= ARRAY_SIZE(stmpe_keypad_resources),
>  };
> -- 
> 1.7.9.5
> 

You guessed it, friendly poke for Dmitry.
Lee Jones Jan. 8, 2013, 8:38 a.m. UTC | #2
Dmitry,

> This patch allows the STMPE driver to be successfully probed and
> initialised when Device Tree support is enabled. Besides the usual
> platform data changes, we also separate the process of filling in
> the 'in use' pin bitmap, as we have to extract the information from
> Device Tree in the DT boot case.
> 
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: linux-input@vger.kernel.org
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Acked-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/input/keyboard/stmpe-keypad.c |   67 ++++++++++++++++++++++++++++-----
>  drivers/mfd/stmpe.c                   |    1 +
>  2 files changed, 59 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
> index 470a877..4ae01d5 100644
> --- a/drivers/input/keyboard/stmpe-keypad.c
> +++ b/drivers/input/keyboard/stmpe-keypad.c
> @@ -257,19 +257,73 @@ static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
>  			      (plat->debounce_ms << 1));
>  }
>  
> +static int stmpe_keypad_fill_used_pins(struct platform_device *pdev,
> +				struct stmpe_keypad *keypad,
> +				struct stmpe_keypad_platform_data *plat)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	unsigned int proplen;
> +	const __be32 *prop;
> +	int i;
> +
> +	if (np) {
> +		prop = of_get_property(np, "linux,keymap", &proplen);
> +		if (!prop) {
> +			dev_err(&pdev->dev,
> +				"linux,keymap property not defined\n");
> +			return -EINVAL;
> +		}
> +
> +		for (i = 0; i < proplen / sizeof(u32); i++) {
> +			unsigned int key = be32_to_cpup(prop + i);
> +
> +			keypad->cols |= 1 << KEY_COL(key);
> +			keypad->rows |= 1 << KEY_ROW(key);
> +		}
> +	} else {
> +		for (i = 0; i < plat->keymap_data->keymap_size; i++) {
> +			unsigned int key = plat->keymap_data->keymap[i];
> +
> +			keypad->cols |= 1 << KEY_COL(key);
> +			keypad->rows |= 1 << KEY_ROW(key);
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static void __devinit stmpe_keypad_of_probe(struct device_node *np,
> +				struct stmpe_keypad_platform_data *plat)
> +{
> +	of_property_read_u32(np, "debounce-interval", &plat->debounce_ms);
> +	of_property_read_u32(np, "st,scan-count", &plat->scan_count);
> +
> +	if (of_get_property(np, "st,no-autorepeat", NULL))
> +		plat->no_autorepeat = true;
> +}
> +
>  static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
>  {
>  	struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
>  	struct stmpe_keypad_platform_data *plat;
> +	struct device_node *np = pdev->dev.of_node;
>  	struct stmpe_keypad *keypad;
>  	struct input_dev *input;
>  	int ret;
>  	int irq;
> -	int i;
>  
>  	plat = stmpe->pdata->keypad;
> -	if (!plat)
> -		return -ENODEV;
> +	if (!plat) {
> +		if (np) {
> +			plat = devm_kzalloc(&pdev->dev,
> +					sizeof(*plat), GFP_KERNEL);
> +			if (!plat)
> +				return -ENOMEM;
> +
> +			stmpe_keypad_of_probe(np, plat);
> +		} else
> +			return -ENODEV;
> +	}
>  
>  	irq = platform_get_irq(pdev, 0);
>  	if (irq < 0)
> @@ -300,12 +354,7 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
>  	if (!plat->no_autorepeat)
>  		__set_bit(EV_REP, input->evbit);
>  
> -	for (i = 0; i < plat->keymap_data->keymap_size; i++) {
> -		unsigned int key = plat->keymap_data->keymap[i];
> -
> -		keypad->cols |= 1 << KEY_COL(key);
> -		keypad->rows |= 1 << KEY_ROW(key);
> -	}
> +	stmpe_keypad_fill_used_pins(pdev, keypad, plat);
>  
>  	keypad->stmpe = stmpe;
>  	keypad->plat = plat;
> diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
> index ba157d4..b03cc64 100644
> --- a/drivers/mfd/stmpe.c
> +++ b/drivers/mfd/stmpe.c
> @@ -321,6 +321,7 @@ static struct resource stmpe_keypad_resources[] = {
>  
>  static struct mfd_cell stmpe_keypad_cell = {
>  	.name		= "stmpe-keypad",
> +	.of_compatible  = "st,stmpe-keypad",
>  	.resources	= stmpe_keypad_resources,
>  	.num_resources	= ARRAY_SIZE(stmpe_keypad_resources),
>  };
> -- 
> 1.7.9.5
> 

I'm less than pleased that you _stole_ authorship of this patch!

Especially, as I've been asking you to review it for some time.
Dmitry Torokhov Jan. 8, 2013, 9:26 a.m. UTC | #3
Hi Lee,

On Tue, Jan 08, 2013 at 08:38:03AM +0000, Lee Jones wrote:
> 
> I'm less than pleased that you _stole_ authorship of this patch!
> 
> Especially, as I've been asking you to review it for some time.

My sincere apologies, it was never my intention to claim anyones work as
my own.

It appears that "stg squash" command (I use stacked git to manage my WIP
queue) produces result with authorship changed to the committer and if
you check the thread you will see that I explicitly mentioned that I
folded the device tree binding documentation (that was also authored by
you) into this patch.

Now that I am looking it appears that sysrq keyreset patch by Mathieu
Poirier was also committed as authored by me, and on that patch I aslo
used "stg squash".

OK, I'll now be aware of this behavior and I will rewind my 'next'
branch and correct the authorship on the commits.

Again, I apologize.
Dmitry Torokhov Jan. 8, 2013, 9:30 a.m. UTC | #4
On Tue, Jan 08, 2013 at 01:26:54AM -0800, Dmitry Torokhov wrote:
> Hi Lee,
> 
> On Tue, Jan 08, 2013 at 08:38:03AM +0000, Lee Jones wrote:
> > 
> > I'm less than pleased that you _stole_ authorship of this patch!
> > 
> > Especially, as I've been asking you to review it for some time.
> 
> My sincere apologies, it was never my intention to claim anyones work as
> my own.
> 
> It appears that "stg squash" command (I use stacked git to manage my WIP
> queue) produces result with authorship changed to the committer and if
> you check the thread you will see that I explicitly mentioned that I
> folded the device tree binding documentation (that was also authored by
> you) into this patch.
> 
> Now that I am looking it appears that sysrq keyreset patch by Mathieu
> Poirier was also committed as authored by me, and on that patch I aslo
> used "stg squash".
> 
> OK, I'll now be aware of this behavior and I will rewind my 'next'
> branch and correct the authorship on the commits.

*sigh* It looks like the stmpe patch is already in mainline, so I will
not be able to correct it.

I am very sorry.
Lee Jones Jan. 8, 2013, 9:53 a.m. UTC | #5
On Tue, 08 Jan 2013, Dmitry Torokhov wrote:

> On Tue, Jan 08, 2013 at 01:26:54AM -0800, Dmitry Torokhov wrote:
> > Hi Lee,
> > 
> > On Tue, Jan 08, 2013 at 08:38:03AM +0000, Lee Jones wrote:
> > > 
> > > I'm less than pleased that you _stole_ authorship of this patch!
> > > 
> > > Especially, as I've been asking you to review it for some time.
> > 
> > My sincere apologies, it was never my intention to claim anyones work as
> > my own.
> > 
> > It appears that "stg squash" command (I use stacked git to manage my WIP
> > queue) produces result with authorship changed to the committer and if
> > you check the thread you will see that I explicitly mentioned that I
> > folded the device tree binding documentation (that was also authored by
> > you) into this patch.
> > 
> > Now that I am looking it appears that sysrq keyreset patch by Mathieu
> > Poirier was also committed as authored by me, and on that patch I aslo
> > used "stg squash".
> > 
> > OK, I'll now be aware of this behavior and I will rewind my 'next'
> > branch and correct the authorship on the commits.
> 
> *sigh* It looks like the stmpe patch is already in mainline, so I will
> not be able to correct it.
> 
> I am very sorry.

Okay, as long as it was a genuine mistake, I will bear no grudges.

Apology graciously accepted. :)
diff mbox

Patch

diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
index 470a877..4ae01d5 100644
--- a/drivers/input/keyboard/stmpe-keypad.c
+++ b/drivers/input/keyboard/stmpe-keypad.c
@@ -257,19 +257,73 @@  static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
 			      (plat->debounce_ms << 1));
 }
 
+static int stmpe_keypad_fill_used_pins(struct platform_device *pdev,
+				struct stmpe_keypad *keypad,
+				struct stmpe_keypad_platform_data *plat)
+{
+	struct device_node *np = pdev->dev.of_node;
+	unsigned int proplen;
+	const __be32 *prop;
+	int i;
+
+	if (np) {
+		prop = of_get_property(np, "linux,keymap", &proplen);
+		if (!prop) {
+			dev_err(&pdev->dev,
+				"linux,keymap property not defined\n");
+			return -EINVAL;
+		}
+
+		for (i = 0; i < proplen / sizeof(u32); i++) {
+			unsigned int key = be32_to_cpup(prop + i);
+
+			keypad->cols |= 1 << KEY_COL(key);
+			keypad->rows |= 1 << KEY_ROW(key);
+		}
+	} else {
+		for (i = 0; i < plat->keymap_data->keymap_size; i++) {
+			unsigned int key = plat->keymap_data->keymap[i];
+
+			keypad->cols |= 1 << KEY_COL(key);
+			keypad->rows |= 1 << KEY_ROW(key);
+		}
+	}
+
+	return 0;
+}
+
+static void __devinit stmpe_keypad_of_probe(struct device_node *np,
+				struct stmpe_keypad_platform_data *plat)
+{
+	of_property_read_u32(np, "debounce-interval", &plat->debounce_ms);
+	of_property_read_u32(np, "st,scan-count", &plat->scan_count);
+
+	if (of_get_property(np, "st,no-autorepeat", NULL))
+		plat->no_autorepeat = true;
+}
+
 static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
 {
 	struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
 	struct stmpe_keypad_platform_data *plat;
+	struct device_node *np = pdev->dev.of_node;
 	struct stmpe_keypad *keypad;
 	struct input_dev *input;
 	int ret;
 	int irq;
-	int i;
 
 	plat = stmpe->pdata->keypad;
-	if (!plat)
-		return -ENODEV;
+	if (!plat) {
+		if (np) {
+			plat = devm_kzalloc(&pdev->dev,
+					sizeof(*plat), GFP_KERNEL);
+			if (!plat)
+				return -ENOMEM;
+
+			stmpe_keypad_of_probe(np, plat);
+		} else
+			return -ENODEV;
+	}
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
@@ -300,12 +354,7 @@  static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
 	if (!plat->no_autorepeat)
 		__set_bit(EV_REP, input->evbit);
 
-	for (i = 0; i < plat->keymap_data->keymap_size; i++) {
-		unsigned int key = plat->keymap_data->keymap[i];
-
-		keypad->cols |= 1 << KEY_COL(key);
-		keypad->rows |= 1 << KEY_ROW(key);
-	}
+	stmpe_keypad_fill_used_pins(pdev, keypad, plat);
 
 	keypad->stmpe = stmpe;
 	keypad->plat = plat;
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index ba157d4..b03cc64 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -321,6 +321,7 @@  static struct resource stmpe_keypad_resources[] = {
 
 static struct mfd_cell stmpe_keypad_cell = {
 	.name		= "stmpe-keypad",
+	.of_compatible  = "st,stmpe-keypad",
 	.resources	= stmpe_keypad_resources,
 	.num_resources	= ARRAY_SIZE(stmpe_keypad_resources),
 };