History log of /linux-master/drivers/input/keyboard/omap4-keypad.c
Revision Date Author Comments
# 02db1749 11-Dec-2023 Andreas Kemnade <andreas@kemnade.info>

Input: omap4-keypad - react on keypresses if device is runtime-suspended

According to SWPU235AB, table 26-6, fclk is required to generate events
at least on OMAP4460, so keep fclk enabled all the time the device
is opened.

Suggested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Reviewed-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20231211221757.517427-1-andreas@kemnade.info
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# ec4c61a6 20-Sep-2023 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Input: omap4-keypad - convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.
To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new() which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230920125829.1478827-8-u.kleine-koenig@pengutronix.de
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# e7963773 10-Jul-2023 Yangtao Li <frank.li@vivo.com>

Input: omap4-keyad - convert to devm_platform_ioremap_resource()

Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Link: https://lore.kernel.org/r/20230705052346.39337-4-frank.li@vivo.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 12c7d0ae 10-Mar-2023 Rob Herring <robh@kernel.org>

Input: Use of_property_read_bool() for boolean properties

It is preferred to use typed property access functions (i.e.
of_property_read_<type> functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to of_property_read_bool().

Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20230310144708.1542751-1-robh@kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# f31e7388 14-Jan-2023 Jonathan Cameron <Jonathan.Cameron@huawei.com>

Input: omap4-keyad - use pm_ptr() and RUNTIME_DEV_PM_OPS()

SET_RUNTIME_DEV_PM_OPS() is deprecated as it requires explicit protection
against unused function warnings. The new combination of pm_ptr()
and RUNTIME_DEV_PM_OPS() allows the compiler to see the functions,
thus suppressing the warning, but still allowing the unused code to be
removed. Thus also drop the __maybe_unused markings.

Note that DEFINE_RUNTIME_DEV_PM_OPS() is not used because that adds
additional callbacks for suspend and resume and would need
testing.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20230114171620.42891-14-jic23@kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 433302dd 24-Apr-2022 Minghao Chi <chi.minghao@zte.com.cn>

Input: omap4-keypad - switch to using pm_runtime_resume_and_get()

Use pm_runtime_resume_and_get() to replace pm_runtime_get_sync and
pm_runtime_put_noidle. This change is just to simplify the code, no
actual functional changes.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Link: https://lore.kernel.org/r/20220414085710.2541867-1-chi.minghao@zte.com.cn
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 81022a17 17-Apr-2022 Miaoqian Lin <linmq006@gmail.com>

Input: omap4-keypad - fix pm_runtime_get_sync() error checking

If the device is already in a runtime PM enabled state
pm_runtime_get_sync() will return 1, so a test for negative
value should be used to check for errors.

Fixes: f77621cc640a ("Input: omap-keypad - dynamically handle register offsets")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Link: https://lore.kernel.org/r/20220412070131.19848-1-linmq006@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 2f6aa61d 10-Jan-2021 Tony Lindgren <tony@atomide.com>

Input: omap4-keypad - implement errata check for lost key-up events

We are still missing handling for errata i689 related issues for the
case where we never see a key up interrupt for the last pressed key.

To fix the issue, we must scan the key state again after the keyboard
controller has idled to check if a key up event was missed. This is
described in the omap4 silicon errata documentation for Errata ID i689
"1.32 Keyboard Key Up Event Can Be Missed":

"When a key is released for a time shorter than the debounce time,
in-between 2 key press (KP1 and KP2), the keyboard state machine will go
to idle mode and will never detect the key release (after KP1, and also
after KP2), and thus will never generate a new IRQ indicating the key
release."

We can use PM runtime autosuspend features to check the keyboard state
after it enters idle.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/X/vrygoBxzGyXhfc@atomide.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 29bf35e5 10-Jan-2021 Tony Lindgren <tony@atomide.com>

Input: omap4-keypad - use PM runtime autosuspend

Implement PM runtime autosuspend support to prepare for adding handling to
clear stuck last pressed key in the following patches. The hardware has
support for autoidle and can wake up to keypress events.

Let's also update omap4_keypad_probe() to use dev instead of &pdev->dev
since we already have it from the earlier changes.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/X/vqCs5/EDURprAJ@atomide.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 98b0c88d 10-Jan-2021 Tony Lindgren <tony@atomide.com>

Input: omap4-keypad - move rest of key scanning to a separate function

Let's move rest of the key scanning code to omap4_keypad_scan_keys().
We will use omap4_keypad_scan_keys() also for implementing errata
handling to clear the stuck last key in the following patch.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20210110190529.46135-4-tony@atomide.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 905dbf1d 10-Jan-2021 Tony Lindgren <tony@atomide.com>

Input: omap4-keypad - scan keys in two phases and simplify with bitmask

Because of errata i689 the keyboard can idle with state where no key
up interrupts are seen until after the next key press.

This means we need to first check for any lost key up events before
scanning for new down events.

For example, rapidly pressing shift-shift-j can sometimes produce a J
instead of j. Let's fix the issue by scanning the keyboard in two
phases. First we scan for any key up events that we may have missed,
and then we scan for key down events.

Let's also simplify things with for_each_set_bit() as suggested by
Dmitry Torokhov <dmitry.torokhov@gmail.com>.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20210110190529.46135-3-tony@atomide.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 7e0541b2 10-Jan-2021 Tony Lindgren <tony@atomide.com>

Input: omap4-keypad - disable unused long interrupts

We are not using the long events and they produce extra interrupts.
Let's not enable them at all.

Note that also the v3.0.8 Linux Android kernel has long interrupts
disabled.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20210110190529.46135-2-tony@atomide.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 60dc4511 10-Jan-2021 Dmitry Torokhov <dmitry.torokhov@gmail.com>

Input: omap4-keypad - switch to use managed resources

Now that input core supports devres-managed input devices we can clean
up this driver a bit.

Link: https://lore.kernel.org/r/X/qfJKiM21uyksYl@google.com
Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# c1b46cd4 22-Nov-2020 Dmitry Torokhov <dmitry.torokhov@gmail.com>

Input: omap4-keypad - set up interrupt as wakeup source

Marking main interrupt as wakeup interrupt in probe allows us to drop
custom suspend/resume methods whose only purpose was to configure interrupt
for waking up the system.

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


# 59bbf838 20-Nov-2020 Zhang Qilong <zhangqilong3@huawei.com>

Input: omap4-keypad - fix runtime PM error handling

In omap4_keypad_probe, the patch fix several bugs.

1) pm_runtime_get_sync will increment pm usage counter even it
failed. Forgetting to pm_runtime_put_noidle will result in
reference leak.

