mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00
Input: cap11xx - add support for various cap11xx devices
There are variants of the cap11xx device with a varying number of capacitance detection channels. Signed-off-by: Matt Ranostay <mranostay@gmail.com> Reviewed-by: Daniel Mack <daniel@zonque.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
c77fd0a42b
commit
7609a5e973
2 changed files with 53 additions and 24 deletions
|
@ -7,9 +7,10 @@ Required properties:
|
||||||
|
|
||||||
compatible: Must contain one of:
|
compatible: Must contain one of:
|
||||||
"microchip,cap1106"
|
"microchip,cap1106"
|
||||||
|
"microchip,cap1126"
|
||||||
|
"microchip,cap1188"
|
||||||
|
|
||||||
reg: The I2C slave address of the device.
|
reg: The I2C slave address of the device.
|
||||||
Only 0x28 is valid.
|
|
||||||
|
|
||||||
interrupts: Property describing the interrupt line the
|
interrupts: Property describing the interrupt line the
|
||||||
device's ALERT#/CM_IRQ# pin is connected to.
|
device's ALERT#/CM_IRQ# pin is connected to.
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Input driver for Microchip CAP11xx based capacitive touch sensors
|
* Input driver for Microchip CAP11xx based capacitive touch sensors
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* (c) 2014 Daniel Mack <linux@zonque.org>
|
* (c) 2014 Daniel Mack <linux@zonque.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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_MANUFACTURER_ID 0xfe
|
||||||
#define CAP11XX_REG_REVISION 0xff
|
#define CAP11XX_REG_REVISION 0xff
|
||||||
|
|
||||||
#define CAP11XX_NUM_CHN 6
|
|
||||||
#define CAP11XX_PRODUCT_ID 0x55
|
|
||||||
#define CAP11XX_MANUFACTURER_ID 0x5d
|
#define CAP11XX_MANUFACTURER_ID 0x5d
|
||||||
|
|
||||||
struct cap11xx_priv {
|
struct cap11xx_priv {
|
||||||
|
@ -63,7 +60,24 @@ struct cap11xx_priv {
|
||||||
struct input_dev *idev;
|
struct input_dev *idev;
|
||||||
|
|
||||||
/* config */
|
/* config */
|
||||||
unsigned short keycodes[CAP11XX_NUM_CHN];
|
u32 keycodes[];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cap11xx_hw_model {
|
||||||
|
u8 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[] = {
|
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)
|
if (ret < 0)
|
||||||
goto out;
|
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],
|
input_report_key(priv->idev, priv->keycodes[i],
|
||||||
status & (1 << i));
|
status & (1 << i));
|
||||||
|
|
||||||
|
@ -187,11 +201,26 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
|
||||||
struct device *dev = &i2c_client->dev;
|
struct device *dev = &i2c_client->dev;
|
||||||
struct cap11xx_priv *priv;
|
struct cap11xx_priv *priv;
|
||||||
struct device_node *node;
|
struct device_node *node;
|
||||||
|
const struct cap11xx_hw_model *cap;
|
||||||
int i, error, irq, gain = 0;
|
int i, error, irq, gain = 0;
|
||||||
unsigned int val, rev;
|
unsigned int val, rev;
|
||||||
u32 gain32, keycodes[CAP11XX_NUM_CHN];
|
u32 gain32;
|
||||||
|
|
||||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
if (id->driver_data >= ARRAY_SIZE(cap11xx_devices)) {
|
||||||
|
dev_err(dev, "Invalid device ID %lu\n", id->driver_data);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cap = &cap11xx_devices[id->driver_data];
|
||||||
|
if (!cap || !cap->num_channels) {
|
||||||
|
dev_err(dev, "Invalid device configuration\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv = devm_kzalloc(dev,
|
||||||
|
sizeof(*priv) +
|
||||||
|
cap->num_channels * sizeof(priv->keycodes[0]),
|
||||||
|
GFP_KERNEL);
|
||||||
if (!priv)
|
if (!priv)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -203,10 +232,10 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
|
||||||
if (error)
|
if (error)
|
||||||
return 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",
|
dev_err(dev, "Product ID: Got 0x%02x, expected 0x%02x\n",
|
||||||
val, CAP11XX_PRODUCT_ID);
|
val, cap->product_id);
|
||||||
return -ENODEV;
|
return -ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val);
|
error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val);
|
||||||
|
@ -216,7 +245,7 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
|
||||||
if (val != CAP11XX_MANUFACTURER_ID) {
|
if (val != CAP11XX_MANUFACTURER_ID) {
|
||||||
dev_err(dev, "Manufacturer ID: Got 0x%02x, expected 0x%02x\n",
|
dev_err(dev, "Manufacturer ID: Got 0x%02x, expected 0x%02x\n",
|
||||||
val, CAP11XX_MANUFACTURER_ID);
|
val, CAP11XX_MANUFACTURER_ID);
|
||||||
return -ENODEV;
|
return -ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev);
|
error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev);
|
||||||
|
@ -234,17 +263,12 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
|
||||||
dev_err(dev, "Invalid sensor-gain value %d\n", gain32);
|
dev_err(dev, "Invalid sensor-gain value %d\n", gain32);
|
||||||
}
|
}
|
||||||
|
|
||||||
BUILD_BUG_ON(ARRAY_SIZE(keycodes) != ARRAY_SIZE(priv->keycodes));
|
|
||||||
|
|
||||||
/* Provide some useful defaults */
|
/* Provide some useful defaults */
|
||||||
for (i = 0; i < ARRAY_SIZE(keycodes); i++)
|
for (i = 0; i < cap->num_channels; i++)
|
||||||
keycodes[i] = KEY_A + i;
|
priv->keycodes[i] = KEY_A + i;
|
||||||
|
|
||||||
of_property_read_u32_array(node, "linux,keycodes",
|
of_property_read_u32_array(node, "linux,keycodes",
|
||||||
keycodes, ARRAY_SIZE(keycodes));
|
priv->keycodes, cap->num_channels);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(keycodes); i++)
|
|
||||||
priv->keycodes[i] = keycodes[i];
|
|
||||||
|
|
||||||
error = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL,
|
error = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL,
|
||||||
CAP11XX_REG_MAIN_CONTROL_GAIN_MASK,
|
CAP11XX_REG_MAIN_CONTROL_GAIN_MASK,
|
||||||
|
@ -268,17 +292,17 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
|
||||||
if (of_property_read_bool(node, "autorepeat"))
|
if (of_property_read_bool(node, "autorepeat"))
|
||||||
__set_bit(EV_REP, priv->idev->evbit);
|
__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);
|
__set_bit(priv->keycodes[i], priv->idev->keybit);
|
||||||
|
|
||||||
__clear_bit(KEY_RESERVED, priv->idev->keybit);
|
__clear_bit(KEY_RESERVED, priv->idev->keybit);
|
||||||
|
|
||||||
priv->idev->keycode = priv->keycodes;
|
priv->idev->keycode = priv->keycodes;
|
||||||
priv->idev->keycodesize = sizeof(priv->keycodes[0]);
|
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.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->id.version = rev;
|
||||||
|
|
||||||
priv->idev->open = cap11xx_input_open;
|
priv->idev->open = cap11xx_input_open;
|
||||||
|
@ -312,12 +336,16 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
|
||||||
|
|
||||||
static const struct of_device_id cap11xx_dt_ids[] = {
|
static const struct of_device_id cap11xx_dt_ids[] = {
|
||||||
{ .compatible = "microchip,cap1106", },
|
{ .compatible = "microchip,cap1106", },
|
||||||
|
{ .compatible = "microchip,cap1126", },
|
||||||
|
{ .compatible = "microchip,cap1188", },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(of, cap11xx_dt_ids);
|
MODULE_DEVICE_TABLE(of, cap11xx_dt_ids);
|
||||||
|
|
||||||
static const struct i2c_device_id cap11xx_i2c_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);
|
MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids);
|
||||||
|
|
Loading…
Add table
Reference in a new issue