aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorMatt Ranostay <mranostay@gmail.com>2014-10-31 23:01:37 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-11-02 02:09:10 -0500
commit7609a5e973c43a647c4e40184fc8404311fdb97c (patch)
treebe68591cfd4b29469510272f68516d0c75a065bb /drivers/input
parentc77fd0a42b24acc2d6cc466e73dcb67d50177df6 (diff)
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>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/cap11xx.c74
1 files changed, 51 insertions, 23 deletions
diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c
index 0da2e838e788..eeda1f9359cd 100644
--- a/drivers/input/keyboard/cap11xx.c
+++ b/drivers/input/keyboard/cap11xx.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * Input driver for Microchip CAP11xx based capacitive touch sensors 2 * Input driver for Microchip CAP11xx based capacitive touch sensors
3 * 3 *
4 *
5 * (c) 2014 Daniel Mack <linux@zonque.org> 4 * (c) 2014 Daniel Mack <linux@zonque.org>
6 * 5 *
7 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
@@ -54,8 +53,6 @@
54#define CAP11XX_REG_MANUFACTURER_ID 0xfe 53#define CAP11XX_REG_MANUFACTURER_ID 0xfe
55#define CAP11XX_REG_REVISION 0xff 54#define CAP11XX_REG_REVISION 0xff
56 55
57#define CAP11XX_NUM_CHN 6
58#define CAP11XX_PRODUCT_ID 0x55
59#define CAP11XX_MANUFACTURER_ID 0x5d 56#define CAP11XX_MANUFACTURER_ID 0x5d
60 57
61struct cap11xx_priv { 58struct cap11xx_priv {
@@ -63,7 +60,24 @@ struct cap11xx_priv {
63 struct input_dev *idev; 60 struct input_dev *idev;
64 61
65 /* config */ 62 /* config */
66 unsigned short keycodes[CAP11XX_NUM_CHN]; 63 u32 keycodes[];
64};
65
66struct cap11xx_hw_model {
67 u8 product_id;
68 unsigned int num_channels;
69};
70
71enum {
72 CAP1106,
73 CAP1126,
74 CAP1188,
75};
76
77static const struct cap11xx_hw_model cap11xx_devices[] = {
78 [CAP1106] = { .product_id = 0x55, .num_channels = 6 },
79 [CAP1126] = { .product_id = 0x53, .num_channels = 6 },
80 [CAP1188] = { .product_id = 0x50, .num_channels = 8 },
67}; 81};
68 82
69static const struct reg_default cap11xx_reg_defaults[] = { 83static const struct reg_default cap11xx_reg_defaults[] = {
@@ -150,7 +164,7 @@ static irqreturn_t cap11xx_thread_func(int irq_num, void *data)
150 if (ret < 0) 164 if (ret < 0)
151 goto out; 165 goto out;
152 166
153 for (i = 0; i < CAP11XX_NUM_CHN; i++) 167 for (i = 0; i < priv->idev->keycodemax; i++)
154 input_report_key(priv->idev, priv->keycodes[i], 168 input_report_key(priv->idev, priv->keycodes[i],
155 status & (1 << i)); 169 status & (1 << i));
156 170
@@ -187,11 +201,26 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
187 struct device *dev = &i2c_client->dev; 201 struct device *dev = &i2c_client->dev;
188 struct cap11xx_priv *priv; 202 struct cap11xx_priv *priv;
189 struct device_node *node; 203 struct device_node *node;
204 const struct cap11xx_hw_model *cap;
190 int i, error, irq, gain = 0; 205 int i, error, irq, gain = 0;
191 unsigned int val, rev; 206 unsigned int val, rev;
192 u32 gain32, keycodes[CAP11XX_NUM_CHN]; 207 u32 gain32;
193 208
194 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 209 if (id->driver_data >= ARRAY_SIZE(cap11xx_devices)) {
210 dev_err(dev, "Invalid device ID %lu\n", id->driver_data);
211 return -EINVAL;
212 }
213
214 cap = &cap11xx_devices[id->driver_data];
215 if (!cap || !cap->num_channels) {
216 dev_err(dev, "Invalid device configuration\n");
217 return -EINVAL;
218 }
219
220 priv = devm_kzalloc(dev,
221 sizeof(*priv) +
222 cap->num_channels * sizeof(priv->keycodes[0]),
223 GFP_KERNEL);
195 if (!priv) 224 if (!priv)
196 return -ENOMEM; 225 return -ENOMEM;
197 226
@@ -203,10 +232,10 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
203 if (error) 232 if (error)
204 return error; 233 return error;
205 234
206 if (val != CAP11XX_PRODUCT_ID) { 235 if (val != cap->product_id) {
207 dev_err(dev, "Product ID: Got 0x%02x, expected 0x%02x\n", 236 dev_err(dev, "Product ID: Got 0x%02x, expected 0x%02x\n",
208 val, CAP11XX_PRODUCT_ID); 237 val, cap->product_id);
209 return -ENODEV; 238 return -ENXIO;
210 } 239 }
211 240
212 error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val); 241 error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val);
@@ -216,7 +245,7 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
216 if (val != CAP11XX_MANUFACTURER_ID) { 245 if (val != CAP11XX_MANUFACTURER_ID) {
217 dev_err(dev, "Manufacturer ID: Got 0x%02x, expected 0x%02x\n", 246 dev_err(dev, "Manufacturer ID: Got 0x%02x, expected 0x%02x\n",
218 val, CAP11XX_MANUFACTURER_ID); 247 val, CAP11XX_MANUFACTURER_ID);
219 return -ENODEV; 248 return -ENXIO;
220 } 249 }
221 250
222 error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev); 251 error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev);
@@ -234,17 +263,12 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
234 dev_err(dev, "Invalid sensor-gain value %d\n", gain32); 263 dev_err(dev, "Invalid sensor-gain value %d\n", gain32);
235 } 264 }
236 265
237 BUILD_BUG_ON(ARRAY_SIZE(keycodes) != ARRAY_SIZE(priv->keycodes));
238
239 /* Provide some useful defaults */ 266 /* Provide some useful defaults */
240 for (i = 0; i < ARRAY_SIZE(keycodes); i++) 267 for (i = 0; i < cap->num_channels; i++)
241 keycodes[i] = KEY_A + i; 268 priv->keycodes[i] = KEY_A + i;
242 269
243 of_property_read_u32_array(node, "linux,keycodes", 270 of_property_read_u32_array(node, "linux,keycodes",
244 keycodes, ARRAY_SIZE(keycodes)); 271 priv->keycodes, cap->num_channels);
245
246 for (i = 0; i < ARRAY_SIZE(keycodes); i++)
247 priv->keycodes[i] = keycodes[i];
248 272
249 error = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, 273 error = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL,
250 CAP11XX_REG_MAIN_CONTROL_GAIN_MASK, 274 CAP11XX_REG_MAIN_CONTROL_GAIN_MASK,
@@ -268,17 +292,17 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
268 if (of_property_read_bool(node, "autorepeat")) 292 if (of_property_read_bool(node, "autorepeat"))
269 __set_bit(EV_REP, priv->idev->evbit); 293 __set_bit(EV_REP, priv->idev->evbit);
270 294
271 for (i = 0; i < CAP11XX_NUM_CHN; i++) 295 for (i = 0; i < cap->num_channels; i++)
272 __set_bit(priv->keycodes[i], priv->idev->keybit); 296 __set_bit(priv->keycodes[i], priv->idev->keybit);
273 297
274 __clear_bit(KEY_RESERVED, priv->idev->keybit); 298 __clear_bit(KEY_RESERVED, priv->idev->keybit);
275 299
276 priv->idev->keycode = priv->keycodes; 300 priv->idev->keycode = priv->keycodes;
277 priv->idev->keycodesize = sizeof(priv->keycodes[0]); 301 priv->idev->keycodesize = sizeof(priv->keycodes[0]);
278 priv->idev->keycodemax = ARRAY_SIZE(priv->keycodes); 302 priv->idev->keycodemax = cap->num_channels;
279 303
280 priv->idev->id.vendor = CAP11XX_MANUFACTURER_ID; 304 priv->idev->id.vendor = CAP11XX_MANUFACTURER_ID;
281 priv->idev->id.product = CAP11XX_PRODUCT_ID; 305 priv->idev->id.product = cap->product_id;
282 priv->idev->id.version = rev; 306 priv->idev->id.version = rev;
283 307
284 priv->idev->open = cap11xx_input_open; 308 priv->idev->open = cap11xx_input_open;
@@ -312,12 +336,16 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client,
312 336
313static const struct of_device_id cap11xx_dt_ids[] = { 337static const struct of_device_id cap11xx_dt_ids[] = {
314 { .compatible = "microchip,cap1106", }, 338 { .compatible = "microchip,cap1106", },
339 { .compatible = "microchip,cap1126", },
340 { .compatible = "microchip,cap1188", },
315 {} 341 {}
316}; 342};
317MODULE_DEVICE_TABLE(of, cap11xx_dt_ids); 343MODULE_DEVICE_TABLE(of, cap11xx_dt_ids);
318 344
319static const struct i2c_device_id cap11xx_i2c_ids[] = { 345static const struct i2c_device_id cap11xx_i2c_ids[] = {
320 { "cap1106", 0 }, 346 { "cap1106", CAP1106 },
347 { "cap1126", CAP1126 },
348 { "cap1188", CAP1188 },
321 {} 349 {}
322}; 350};
323MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids); 351MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids);