linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Miao <eric.y.miao@gmail.com>
To: Trilok Soni <soni.trilok@gmail.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Paulius Zaleckas <paulius.zaleckas@teltonika.lt>,
	Uli Luckas <u.luckas@road.de>,
	linux-input@vger.kernel.org
Subject: Re: [PATCH] input: add support for generic GPIO-based matrix keypad
Date: Mon, 20 Jul 2009 19:43:56 +0800	[thread overview]
Message-ID: <4A64587C.4040109@gmail.com> (raw)
In-Reply-To: <5d5443650907200343l3f1f4f9clac79b60847830209@mail.gmail.com>

Trilok Soni wrote:
> Hi Eric,
> 
> On Mon, Jul 20, 2009 at 4:07 PM, Eric Miao<eric.y.miao@gmail.com> wrote:
>>>>> Did you tried assigning max_keypmap_size in platform data to
>>>>> MATRIX_MAX_COLS * MATRIX_MAX_ROWS ?
>>>>>
>>>> Yes, this fixes crashes. But this is just workaround for bug in driver.
>>>>
>>> As you have access to h/w, care to submit a patch which fixes this?
>>>
>> Dmitry & Trilok,
>>
>> How about this?  Due to the fact that we are not able to sort out the
>> proper solution for a dynamic maximum of columns/rows, let's simplify
>> the fix to the patch below:
>>
>>
>> From 61ea1bd16a3636f526fb12619e84a75fa16b7f38 Mon Sep 17 00:00:00 2001
>> From: Eric Miao <eric.y.miao@gmail.com>
>> Date: Mon, 20 Jul 2009 11:31:08 +0800
>> Subject: [PATCH] input: matrix keymap size fixed to maximum
>>
>> Introduced KEY_IDX(), merged keymap_data into 'matrix_keypad_platform_data'.
>>
>> Signed-off-by: Eric Miao <eric.y.miao@gmail.com>
>> ---
>>  drivers/input/keyboard/matrix_keypad.c |   22 ++++++----------------
>>  include/linux/input/matrix_keypad.h    |   21 +++++----------------
>>  2 files changed, 11 insertions(+), 32 deletions(-)
>>
>> diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
>> index e9b2e7c..a0ba134 100644
>> --- a/drivers/input/keyboard/matrix_keypad.c
>> +++ b/drivers/input/keyboard/matrix_keypad.c
>> @@ -136,7 +136,7 @@ static void matrix_keypad_scan(struct work_struct *work)
>>                        if ((bits_changed & (1 << row)) == 0)
>>                                continue;
>>
>> -                       code = (row << 4) + col;
>> +                       code = KEY_IDX(row, col);
>>                        input_event(input_dev, EV_MSC, MSC_SCAN, code);
>>                        input_report_key(input_dev,
>>                                         keypad->keycodes[code],
>> @@ -313,7 +313,6 @@ err_free_cols:
>>  static int __devinit matrix_keypad_probe(struct platform_device *pdev)
>>  {
>>        const struct matrix_keypad_platform_data *pdata;
>> -       const struct matrix_keymap_data *keymap_data;
>>        struct matrix_keypad *keypad;
>>        struct input_dev *input_dev;
>>        unsigned short *keycodes;
>> @@ -326,20 +325,13 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
>>                return -EINVAL;
>>        }
>>
>> -       keymap_data = pdata->keymap_data;
>> -       if (!keymap_data) {
>> +       if (!pdata->keymap) {
>>                dev_err(&pdev->dev, "no keymap data defined\n");
>>                return -EINVAL;
>>        }
>>
>> -       if (!keymap_data->max_keymap_size) {
>> -               dev_err(&pdev->dev, "invalid keymap data supplied\n");
>> -               return -EINVAL;
>> -       }
>> -
>>        keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL);
>> -       keycodes = kzalloc(keymap_data->max_keymap_size *
>> -                               sizeof(keypad->keycodes),
>> +       keycodes = kzalloc(sizeof(keypad->keycodes) * MATRIX_MAX_KEYS,
>>                           GFP_KERNEL);
>>        input_dev = input_allocate_device();
>>        if (!keypad || !keycodes || !input_dev) {
>> @@ -362,16 +354,14 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
>>        input_dev->close        = matrix_keypad_stop;
>>
>>        input_dev->keycode      = keycodes;
>> -       input_dev->keycodesize  = sizeof(*keycodes);
>> -       input_dev->keycodemax   = keymap_data->max_keymap_size;
>>
>> -       for (i = 0; i < keymap_data->keymap_size; i++) {
>> -               unsigned int key = keymap_data->keymap[i];
>> +       for (i = 0; i < pdata->keymap_size; i++) {
>> +               unsigned int key = pdata->keymap[i];
>>                unsigned int row = KEY_ROW(key);
>>                unsigned int col = KEY_COL(key);
>>                unsigned short code = KEY_VAL(key);
>>
>> -               keycodes[(row << 4) + col] = code;
>> +               keycodes[KEY_IDX(row, col)] = code;
> 
> 
> How about just doing like this
> 
> keycodes[(row << ((fls(MATRIX_MAX_COLS) - 1))) + col] ?
> 

I doubt this will work correctly if MATRIX_MAX_COLS isn't something 2 ^ N

  reply	other threads:[~2009-07-20 11:44 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-07  8:00 [PATCH] input: add support for generic GPIO-based matrix keypad Eric Miao
2009-05-07  8:41 ` Trilok Soni
2009-05-07  8:48   ` Eric Miao
2009-05-07  8:51     ` Trilok Soni
2009-05-08  1:29       ` Eric Miao
2009-05-08  4:54         ` Trilok Soni
2009-05-08  5:52         ` Arve Hjønnevåg
2009-05-25  3:36           ` Trilok Soni
2009-05-25  7:05             ` Eric Miao
2009-05-27 13:26 ` Uli Luckas
2009-05-31 14:12   ` Eric Miao
2009-05-31 14:20     ` Russell King - ARM Linux
2009-05-31 14:29       ` Eric Miao
2009-05-31 17:38         ` Dmitry Torokhov
2009-06-01  3:43           ` Eric Miao
2009-05-31 17:39         ` Robert Jarzmik
2009-06-01  4:02           ` Eric Miao
2009-06-02 14:55     ` Uli Luckas
2009-06-02 15:14       ` Uli Luckas
2009-06-03  6:24         ` Eric Miao
2009-06-10  4:10           ` Trilok Soni
2009-07-04  5:54             ` Marek Vasut
2009-07-06  6:02               ` Eric Miao
2009-07-06 10:58                 ` Marek Vasut
     [not found]           ` <f17812d70906070704s10f8eac6ybc353041e2db5a03@mail.gmail.com>
2009-06-12  4:03             ` Dmitry Torokhov
2009-06-12 13:01               ` Trilok Soni
2009-06-12 13:26                 ` Eric Miao
2009-06-19  6:54                   ` Trilok Soni
2009-06-29 16:26                   ` Dmitry Torokhov
2009-06-30  6:43                     ` Trilok Soni
2009-07-01 12:14                       ` Kim Kyuwon
2009-07-09  9:46                     ` Eric Miao
2009-07-09 10:01                       ` Trilok Soni
2009-07-17  7:51                       ` Paulius Zaleckas
2009-07-17  8:32                         ` Trilok Soni
2009-07-17  9:20                           ` Paulius Zaleckas
2009-07-20  7:12                             ` Trilok Soni
2009-07-20 10:37                               ` Eric Miao
2009-07-20 10:43                                 ` Trilok Soni
2009-07-20 11:43                                   ` Eric Miao [this message]
2009-07-21  8:00                                 ` Dmitry Torokhov
2009-07-21  8:26                                   ` Eric Miao
2009-07-21 15:58                                     ` Dmitry Torokhov
2009-07-27  8:54                                       ` Eric Miao
2009-06-03  6:06       ` Eric Miao
2009-06-03 18:06       ` Trilok Soni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A64587C.4040109@gmail.com \
    --to=eric.y.miao@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=paulius.zaleckas@teltonika.lt \
    --cc=soni.trilok@gmail.com \
    --cc=u.luckas@road.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).