[PATCH 0/2] add driver for cypress cy8cmbr3102
* compiles without errors * no errors when using checkpatch * tested with a connected touch button on HW NOTE: This implementation does not implement the full range of functions the Cypress CY8CMBR3102 CapSense Express controller provides. It only implements its use for connected touch buttons (yet). Patrick Vogelaar (2): add driver for cypress cy8cmbr3102 add device tree documentation for cy8cmbr3102 .../bindings/input/cypress,cy8cmbr3102.txt | 32 +++ drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile| 1 + drivers/input/misc/cy8cmbr3102.c | 222 + 4 files changed, 267 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt create mode 100644 drivers/input/misc/cy8cmbr3102.c -- 2.7.4
[PATCH 2/2] add device tree documentation for cy8cmbr3102
Signed-off-by: Patrick Vogelaar --- .../bindings/input/cypress,cy8cmbr3102.txt | 32 ++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt diff --git a/Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt b/Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt new file mode 100644 index 000..d5294b3 --- /dev/null +++ b/Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt @@ -0,0 +1,32 @@ +Device tree bindings for Cypress CY8CMBR3102 CapSense Express controller. + +The node for this device must be a child of a I2C controller node, as the +device communicates via I2C. + +Required properties: + + compatible: Must be "cypress,cy8cmbr3102". + reg:The I2C slave address of the device. + linux,keycodes: Specifies an array of numeric keycode values to + be used for reporting button presses. The array can + contain up to two entries. + +Optional properties: + + autorepeat: Enables the Linux input system's autorepeat + feature on the input device. + +Example: + + &i2c1 { + /* ... */ + + touchb_tn: cy8cmbr3102@37 { + compatible = "cypress,cy8cmbr3102"; + reg = <0x37>; + linux,keycodes = , ; + autorepeat; + }; + + /* ... */ + }; -- 2.7.4
[PATCH 1/2] add driver for cypress cy8cmbr3102
Signed-off-by: Patrick Vogelaar --- drivers/input/misc/Kconfig | 12 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/cy8cmbr3102.c | 222 +++ 3 files changed, 235 insertions(+) create mode 100644 drivers/input/misc/cy8cmbr3102.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 5b6c522..be3071e 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -822,4 +822,16 @@ config INPUT_HISI_POWERKEY To compile this driver as a module, choose M here: the module will be called hisi_powerkey. +config INPUT_CY8CMBR3102 + tristate "Cypress CY8CMBR3102 CapSense Express controller" + depends on I2C + select INPUT_POLLDEV + default n + help + Say yes here to enable support for the Cypress CY8CMBR3102 + CapSense Express controller. + + To compile this driver as a module, choose M here: the module + will be called cy8cmbr3102. + endif diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index b10523f..f9959ed 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -77,3 +77,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o obj-$(CONFIG_INPUT_YEALINK)+= yealink.o obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o +obj-$(CONFIG_INPUT_CY8CMBR3102)+= cy8cmbr3102.o diff --git a/drivers/input/misc/cy8cmbr3102.c b/drivers/input/misc/cy8cmbr3102.c new file mode 100644 index 000..e2f5167 --- /dev/null +++ b/drivers/input/misc/cy8cmbr3102.c @@ -0,0 +1,222 @@ +/* Driver for Cypress CY8CMBR3102 CapSense Express Controller + * + * (C) 2017 by Gigatronik Technologies GmbH + * Author: Patrick Vogelaar + * All rights reserved. + * + * This code is based on mma8450.c and atmel_captouch.c. + * + * 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; version 2 of the License. + * + * 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. + * + * NOTE: This implementation does not implement the full range of functions the + * Cypress CY8CMBR3102 CapSense Express controller provides. It only implements + * its use for connected touch buttons (yet). + */ + +#define DRV_VERSION "0.1" + +#include +#include +#include +#include +#include +#include +#include +#include + +/* I2C Registers */ +#define CY8CMBR3102_DEVICE_ID_REG 0x90 +#define CY8CMBR3102_BUTTON_STAT0xAA + + +#define CY8CMBR3102_MAX_NUM_OF_BUTTONS 0x02 +#define CY8CMBR3102_DRV_NAME "cy8cmbr3102" +#define CY8CMBR3102_POLL_INTERVAL 200 +#define CY8CMBR3102_POLL_INTERVAL_MAX 300 +#define CY8CMBR3102_DEVICE_ID 2561 +#define CY8CMBR3102_MAX_RETRY 5 + +/* + * @i2c_client: I2C slave device client pointer + * @idev: Input (polled) device pointer + * @num_btn: Number of buttons + * @keycodes: map of button# to KeyCode + * @cy8cmbr3102_lock: mutex lock + */ +struct cy8cmbr3102_device { + struct i2c_client *client; + struct input_polled_dev *idev; + u32 num_btn; + u32 keycodes[CY8CMBR3102_MAX_NUM_OF_BUTTONS]; + struct mutex cy8cmbr3102_lock; +}; + +static const struct i2c_device_id cy8cmbr3102_idtable[] = { + {"cy8cmbr3102", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, cy8cmbr3102_idtable); + +static void cy8cmbr3102_poll(struct input_polled_dev *idev) +{ + struct cy8cmbr3102_device *dev = idev->private; + int i, ret, btn_state; + + mutex_lock(&dev->cy8cmbr3102_lock); + + ret = i2c_smbus_read_word_data(dev->client, CY8CMBR3102_BUTTON_STAT); + if (ret < 0) { + dev_err(&dev->client->dev, "i2c io error: %d\n", ret); + mutex_unlock(&dev->cy8cmbr3102_lock); + return; + } + + for (i = 0; i < dev->num_btn; i++) { + btn_state = ret & (0x1 << i); + input_report_key(idev->input, dev->keycodes[i], btn_state); + input_sync(idev->input); + } + + mutex_unlock(&dev->cy8cmbr3102_lock); +} + +static int cy8cmbr3102_remove(struct i2c_client *client) +{ + struct cy8cmbr3102_device *dev = i2c_get_clientdata(client); + struct input_polled_dev *idev = dev->idev; + + dev_dbg(&client->dev, "%s\n", __func__); + + mutex_destroy(&dev->cy8cmbr3102_lock); + input_unregister_polle
[PATCH v2 2/2] add device tree documentation for cy8cmbr3102
Version 2: * based on branch next Signed-off-by: Patrick Vogelaar --- .../bindings/input/cypress,cy8cmbr3102.txt | 32 ++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt diff --git a/Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt b/Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt new file mode 100644 index 000..d5294b3 --- /dev/null +++ b/Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt @@ -0,0 +1,32 @@ +Device tree bindings for Cypress CY8CMBR3102 CapSense Express controller. + +The node for this device must be a child of a I2C controller node, as the +device communicates via I2C. + +Required properties: + + compatible: Must be "cypress,cy8cmbr3102". + reg:The I2C slave address of the device. + linux,keycodes: Specifies an array of numeric keycode values to + be used for reporting button presses. The array can + contain up to two entries. + +Optional properties: + + autorepeat: Enables the Linux input system's autorepeat + feature on the input device. + +Example: + + &i2c1 { + /* ... */ + + touchb_tn: cy8cmbr3102@37 { + compatible = "cypress,cy8cmbr3102"; + reg = <0x37>; + linux,keycodes = , ; + autorepeat; + }; + + /* ... */ + }; -- 2.7.4
[PATCH v2 0/2] add driver for cypress cy8cmbr3102
* compiles without errors * no errors when using checkpatch * tested with a connected touch button on HW NOTE: This implementation does not implement the full range of functions the Cypress CY8CMBR3102 CapSense Express controller provides. It only implements its use for connected touch buttons (yet). Version 2: * removed .owner * based on branch next Patrick Vogelaar (2): add driver for cypress cy8cmbr3102 add device tree documentation for cy8cmbr3102 .../bindings/input/cypress,cy8cmbr3102.txt | 32 +++ drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile| 1 + drivers/input/misc/cy8cmbr3102.c | 221 + 4 files changed, 266 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cypress,cy8cmbr3102.txt create mode 100644 drivers/input/misc/cy8cmbr3102.c -- 2.7.4
[PATCH v2 1/2] add driver for cypress cy8cmbr3102
Version 2: * removed .owner * based on branch next Signed-off-by: Patrick Vogelaar --- drivers/input/misc/Kconfig | 12 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/cy8cmbr3102.c | 221 +++ 3 files changed, 234 insertions(+) create mode 100644 drivers/input/misc/cy8cmbr3102.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 5b6c522..be3071e 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -822,4 +822,16 @@ config INPUT_HISI_POWERKEY To compile this driver as a module, choose M here: the module will be called hisi_powerkey. +config INPUT_CY8CMBR3102 + tristate "Cypress CY8CMBR3102 CapSense Express controller" + depends on I2C + select INPUT_POLLDEV + default n + help + Say yes here to enable support for the Cypress CY8CMBR3102 + CapSense Express controller. + + To compile this driver as a module, choose M here: the module + will be called cy8cmbr3102. + endif diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index b10523f..f9959ed 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -77,3 +77,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o obj-$(CONFIG_INPUT_YEALINK)+= yealink.o obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o +obj-$(CONFIG_INPUT_CY8CMBR3102)+= cy8cmbr3102.o diff --git a/drivers/input/misc/cy8cmbr3102.c b/drivers/input/misc/cy8cmbr3102.c new file mode 100644 index 000..ed67a63 --- /dev/null +++ b/drivers/input/misc/cy8cmbr3102.c @@ -0,0 +1,221 @@ +/* Driver for Cypress CY8CMBR3102 CapSense Express Controller + * + * (C) 2017 by Gigatronik Technologies GmbH + * Author: Patrick Vogelaar + * All rights reserved. + * + * This code is based on mma8450.c and atmel_captouch.c. + * + * 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; version 2 of the License. + * + * 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. + * + * NOTE: This implementation does not implement the full range of functions the + * Cypress CY8CMBR3102 CapSense Express controller provides. It only implements + * its use for connected touch buttons (yet). + */ + +#define DRV_VERSION "0.1" + +#include +#include +#include +#include +#include +#include +#include +#include + +/* I2C Registers */ +#define CY8CMBR3102_DEVICE_ID_REG 0x90 +#define CY8CMBR3102_BUTTON_STAT0xAA + + +#define CY8CMBR3102_MAX_NUM_OF_BUTTONS 0x02 +#define CY8CMBR3102_DRV_NAME "cy8cmbr3102" +#define CY8CMBR3102_POLL_INTERVAL 200 +#define CY8CMBR3102_POLL_INTERVAL_MAX 300 +#define CY8CMBR3102_DEVICE_ID 2561 +#define CY8CMBR3102_MAX_RETRY 5 + +/* + * @i2c_client: I2C slave device client pointer + * @idev: Input (polled) device pointer + * @num_btn: Number of buttons + * @keycodes: map of button# to KeyCode + * @cy8cmbr3102_lock: mutex lock + */ +struct cy8cmbr3102_device { + struct i2c_client *client; + struct input_polled_dev *idev; + u32 num_btn; + u32 keycodes[CY8CMBR3102_MAX_NUM_OF_BUTTONS]; + struct mutex cy8cmbr3102_lock; +}; + +static const struct i2c_device_id cy8cmbr3102_idtable[] = { + {"cy8cmbr3102", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, cy8cmbr3102_idtable); + +static void cy8cmbr3102_poll(struct input_polled_dev *idev) +{ + struct cy8cmbr3102_device *dev = idev->private; + int i, ret, btn_state; + + mutex_lock(&dev->cy8cmbr3102_lock); + + ret = i2c_smbus_read_word_data(dev->client, CY8CMBR3102_BUTTON_STAT); + if (ret < 0) { + dev_err(&dev->client->dev, "i2c io error: %d\n", ret); + mutex_unlock(&dev->cy8cmbr3102_lock); + return; + } + + for (i = 0; i < dev->num_btn; i++) { + btn_state = ret & (0x1 << i); + input_report_key(idev->input, dev->keycodes[i], btn_state); + input_sync(idev->input); + } + + mutex_unlock(&dev->cy8cmbr3102_lock); +} + +static int cy8cmbr3102_remove(struct i2c_client *client) +{ + struct cy8cmbr3102_device *dev = i2c_get_clientdata(client); + struct input_polled_dev *idev = dev->idev; + + dev_dbg(&client->dev, "%s\n", __func__); + + mutex_destroy(&dev->cy8