From de901cc31d151c4c855346c29fb61eaf5ffac3ad Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Sun, 15 Jan 2017 14:51:12 -0800 Subject: Input: mpr121 - switch to device tree probe This driver currently only supports legacy platform data probe. This change adds device tree support and gets rid of platform data probe code since no one is actually using mpr121 platform data in the mainline. The device tree property parsing code is based on the work of atmel_captouch driver. Signed-off-by: Akinobu Mita Signed-off-by: Dmitry Torokhov --- .../devicetree/bindings/input/mpr121-touchkey.txt | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/mpr121-touchkey.txt (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/input/mpr121-touchkey.txt b/Documentation/devicetree/bindings/input/mpr121-touchkey.txt new file mode 100644 index 000000000000..b7c61ee5841b --- /dev/null +++ b/Documentation/devicetree/bindings/input/mpr121-touchkey.txt @@ -0,0 +1,30 @@ +* Freescale MPR121 Controllor + +Required Properties: +- compatible: Should be "fsl,mpr121-touchkey" +- reg: The I2C slave address of the device. +- interrupts: The interrupt number to the cpu. +- vdd-supply: Phandle to the Vdd power supply. +- linux,keycodes: Specifies an array of numeric keycode values to + be used for reporting button presses. The array can + contain up to 12 entries. + +Optional Properties: +- wakeup-source: Use any event on keypad as wakeup event. +- autorepeat: Enable autorepeat feature. + +Example: + +#include "dt-bindings/input/input.h" + + touchkey: mpr121@5a { + compatible = "fsl,mpr121-touchkey"; + reg = <0x5a>; + interrupt-parent = <&gpio1>; + interrupts = <28 2>; + autorepeat; + vdd-supply = <&ldo4_reg>; + linux,keycodes = , , , , + , , , + , , , ; + }; -- cgit v1.2.3 From 72d1f2346ded5b1743d7938f4522550b4da9c82d Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Wed, 18 Jan 2017 14:35:42 -0800 Subject: Input: tm2-touchkey - add touchkey driver support for TM2 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 Reviewed-by: Chanwoo Choi Tested-by: Chanwoo Choi Acked-by: Krzysztof Kozlowski Acked-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../bindings/input/cypress,tm2-touchkey.txt | 27 ++ drivers/input/keyboard/Kconfig | 11 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/tm2-touchkey.c | 286 +++++++++++++++++++++ 4 files changed, 325 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt create mode 100644 drivers/input/keyboard/tm2-touchkey.c (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt new file mode 100644 index 000000000000..635f62c756ee --- /dev/null +++ b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt @@ -0,0 +1,27 @@ +Samsung tm2-touchkey + +Required properties: +- compatible: must be "cypress,tm2-touchkey" +- reg: I2C address of the chip. +- interrupt-parent: a phandle for the interrupt controller (see interrupt + binding[0]). +- interrupts: interrupt to which the chip is connected (see interrupt + binding[0]). +- vcc-supply : internal regulator output. 1.8V +- vdd-supply : power supply for IC 3.3V + +[0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + +Example: + &i2c0 { + /* ... */ + + touchkey@20 { + compatible = "cypress,tm2-touchkey"; + reg = <0x20>; + interrupt-parent = <&gpa3>; + interrupts = <2 IRQ_TYPE_EDGE_FALLING>; + vcc-supply=<&ldo32_reg>; + vdd-supply=<&ldo33_reg>; + }; + }; diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index cbd75cf44739..97acd6524ad7 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..916e2f3a9bbb --- /dev/null +++ b/drivers/input/keyboard/tm2-touchkey.c @@ -0,0 +1,286 @@ +/* + * 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 *vdd; + struct regulator_bulk_data regulators[2]; +}; + +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->vdd, 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 error; + + error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators), + touchkey->regulators); + if (error) + return error; + + /* 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; + int data; + int key; + + 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: %d\n", data); + 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: + dev_warn(&touchkey->client->dev, + "unhandled keycode, data %#02x\n", data); + 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); + } else { + input_report_key(touchkey->input_dev, key, 1); + } + + input_sync(touchkey->input_dev); + +out: + return IRQ_HANDLED; +} + +static int tm2_touchkey_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct tm2_touchkey_data *touchkey; + int error; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA)) { + dev_err(&client->dev, "incompatible I2C adapter\n"); + return -EIO; + } + + touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL); + if (!touchkey) + return -ENOMEM; + + touchkey->client = client; + i2c_set_clientdata(client, touchkey); + + touchkey->regulators[0].supply = "vcc"; + touchkey->regulators[1].supply = "vdd"; + error = devm_regulator_bulk_get(&client->dev, + ARRAY_SIZE(touchkey->regulators), + touchkey->regulators); + if (error) { + dev_err(&client->dev, "failed to get regulators: %d\n", error); + return error; + } + + /* Save VDD for easy access */ + touchkey->vdd = touchkey->regulators[1].consumer; + + error = tm2_touchkey_power_enable(touchkey); + if (error) { + dev_err(&client->dev, "failed to power up device: %d\n", error); + return error; + } + + error = devm_add_action_or_reset(&client->dev, + tm2_touchkey_power_disable, touchkey); + if (error) { + dev_err(&client->dev, + "failed to install poweroff handler: %d\n", error); + return error; + } + + /* input device */ + touchkey->input_dev = devm_input_allocate_device(&client->dev); + if (!touchkey->input_dev) { + dev_err(&client->dev, "failed to allocate input device\n"); + return -ENOMEM; + } + + touchkey->input_dev->name = TM2_TOUCHKEY_DEV_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); + + input_set_drvdata(touchkey->input_dev, touchkey); + + error = input_register_device(touchkey->input_dev); + if (error) { + dev_err(&client->dev, + "failed to register input device: %d\n", error); + return error; + } + + error = devm_request_threaded_irq(&client->dev, client->irq, + NULL, tm2_touchkey_irq_handler, + IRQF_ONESHOT, + TM2_TOUCHKEY_DEV_NAME, touchkey); + if (error) { + dev_err(&client->dev, + "failed to request threaded irq: %d\n", error); + return error; + } + + /* 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; + + error = devm_led_classdev_register(&client->dev, &touchkey->led_dev); + if (error) { + dev_err(&client->dev, + "failed to register touchkey led: %d\n", error); + return error; + } + + return 0; +} + +static int __maybe_unused tm2_touchkey_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct tm2_touchkey_data *touchkey = i2c_get_clientdata(client); + + disable_irq(client->irq); + tm2_touchkey_power_disable(touchkey); + + return 0; +} + +static int __maybe_unused tm2_touchkey_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct tm2_touchkey_data *touchkey = i2c_get_clientdata(client); + int ret; + + enable_irq(client->irq); + + ret = tm2_touchkey_power_enable(touchkey); + if (ret) + dev_err(dev, "failed to enable power: %d\n", ret); + + 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"); -- cgit v1.2.3 From 9e54924432783bfb21e905e0bf7042556bcb4b90 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sun, 15 Jan 2017 17:09:43 -0800 Subject: Input: pwm-beeper - add optional amplifier regulator This adds an optional regulator to the pwm-beeper device. This regulator acts as an amplifier. The amplifier is only enabled while beeping in order to reduce power consumption. Tested on LEGO MINDSTORMS EV3, which has a speaker connected to PWM through an amplifier. Signed-off-by: David Lechner Acked-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../devicetree/bindings/input/pwm-beeper.txt | 16 ++++++ drivers/input/misc/pwm-beeper.c | 63 +++++++++++++++++----- 2 files changed, 66 insertions(+), 13 deletions(-) (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/input/pwm-beeper.txt b/Documentation/devicetree/bindings/input/pwm-beeper.txt index be332ae4f2d6..529408b4431a 100644 --- a/Documentation/devicetree/bindings/input/pwm-beeper.txt +++ b/Documentation/devicetree/bindings/input/pwm-beeper.txt @@ -5,3 +5,19 @@ Registers a PWM device as beeper. Required properties: - compatible: should be "pwm-beeper" - pwms: phandle to the physical PWM device + +Optional properties: +- amp-supply: phandle to a regulator that acts as an amplifier for the beeper + +Example: + +beeper_amp: amplifier { + compatible = "fixed-regulator"; + gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>; +}; + +beeper { + compatible = "pwm-beeper"; + pwms = <&pwm0>; + amp-supply = <&beeper_amp>; +}; diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 069d594554bd..ad9b231e8468 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -25,30 +26,59 @@ struct pwm_beeper { struct input_dev *input; struct pwm_device *pwm; + struct regulator *amplifier; struct work_struct work; unsigned long period; bool suspended; + bool amplifier_on; }; #define HZ_TO_NANOSECONDS(x) (1000000000UL/(x)) -static void __pwm_beeper_set(struct pwm_beeper *beeper) +static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period) { - unsigned long period = beeper->period; + int error; + + error = pwm_config(beeper->pwm, period / 2, period); + if (error) + return error; + + error = pwm_enable(beeper->pwm); + if (error) + return error; + + if (!beeper->amplifier_on) { + error = regulator_enable(beeper->amplifier); + if (error) { + pwm_disable(beeper->pwm); + return error; + } - if (period) { - pwm_config(beeper->pwm, period / 2, period); - pwm_enable(beeper->pwm); - } else - pwm_disable(beeper->pwm); + beeper->amplifier_on = true; + } + + return 0; +} + +static void pwm_beeper_off(struct pwm_beeper *beeper) +{ + if (beeper->amplifier_on) { + regulator_disable(beeper->amplifier); + beeper->amplifier_on = false; + } + + pwm_disable(beeper->pwm); } static void pwm_beeper_work(struct work_struct *work) { - struct pwm_beeper *beeper = - container_of(work, struct pwm_beeper, work); + struct pwm_beeper *beeper = container_of(work, struct pwm_beeper, work); + unsigned long period = READ_ONCE(beeper->period); - __pwm_beeper_set(beeper); + if (period) + pwm_beeper_on(beeper, period); + else + pwm_beeper_off(beeper); } static int pwm_beeper_event(struct input_dev *input, @@ -83,9 +113,7 @@ static int pwm_beeper_event(struct input_dev *input, static void pwm_beeper_stop(struct pwm_beeper *beeper) { cancel_work_sync(&beeper->work); - - if (beeper->period) - pwm_disable(beeper->pwm); + pwm_beeper_off(beeper); } static void pwm_beeper_close(struct input_dev *input) @@ -120,6 +148,15 @@ static int pwm_beeper_probe(struct platform_device *pdev) */ pwm_apply_args(beeper->pwm); + beeper->amplifier = devm_regulator_get(dev, "amp"); + if (IS_ERR(beeper->amplifier)) { + error = PTR_ERR(beeper->amplifier); + if (error != -EPROBE_DEFER) + dev_err(dev, "Failed to get 'amp' regulator: %d\n", + error); + return error; + } + INIT_WORK(&beeper->work, pwm_beeper_work); beeper->input = devm_input_allocate_device(dev); -- cgit v1.2.3 From 83f66a6f08fa4004d6fb9d50c57735067bbbb405 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sat, 14 Jan 2017 10:25:02 -0800 Subject: Input: add driver for Zeitec ZET6223 This is a basic driver for the Zeitec ZET6223 I2C touchscreen controllers. The driver does not support firmware loading, which is not required for all tablets which contain this chip. Signed-off-by: Jelle van der Waa Acked-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../bindings/input/touchscreen/zet6223.txt | 32 +++ .../devicetree/bindings/vendor-prefixes.txt | 1 + drivers/input/touchscreen/Kconfig | 11 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/zet6223.c | 267 +++++++++++++++++++++ 5 files changed, 312 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/zet6223.txt create mode 100644 drivers/input/touchscreen/zet6223.c (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/input/touchscreen/zet6223.txt b/Documentation/devicetree/bindings/input/touchscreen/zet6223.txt new file mode 100644 index 000000000000..fe6a1feef703 --- /dev/null +++ b/Documentation/devicetree/bindings/input/touchscreen/zet6223.txt @@ -0,0 +1,32 @@ +Zeitec ZET6223 I2C touchscreen controller + +Required properties: +- compatible : "zeitec,zet6223" +- reg : I2C slave address of the chip (0x76) +- interrupt-parent : a phandle pointing to the interrupt controller + serving the interrupt for this chip +- interrupts : interrupt specification for the zet6223 interrupt + +Optional properties: + +- vio-supply : Specification for VIO supply (1.8V or 3.3V, + depending on system interface needs). +- vcc-supply : Specification for 3.3V VCC supply. +- touchscreen-size-x : See touchscreen.txt +- touchscreen-size-y : See touchscreen.txt +- touchscreen-inverted-x : See touchscreen.txt +- touchscreen-inverted-y : See touchscreen.txt +- touchscreen-swapped-x-y : See touchscreen.txt + +Example: + +i2c@00000000 { + + zet6223: touchscreen@76 { + compatible = "zeitec,zet6223"; + reg = <0x76>; + interrupt-parent = <&pio>; + interrupts = <6 11 IRQ_TYPE_EDGE_FALLING> + }; + +}; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 16d3b5e7f5d1..e6f63f4a0d6d 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -329,6 +329,7 @@ xes Extreme Engineering Solutions (X-ES) xillybus Xillybus Ltd. xlnx Xilinx zarlink Zarlink Semiconductor +zeitec ZEITEC Semiconductor Co., LTD. zii Zodiac Inflight Innovations zte ZTE Corp. zyxel ZyXEL Communications Corp. diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 8650c94e29d0..033599777651 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1165,6 +1165,17 @@ config TOUCHSCREEN_TPS6507X To compile this driver as a module, choose M here: the module will be called tps6507x_ts. +config TOUCHSCREEN_ZET6223 + tristate "Zeitec ZET6223 touchscreen driver" + depends on I2C + help + Say Y here if you have a touchscreen using Zeitec ZET6223 + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called zet6223. + config TOUCHSCREEN_ZFORCE tristate "Neonode zForce infrared touchscreens" depends on I2C diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index e41e3c7aa427..b622e5344137 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -95,6 +95,7 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o obj-$(CONFIG_TOUCHSCREEN_SX8654) += sx8654.o obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o +obj-$(CONFIG_TOUCHSCREEN_ZET6223) += zet6223.o obj-$(CONFIG_TOUCHSCREEN_ZFORCE) += zforce_ts.o obj-$(CONFIG_TOUCHSCREEN_COLIBRI_VF50) += colibri-vf50-ts.o obj-$(CONFIG_TOUCHSCREEN_ROHM_BU21023) += rohm_bu21023.o diff --git a/drivers/input/touchscreen/zet6223.c b/drivers/input/touchscreen/zet6223.c new file mode 100644 index 000000000000..e7fb00b511ec --- /dev/null +++ b/drivers/input/touchscreen/zet6223.c @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2016, Jelle van der Waa + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ZET6223_MAX_FINGERS 16 +#define ZET6223_MAX_PKT_SIZE (3 + 4 * ZET6223_MAX_FINGERS) + +#define ZET6223_CMD_INFO 0xB2 +#define ZET6223_CMD_INFO_LENGTH 17 +#define ZET6223_VALID_PACKET 0x3c + +#define ZET6223_POWER_ON_DELAY_MSEC 30 + +struct zet6223_ts { + struct i2c_client *client; + struct input_dev *input; + struct regulator *vcc; + struct regulator *vio; + struct touchscreen_properties prop; + struct regulator_bulk_data supplies[2]; + u16 max_x; + u16 max_y; + u8 fingernum; +}; + +static int zet6223_start(struct input_dev *dev) +{ + struct zet6223_ts *ts = input_get_drvdata(dev); + + enable_irq(ts->client->irq); + + return 0; +} + +static void zet6223_stop(struct input_dev *dev) +{ + struct zet6223_ts *ts = input_get_drvdata(dev); + + disable_irq(ts->client->irq); +} + +static irqreturn_t zet6223_irq(int irq, void *dev_id) +{ + struct zet6223_ts *ts = dev_id; + u16 finger_bits; + + /* + * First 3 bytes are an identifier, two bytes of finger data. + * X, Y data per finger is 4 bytes. + */ + u8 bufsize = 3 + 4 * ts->fingernum; + u8 buf[ZET6223_MAX_PKT_SIZE]; + int i; + int ret; + int error; + + ret = i2c_master_recv(ts->client, buf, bufsize); + if (ret != bufsize) { + error = ret < 0 ? ret : -EIO; + dev_err_ratelimited(&ts->client->dev, + "Error reading input data: %d\n", error); + return IRQ_HANDLED; + } + + if (buf[0] != ZET6223_VALID_PACKET) + return IRQ_HANDLED; + + finger_bits = get_unaligned_be16(buf + 1); + for (i = 0; i < ts->fingernum; i++) { + if (!(finger_bits & BIT(15 - i))) + continue; + + input_mt_slot(ts->input, i); + input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, true); + input_event(ts->input, EV_ABS, ABS_MT_POSITION_X, + ((buf[i + 3] >> 4) << 8) + buf[i + 4]); + input_event(ts->input, EV_ABS, ABS_MT_POSITION_Y, + ((buf[i + 3] & 0xF) << 8) + buf[i + 5]); + } + + input_mt_sync_frame(ts->input); + input_sync(ts->input); + + return IRQ_HANDLED; +} + +static void zet6223_power_off(void *_ts) +{ + struct zet6223_ts *ts = _ts; + + regulator_bulk_disable(ARRAY_SIZE(ts->supplies), ts->supplies); +} + +static int zet6223_power_on(struct zet6223_ts *ts) +{ + struct device *dev = &ts->client->dev; + int error; + + ts->supplies[0].supply = "vio"; + ts->supplies[1].supply = "vcc"; + + error = devm_regulator_bulk_get(dev, ARRAY_SIZE(ts->supplies), + ts->supplies); + if (error) + return error; + + error = regulator_bulk_enable(ARRAY_SIZE(ts->supplies), ts->supplies); + if (error) + return error; + + msleep(ZET6223_POWER_ON_DELAY_MSEC); + + error = devm_add_action_or_reset(dev, zet6223_power_off, ts); + if (error) { + dev_err(dev, "failed to install poweroff action: %d\n", error); + return error; + } + + return 0; +} + +static int zet6223_query_device(struct zet6223_ts *ts) +{ + u8 buf[ZET6223_CMD_INFO_LENGTH]; + u8 cmd = ZET6223_CMD_INFO; + int ret; + int error; + + ret = i2c_master_send(ts->client, &cmd, sizeof(cmd)); + if (ret != sizeof(cmd)) { + error = ret < 0 ? ret : -EIO; + dev_err(&ts->client->dev, + "touchpanel info cmd failed: %d\n", error); + return error; + } + + ret = i2c_master_recv(ts->client, buf, sizeof(buf)); + if (ret != sizeof(buf)) { + error = ret < 0 ? ret : -EIO; + dev_err(&ts->client->dev, + "failed to retrieve touchpanel info: %d\n", error); + return error; + } + + ts->fingernum = buf[15] & 0x7F; + if (ts->fingernum > ZET6223_MAX_FINGERS) { + dev_warn(&ts->client->dev, + "touchpanel reports %d fingers, limiting to %d\n", + ts->fingernum, ZET6223_MAX_FINGERS); + ts->fingernum = ZET6223_MAX_FINGERS; + } + + ts->max_x = get_unaligned_le16(&buf[8]); + ts->max_y = get_unaligned_le16(&buf[10]); + + return 0; +} + +static int zet6223_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct zet6223_ts *ts; + struct input_dev *input; + int error; + + if (!client->irq) { + dev_err(dev, "no irq specified\n"); + return -EINVAL; + } + + ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + if (!ts) + return -ENOMEM; + + ts->client = client; + + error = zet6223_power_on(ts); + if (error) + return error; + + error = zet6223_query_device(ts); + if (error) + return error; + + ts->input = input = devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; + + input_set_drvdata(input, ts); + + input->name = client->name; + input->id.bustype = BUS_I2C; + input->open = zet6223_start; + input->close = zet6223_stop; + + input_set_abs_params(input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0); + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0); + + touchscreen_parse_properties(input, true, &ts->prop); + + error = input_mt_init_slots(input, ts->fingernum, + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); + if (error) + return error; + + error = devm_request_threaded_irq(dev, client->irq, NULL, zet6223_irq, + IRQF_ONESHOT, client->name, ts); + if (error) { + dev_err(dev, "failed to request irq %d: %d\n", + client->irq, error); + return error; + } + + zet6223_stop(input); + + error = input_register_device(input); + if (error) + return error; + + return 0; +} + +static const struct of_device_id zet6223_of_match[] = { + { .compatible = "zeitec,zet6223" }, + { } +}; + +static const struct i2c_device_id zet6223_id[] = { + { "zet6223", 0}, + { } +}; +MODULE_DEVICE_TABLE(i2c, zet6223_id); + +static struct i2c_driver zet6223_driver = { + .driver = { + .name = "zet6223", + .of_match_table = zet6223_of_match, + }, + .probe = zet6223_probe, + .id_table = zet6223_id +}; +module_i2c_driver(zet6223_driver); + +MODULE_AUTHOR("Jelle van der Waa "); +MODULE_DESCRIPTION("ZEITEC zet622x I2C touchscreen driver"); +MODULE_LICENSE("GPL"); -- cgit v1.2.3