2) In err_unmap, forget to disable runtime of device,
pm_runtime_enable will increase power disable depth. Thus a
pairing decrement is needed on the error handling path to keep
it balanced.

3) In err_pm_disable, it will call pm_runtime_put_sync twice not
one time.

To fix this we factor out code reading revision and disabling touchpad, and
drop PM reference once we are done talking to the device.

Fixes: f77621cc640a7 ("Input: omap-keypad - dynamically handle register offsets")
Fixes: 5ad567ffbaf20 ("Input: omap4-keypad - wire up runtime PM handling")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201120133918.2559681-1-zhangqilong3@huawei.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 4738dd19 15-Sep-2020 Krzysztof Kozlowski <krzk@kernel.org>

Input: omap4-keypad - fix handling of platform_get_irq() error

platform_get_irq() returns -ERRNO on error. In such case comparison
to 0 would pass the check.

Fixes: f3a1ba60dbdb ("Input: omap4-keypad - use platform device helpers")
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Link: https://lore.kernel.org/r/20200828145744.3636-2-krzk@kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 1a59d1b8 27-May-2019 Thomas Gleixner <tglx@linutronix.de>

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156

Based on 1 normalized pattern(s):

this program is free software you can redistribute it and or modify
it under the terms of the gnu general public license as published by
the free software foundation either version 2 of the license or at
your option any later version this program is distributed in the
hope that it will be useful but without any warranty without even
the implied warranty of merchantability or fitness for a particular
purpose see the gnu general public license for more details you
should have received a copy of the gnu general public license along
with this program if not write to the free software foundation inc
59 temple place suite 330 boston ma 02111 1307 usa

