From patchwork Wed Jan 11 17:42:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 9510827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C657E6075C for ; Wed, 11 Jan 2017 17:43:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B596E284E6 for ; Wed, 11 Jan 2017 17:43:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA525285BB; Wed, 11 Jan 2017 17:43:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33EC2284E6 for ; Wed, 11 Jan 2017 17:43:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938783AbdAKRm6 (ORCPT ); Wed, 11 Jan 2017 12:42:58 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33418 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938782AbdAKRm4 (ORCPT ); Wed, 11 Jan 2017 12:42:56 -0500 Received: by mail-pg0-f66.google.com with SMTP id 194so9812352pgd.0; Wed, 11 Jan 2017 09:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6SsQCJNSXTbu4fnPN8jsKBbO615wg+f2U3q07m+Faw8=; b=uVzzIyrBYEd4G0VsrEBjEAgUxQbczyG6PBNrns9ONz88kWTkxwjILPiaTRxsmE/o7A CEEV9zISNa3QlHt+kDek4RkN5Qxqqnve87WKEq/M0ZlbLOPq4vKmhE/wA6llth9KkpXl OmseGu/kzxFw2rSwfLL1J7Cs/s57OsXoBpWlOiCOpT4vODoOpG1jwpljESlXrhBXC0PN ghreDXEUkVSAsEN9jy5zECAq62mnQ/9fO+K+s9GS7qrU9CKDQc7EuQbZPftQejm0bAdA aId/GiNMx72YImuDAOdp/+k5GpXKs6LGP7EdWH+UTYRx3w6T8f3EmGeVidc+ULFDYH/l Ia4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6SsQCJNSXTbu4fnPN8jsKBbO615wg+f2U3q07m+Faw8=; b=Qa2U8bB02iOjfuovEwZDI+plnEmzmkLLfUD0968hUCSIbDSVmzKXl4ndlwlSUkJkVe AtMFrOYHMnZxrOk1D6Jxo9Fa83b2m8a9njp5DC9nhhC6p8Z5GI0wVhbsrj0s6m3EAl8n abjjGVjeVAOMD0dxzZU23d9l058mWfEvFavF5PyarY3z73qSM5VLH8SD9ZZ9b+ItXh0Y fYf1UO82nlDqfgKfPtDYkeRz96gkJdEFE3uesEII7Ax7UmBq1MkuXOXfFxZOyn5CEhF4 Y4QxJio1MSNsMkDCdkiHuwKy7zf84Wd/6r0QITuiTy59HMW41QUGaINyO4MutUN02n40 4SNQ== X-Gm-Message-State: AIkVDXKp8Ah+NXSYoxPySqGmFDJyb6aeITvoPC6/1rDFpk9qUJDhXkP1lLUP1u1L/CulyA== X-Received: by 10.98.3.7 with SMTP id 7mr11772194pfd.9.1484156574985; Wed, 11 Jan 2017 09:42:54 -0800 (PST) Received: from localhost.localdomain ([240f:4:c2bc:1:9509:afdd:5ccb:93b]) by smtp.gmail.com with ESMTPSA id d69sm15350651pfd.11.2017.01.11.09.42.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 09:42:54 -0800 (PST) From: Akinobu Mita To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: Akinobu Mita , Dmitry Torokhov Subject: [PATCH 4/5] Input: mpr121 - use matrix keypad helper API Date: Thu, 12 Jan 2017 02:42:28 +0900 Message-Id: <1484156549-26585-5-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484156549-26585-1-git-send-email-akinobu.mita@gmail.com> References: <1484156549-26585-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert to use matrix_kaypad_build_keymap() helper. This is preparation for adding device tree support. This change enables to share code between legacy platform data probe and device tree probe. Cc: Dmitry Torokhov Signed-off-by: Akinobu Mita --- drivers/input/keyboard/Kconfig | 1 + drivers/input/keyboard/mpr121_touchkey.c | 64 +++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index cbd75cf..b436e71 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -407,6 +407,7 @@ config KEYBOARD_MCS config KEYBOARD_MPR121 tristate "Freescale MPR121 Touchkey" depends on I2C + select INPUT_MATRIXKMAP help Say Y here if you have Freescale MPR121 touchkey controller chip in your system. diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index c809f70..7e85512 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -20,6 +20,7 @@ #include #include #include +#include /* Register definitions */ #define ELE_TOUCH_STATUS_0_ADDR 0x0 @@ -61,7 +62,6 @@ struct mpr121_touchkey { struct input_dev *input_dev; unsigned int statusbits; unsigned int keycount; - u16 keycodes[MPR121_MAX_KEY_COUNT]; }; struct mpr121_init_register { @@ -88,6 +88,7 @@ static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id) struct input_dev *input = mpr121->input_dev; unsigned int bit_changed; unsigned int key_num; + const unsigned short *keycode = input->keycode; int reg; reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR); @@ -114,7 +115,7 @@ static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id) continue; pressed = reg & (1 << key_num); - key_val = mpr121->keycodes[key_num]; + key_val = keycode[key_num]; input_event(input, EV_MSC, MSC_SCAN, key_num); input_report_key(input, key_val, pressed); @@ -196,23 +197,46 @@ static int mpr_touchkey_probe(struct i2c_client *client, { const struct mpr121_platform_data *pdata = dev_get_platdata(&client->dev); + struct device *dev = &client->dev; + unsigned int keymap_size; + struct matrix_keymap_data *keymap_data; struct mpr121_touchkey *mpr121; struct input_dev *input_dev; int error; int i; - if (!pdata) { - dev_err(&client->dev, "no platform data defined\n"); - return -EINVAL; - } + if (pdata) { + uint32_t *keymap; - if (!pdata->keymap || !pdata->keymap_size) { - dev_err(&client->dev, "missing keymap data\n"); - return -EINVAL; - } + if (!pdata->keymap || !pdata->keymap_size) { + dev_err(dev, "missing keymap data\n"); + return -EINVAL; + } + + if (pdata->keymap_size > MPR121_MAX_KEY_COUNT) { + dev_err(dev, "too many keys defined\n"); + return -EINVAL; + } + + keymap_size = pdata->keymap_size; + + keymap = devm_kcalloc(dev, keymap_size, + sizeof(keymap_data->keymap[0]), GFP_KERNEL); + if (!keymap) + return -ENOMEM; - if (pdata->keymap_size > MPR121_MAX_KEY_COUNT) { - dev_err(&client->dev, "too many keys defined\n"); + for (i = 0; i < keymap_size; i++) + keymap[i] = KEY(0, i, pdata->keymap[i]); + + keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), + GFP_KERNEL); + if (!keymap_data) + return -ENOMEM; + + keymap_data->keymap_size = keymap_size; + keymap_data->keymap = keymap; + } else { + dev_err(&client->dev, "no platform data defined\n"); return -EINVAL; } @@ -232,22 +256,18 @@ static int mpr_touchkey_probe(struct i2c_client *client, mpr121->client = client; mpr121->input_dev = input_dev; - mpr121->keycount = pdata->keymap_size; + mpr121->keycount = keymap_size; input_dev->name = "Freescale MPR121 Touchkey"; input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = &client->dev; - input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); + input_dev->evbit[0] = BIT_MASK(EV_REP); input_set_capability(input_dev, EV_MSC, MSC_SCAN); - input_dev->keycode = mpr121->keycodes; - input_dev->keycodesize = sizeof(mpr121->keycodes[0]); - input_dev->keycodemax = mpr121->keycount; - - for (i = 0; i < pdata->keymap_size; i++) { - input_set_capability(input_dev, EV_KEY, pdata->keymap[i]); - mpr121->keycodes[i] = pdata->keymap[i]; - } + error = matrix_keypad_build_keymap(keymap_data, NULL, 1, keymap_size, + NULL, input_dev); + if (error) + return error; error = mpr121_phys_init(pdata, mpr121, client); if (error) {