cap1106: add support for cap11xx variants
Subsystems (3)
v4 cover cap1106: add support for cap11xx variants
Changes from v3:
* Resubmit with "git format-patch -M" to make file rename clear in cover letter
Matt Ranostay (3):
cap11xx: make driver generic for variant support
cap11xx: Add support for various cap11xx devices
cap11xx: support for irq-active-high option
.../bindings/input/{cap1106.txt => cap11xx.txt} | 12 +-
drivers/input/keyboard/Kconfig | 8 +-
drivers/input/keyboard/Makefile | 2 +-
drivers/input/keyboard/cap1106.c | 341 -------------------
drivers/input/keyboard/cap11xx.c | 371 +++++++++++++++++++++
5 files changed, 385 insertions(+), 349 deletions(-)
rename Documentation/devicetree/bindings/input/{cap1106.txt => cap11xx.txt} (78%)
delete mode 100644 drivers/input/keyboard/cap1106.c
create mode 100644 drivers/input/keyboard/cap11xx.cSignature · 1 line
1.9.1
PATCH v4 1/3 cap11xx: make driver generic for variant support
cap1106 driver can support much more one device make the driver generic for support of similiar parts.
---
.../bindings/input/{cap1106.txt => cap11xx.txt} | 5 +-
drivers/input/keyboard/Kconfig | 8 +-
drivers/input/keyboard/Makefile | 2 +-
drivers/input/keyboard/cap1106.c | 341 ---------------------
drivers/input/keyboard/cap11xx.c | 340 ++++++++++++++++++++
5 files changed, 348 insertions(+), 348 deletions(-)
rename Documentation/devicetree/bindings/input/{cap1106.txt => cap11xx.txt} (89%)
delete mode 100644 drivers/input/keyboard/cap1106.c
create mode 100644 drivers/input/keyboard/cap11xx.cDocumentation/devicetree/bindings/input/cap11xx.txt renamed from Documentation/devicetree/bindings/input/cap1106.txt +3 -2
@@ -1,11 +1,12 @@ -Device tree bindings for Microchip CAP1106, 6 channel capacitive touch sensor +Device tree bindings for Microchip CAP1106 based capacitive touch sensor The node for this driver must be a child of a I2C controller node, as the device communication via I2C only. Required properties: - compatible: Must be "microchip,cap1106" + compatible: Must be on the following, depending on the model: + "microchip,cap1106" reg: The I2C slave address of the device. Only 0x28 is valid.
drivers/input/keyboard/Kconfig +4 -4
@@ -665,14 +665,14 @@ config KEYBOARD_CROS_EC To compile this driver as a module, choose M here: the module will be called cros_ec_keyb. -config KEYBOARD_CAP1106 - tristate "Microchip CAP1106 touch sensor" +config KEYBOARD_CAP11XX + tristate "Microchip CAP11XX based touch sensors" depends on OF && I2C select REGMAP_I2C help - Say Y here to enable the CAP1106 touch sensor driver. + Say Y here to enable the CAP11XX touch sensor driver. To compile this driver as a module, choose M here: the - module will be called cap1106. + module will be called cap11xx. endif
drivers/input/keyboard/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o -obj-$(CONFIG_KEYBOARD_CAP1106) += cap1106.o +obj-$(CONFIG_KEYBOARD_CAP11XX) += cap11xx.o obj-$(CONFIG_KEYBOARD_CLPS711X) += clps711x-keypad.o obj-$(CONFIG_KEYBOARD_CROS_EC) += cros_ec_keyb.o obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o
drivers/input/keyboard/cap1106.c deleted +0 -341
341 lines not on this page · raw message
drivers/input/keyboard/cap11xx.c new file +340 -0
340 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 2/3 cap11xx: Add support for various cap11xx devices
In reply to Matt RanostaySeveral other variants of the cap11xx device exists with a varying number of capacitance detection channels. Add support for creating the channels dynamically.
--- .../devicetree/bindings/input/cap11xx.txt | 3 +- drivers/input/keyboard/cap11xx.c | 65 +++++++++++++++------- 2 files changed, 46 insertions(+), 22 deletions(-)
Documentation/devicetree/bindings/input/cap11xx.txt +2 -1
@@ -7,9 +7,10 @@ Required properties: compatible: Must be on the following, depending on the model: "microchip,cap1106" + "microchip,cap1126" + "microchip,cap1188" reg: The I2C slave address of the device. - Only 0x28 is valid. interrupts: Property describing the interrupt line the device's ALERT#/CM_IRQ# pin is connected to.
drivers/input/keyboard/cap11xx.c +44 -21
142 lines not on this page · raw message
Signature · 1 line
1.9.1
Dmitry Torokhov
maintainerRe: [PATCH v4 2/3] cap11xx: Add support for various cap11xx devices
Hi Matt,
Review
Quoted 5 lines · Matt Ranostay
(quoted diff) +5
-0+ priv->num_channels = cap->num_channels; + priv->keycodes = devm_kcalloc(dev, + priv->num_channels, sizeof(u32), GFP_KERNEL); + if (!priv->keycodes) + return -ENOMEM;
Instead of allocating keymap separately can we do something like below?
Thanks.
Signature · 18 lines
Dmitry Input: cap11xx - add support for various cap11xx devices From: Matt Ranostay <[email protected]> Several other variants of the cap11xx device exists with a varying number of capacitance detection channels. Add support for creating the channels dynamically. Signed-off-by: Matt Ranostay <[email protected]> Reviewed-by: Daniel Mack <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> --- .../devicetree/bindings/input/cap11xx.txt | 3 + drivers/input/keyboard/cap11xx.c | 62 +++++++++++++------- 2 files changed, 42 insertions(+), 23 deletions(-)
Documentation/devicetree/bindings/input/cap11xx.txt +2 -1
@@ -7,9 +7,10 @@ Required properties: compatible: Must be on the following, depending on the model: "microchip,cap1106" + "microchip,cap1126" + "microchip,cap1188" reg: The I2C slave address of the device. - Only 0x28 is valid. interrupts: Property describing the interrupt line the device's ALERT#/CM_IRQ# pin is connected to.
drivers/input/keyboard/cap11xx.c +40 -22
143 lines not on this page · raw message
Re: [PATCH v4 2/3] cap11xx: Add support for various cap11xx devices
Oh good catch! Will resubmitted with v5.
Quoted 206 lines · Dmitry Torokhov
Hi Matt,
Review
Quoted 5 lines · Matt Ranostay
(quoted diff) +5
-0+ priv->num_channels = cap->num_channels; + priv->keycodes = devm_kcalloc(dev, + priv->num_channels, sizeof(u32), GFP_KERNEL); + if (!priv->keycodes) + return -ENOMEM;Instead of allocating keymap separately can we do something like below?
Thanks.
--
DmitryInput: cap11xx - add support for various cap11xx devices
From: Matt Ranostay <[email protected]>
Several other variants of the cap11xx device exists with a varying number of capacitance detection channels. Add support for creating the channels dynamically.
Signed-off-by Matt Ranostay <[email protected]>Reviewed-by Daniel Mack <[email protected]>Signed-off-by Dmitry Torokhov <[email protected]>--- .../devicetree/bindings/input/cap11xx.txt | 3 + drivers/input/keyboard/cap11xx.c | 62 +++++++++++++------- 2 files changed, 42 insertions(+), 23 deletions(-)Documentation/devicetree/bindings/input/cap11xx.txt +2
-1@@ -7,9 +7,10 @@ Required properties: compatible: Must be on the following, depending on the model: "microchip,cap1106" + "microchip,cap1126" + "microchip,cap1188" reg: The I2C slave address of the device. - Only 0x28 is valid. interrupts: Property describing the interrupt line the device's ALERT#/CM_IRQ# pin is connected to.drivers/input/keyboard/cap11xx.c +40
-22@@ -1,7 +1,6 @@/* * Input driver for Microchip CAP11xx based capacitive touch sensors * -* * (c) 2014 Daniel Mack <[email protected]> * * This program is free software; you can redistribute it and/or modify @@ -54,8 +53,6 @@#define CAP11XX_REG_MANUFACTURER_ID 0xfe#define CAP11XX_REG_REVISION 0xff -#define CAP11XX_NUM_CHN 6 -#define CAP11XX_PRODUCT_ID 0x55#define CAP11XX_MANUFACTURER_ID 0x5dstruct cap11xx_priv {@@ -63,7 +60,24 @@ struct cap11xx_priv {struct input_dev *idev;/* config */ -unsigned short keycodes[CAP11XX_NUM_CHN ]; +u32 keycodes[]; +}; + +struct cap11xx_hw_model { +uint8_t product_id; +unsigned int num_channels; +}; + +enum { +CAP1106 , +CAP1126 , +CAP1188 , +}; + +static const struct cap11xx_hw_model cap11xx_devices[] = { + [CAP1106 ] = { .product_id =0x55 , .num_channels =6 }, + [CAP1126 ] = { .product_id =0x53 , .num_channels =6 }, + [CAP1188 ] = { .product_id =0x50 , .num_channels =8 }, };static const struct reg_default cap11xx_reg_defaults[] = {@@ -150,7 +164,7 @@ static irqreturn_t cap11xx_thread_func(int irq_num, void *data)if (ret <0 ) goto out; -for (i =0 ; i <CAP11XX_NUM_CHN ; i++) +for (i =0 ; i < priv->idev->keycodemax; i++)input_report_key (priv->idev, priv->keycodes[i], status & (1 << i));@@ -187,11 +201,16 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,struct device *dev = &i2c_client->dev;struct cap11xx_priv *priv;struct device_node *node; +const struct cap11xx_hw_model *cap = &cap11xx_devices[id->driver_data];int i, error, irq, gain =0 ;unsigned int val, rev; -u32 gain32, keycodes[CAP11XX_NUM_CHN ]; +u32 gain32; + +BUG_ON (!cap->num_channels); - priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); + priv =devm_kzalloc (dev, +sizeof (*priv) + cap->num_channels *sizeof (u32), +GFP_KERNEL );if (!priv)return -ENOMEM ;@@ -203,9 +222,9 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,if (error)return error; -if (val !=CAP11XX_PRODUCT_ID ) { +if (val != cap->product_id) {dev_err (dev,"Product ID: Got 0x%02x, expected 0x%02x\n" , - val,CAP11XX_PRODUCT_ID ); + val, cap->product_id);return -ENODEV ; }@@ -225,8 +244,8 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,dev_info (dev,"CAP11XX detected, revision 0x%02x\n" , rev);i2c_set_clientdata (i2c_client, priv); - node = dev->of_node; + node = dev->of_node;if (!of_property_read_u32 (node,"microchip,sensor-gain" , &gain32)) {if (is_power_of_2 (gain32) && gain32 <=8 ) gain =ilog2 (gain32);@@ -234,17 +253,12 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,dev_err (dev,"Invalid sensor-gain value %d\n" , gain32); } -BUILD_BUG_ON (ARRAY_SIZE (keycodes) !=ARRAY_SIZE (priv->keycodes)); -/* Provide some useful defaults */ -for (i =0 ; i <ARRAY_SIZE (keycodes); i++) - keycodes[i] =KEY_A + i; +for (i =0 ; i < cap->num_channels; i++) + priv->keycodes[i] =KEY_A + i;of_property_read_u32_array (node,"linux,keycodes" , - keycodes,ARRAY_SIZE (keycodes)); - -for (i =0 ; i <ARRAY_SIZE (keycodes); i++) - priv->keycodes[i] = keycodes[i]; + priv->keycodes, cap->num_channels); error = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, CAP11XX_REG_MAIN_CONTROL_GAIN_MASK,@@ -268,17 +282,17 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,if (of_property_read_bool (node,"autorepeat" ))__set_bit (EV_REP , priv->idev->evbit); -for (i =0 ; i <CAP11XX_NUM_CHN ; i++) +for (i =0 ; i < cap->num_channels; i++)__set_bit (priv->keycodes[i], priv->idev->keybit);__clear_bit (KEY_RESERVED , priv->idev->keybit); priv->idev->keycode = priv->keycodes; priv->idev->keycodesize =sizeof (priv->keycodes[0 ]); - priv->idev->keycodemax =ARRAY_SIZE (priv->keycodes); + priv->idev->keycodemax = cap->num_channels; priv->idev->id.vendor =CAP11XX_MANUFACTURER_ID ; - priv->idev->id.product =CAP11XX_PRODUCT_ID ; + priv->idev->id.product = cap->product_id; priv->idev->id.version = rev; priv->idev->open = cap11xx_input_open;@@ -312,12 +326,16 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,static const struct of_device_id cap11xx_dt_ids[] = { { .compatible ="microchip,cap1106" , }, + { .compatible ="microchip,cap1126" , }, + { .compatible ="microchip,cap1188" , }, {} };MODULE_DEVICE_TABLE (of, cap11xx_dt_ids);static const struct i2c_device_id cap11xx_i2c_ids[] = { - {"cap1106" ,0 }, + {"cap1106" ,CAP1106 }, + {"cap1126" ,CAP1126 }, + {"cap1188" ,CAP1188 }, {} };MODULE_DEVICE_TABLE (i2c, cap11xx_i2c_ids);
PATCH v4 3/3 cap11xx: support for irq-active-high option
In reply to Matt RanostaySome applications need to use the irq-active-high push-pull option. This allows it be enabled in the device tree child node.
--- Documentation/devicetree/bindings/input/cap11xx.txt | 4 ++++ drivers/input/keyboard/cap11xx.c | 8 ++++++++ 2 files changed, 12 insertions(+)
Documentation/devicetree/bindings/input/cap11xx.txt +4 -0
@@ -28,6 +28,10 @@ Optional properties: Valid values are 1, 2, 4, and 8. By default, a gain of 1 is set. + microchip,irq-active-high: By default the interrupt pin is active low + open drain. This property allows using the active + high push-pull output. + linux,keycodes: Specifies an array of numeric keycode values to be used for the channels. If this property is omitted, KEY_A, KEY_B, etc are used as
drivers/input/keyboard/cap11xx.c +8 -0
@@ -45,6 +45,7 @@#define CAP11XX_REG_STANDBY_SENSITIVITY 0x42#define CAP11XX_REG_STANDBY_THRESH 0x43#define CAP11XX_REG_CONFIG2 0x44 +#define CAP11XX_REG_CONFIG2_ALT_POL BIT(6)#define CAP11XX_REG_SENSOR_BASE_CNT (X ) (0x50 + (X))#define CAP11XX_REG_SENSOR_CALIB (0xb1 + (X))#define CAP11XX_REG_SENSOR_CALIB_LSB1 0xb9
@@ -258,6 +259,13 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,dev_err (dev,"Invalid sensor-gain value %d\n" , gain32); } +if (of_property_read_bool (node,"microchip,irq-active-high" )) { + error =regmap_update_bits (priv->regmap,CAP11XX_REG_CONFIG2 , +CAP11XX_REG_CONFIG2_ALT_POL ,0 ); +if (error) +return error; + } +/* Provide some useful defaults */ for (i =0 ; i < priv->num_channels; i++) priv->keycodes[i] =KEY_A + i;
Signature · 1 line
1.9.1