extracted by the scancode license scanner the SPDX license identifier

GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 1334 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Richard Fontana <rfontana@redhat.com>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# e2ca26ec 04-Dec-2018 Tony Lindgren <tony@atomide.com>

Input: omap-keypad - fix idle configuration to not block SoC idle states

With PM enabled, I noticed that pressing a key on the droid4 keyboard will
block deeper idle states for the SoC. Let's fix this by using IRQF_ONESHOT
and stop constantly toggling the device OMAP4_KBD_IRQENABLE register as
suggested by Dmitry Torokhov <dmitry.torokhov@gmail.com>.

From the hardware point of view, looks like we need to manage the registers
for OMAP4_KBD_IRQENABLE and OMAP4_KBD_WAKEUPENABLE together to avoid
blocking deeper SoC idle states. And with toggling of OMAP4_KBD_IRQENABLE
register now gone with IRQF_ONESHOT, also the SoC idle state problem is
gone during runtime. We still also need to clear OMAP4_KBD_WAKEUPENABLE in
omap4_keypad_close() though to pair it with omap4_keypad_open() to prevent
blocking deeper SoC idle states after rmmod omap4-keypad.

Reported-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 6c3516fe 03-Dec-2018 Tony Lindgren <tony@atomide.com>

Input: omap-keypad - fix keyboard debounce configuration

I noticed that the Android v3.0.8 kernel on droid4 is using different
keypad values from the mainline kernel and does not have issues with
keys occasionally being stuck until pressed again. Turns out there was
an earlier patch posted to fix this as "Input: omap-keypad: errata i689:
Correct debounce time", but it was never reposted to fix use macros
for timing calculations.

This updated version is using macros, and also fixes the use of the
input clock rate to use 32768KiHz instead of 32000KiHz. And we want to
use the known good Android kernel values of 3 and 6 instead of 2 and 6
in the earlier patch.

Reported-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 6396bb22 12-Jun-2018 Kees Cook <keescook@chromium.org>

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>


# 9bb9dc13 10-Apr-2017 Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Input: omap-keypad - fix error handling code

According to the previous error handling code, it is likely that 'goto
err_free_keymap' is expected here in order to avoid a memory leak in error
handling path.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# aef01aad 11-Nov-2016 Dmitry Torokhov <dmitry.torokhov@gmail.com>

Input: matrix-keypad - switch to using generic device properties

Instead of being OF-specific, let's switch to using generic device
properties, which will make this code usable on ACPI, device tree and
legacy boards that use property sets.

As part of the change let's rename matrix_keypad_parse_of_params() to
matrix_keypad_parse_properties().

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


# de3a00ef 22-Jan-2017 Guenter Roeck <linux@roeck-us.net>

Input: keyboard - drop unnecessary calls to device_init_wakeup

Calling device_init_wakeup in the remove function is unnecessary since the
device is going away, and thus won't be able to cause any wakeups under any
circumstances. Besides, the driver cleanup code already handles the
necessary cleanup.

Similarly, disabling wakeup in the probe error path is unnecessary, as is
disabling wakeup in the probe function in the first place.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# b83b1459 28-Sep-2015 Sudip Mukherjee <sudipm.mukherjee@gmail.com>

Input: omap4-keypad - fix memory leak

