From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761824AbdAIHaC (ORCPT ); Mon, 9 Jan 2017 02:30:02 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:55428 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752021AbdAIH36 (ORCPT ); Mon, 9 Jan 2017 02:29:58 -0500 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 X-AuditID: b6c32a59-f79c56d000006d2c-c4-58733bf387a6 Content-transfer-encoding: 8BIT Message-id: <58733BF2.7040304@samsung.com> Date: Mon, 09 Jan 2017 16:29:54 +0900 From: Chanwoo Choi Organization: Samsung Electronics User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: Jaechul Lee , Dmitry Torokhov , Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , Kukjin Kim , Krzysztof Kozlowski , Javier Martinez Canillas Cc: Andi Shyti , beomho.seo@samsung.com, galaxyra@gmail.com, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: Re: [PATCH v6 2/3] input: tm2-touchkey: Add touchkey driver support for TM2 In-reply-to: <1483946535-4703-3-git-send-email-jcsing.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHJsWRmVeSWpSXmKPExsWy7bCmlu5n6+IIg1e3DS22H3nGanH60zZ2 i/fLehgt5h85x2pxeNELRovjK2cxW7x5u4bJ4u3+bmaL/sevmS3On9/AbrHp8TVWi5ufvrFa XN41h81ixvl9TBZLr19ksmjde4Td4uXHEywOgh5r5q1h9Ng56y67x6ZVnWwem5fUe2zpB/L6 tqxi9Pi8SS6APSrVJiM1MSW1SCE1Lzk/JTMv3VbJOzjeOd7UzMBQ19DSwlxJIS8xN9VWycUn QNctMwf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yWbTuPcJu8fLjCRYHQY8189YweuycdZfdY9OqTjaPzUvqPbb0A3l9 W1YxenzeJBfAHuVmk5GamJJapJCal5yfkpmXbqsUGuKma6GkkJeYm2qrFKHrGxKkpFCWmFMK 5BkZoAEH5wD3YCV9uwS3jC3T17IVtERWHDv+krmB8YtHFyMnh4SAicT81hZGCFtM4sK99Wxd jFwcQgJLGSVmLnnFCpLgFRCU+DH5HksXIwcHs4C8xJFL2SBhZgF1iUnzFjFD1D9glGj/dhqq Xkuio2sD2FAWAVWJRXeuM4PYbEDx/S9usIHY/AKKEld/PGYEmSkqECHRfaISZI6IwFsmicZb DUwgDrPAT0aJlZsesYM0CAuESVz43cQCse0qo8SDzv9gCU4BN4kfLV0sExgFZyE5dhbCsbOQ HLuAkXkVo0RqQXJBcVJ6rlFearlecWJucWleul5yfu4mRnDMP5PewXh4l/shRgEORiUe3orT RRFCrIllxZW5hxglOJiVRHh3mhVHCPGmJFZWpRblxxeV5qQWH2I0Bfp2IrOUaHI+MB3llcQb mpibmBsbWJhbWpoYKYnzNs5+Fi4kkJ5YkpqdmlqQWgTTx8TBKdXAuMhjw604D1v2d7Uzl/K4 6smZsivE/d49r/DCRWHZZzd4ORsenD9r4tGczXCrJ6zi7qF6xxhewW33znvtEjbe+Ebp9bGi Z1yv/q16O7O8Y1bsyahn/v/PhJUxKv9S4w/9qFJy2j2okdE682DqsdDDSxqemb567poSyXZP eFbzt9wg059h8+dPUWIpzkg01GIuKk4EALnUnFcPAwAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170109072955epcas5p2f7ace86574f59aacc7505870ba0c5a77 X-Msg-Generator: CA X-Sender-IP: 203.254.230.27 X-Local-Sender: =?UTF-8?B?7LWc7LCs7JqwG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLw=?= =?UTF-8?B?7YSwKRvsgrzshLHsoITsnpAbUzUo7LGF7J6EKS9DaGFuZ2UgQWdlbnQ=?= X-Global-Sender: =?UTF-8?B?Q2hhbndvbyBDaG9pG1RpemVuIFBsYXRmb3JtIExhYi4bU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtTNS9TZW5pb3IgRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG1NUQUYbQzEwVjgxMTE=?= CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-HopCount: 7 X-CMS-RootMailID: 20170109072218epcas1p1f95be49f7f466712c146d1e9163601e1 X-RootMTR: 20170109072218epcas1p1f95be49f7f466712c146d1e9163601e1 References: <1483946535-4703-1-git-send-email-jcsing.lee@samsung.com> <1483946535-4703-3-git-send-email-jcsing.lee@samsung.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jaechul, Looks good to me. I tested this patch on TM2 board. It is well working. Reviewed-by: Chanwoo Choi Tested-by: Chanwoo Choi Best Regards, Chanwoo Choi On 2017년 01월 09일 16:22, Jaechul Lee wrote: > This patch adds support for the TM2 touch key and led > functionality. > > The driver interfaces with userspace through an input device and > reports KEY_PHONE and KEY_BACK event types. LED brightness can be > controlled by "/sys/class/leds/tm2-touchkey/brightness". > > Signed-off-by: Beomho Seo > Signed-off-by: Jaechul Lee > Reviewed-by: Javier Martinez Canillas > Reviewed-by: Andi Shyti > Acked-by: Krzysztof Kozlowski > --- > drivers/input/keyboard/Kconfig | 11 ++ > drivers/input/keyboard/Makefile | 1 + > drivers/input/keyboard/tm2-touchkey.c | 287 ++++++++++++++++++++++++++++++++++ > 3 files changed, 299 insertions(+) > create mode 100644 drivers/input/keyboard/tm2-touchkey.c > > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig > index cbd75cf..97acd65 100644 > --- a/drivers/input/keyboard/Kconfig > +++ b/drivers/input/keyboard/Kconfig > @@ -666,6 +666,17 @@ config KEYBOARD_TC3589X > To compile this driver as a module, choose M here: the > module will be called tc3589x-keypad. > > +config KEYBOARD_TM2_TOUCHKEY > + tristate "TM2 touchkey support" > + depends on I2C > + depends on LEDS_CLASS > + help > + Say Y here to enable device driver for tm2-touchkey with > + LED control for the Exynos5433 TM2 board. > + > + To compile this driver as a module, choose M here. > + module will be called tm2-touchkey. > + > config KEYBOARD_TWL4030 > tristate "TI TWL4030/TWL5030/TPS659x0 keypad support" > depends on TWL4030_CORE > diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile > index d9f4cfc..7d9acff 100644 > --- a/drivers/input/keyboard/Makefile > +++ b/drivers/input/keyboard/Makefile > @@ -61,6 +61,7 @@ obj-$(CONFIG_KEYBOARD_SUN4I_LRADC) += sun4i-lradc-keys.o > obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o > obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o > obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o > +obj-$(CONFIG_KEYBOARD_TM2_TOUCHKEY) += tm2-touchkey.o > obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o > obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o > obj-$(CONFIG_KEYBOARD_W90P910) += w90p910_keypad.o > diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c > new file mode 100644 > index 0000000..e927d06 > --- /dev/null > +++ b/drivers/input/keyboard/tm2-touchkey.c > @@ -0,0 +1,287 @@ > +/* > + * TM2 touchkey device driver > + * > + * Copyright 2005 Phil Blundell > + * Copyright 2016 Samsung Electronics Co., Ltd. > + * > + * Author: Beomho Seo > + * Author: Jaechul Lee > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey" > +#define TM2_TOUCHKEY_KEYCODE_REG 0x03 > +#define TM2_TOUCHKEY_BASE_REG 0x00 > +#define TM2_TOUCHKEY_CMD_LED_ON 0x10 > +#define TM2_TOUCHKEY_CMD_LED_OFF 0x20 > +#define TM2_TOUCHKEY_BIT_PRESS_EV BIT(3) > +#define TM2_TOUCHKEY_BIT_KEYCODE GENMASK(2, 0) > +#define TM2_TOUCHKEY_LED_VOLTAGE_MIN 2500000 > +#define TM2_TOUCHKEY_LED_VOLTAGE_MAX 3300000 > + > +enum { > + TM2_TOUCHKEY_KEY_MENU = 0x1, > + TM2_TOUCHKEY_KEY_BACK, > +}; > + > +enum { > + TM2_TOUCHKEY_SUPPLIES_VCC, > + TM2_TOUCHKEY_SUPPLIES_VDD, > +}; > + > +struct tm2_touchkey_data { > + struct i2c_client *client; > + struct input_dev *input_dev; > + struct led_classdev led_dev; > + struct regulator_bulk_data regulators[2]; > + > + u8 keycode_type; > + u8 pressed; > +}; > + > +static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev, > + enum led_brightness brightness) > +{ > + struct tm2_touchkey_data *touchkey = > + container_of(led_dev, struct tm2_touchkey_data, led_dev); > + u32 volt; > + u8 data; > + > + if (brightness == LED_OFF) { > + volt = TM2_TOUCHKEY_LED_VOLTAGE_MIN; > + data = TM2_TOUCHKEY_CMD_LED_OFF; > + } else { > + volt = TM2_TOUCHKEY_LED_VOLTAGE_MAX; > + data = TM2_TOUCHKEY_CMD_LED_ON; > + } > + > + regulator_set_voltage( > + touchkey->regulators[TM2_TOUCHKEY_SUPPLIES_VDD].consumer, > + volt, volt); > + i2c_smbus_write_byte_data(touchkey->client, > + TM2_TOUCHKEY_BASE_REG, data); > +} > + > +static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey) > +{ > + int ret = 0; > + > + ret = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators), > + touchkey->regulators); > + if (ret) > + return ret; > + > + /* waiting for device initialization, at least 150ms */ > + msleep(150); > + > + return 0; > +} > + > +static void tm2_touchkey_power_disable(void *data) > +{ > + struct tm2_touchkey_data *touchkey = data; > + > + regulator_bulk_disable(ARRAY_SIZE(touchkey->regulators), > + touchkey->regulators); > +} > + > +static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) > +{ > + struct tm2_touchkey_data *touchkey = devid; > + u32 data; > + > + data = i2c_smbus_read_byte_data(touchkey->client, > + TM2_TOUCHKEY_KEYCODE_REG); > + > + if (data < 0) { > + dev_err(&touchkey->client->dev, "Failed to read i2c data\n"); > + return IRQ_HANDLED; > + } > + > + touchkey->keycode_type = data & TM2_TOUCHKEY_BIT_KEYCODE; > + touchkey->pressed = !(data & TM2_TOUCHKEY_BIT_PRESS_EV); > + > + if (touchkey->keycode_type != TM2_TOUCHKEY_KEY_MENU && > + touchkey->keycode_type != TM2_TOUCHKEY_KEY_BACK) { > + dev_warn(&touchkey->client->dev, "Skip unhandled keycode(%d)\n", > + touchkey->keycode_type); > + return IRQ_HANDLED; > + } > + > + if (!touchkey->pressed) { > + input_report_key(touchkey->input_dev, KEY_PHONE, 0); > + input_report_key(touchkey->input_dev, KEY_BACK, 0); > + } else { > + if (touchkey->keycode_type == TM2_TOUCHKEY_KEY_MENU) > + input_report_key(touchkey->input_dev, > + KEY_PHONE, 1); > + else > + input_report_key(touchkey->input_dev, > + KEY_BACK, 1); > + } > + input_sync(touchkey->input_dev); > + > + return IRQ_HANDLED; > +} > + > +static int tm2_touchkey_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + struct tm2_touchkey_data *touchkey; > + int ret; > + > + ret = i2c_check_functionality(client->adapter, > + I2C_FUNC_SMBUS_BYTE | > + I2C_FUNC_SMBUS_BYTE_DATA); > + if (!ret) { > + dev_err(&client->dev, "No I2C functionality found\n"); > + return -ENODEV; > + } > + > + touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL); > + if (!touchkey) > + return -ENOMEM; > + > + touchkey->client = client; > + i2c_set_clientdata(client, touchkey); > + > + /* regulators */ > + touchkey->regulators[TM2_TOUCHKEY_SUPPLIES_VCC].supply = "vcc"; > + touchkey->regulators[TM2_TOUCHKEY_SUPPLIES_VDD].supply = "vdd"; > + ret = devm_regulator_bulk_get(&client->dev, > + ARRAY_SIZE(touchkey->regulators), > + touchkey->regulators); > + if (ret) { > + dev_err(&client->dev, "Failed to get regulators\n"); > + return ret; > + } > + > + /* power */ > + ret = tm2_touchkey_power_enable(touchkey); > + if (ret) { > + dev_err(&client->dev, "Failed to enable power\n"); > + return ret; > + } > + > + ret = devm_add_action_or_reset(&client->dev, > + tm2_touchkey_power_disable, touchkey); > + if (ret) > + return ret; > + > + /* input device */ > + touchkey->input_dev = devm_input_allocate_device(&client->dev); > + if (!touchkey->input_dev) { > + dev_err(&client->dev, "Failed to alloc input device\n"); > + return -ENOMEM; > + } > + touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME; > + touchkey->input_dev->id.bustype = BUS_I2C; > + > + set_bit(EV_KEY, touchkey->input_dev->evbit); > + input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE); > + input_set_capability(touchkey->input_dev, EV_KEY, KEY_BACK); > + > + input_set_drvdata(touchkey->input_dev, touchkey); > + > + ret = input_register_device(touchkey->input_dev); > + if (ret) { > + dev_err(&client->dev, "Failed to register input device\n"); > + return ret; > + } > + > + /* irq */ > + ret = devm_request_threaded_irq(&client->dev, > + client->irq, NULL, > + tm2_touchkey_irq_handler, > + IRQF_ONESHOT, TM2_TOUCHKEY_DEV_NAME, > + touchkey); > + if (ret) { > + dev_err(&client->dev, "Failed to request threaded irq\n"); > + return ret; > + } > + > + /* led device */ > + touchkey->led_dev.name = TM2_TOUCHKEY_DEV_NAME; > + touchkey->led_dev.brightness = LED_FULL; > + touchkey->led_dev.max_brightness = LED_FULL; > + touchkey->led_dev.brightness_set = tm2_touchkey_led_brightness_set; > + > + ret = devm_led_classdev_register(&client->dev, &touchkey->led_dev); > + if (ret < 0) { > + dev_err(&client->dev, "Failed to register touchkey led\n"); > + return ret; > + } > + > + return 0; > +} > + > +static int __maybe_unused tm2_touchkey_suspend(struct device *dev) > +{ > + struct tm2_touchkey_data *touchkey = dev_get_drvdata(dev); > + > + disable_irq(touchkey->client->irq); > + tm2_touchkey_power_disable(touchkey); > + > + return 0; > +} > + > +static int __maybe_unused tm2_touchkey_resume(struct device *dev) > +{ > + struct tm2_touchkey_data *touchkey = dev_get_drvdata(dev); > + int ret; > + > + enable_irq(touchkey->client->irq); > + ret = tm2_touchkey_power_enable(touchkey); > + if (ret) > + dev_err(dev, "Failed to enable power\n"); > + > + return ret; > +} > + > +static SIMPLE_DEV_PM_OPS(tm2_touchkey_pm_ops, tm2_touchkey_suspend, > + tm2_touchkey_resume); > + > +static const struct i2c_device_id tm2_touchkey_id_table[] = { > + {TM2_TOUCHKEY_DEV_NAME, 0}, > + {}, > +}; > +MODULE_DEVICE_TABLE(i2c, tm2_touchkey_id_table); > + > +static const struct of_device_id tm2_touchkey_of_match[] = { > + {.compatible = "cypress,tm2-touchkey",}, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, tm2_touchkey_of_match); > + > +static struct i2c_driver tm2_touchkey_driver = { > + .driver = { > + .name = TM2_TOUCHKEY_DEV_NAME, > + .pm = &tm2_touchkey_pm_ops, > + .of_match_table = of_match_ptr(tm2_touchkey_of_match), > + }, > + .probe = tm2_touchkey_probe, > + .id_table = tm2_touchkey_id_table, > +}; > + > +module_i2c_driver(tm2_touchkey_driver); > + > +MODULE_AUTHOR("Beomho Seo "); > +MODULE_AUTHOR("Jaechul Lee "); > +MODULE_DESCRIPTION("Samsung touchkey driver"); > +MODULE_LICENSE("GPL v2"); >