Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp397678imu; Fri, 7 Dec 2018 02:59:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/W+7jGrCBs+hFHwLcZPtNaD9+AttODbrj2KHveXsDGgYJq/CoKi7VgAptVXp4Mbkzv+ukyJ X-Received: by 2002:a62:7f94:: with SMTP id a142mr1785654pfd.96.1544180395525; Fri, 07 Dec 2018 02:59:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544180395; cv=none; d=google.com; s=arc-20160816; b=G15GVqRHwneIqDAPhmx4w6iqwqvf7XNNGDIzNtu6xme6cnpFZsKDBNdq6F4O2Mnwcm 4rWnsKmtNdlmUr++thifbJ/dCNd1ir87wGR1yI8qsRMPXUyq2L/Lie7R4HXbF6qkT542 Wuf1BHa64ULJZxjYfCgRUjMkeW9XSOLc7g1Js40tzioEpzrdcaXWKKfWSt/lI8sQrSan kQ4w7Ohy1W/sUI9aEJBCcej67bksymUNLG41had1Mf7SYnZmvyW9YEB/daIEysoL0hso WpI76+OTvEy+PSkQNP/nKlKuFMgz1L40lDxy6eXIFU6btoCFebiqv5KWXoM/b8bZ3h42 YZeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=knG6SyfDCGJn7gk77p8M/RfgY6AhBS/jOJor+ETKwuw=; b=mqY4NzzTq/Jc7SLMrBCWY8jr5wK/AEYyP6479EM8qL/Qoa7BpJ9FCTsJ7JMo6RO/U0 ROS03aD/C9OaVOoE3I0Kg9t17YEP8YtQ234cJaJTZUeaSHUu/6VQ+9jECj9Q2gifN4X1 vtAFjBEoRLnwxVUkIeud9QOQoDL4wjtkGpPsotctwSUVrwSBfeRleWqsdBI9C4sBDQ/i ilFslMl8jG9LuWqsJVk79wWTzOjNrHsZzFWEucwRX/5SczC29oPpHQQ/7OWiCSQUTNlm 30I0ljs0aokI9vN6k3hShX8gxOfgbKh99Q95oly1A685bvgvBF2b9VJg15V2iY3XbQdR Vu+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="uis4/8d3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 123si2901743pfx.109.2018.12.07.02.59.40; Fri, 07 Dec 2018 02:59:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="uis4/8d3"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726127AbeLGK6b (ORCPT + 99 others); Fri, 7 Dec 2018 05:58:31 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:32845 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbeLGK6a (ORCPT ); Fri, 7 Dec 2018 05:58:30 -0500 Received: by mail-lj1-f195.google.com with SMTP id v1-v6so3215272ljd.0; Fri, 07 Dec 2018 02:58:27 -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 :mime-version:content-transfer-encoding; bh=knG6SyfDCGJn7gk77p8M/RfgY6AhBS/jOJor+ETKwuw=; b=uis4/8d3PSYf/KxJPBFPuq9zQk3n9I1r43bfgu34jnZp3cClc8v7T0hFu/ZmO74kCG +z2odhEXVfiUA//0yijq0pqdjlX82wEGazAVERPdykzpT6cjeo2C3ZAu5e1TgC8w90K/ yl+1zI7nmr04kclTC1N4IHQLhTnucirn6ogWZgWYaH9zfoCom0vFodXEGrSP4mSt/e/8 wN56qiGqB/Q0k8eTsbZMM5gGl6qYbQoxg9g2YPs2c9ZEwrVP7k6xEldGNrKnc+O3+vOZ tF7bgt4vm4XOC9zWhkZqXtuSAeTekWtYSp9D10x6Az0eDFe9dpmWN/2OMGbKnFp6UPIw Xbhg== 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:mime-version:content-transfer-encoding; bh=knG6SyfDCGJn7gk77p8M/RfgY6AhBS/jOJor+ETKwuw=; b=JD3uRaMdnuk84MaRZ0R85kJ9lwXPieCmDdiZsBwmA4zI2UdRdQMQQIEqoGHQbJx90j uK5SBJAxJGpaaWWBHNOiiEwpixQQiyNwiXhSOjMrL0u0x/IxunhGPFGPTuDJNviLzTa7 BPfP1s1WqBpsePLLhnyw1H0Wc4vfjTYVoqEnZJ3n85XAt5x0kbo5JVgskeeQcMPmCyWk XNwwKGHA7EpK7b3Ycs00+mZX2Gtc9hQK0F5pecd9KQDq/idFyQUp/ADexl8tAUjnxNyC fBNO0bCqpkYUzKhv33JbF21JBqfsOl/KUyqgsTZOngnQl1PTvv8j+QhDidjEknZc5OLb N2/g== X-Gm-Message-State: AA+aEWZ1Lb3e/aiXiL0zZCUqVXm8HnBsKqh5vPT2h/x/+oEtf32TNWNU NtZTqjckPb6I+aA/S1cXOFk= X-Received: by 2002:a2e:9356:: with SMTP id m22-v6mr1048761ljh.135.1544180306549; Fri, 07 Dec 2018 02:58:26 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:74d5:51ba:2673:f3f4]) by smtp.googlemail.com with ESMTPSA id a20-v6sm523362ljf.28.2018.12.07.02.58.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Dec 2018 02:58:25 -0800 (PST) From: =?UTF-8?q?Pawe=C5=82=20Chmiel?= To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com Cc: devicetree@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, pawel.mikolaj.chmiel@gmail.com, xc-racer2@live.ca, simon@lineageos.org Subject: [PATCH 5/8] Input: tm2-touchkey: Allow specifying custom keycodes Date: Fri, 7 Dec 2018 11:58:08 +0100 Message-Id: <20181207105811.1831-6-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181207105811.1831-1-pawel.mikolaj.chmiel@gmail.com> References: <20181207105811.1831-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Bakker Not all devices use the same keycodes in the same order Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/keyboard/tm2-touchkey.c | 49 +++++++++++++++------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c index a73894b8dede..ebc275ab8ad1 100644 --- a/drivers/input/keyboard/tm2-touchkey.c +++ b/drivers/input/keyboard/tm2-touchkey.c @@ -36,11 +36,6 @@ #define TM2_TOUCHKEY_LED_VOLTAGE_MIN 2500000 #define TM2_TOUCHKEY_LED_VOLTAGE_MAX 3300000 -enum { - TM2_TOUCHKEY_KEY_MENU = 0x1, - TM2_TOUCHKEY_KEY_BACK, -}; - struct touchkey_variant { const char *name; u8 keycode_reg; @@ -54,6 +49,8 @@ struct tm2_touchkey_data { struct regulator *vdd; struct regulator_bulk_data regulators[2]; struct touchkey_variant *variant; + u8 keycodes[4]; + int num_keycodes; }; static struct touchkey_variant tm2_touchkey_variant = { @@ -116,7 +113,8 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) { struct tm2_touchkey_data *touchkey = devid; int data; - int key; + int index; + int i; data = i2c_smbus_read_byte_data(touchkey->client, touchkey->variant->keycode_reg); @@ -126,26 +124,20 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) goto out; } - switch (data & TM2_TOUCHKEY_BIT_KEYCODE) { - case TM2_TOUCHKEY_KEY_MENU: - key = KEY_PHONE; - break; - - case TM2_TOUCHKEY_KEY_BACK: - key = KEY_BACK; - break; - - default: + index = (data & TM2_TOUCHKEY_BIT_KEYCODE) - 1; + if (index < 0 || index >= touchkey->num_keycodes) { dev_warn(&touchkey->client->dev, - "unhandled keycode, data %#02x\n", data); + "invalid keycode index %d\n", index); goto out; } if (data & TM2_TOUCHKEY_BIT_PRESS_EV) { - input_report_key(touchkey->input_dev, KEY_PHONE, 0); - input_report_key(touchkey->input_dev, KEY_BACK, 0); + for (i = 0; i < touchkey->num_keycodes; i++) + input_report_key(touchkey->input_dev, + touchkey->keycodes[i], 0); } else { - input_report_key(touchkey->input_dev, key, 1); + input_report_key(touchkey->input_dev, + touchkey->keycodes[index], 1); } input_sync(touchkey->input_dev); @@ -157,8 +149,10 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) static int tm2_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device_node *np = client->dev.of_node; struct tm2_touchkey_data *touchkey; int error; + int i; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA)) { @@ -189,6 +183,16 @@ static int tm2_touchkey_probe(struct i2c_client *client, /* Save VDD for easy access */ touchkey->vdd = touchkey->regulators[1].consumer; + touchkey->num_keycodes = of_property_read_variable_u8_array(np, + "keycodes", touchkey->keycodes, 0, + ARRAY_SIZE(touchkey->keycodes)); + if (touchkey->num_keycodes <= 0) { + /* default keycodes */ + touchkey->keycodes[0] = KEY_PHONE; + touchkey->keycodes[1] = KEY_BACK; + touchkey->num_keycodes = 2; + } + error = tm2_touchkey_power_enable(touchkey); if (error) { dev_err(&client->dev, "failed to power up device: %d\n", error); @@ -213,8 +217,9 @@ static int tm2_touchkey_probe(struct i2c_client *client, touchkey->input_dev->name = touchkey->variant->name; touchkey->input_dev->id.bustype = BUS_I2C; - input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE); - input_set_capability(touchkey->input_dev, EV_KEY, KEY_BACK); + for (i = 0; i < touchkey->num_keycodes; i++) + input_set_capability(touchkey->input_dev, EV_KEY, + touchkey->keycodes[i]); error = input_register_device(touchkey->input_dev); if (error) { -- 2.17.1