If omap4_keypad_parse_dt() fails we returned the error code but we
missed releasing keypad_data.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# d79bdc7f 28-Sep-2015 Sudip Mukherjee <sudipm.mukherjee@gmail.com>

Input: omap4-keypad - fix memory leak

If omap4_keypad_parse_dt() fails we returned the error code but we
missed releasing keypad_data.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 1d05726c 20-Oct-2014 Wolfram Sang <wsa@kernel.org>

input: keyboard: drop owner assignment from platform_drivers

A platform_driver does not need to set an owner, it will be populated by the
driver core.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>


# 61721c88 29-May-2014 Joachim Eastwood <manabian@gmail.com>

Input: omap-keypad - remove platform data support

This is unused since all users (OMAP4/5) are DT only.

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


# bf9a9f8e 06-Jan-2014 Paul Gortmaker <paul.gortmaker@windriver.com>

Input: delete non-required instances of include <linux/init.h>

None of these files are actually using any __init type directives
and hence don't need to include <linux/init.h>. Most are just a
left over from __devinit and __cpuinit removal, or simply due to
code getting copied from one driver to the next.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 50f3c163 26-Aug-2013 Illia Smyrnov <illia.smyrnov@ti.com>

Input: omap-keypad - set up irq type from DT

OMAP4 is DT only, so read the keypad IRQ type from DT instead hard-coding
it in the driver.

Signed-off-by: Illia Smyrnov <illia.smyrnov@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 78608a0d 26-Aug-2013 Illia Smyrnov <illia.smyrnov@ti.com>

Input: omap-keypad - enable wakeup capability for keypad.

Enable/disable IRQ wake in suspend/resume handlers
to make the keypad wakeup capable.

Signed-off-by: Illia Smyrnov <illia.smyrnov@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# afbac60b 26-Aug-2013 Illia Smyrnov <illia.smyrnov@ti.com>

Input: omap-keypad - clear interrupts on open

According to TRM, the recommended way for keyboard controller
initialization is clear the interrupt-status register, then set up
certain keyboard events for generating an interrupt request and
set up expected source of wake-up event that generates a wake-up
request.

Signed-off-by: Illia Smyrnov <illia.smyrnov@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# c683da3e 26-Aug-2013 Illia Smyrnov <illia.smyrnov@ti.com>

Input: omap-keypad - convert to threaded IRQ

Convert to use threaded IRQ.

Signed-off-by: Illia Smyrnov <illia.smyrnov@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 875ad696 26-Aug-2013 Illia Smyrnov <illia.smyrnov@ti.com>

Input: omap-keypad - use bitfiled instead of hardcoded values

Use bitfiled instead of hardcoded values to set KBD_CTRL, use BIT macro,
remove unused defines.

Signed-off-by: Illia Smyrnov <illia.smyrnov@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 19b1d74f 06-May-2013 Sachin Kamat <sachin.kamat@linaro.org>

Input: omap4-keypad - remove redundant platform_set_drvdata()

Commit 0998d06310 (device-core: Ensure drvdata = NULL when no
driver is bound) removes the need to set driver data field to
NULL.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 43840415 25-Feb-2013 Simon Glass <sjg@chromium.org>

input: matrix-keymap: Add function to read the new DT binding

We now have a binding which adds two parameters to the matrix keypad DT
node. This is separate from the GPIO-driven matrix keypad binding, and
unfortunately incompatible, since that uses row-gpios/col-gpios for the
row and column counts.

So the easiest option here is to provide a function for non-GPIO drivers
to use to decode the binding.

Note: We could in fact create an entirely separate structure to hold
these two fields, but it does not seem worth it, yet. If we have more
parameters then we can add this, and then refactor each driver to hold
such a structure.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Tested-by: Sourav Poddar <sourav.poddar@ti.com> (v2)
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>


# e2619cf7 23-Nov-2012 Bill Pemberton <wfp5p@virginia.edu>

Input: remove use of __devexit

