2019-05-27 13:55:05 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-09-01 07:05:27 +07:00
|
|
|
/*
|
|
|
|
* OMAP4 Keypad Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Texas Instruments
|
|
|
|
*
|
|
|
|
* Author: Abraham Arce <x0066660@ti.com>
|
|
|
|
* Initial Code: Syed Rafiuddin <rafiuddin.syed@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/io.h>
|
2012-07-13 14:10:47 +07:00
|
|
|
#include <linux/of.h>
|
2010-09-01 07:05:27 +07:00
|
|
|
#include <linux/input.h>
|
2014-05-29 14:30:02 +07:00
|
|
|
#include <linux/input/matrix_keypad.h>
|
2010-09-01 07:05:27 +07:00
|
|
|
#include <linux/slab.h>
|
2011-02-23 13:25:59 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
2010-09-01 07:05:27 +07:00
|
|
|
|
|
|
|
/* OMAP4 registers */
|
|
|
|
#define OMAP4_KBD_REVISION 0x00
|
|
|
|
#define OMAP4_KBD_SYSCONFIG 0x10
|
|
|
|
#define OMAP4_KBD_SYSSTATUS 0x14
|
|
|
|
#define OMAP4_KBD_IRQSTATUS 0x18
|
|
|
|
#define OMAP4_KBD_IRQENABLE 0x1C
|
|
|
|
#define OMAP4_KBD_WAKEUPENABLE 0x20
|
|
|
|
#define OMAP4_KBD_PENDING 0x24
|
|
|
|
#define OMAP4_KBD_CTRL 0x28
|
|
|
|
#define OMAP4_KBD_DEBOUNCINGTIME 0x2C
|
|
|
|
#define OMAP4_KBD_LONGKEYTIME 0x30
|
|
|
|
#define OMAP4_KBD_TIMEOUT 0x34
|
|
|
|
#define OMAP4_KBD_STATEMACHINE 0x38
|
|
|
|
#define OMAP4_KBD_ROWINPUTS 0x3C
|
|
|
|
#define OMAP4_KBD_COLUMNOUTPUTS 0x40
|
|
|
|
#define OMAP4_KBD_FULLCODE31_0 0x44
|
|
|
|
#define OMAP4_KBD_FULLCODE63_32 0x48
|
|
|
|
|
|
|
|
/* OMAP4 bit definitions */
|
2013-08-26 13:25:18 +07:00
|
|
|
#define OMAP4_DEF_IRQENABLE_EVENTEN BIT(0)
|
|
|
|
#define OMAP4_DEF_IRQENABLE_LONGKEY BIT(1)
|
|
|
|
#define OMAP4_DEF_WUP_EVENT_ENA BIT(0)
|
|
|
|
#define OMAP4_DEF_WUP_LONG_KEY_ENA BIT(1)
|
|
|
|
#define OMAP4_DEF_CTRL_NOSOFTMODE BIT(1)
|
|
|
|
#define OMAP4_DEF_CTRL_PTV_SHIFT 2
|
2010-09-01 07:05:27 +07:00
|
|
|
|
|
|
|
/* OMAP4 values */
|
2013-08-26 13:25:18 +07:00
|
|
|
#define OMAP4_VAL_IRQDISABLE 0x0
|
2018-12-04 02:24:30 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Errata i689: If a key is released for a time shorter than debounce time,
|
|
|
|
* the keyboard will idle and never detect the key release. The workaround
|
|
|
|
* is to use at least a 12ms debounce time. See omap5432 TRM chapter
|
|
|
|
* "26.4.6.2 Keyboard Controller Timer" for more information.
|
|
|
|
*/
|
|
|
|
#define OMAP4_KEYPAD_PTV_DIV_128 0x6
|
|
|
|
#define OMAP4_KEYPAD_DEBOUNCINGTIME_MS(dbms, ptv) \
|
|
|
|
((((dbms) * 1000) / ((1 << ((ptv) + 1)) * (1000000 / 32768))) - 1)
|
|
|
|
#define OMAP4_VAL_DEBOUNCINGTIME_16MS \
|
|
|
|
OMAP4_KEYPAD_DEBOUNCINGTIME_MS(16, OMAP4_KEYPAD_PTV_DIV_128)
|
2010-09-01 07:05:27 +07:00
|
|
|
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
enum {
|
|
|
|
KBD_REVISION_OMAP4 = 0,
|
|
|
|
KBD_REVISION_OMAP5,
|
|
|
|
};
|
|
|
|
|
2010-09-01 07:05:27 +07:00
|
|
|
struct omap4_keypad {
|
|
|
|
struct input_dev *input;
|
|
|
|
|
|
|
|
void __iomem *base;
|
2013-08-26 13:29:30 +07:00
|
|
|
bool irq_wake_enabled;
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
unsigned int irq;
|
2010-09-01 07:05:27 +07:00
|
|
|
|
|
|
|
unsigned int rows;
|
|
|
|
unsigned int cols;
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
u32 reg_offset;
|
|
|
|
u32 irqreg_offset;
|
2010-09-01 07:05:27 +07:00
|
|
|
unsigned int row_shift;
|
2012-07-13 14:10:47 +07:00
|
|
|
bool no_autorepeat;
|
2010-09-01 07:05:27 +07:00
|
|
|
unsigned char key_state[8];
|
2012-07-13 14:10:47 +07:00
|
|
|
unsigned short *keymap;
|
2010-09-01 07:05:27 +07:00
|
|
|
};
|
|
|
|
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
|
|
|
|
{
|
|
|
|
return __raw_readl(keypad_data->base +
|
|
|
|
keypad_data->reg_offset + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
|
|
|
|
{
|
|
|
|
__raw_writel(value,
|
|
|
|
keypad_data->base + keypad_data->reg_offset + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
|
|
|
|
{
|
|
|
|
return __raw_readl(keypad_data->base +
|
|
|
|
keypad_data->irqreg_offset + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
|
|
|
|
u32 offset, u32 value)
|
|
|
|
{
|
|
|
|
__raw_writel(value,
|
|
|
|
keypad_data->base + keypad_data->irqreg_offset + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-26 13:25:50 +07:00
|
|
|
/* Interrupt handlers */
|
|
|
|
static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct omap4_keypad *keypad_data = dev_id;
|
|
|
|
|
2018-12-05 04:52:49 +07:00
|
|
|
if (kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS))
|
2013-08-26 13:25:50 +07:00
|
|
|
return IRQ_WAKE_THREAD;
|
|
|
|
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
|
2010-09-01 07:05:27 +07:00
|
|
|
{
|
|
|
|
struct omap4_keypad *keypad_data = dev_id;
|
|
|
|
struct input_dev *input_dev = keypad_data->input;
|
|
|
|
unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)];
|
|
|
|
unsigned int col, row, code, changed;
|
|
|
|
u32 *new_state = (u32 *) key_state;
|
|
|
|
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
*new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
|
|
|
|
*(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
|
2010-09-01 07:05:27 +07:00
|
|
|
|
|
|
|
for (row = 0; row < keypad_data->rows; row++) {
|
|
|
|
changed = key_state[row] ^ keypad_data->key_state[row];
|
|
|
|
if (!changed)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (col = 0; col < keypad_data->cols; col++) {
|
|
|
|
if (changed & (1 << col)) {
|
|
|
|
code = MATRIX_SCAN_CODE(row, col,
|
|
|
|
keypad_data->row_shift);
|
|
|
|
input_event(input_dev, EV_MSC, MSC_SCAN, code);
|
|
|
|
input_report_key(input_dev,
|
|
|
|
keypad_data->keymap[code],
|
|
|
|
key_state[row] & (1 << col));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input_sync(input_dev);
|
|
|
|
|
|
|
|
memcpy(keypad_data->key_state, key_state,
|
|
|
|
sizeof(keypad_data->key_state));
|
|
|
|
|
|
|
|
/* clear pending interrupts */
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
|
|
|
|
kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
|
2010-09-01 07:05:27 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2011-02-23 13:25:59 +07:00
|
|
|
static int omap4_keypad_open(struct input_dev *input)
|
|
|
|
{
|
|
|
|
struct omap4_keypad *keypad_data = input_get_drvdata(input);
|
|
|
|
|
|
|
|
pm_runtime_get_sync(input->dev.parent);
|
|
|
|
|
|
|
|
disable_irq(keypad_data->irq);
|
|
|
|
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
kbd_writel(keypad_data, OMAP4_KBD_CTRL,
|
2013-08-26 13:25:18 +07:00
|
|
|
OMAP4_DEF_CTRL_NOSOFTMODE |
|
2018-12-04 02:24:30 +07:00
|
|
|
(OMAP4_KEYPAD_PTV_DIV_128 << OMAP4_DEF_CTRL_PTV_SHIFT));
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
|
2018-12-04 02:24:30 +07:00
|
|
|
OMAP4_VAL_DEBOUNCINGTIME_16MS);
|
2013-08-26 13:26:16 +07:00
|
|
|
/* clear pending interrupts */
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
|
2013-08-26 13:26:16 +07:00
|
|
|
kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
|
|
|
|
OMAP4_DEF_IRQENABLE_EVENTEN |
|
|
|
|
OMAP4_DEF_IRQENABLE_LONGKEY);
|
|
|
|
kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
|
|
|
|
OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
|
2011-02-23 13:25:59 +07:00
|
|
|
|
|
|
|
enable_irq(keypad_data->irq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap4_keypad_close(struct input_dev *input)
|
|
|
|
{
|
|
|
|
struct omap4_keypad *keypad_data = input_get_drvdata(input);
|
|
|
|
|
|
|
|
disable_irq(keypad_data->irq);
|
|
|
|
|
2018-12-05 04:52:49 +07:00
|
|
|
/* Disable interrupts and wake-up events */
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
|
|
|
|
OMAP4_VAL_IRQDISABLE);
|
2018-12-05 04:52:49 +07:00
|
|
|
kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE, 0);
|
2011-02-23 13:25:59 +07:00
|
|
|
|
|
|
|
/* clear pending interrupts */
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
|
|
|
|
kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
|
2011-02-23 13:25:59 +07:00
|
|
|
|
|
|
|
enable_irq(keypad_data->irq);
|
|
|
|
|
|
|
|
pm_runtime_put_sync(input->dev.parent);
|
|
|
|
}
|
|
|
|
|
2012-11-24 12:38:25 +07:00
|
|
|
static int omap4_keypad_parse_dt(struct device *dev,
|
|
|
|
struct omap4_keypad *keypad_data)
|
2012-07-13 14:10:47 +07:00
|
|
|
{
|
|
|
|
struct device_node *np = dev->of_node;
|
2013-02-26 05:08:40 +07:00
|
|
|
int err;
|
2012-07-13 14:10:47 +07:00
|
|
|
|
2016-11-12 03:43:12 +07:00
|
|
|
err = matrix_keypad_parse_properties(dev, &keypad_data->rows,
|
|
|
|
&keypad_data->cols);
|
2013-02-26 05:08:40 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
2012-07-13 14:10:47 +07:00
|
|
|
|
|
|
|
if (of_get_property(np, "linux,input-no-autorepeat", NULL))
|
|
|
|
keypad_data->no_autorepeat = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-24 12:38:25 +07:00
|
|
|
static int omap4_keypad_probe(struct platform_device *pdev)
|
2010-09-01 07:05:27 +07:00
|
|
|
{
|
|
|
|
struct omap4_keypad *keypad_data;
|
|
|
|
struct input_dev *input_dev;
|
2010-09-30 13:35:57 +07:00
|
|
|
struct resource *res;
|
2012-07-13 14:10:47 +07:00
|
|
|
unsigned int max_keys;
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
int rev;
|
2010-09-30 13:35:57 +07:00
|
|
|
int irq;
|
2010-09-01 07:05:27 +07:00
|
|
|
int error;
|
|
|
|
|
2010-09-30 13:35:57 +07:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res) {
|
2010-09-01 07:05:27 +07:00
|
|
|
dev_err(&pdev->dev, "no base address specified\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-09-30 13:35:57 +07:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (!irq) {
|
2010-09-01 07:05:27 +07:00
|
|
|
dev_err(&pdev->dev, "no keyboard irq assigned\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:10:47 +07:00
|
|
|
keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
|
2010-09-01 07:05:27 +07:00
|
|
|
if (!keypad_data) {
|
|
|
|
dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:10:47 +07:00
|
|
|
keypad_data->irq = irq;
|
|
|
|
|
2014-05-29 14:30:02 +07:00
|
|
|
error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
|
|
|
|
if (error)
|
2015-09-29 05:59:22 +07:00
|
|
|
goto err_free_keypad;
|
2010-09-30 13:35:57 +07:00
|
|
|
|
2012-07-13 14:10:47 +07:00
|
|
|
res = request_mem_region(res->start, resource_size(res), pdev->name);
|
2010-09-30 13:35:57 +07:00
|
|
|
if (!res) {
|
|
|
|
dev_err(&pdev->dev, "can't request mem region\n");
|
|
|
|
error = -EBUSY;
|
|
|
|
goto err_free_keypad;
|
|
|
|
}
|
2010-09-01 07:05:27 +07:00
|
|
|
|
2010-09-30 13:35:57 +07:00
|
|
|
keypad_data->base = ioremap(res->start, resource_size(res));
|
|
|
|
if (!keypad_data->base) {
|
|
|
|
dev_err(&pdev->dev, "can't ioremap mem resource\n");
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto err_release_mem;
|
|
|
|
}
|
|
|
|
|
2010-09-01 07:05:27 +07:00
|
|
|
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
/*
|
2012-07-13 14:10:47 +07:00
|
|
|
* Enable clocks for the keypad module so that we can read
|
|
|
|
* revision register.
|
|
|
|
*/
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
error = pm_runtime_get_sync(&pdev->dev);
|
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
|
|
|
|
goto err_unmap;
|
|
|
|
}
|
|
|
|
rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
|
|
|
|
rev &= 0x03 << 30;
|
|
|
|
rev >>= 30;
|
|
|
|
switch (rev) {
|
|
|
|
case KBD_REVISION_OMAP4:
|
|
|
|
keypad_data->reg_offset = 0x00;
|
|
|
|
keypad_data->irqreg_offset = 0x00;
|
|
|
|
break;
|
|
|
|
case KBD_REVISION_OMAP5:
|
|
|
|
keypad_data->reg_offset = 0x10;
|
|
|
|
keypad_data->irqreg_offset = 0x0c;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"Keypad reports unsupported revision %d", rev);
|
|
|
|
error = -EINVAL;
|
|
|
|
goto err_pm_put_sync;
|
|
|
|
}
|
|
|
|
|
2010-09-01 07:05:27 +07:00
|
|
|
/* input device allocation */
|
|
|
|
keypad_data->input = input_dev = input_allocate_device();
|
|
|
|
if (!input_dev) {
|
|
|
|
error = -ENOMEM;
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
goto err_pm_put_sync;
|
2010-09-01 07:05:27 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
input_dev->name = pdev->name;
|
|
|
|
input_dev->dev.parent = &pdev->dev;
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
|
|
|
input_dev->id.vendor = 0x0001;
|
|
|
|
input_dev->id.product = 0x0001;
|
|
|
|
input_dev->id.version = 0x0001;
|
|
|
|
|
2011-02-23 13:25:59 +07:00
|
|
|
input_dev->open = omap4_keypad_open;
|
|
|
|
input_dev->close = omap4_keypad_close;
|
|
|
|
|
2012-07-13 14:10:47 +07:00
|
|
|
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
|
|
|
|
if (!keypad_data->no_autorepeat)
|
|
|
|
__set_bit(EV_REP, input_dev->evbit);
|
|
|
|
|
|
|
|
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;
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:03:40 +07:00
|
|
|
keypad_data->keymap = kcalloc(max_keys,
|
|
|
|
sizeof(keypad_data->keymap[0]),
|
2012-07-13 14:10:47 +07:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!keypad_data->keymap) {
|
|
|
|
dev_err(&pdev->dev, "Not enough memory for keymap\n");
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto err_free_input;
|
|
|
|
}
|
|
|
|
|
2014-05-29 14:30:02 +07:00
|
|
|
error = matrix_keypad_build_keymap(NULL, NULL,
|
2012-07-13 14:10:47 +07:00
|
|
|
keypad_data->rows, keypad_data->cols,
|
2012-05-11 12:37:08 +07:00
|
|
|
keypad_data->keymap, input_dev);
|
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "failed to build keymap\n");
|
2012-07-13 14:10:47 +07:00
|
|
|
goto err_free_keymap;
|
2012-05-11 12:37:08 +07:00
|
|
|
}
|
2010-09-01 07:05:27 +07:00
|
|
|
|
2013-08-26 13:25:50 +07:00
|
|
|
error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler,
|
2018-12-05 04:52:49 +07:00
|
|
|
omap4_keypad_irq_thread_fn, IRQF_ONESHOT,
|
2013-08-26 13:25:50 +07:00
|
|
|
"omap4-keypad", keypad_data);
|
2010-09-01 07:05:27 +07:00
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "failed to register interrupt\n");
|
2017-04-11 10:48:16 +07:00
|
|
|
goto err_free_keymap;
|
2010-09-01 07:05:27 +07:00
|
|
|
}
|
|
|
|
|
2013-08-26 13:29:30 +07:00
|
|
|
device_init_wakeup(&pdev->dev, true);
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
pm_runtime_put_sync(&pdev->dev);
|
2011-02-23 13:25:59 +07:00
|
|
|
|
2010-09-01 07:05:27 +07:00
|
|
|
error = input_register_device(keypad_data->input);
|
|
|
|
if (error < 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to register input device\n");
|
2011-02-23 13:25:59 +07:00
|
|
|
goto err_pm_disable;
|
2010-09-01 07:05:27 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, keypad_data);
|
|
|
|
return 0;
|
|
|
|
|
2011-02-23 13:25:59 +07:00
|
|
|
err_pm_disable:
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
2010-09-01 07:05:27 +07:00
|
|
|
free_irq(keypad_data->irq, keypad_data);
|
2012-07-13 14:10:47 +07:00
|
|
|
err_free_keymap:
|
|
|
|
kfree(keypad_data->keymap);
|
2010-09-01 07:05:27 +07:00
|
|
|
err_free_input:
|
|
|
|
input_free_device(input_dev);
|
Input: omap-keypad - dynamically handle register offsets
Hi Dmitry,
On Wed, May 9, 2012 at 3:14 PM, Poddar, Sourav <sourav.poddar@ti.com> wrote:
> Hi Dmitry,
>
> I did some minor fixes to the patch which you suggested above and
> the keypad is functional now.
>
> Changes:
> - Move "pm_runtime_enable" before using "pm_runtime_get_sync".
>
> Sending the patch inlined..(also attached).
>
> From: G, Manjunath Kondaiah <manjugk@ti.com>
> Date: Mon, 10 Oct 2011 20:52:05 +0530
> Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
>
> Keypad controller register offsets are different for omap4
> and omap5. Handle these offsets through static mapping and
> assign these mappings during run time.
>
> Tested on omap4430 sdp with 3.4-rc3.
> Tested on omap5430evm with 3.1-custom kernel.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Felipe Balbi <balbi@ti.com>
> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> drivers/input/keyboard/Kconfig | 4 +-
> drivers/input/keyboard/omap4-keypad.c | 120 +++++++++++++++++++++++++-------
> 2 files changed, 95 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index f354813..33bbdee 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -512,9 +512,9 @@ config KEYBOARD_OMAP
> module will be called omap-keypad.
>
> config KEYBOARD_OMAP4
> - tristate "TI OMAP4 keypad support"
> + tristate "TI OMAP4+ keypad support"
> help
> - Say Y here if you want to use the OMAP4 keypad.
> + Say Y here if you want to use the OMAP4+ keypad.
>
> To compile this driver as a module, choose M here: the
> module will be called omap4-keypad.
> diff --git a/drivers/input/keyboard/omap4-keypad.c
> b/drivers/input/keyboard/omap4-keypad.c
> index e809ac0..d7102e8 100644
> --- a/drivers/input/keyboard/omap4-keypad.c
> +++ b/drivers/input/keyboard/omap4-keypad.c
> @@ -68,19 +68,52 @@
>
> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>
> +enum {
> + KBD_REVISION_OMAP4 = 0,
> + KBD_REVISION_OMAP5,
> +};
> +
> struct omap4_keypad {
> struct input_dev *input;
>
> void __iomem *base;
> - int irq;
> + unsigned int irq;
>
> unsigned int rows;
> unsigned int cols;
> + u32 reg_offset;
> + u32 irqreg_offset;
> unsigned int row_shift;
> unsigned char key_state[8];
> unsigned short keymap[];
> };
>
> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->reg_offset + offset);
> +}
> +
> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->reg_offset + offset);
> +}
> +
> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
> +{
> + return __raw_readl(keypad_data->base +
> + keypad_data->irqreg_offset + offset);
> +}
> +
> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
> + u32 offset, u32 value)
> +{
> + __raw_writel(value,
> + keypad_data->base + keypad_data->irqreg_offset + offset);
> +}
> +
> +
> /* Interrupt handler */
> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
> {
> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> u32 *new_state = (u32 *) key_state;
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
> - *(new_state + 1) = __raw_readl(keypad_data->base
> - + OMAP4_KBD_FULLCODE63_32);
> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>
> for (row = 0; row < keypad_data->rows; row++) {
> changed = key_state[row] ^ keypad_data->key_state[row];
> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int
> irq, void *dev_id)
> sizeof(keypad_data->key_state));
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> /* enable interrupts */
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
>
> return IRQ_HANDLED;
> }
> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>
> disable_irq(keypad_data->irq);
>
> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
> - keypad_data->base + OMAP4_KBD_CTRL);
> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
> + OMAP4_VAL_FUNCTIONALCFG);
> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
> + OMAP4_VAL_DEBOUNCINGTIME);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + OMAP4_VAL_IRQDISABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_DEF_IRQENABLE_EVENTEN |
> + OMAP4_DEF_IRQENABLE_LONGKEY);
> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>
> enable_irq(keypad_data->irq);
>
> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
> disable_irq(keypad_data->irq);
>
> /* Disable interrupts */
> - __raw_writel(OMAP4_VAL_IRQDISABLE,
> - keypad_data->base + OMAP4_KBD_IRQENABLE);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
> + OMAP4_VAL_IRQDISABLE);
>
> /* clear pending interrupts */
> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>
> enable_irq(keypad_data->irq);
>
> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> struct resource *res;
> resource_size_t size;
> unsigned int row_shift, max_keys;
> + int rev;
> int irq;
> int error;
>
> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> keypad_data->rows = pdata->rows;
> keypad_data->cols = pdata->cols;
>
> + /*
> + * 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) {
> + dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
> + goto err_unmap;
> + }
> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
> + rev &= 0x03 << 30;
> + rev >>= 30;
> + switch (rev) {
> + case KBD_REVISION_OMAP4:
> + keypad_data->reg_offset = 0x00;
> + keypad_data->irqreg_offset = 0x00;
> + break;
> + case KBD_REVISION_OMAP5:
> + keypad_data->reg_offset = 0x10;
> + keypad_data->irqreg_offset = 0x0c;
> + break;
> + default:
> + dev_err(&pdev->dev,
> + "Keypad reports unsupported revision %d", rev);
> + error = -EINVAL;
> + goto err_pm_put_sync;
> + }
> +
> /* input device allocation */
> keypad_data->input = input_dev = input_allocate_device();
> if (!input_dev) {
> error = -ENOMEM;
> - goto err_unmap;
> + goto err_pm_put_sync;
> }
>
> input_dev->name = pdev->name;
> @@ -273,14 +337,14 @@ static int __devinit omap4_keypad_probe(struct
> platform_device *pdev)
> input_dev->keycode, input_dev->keybit);
>
> error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
> - IRQF_TRIGGER_RISING,
> + IRQF_DISABLED | IRQF_TRIGGER_RISING,
Sorry, " IRQF_DISABLED" got included by mistake.
Removing this stray change and sending it again.
> "omap4-keypad", keypad_data);
> if (error) {
> dev_err(&pdev->dev, "failed to register interrupt\n");
> goto err_free_input;
> }
>
> - pm_runtime_enable(&pdev->dev);
> + pm_runtime_put_sync(&pdev->dev);
>
> error = input_register_device(keypad_data->input);
> if (error < 0) {
> @@ -296,6 +360,8 @@ err_pm_disable:
> free_irq(keypad_data->irq, keypad_data);
> err_free_input:
> input_free_device(input_dev);
> +err_pm_put_sync:
> + pm_runtime_put_sync(&pdev->dev);
> err_unmap:
> iounmap(keypad_data->base);
> err_release_mem:
>
>
> ~Sourav
>
> On Wed, May 9, 2012 at 1:15 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>>> Hi Dmitry ,
>>>
>>>
>>> On Wed, May 9, 2012 at 10:48 AM, Dmitry Torokhov
>>> <dmitry.torokhov@gmail.com> wrote:
>>> > Ho Sourav,
>>> >
>>> > On Thu, Apr 26, 2012 at 11:24:37AM +0530, Sourav Poddar wrote:
>>> >>
>>> >> -config KEYBOARD_OMAP4
>>> >> - tristate "TI OMAP4 keypad support"
>>> >> +config KEYBOARD_OMAP4+
>>> >
>>> > I think this works purely by accident - '+' sign getting dropped by
>>> > parser...
>>> >
>>> >> @@ -139,16 +192,33 @@ static int omap4_keypad_open(struct input_dev *input)
>>> >>
>>> >> disable_irq(keypad_data->irq);
>>> >>
>>> >> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>>> >> - keypad_data->base + OMAP4_KBD_CTRL);
>>> >> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>>> >> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>>> >> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>>> >> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>>> >> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>>> >> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>>> >> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>>> >> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>>> >> + keypad_data->revision = kbd_read_revision(keypad_data,
>>> >> + OMAP4_KBD_REVISION);
>>> >> + switch (keypad_data->revision) {
>>> >> + case 1:
>>> >> + keypad_data->irqstatus = OMAP4_KBD_IRQSTATUS + 0x0c;
>>> >> + keypad_data->irqenable = OMAP4_KBD_IRQENABLE + 0x0c;
>>> >> + keypad_data->reg_offset = 0x10;
>>> >> + break;
>>> >
>>> > This should be done in probe().
>>> >
>>> Dont we then require "pm_runtime_put_sync" in probe, since we are trying
>>> to read the keypad revision register.?
>>
>> Ah, indeed, but I think not pm_runtime_get_sync() but
>> pm_runtime_set_active().
>>
>> Not sure if this will fix the crash...
>>
>> --
>> Dmitry
>>
>>
>> Input: omap-keypad - dynamically handle register offsets
>>
>> From: G, Manjunath Kondaiah <manjugk@ti.com>
>>
>> Keypad controller register offsets are different for omap4
>> and omap5. Handle these offsets through static mapping and
>> assign these mappings during run time.
>>
>> Tested on omap4430 sdp with 3.4-rc3.
>> Tested on omap5430evm with 3.1-custom kernel.
>>
>> Signed-off-by: Felipe Balbi <balbi@ti.com>
>> Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
>> Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
>> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> ---
>>
>> drivers/input/keyboard/Kconfig | 4 +
>> drivers/input/keyboard/omap4-keypad.c | 117 ++++++++++++++++++++++++++-------
>> 2 files changed, 94 insertions(+), 27 deletions(-)
>>
>>
>> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
>> index 20a3753..84ee155 100644
>> --- a/drivers/input/keyboard/Kconfig
>> +++ b/drivers/input/keyboard/Kconfig
>> @@ -531,9 +531,9 @@ config KEYBOARD_OMAP
>> module will be called omap-keypad.
>>
>> config KEYBOARD_OMAP4
>> - tristate "TI OMAP4 keypad support"
>> + tristate "TI OMAP4+ keypad support"
>> help
>> - Say Y here if you want to use the OMAP4 keypad.
>> + Say Y here if you want to use the OMAP4+ keypad.
>>
>> To compile this driver as a module, choose M here: the
>> module will be called omap4-keypad.
>> diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
>> index e809ac0..c9fd0df 100644
>> --- a/drivers/input/keyboard/omap4-keypad.c
>> +++ b/drivers/input/keyboard/omap4-keypad.c
>> @@ -68,19 +68,52 @@
>>
>> #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
>>
>> +enum {
>> + KBD_REVISION_OMAP4 = 0,
>> + KBD_REVISION_OMAP5,
>> +};
>> +
>> struct omap4_keypad {
>> struct input_dev *input;
>>
>> void __iomem *base;
>> - int irq;
>> + unsigned int irq;
>>
>> unsigned int rows;
>> unsigned int cols;
>> + u32 reg_offset;
>> + u32 irqreg_offset;
>> unsigned int row_shift;
>> unsigned char key_state[8];
>> unsigned short keymap[];
>> };
>>
>> +static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->reg_offset + offset);
>> +}
>> +
>> +static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset)
>> +{
>> + return __raw_readl(keypad_data->base +
>> + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
>> + u32 offset, u32 value)
>> +{
>> + __raw_writel(value,
>> + keypad_data->base + keypad_data->irqreg_offset + offset);
>> +}
>> +
>> +
>> /* Interrupt handler */
>> static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> {
>> @@ -91,12 +124,11 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> u32 *new_state = (u32 *) key_state;
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> - *new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
>> - *(new_state + 1) = __raw_readl(keypad_data->base
>> - + OMAP4_KBD_FULLCODE63_32);
>> + *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
>> + *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
>>
>> for (row = 0; row < keypad_data->rows; row++) {
>> changed = key_state[row] ^ keypad_data->key_state[row];
>> @@ -121,12 +153,13 @@ static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
>> sizeof(keypad_data->key_state));
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> /* enable interrupts */
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>>
>> return IRQ_HANDLED;
>> }
>> @@ -139,16 +172,17 @@ static int omap4_keypad_open(struct input_dev *input)
>>
>> disable_irq(keypad_data->irq);
>>
>> - __raw_writel(OMAP4_VAL_FUNCTIONALCFG,
>> - keypad_data->base + OMAP4_KBD_CTRL);
>> - __raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
>> - keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> - __raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN | OMAP4_DEF_IRQENABLE_LONGKEY,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> - __raw_writel(OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA,
>> - keypad_data->base + OMAP4_KBD_WAKEUPENABLE);
>> + kbd_writel(keypad_data, OMAP4_KBD_CTRL,
>> + OMAP4_VAL_FUNCTIONALCFG);
>> + kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME,
>> + OMAP4_VAL_DEBOUNCINGTIME);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + OMAP4_VAL_IRQDISABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_DEF_IRQENABLE_EVENTEN |
>> + OMAP4_DEF_IRQENABLE_LONGKEY);
>> + kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
>> + OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -162,12 +196,12 @@ static void omap4_keypad_close(struct input_dev *input)
>> disable_irq(keypad_data->irq);
>>
>> /* Disable interrupts */
>> - __raw_writel(OMAP4_VAL_IRQDISABLE,
>> - keypad_data->base + OMAP4_KBD_IRQENABLE);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
>> + OMAP4_VAL_IRQDISABLE);
>>
>> /* clear pending interrupts */
>> - __raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
>> - keypad_data->base + OMAP4_KBD_IRQSTATUS);
>> + kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
>> + kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
>>
>> enable_irq(keypad_data->irq);
>>
>> @@ -182,6 +216,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> struct resource *res;
>> resource_size_t size;
>> unsigned int row_shift, max_keys;
>> + int rev;
>> int irq;
>> int error;
>>
>> @@ -241,11 +276,40 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> keypad_data->rows = pdata->rows;
>> keypad_data->cols = pdata->cols;
>>
>> + /*
>> + * Mark device as active (and wake up its parent) so we can read
>> + * revision register.
>> + */
>> + error = pm_runtime_set_active(&pdev->dev);
>> + if (error) {
>> + dev_err(&pdev->dev, "pm_runtime_set_active() failed\n");
>> + goto err_unmap;
>> + }
>> +
>> + rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
>> + rev &= 0x03 << 30;
>> + rev >>= 30;
>> + switch (rev) {
>> + case KBD_REVISION_OMAP4:
>> + keypad_data->reg_offset = 0x00;
>> + keypad_data->irqreg_offset = 0x00;
>> + break;
>> + case KBD_REVISION_OMAP5:
>> + keypad_data->reg_offset = 0x10;
>> + keypad_data->irqreg_offset = 0x0c;
>> + break;
>> + default:
>> + dev_err(&pdev->dev,
>> + "Keypad reports unsupported revision %d", rev);
>> + error = -EINVAL;
>> + goto err_pm_suspended;
>> + }
>> +
>> /* input device allocation */
>> keypad_data->input = input_dev = input_allocate_device();
>> if (!input_dev) {
>> error = -ENOMEM;
>> - goto err_unmap;
>> + goto err_pm_suspended;
>> }
>>
>> input_dev->name = pdev->name;
>> @@ -281,6 +345,7 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
>> }
>>
>> pm_runtime_enable(&pdev->dev);
>> + pm_runtime_put_sync(&pdev->dev);
>>
>> error = input_register_device(keypad_data->input);
>> if (error < 0) {
>> @@ -296,6 +361,8 @@ err_pm_disable:
>> free_irq(keypad_data->irq, keypad_data);
>> err_free_input:
>> input_free_device(input_dev);
>> +err_pm_suspended:
>> + pm_runtime_set_suspended(&pdev->dev);
>> err_unmap:
>> iounmap(keypad_data->base);
>> err_release_mem:
From: G, Manjunath Kondaiah <manjugk@ti.com>
Date: Mon, 10 Oct 2011 20:52:05 +0530
Subject: [PATCH] Input: omap-keypad: dynamically handle register offsets
Keypad controller register offsets are different for omap4
and omap5. Handle these offsets through static mapping and
assign these mappings during run time.
Tested on omap4430 sdp with 3.4-rc3.
Tested on omap5430evm with 3.1-custom kernel.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: G, Manjunath Kondaiah <manjugk@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2012-05-11 12:32:00 +07:00
|
|
|
err_pm_put_sync:
|
|
|
|
pm_runtime_put_sync(&pdev->dev);
|
2010-09-30 13:35:57 +07:00
|
|
|
err_unmap:
|
|
|
|
iounmap(keypad_data->base);
|
|
|
|
err_release_mem:
|
2012-07-13 14:10:47 +07:00
|
|
|
release_mem_region(res->start, resource_size(res));
|
2010-09-01 07:05:27 +07:00
|
|
|
err_free_keypad:
|
|
|
|
kfree(keypad_data);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2012-11-24 12:50:47 +07:00
|
|
|
static int omap4_keypad_remove(struct platform_device *pdev)
|
2010-09-01 07:05:27 +07:00
|
|
|
{
|
|
|
|
struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
|
2010-09-30 13:35:57 +07:00
|
|
|
struct resource *res;
|
2010-09-01 07:05:27 +07:00
|
|
|
|
|
|
|
free_irq(keypad_data->irq, keypad_data);
|
2011-02-23 13:25:59 +07:00
|
|
|
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
|
2010-09-01 07:05:27 +07:00
|
|
|
input_unregister_device(keypad_data->input);
|
2010-09-30 13:35:57 +07:00
|
|
|
|
|
|
|
iounmap(keypad_data->base);
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
release_mem_region(res->start, resource_size(res));
|
|
|
|
|
2012-07-13 14:10:47 +07:00
|
|
|
kfree(keypad_data->keymap);
|
2010-09-01 07:05:27 +07:00
|
|
|
kfree(keypad_data);
|
2012-07-13 14:10:47 +07:00
|
|
|
|
2010-09-01 07:05:27 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:10:47 +07:00
|
|
|
static const struct of_device_id omap_keypad_dt_match[] = {
|
|
|
|
{ .compatible = "ti,omap4-keypad" },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
|
|
|
|
|
2013-08-26 13:29:30 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int omap4_keypad_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (device_may_wakeup(&pdev->dev)) {
|
|
|
|
error = enable_irq_wake(keypad_data->irq);
|
|
|
|
if (!error)
|
|
|
|
keypad_data->irq_wake_enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap4_keypad_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
if (device_may_wakeup(&pdev->dev) && keypad_data->irq_wake_enabled) {
|
|
|
|
disable_irq_wake(keypad_data->irq);
|
|
|
|
keypad_data->irq_wake_enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(omap4_keypad_pm_ops,
|
|
|
|
omap4_keypad_suspend, omap4_keypad_resume);
|
|
|
|
|
2010-09-01 07:05:27 +07:00
|
|
|
static struct platform_driver omap4_keypad_driver = {
|
|
|
|
.probe = omap4_keypad_probe,
|
2012-11-24 12:27:39 +07:00
|
|
|
.remove = omap4_keypad_remove,
|
2010-09-01 07:05:27 +07:00
|
|
|
.driver = {
|
|
|
|
.name = "omap4-keypad",
|
2013-08-26 13:29:30 +07:00
|
|
|
.pm = &omap4_keypad_pm_ops,
|
2014-05-29 14:30:02 +07:00
|
|
|
.of_match_table = omap_keypad_dt_match,
|
2010-09-01 07:05:27 +07:00
|
|
|
},
|
|
|
|
};
|
2011-11-30 02:08:39 +07:00
|
|
|
module_platform_driver(omap4_keypad_driver);
|
2010-09-01 07:05:27 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Texas Instruments");
|
|
|
|
MODULE_DESCRIPTION("OMAP4 Keypad Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:omap4-keypad");
|