From patchwork Fri Jan 6 11:41:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 9500777 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 48B2A606B4 for ; Fri, 6 Jan 2017 11:42:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 319A5283D4 for ; Fri, 6 Jan 2017 11:42:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26015283F4; Fri, 6 Jan 2017 11:42:02 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 77427283F9 for ; Fri, 6 Jan 2017 11:42:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cPSuF-0000bm-0L; Fri, 06 Jan 2017 11:41:59 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cPSu0-0000JZ-PT for linux-arm-kernel@lists.infradead.org; Fri, 06 Jan 2017 11:41:47 +0000 Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OJC02SCOWGXZ330@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Fri, 06 Jan 2017 20:41:21 +0900 (KST) Received: from epsmges5p4.samsung.com (unknown [182.195.40.65]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20170106114121epcas1p345952acc1a03cdc95469deff26c30785~XK_jVkY3T0602606026epcas1p3q; Fri, 6 Jan 2017 11:41:21 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p4.samsung.com (EPCPMTA) with SMTP id 57.DB.06849.1628F685; Fri, 6 Jan 2017 20:41:21 +0900 (KST) Received: from epcpsbgm2new.samsung.com (u27.gpu120.samsung.co.kr [203.254.230.27]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20170106114120epcas5p26f09370d63026c8fbb64df049d2e2cfd~XK_jGDskY2545825458epcas5p2k; Fri, 6 Jan 2017 11:41:20 +0000 (GMT) X-AuditID: b6c32a58-f79726d000001ac1-6f-586f82616c44 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 52.BE.28332.0628F685; Fri, 6 Jan 2017 20:41:20 +0900 (KST) Received: from gangnam.samsung ([10.113.62.47]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OJC009W6WGS7Y30@mmp2.samsung.com>; Fri, 06 Jan 2017 20:41:20 +0900 (KST) From: Andi Shyti To: Dmitry Torokhov , Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , Kukjin Kim , Krzysztof Kozlowski , Javier Martinez Canillas , Chanwoo Choi , Beomho Seo Subject: [PATCH v4 4/5] input: tm2-touchkey: Add touchkey driver support for TM2 Date: Fri, 06 Jan 2017 20:41:13 +0900 Message-id: <20170106114114.19321-5-andi.shyti@samsung.com> X-Mailer: git-send-email 2.11.0 In-reply-to: <20170106114114.19321-1-andi.shyti@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSeUwTQRTGnd12u6A1mwI6wQ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/1UhLeAPLhOEWnv0HxgK9k58DAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRmVeSWpSXmKPExsVy+t9jQd2EpvwIgy8PLC22H3nGarH4x3Mm i9OftrFbvF/Ww2hx/ctzVov5R86xWhxe9ILR4vjKWcwWb96uYbJ4u7+b2aL/8Wtmi/PnN7Bb bHp8jdXi5qdvrBaXd81hs5hxfh+TxdLrF5ksWvceYbd4+fEEi4Owx5p5axg9ri/5xOyxc9Zd do9NqzrZPDYvqffY0g/k9W1ZxejxeZNcAEeUm01GamJKapFCal5yfkpmXrqtUmiIm66FkkJe Ym6qrVKErm9IkJJCWWJOKZBnZIAGHJwD3IOV9O0S3DJOvnjAVvAjoOLDhW7mBsZmly5GTg4J AROJ5X8vs0HYYhIX7q0Hs4UEZjFK/J5f08XIBWR/ZJRY1fCACSTBJqAp0XT7BxtIQkRgErNE 8+VeRpAEs8A2JomO51ogtrBAgMTfr3fAGlgEVCWO3D/CDmLzClhLPLh/kB1im7zErraLrCA2 p4CNxNtl/UwQm60llj3ayTqBkXcBI8MqRonUguSC4qT0XKO81HK94sTc4tK8dL3k/NxNjOBI eya9g/HwLvdDjAIcjEo8vBFeeRFCrIllxZW5hxglOJiVRHiTGvIjhHhTEiurUovy44tKc1KL DzGaAh02kVlKNDkfmATySuINTcxNzI0NLMwtLU2MlMR5G2c/CxcSSE8sSc1OTS1ILYLpY+Lg lGpg7PA1aTvtvnLPay87wR3nvkTM+d216KfExe1hiZPf3DvJ1JugeH5fq9K8oOwrlQInlv+6 72TaLPLpTmTsKhG9A+9fO9cd/Mdw/Vmhpe2kFf/ifPdubZ4plz5hxiGxDQnMq6p+LfBTq4m1 PaM77difaZvkHfLKj7M8veV+54SS5Dpn45PC7PKr3ZVYijMSDbWYi4oTAblA2nbKAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170106114120epcas5p26f09370d63026c8fbb64df049d2e2cfd X-Msg-Generator: CA X-Sender-IP: 203.254.230.27 X-Local-Sender: =?UTF-8?B?7JWI65SUG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLzthLAp?= =?UTF-8?B?G+yCvOyEseyghOyekBvssYXsnoQ=?= X-Global-Sender: =?UTF-8?B?QW5kaSBTaHl0aRtUaXplbiBQbGF0Zm9ybSBMYWIuG1NhbXN1?= =?UTF-8?B?bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG1NUQUYbQzEwVjgxMTE=?= CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-HopCount: 7 X-CMS-RootMailID: 20170106114120epcas5p26f09370d63026c8fbb64df049d2e2cfd X-RootMTR: 20170106114120epcas5p26f09370d63026c8fbb64df049d2e2cfd References: <20170106114114.19321-1-andi.shyti@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170106_034145_128433_FC71B11E X-CRM114-Status: GOOD ( 26.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Jaechul Lee , linux-kernel@vger.kernel.org, Andi Shyti , Andi Shyti , linux-input@vger.kernel.org, Jaechul Lee , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jaechul Lee 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 Signed-off-by: Andi Shyti Acked-by: Krzysztof Kozlowski --- drivers/input/keyboard/Kconfig | 11 ++ drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/tm2-touchkey.c | 280 ++++++++++++++++++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 drivers/input/keyboard/tm2-touchkey.c diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index cbd75cf44739..e6e98585b4b0 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 d9f4cfcf3410..7d9acff819a7 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 000000000000..92eacb62f8e7 --- /dev/null +++ b/drivers/input/keyboard/tm2-touchkey.c @@ -0,0 +1,280 @@ +/* + * 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, +}; + +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[1].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[0].supply = "vcc"; + touchkey->regulators[1].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 = "samsung,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");