CONFIG_HOTPLUG is going away as an option so __devexit is no
longer needed.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 5298cc4c 23-Nov-2012 Bill Pemberton <wfp5p@virginia.edu>

Input: remove use of __devinit

CONFIG_HOTPLUG is going away as an option so __devinit is no longer
needed.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Javier Martinez Canillas <javier@dowhile0.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 1cb0aa88 23-Nov-2012 Bill Pemberton <wfp5p@virginia.edu>

Input: remove use of __devexit_p

CONFIG_HOTPLUG is going away as an option so __devexit_p is no longer
needed.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 13987435 13-Jul-2012 Sourav Poddar <sourav.poddar@ti.com>

Input: omap4-keypad - add device tree support

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

Tested on omap4430 sdp.

Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>


# 1932811f 10-May-2012 Dmitry Torokhov <dmitry.torokhov@gmail.com>

Input: matrix-keymap - uninline and prepare for device tree support

Change matrix-keymap helper to be out-of-line, like sparse keymap,
allow the helper perform basic keymap validation and return errors,
and prepare for device tree support.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# f77621cc 10-May-2012 Poddar, Sourav <sourav.poddar@ti.com>

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>


# 0f1142a5 16-Mar-2012 Felipe Balbi <balbi@ti.com>

Input: omap4-keypad - move platform_data to <linux/platform_data>

This patch allows us to drop the OMAP dependency from the OMAP4 keypad
driver.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sourav Poddar <sourav.poddar@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# 5146c84f 29-Nov-2011 JJ Ding <dgdunix@gmail.com>

Input: keyboard - use macro module_platform_driver()

Commit 940ab88962bc1aff3273a8356d64577a6e386736 introduced a new macro to
save some platform_driver boilerplate code. Use it.

Signed-off-by: JJ Ding <dgdunix@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# 5ad567ff 22-Feb-2011 Abraham Arce <x0066660@ti.com>

Input: omap4-keypad - wire up runtime PM handling

Enable Runtime PM functionality in OMAP4 driver based on the following
assumptions:

- keyboard controller in wakeup domain so it is always on and power
impact is minimal;
- in OMAP4 the device control is at module/device level and ick/fclk
level control is difficult so cutting of clocks will prevent
interrupts.

Signed-off-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# 9a34bc61 30-Sep-2010 Mike Turquette <mturquette@ti.com>

Input: omap4-keypad - wake-up on events & long presses

Program keyboard controller to generate a wake-up request on events and
on long key presses. It will not generate wake-up requests on timeouts
since driver code does not handle them.

This allows keyboard to wake-up OMAP from suspend.

Signed-off-by: Mike Turquette <mturquette@ti.com>
Signed-off-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# f8038c42 30-Sep-2010 Abraham Arce <x0066660@ti.com>

Input: omap4-keypad - fix interrupt line configuration

Select correct interrupt line behaviour.

Signed-off-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# 05362f48 30-Sep-2010 Abraham Arce <x0066660@ti.com>

Input: omap4-keypad - SYSCONFIG register configuration

Remove SYSCONFIG register configuration, omap hwmod framework will
use internal API to modify as required.

Other minor updates:

- Change a variable name from DEF to VAL, this represents a value
- Break line width to 80 characters

Signed-off-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# f3a1ba60 30-Sep-2010 Abraham Arce <x0066660@ti.com>

Input: omap4-keypad - use platform device helpers

Get mem and irq resources using platform helpers

- platform_get_base
- platform_get_irq

Signed-off-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


# a17f7955 31-Aug-2010 Abraham Arce <x0066660@ti.com>

Input: add support for OMAP4 keyboard controller

OMAP4 keyboard controller includes:
- built-in scanning algorithm
- debouncing feature

Driver implementation is based on matrix_keypad.c

Signed-off-by: Syed Rafiuddin <rafiuddin.syed@ti.com>
Signed-off-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>