Lines Matching +full:linux +full:- +full:keycodes

1 // SPDX-License-Identifier: GPL-2.0-only
5 * (c) 2014 Daniel Mack <linux@zonque.org>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/interrupt.h>
11 #include <linux/input.h>
12 #include <linux/leds.h>
13 #include <linux/of_irq.h>
14 #include <linux/regmap.h>
15 #include <linux/i2c.h>
16 #include <linux/gpio/consumer.h>
87 u32 keycodes[]; member
194 ret = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, 1, 0); in cap11xx_thread_func()
198 ret = regmap_read(priv->regmap, CAP11XX_REG_SENSOR_INPUT, &status); in cap11xx_thread_func()
202 for (i = 0; i < priv->idev->keycodemax; i++) in cap11xx_thread_func()
203 input_report_key(priv->idev, priv->keycodes[i], in cap11xx_thread_func()
206 input_sync(priv->idev); in cap11xx_thread_func()
217 if (IS_ENABLED(CONFIG_LEDS_CLASS) && priv->num_leds) in cap11xx_set_sleep()
220 return regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, in cap11xx_set_sleep()
244 struct cap11xx_priv *priv = led->priv; in cap11xx_led_set()
251 return regmap_update_bits(priv->regmap, in cap11xx_led_set()
253 BIT(led->reg), in cap11xx_led_set()
254 value ? BIT(led->reg) : 0); in cap11xx_led_set()
260 struct device_node *node = dev->of_node, *child; in cap11xx_init_leds()
269 return -EINVAL; in cap11xx_init_leds()
273 return -ENOMEM; in cap11xx_init_leds()
275 priv->leds = led; in cap11xx_init_leds()
277 error = regmap_update_bits(priv->regmap, in cap11xx_init_leds()
282 error = regmap_update_bits(priv->regmap, CAP11XX_REG_LED_DUTY_CYCLE_4, in cap11xx_init_leds()
292 led->cdev.name = in cap11xx_init_leds()
293 of_get_property(child, "label", NULL) ? : child->name; in cap11xx_init_leds()
294 led->cdev.default_trigger = in cap11xx_init_leds()
295 of_get_property(child, "linux,default-trigger", NULL); in cap11xx_init_leds()
296 led->cdev.flags = 0; in cap11xx_init_leds()
297 led->cdev.brightness_set_blocking = cap11xx_led_set; in cap11xx_init_leds()
298 led->cdev.max_brightness = 1; in cap11xx_init_leds()
299 led->cdev.brightness = LED_OFF; in cap11xx_init_leds()
304 return -EINVAL; in cap11xx_init_leds()
307 led->reg = reg; in cap11xx_init_leds()
308 led->priv = priv; in cap11xx_init_leds()
310 error = devm_led_classdev_register(dev, &led->cdev); in cap11xx_init_leds()
316 priv->num_leds++; in cap11xx_init_leds()
333 struct device *dev = &i2c_client->dev; in cap11xx_i2c_probe()
341 if (id->driver_data >= ARRAY_SIZE(cap11xx_devices)) { in cap11xx_i2c_probe()
342 dev_err(dev, "Invalid device ID %lu\n", id->driver_data); in cap11xx_i2c_probe()
343 return -EINVAL; in cap11xx_i2c_probe()
346 cap = &cap11xx_devices[id->driver_data]; in cap11xx_i2c_probe()
347 if (!cap || !cap->num_channels) { in cap11xx_i2c_probe()
349 return -EINVAL; in cap11xx_i2c_probe()
353 struct_size(priv, keycodes, cap->num_channels), in cap11xx_i2c_probe()
356 return -ENOMEM; in cap11xx_i2c_probe()
358 priv->regmap = devm_regmap_init_i2c(i2c_client, &cap11xx_regmap_config); in cap11xx_i2c_probe()
359 if (IS_ERR(priv->regmap)) in cap11xx_i2c_probe()
360 return PTR_ERR(priv->regmap); in cap11xx_i2c_probe()
362 error = regmap_read(priv->regmap, CAP11XX_REG_PRODUCT_ID, &val); in cap11xx_i2c_probe()
366 if (val != cap->product_id) { in cap11xx_i2c_probe()
368 val, cap->product_id); in cap11xx_i2c_probe()
369 return -ENXIO; in cap11xx_i2c_probe()
372 error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val); in cap11xx_i2c_probe()
379 return -ENXIO; in cap11xx_i2c_probe()
382 error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev); in cap11xx_i2c_probe()
387 id->name, rev); in cap11xx_i2c_probe()
388 node = dev->of_node; in cap11xx_i2c_probe()
390 if (!of_property_read_u32(node, "microchip,sensor-gain", &gain32)) { in cap11xx_i2c_probe()
391 if (cap->no_gain) in cap11xx_i2c_probe()
397 dev_err(dev, "Invalid sensor-gain value %d\n", gain32); in cap11xx_i2c_probe()
400 if (id->driver_data == CAP1106 || in cap11xx_i2c_probe()
401 id->driver_data == CAP1126 || in cap11xx_i2c_probe()
402 id->driver_data == CAP1188) { in cap11xx_i2c_probe()
403 if (of_property_read_bool(node, "microchip,irq-active-high")) { in cap11xx_i2c_probe()
404 error = regmap_update_bits(priv->regmap, in cap11xx_i2c_probe()
414 for (i = 0; i < cap->num_channels; i++) in cap11xx_i2c_probe()
415 priv->keycodes[i] = KEY_A + i; in cap11xx_i2c_probe()
417 of_property_read_u32_array(node, "linux,keycodes", in cap11xx_i2c_probe()
418 priv->keycodes, cap->num_channels); in cap11xx_i2c_probe()
420 if (!cap->no_gain) { in cap11xx_i2c_probe()
421 error = regmap_update_bits(priv->regmap, in cap11xx_i2c_probe()
429 /* Disable autorepeat. The Linux input system has its own handling. */ in cap11xx_i2c_probe()
430 error = regmap_write(priv->regmap, CAP11XX_REG_REPEAT_RATE, 0); in cap11xx_i2c_probe()
434 priv->idev = devm_input_allocate_device(dev); in cap11xx_i2c_probe()
435 if (!priv->idev) in cap11xx_i2c_probe()
436 return -ENOMEM; in cap11xx_i2c_probe()
438 priv->idev->name = "CAP11XX capacitive touch sensor"; in cap11xx_i2c_probe()
439 priv->idev->id.bustype = BUS_I2C; in cap11xx_i2c_probe()
440 priv->idev->evbit[0] = BIT_MASK(EV_KEY); in cap11xx_i2c_probe()
443 __set_bit(EV_REP, priv->idev->evbit); in cap11xx_i2c_probe()
445 for (i = 0; i < cap->num_channels; i++) in cap11xx_i2c_probe()
446 __set_bit(priv->keycodes[i], priv->idev->keybit); in cap11xx_i2c_probe()
448 __clear_bit(KEY_RESERVED, priv->idev->keybit); in cap11xx_i2c_probe()
450 priv->idev->keycode = priv->keycodes; in cap11xx_i2c_probe()
451 priv->idev->keycodesize = sizeof(priv->keycodes[0]); in cap11xx_i2c_probe()
452 priv->idev->keycodemax = cap->num_channels; in cap11xx_i2c_probe()
454 priv->idev->id.vendor = CAP11XX_MANUFACTURER_ID; in cap11xx_i2c_probe()
455 priv->idev->id.product = cap->product_id; in cap11xx_i2c_probe()
456 priv->idev->id.version = rev; in cap11xx_i2c_probe()
458 priv->idev->open = cap11xx_input_open; in cap11xx_i2c_probe()
459 priv->idev->close = cap11xx_input_close; in cap11xx_i2c_probe()
461 error = cap11xx_init_leds(dev, priv, cap->num_leds); in cap11xx_i2c_probe()
465 input_set_drvdata(priv->idev, priv); in cap11xx_i2c_probe()
469 * ->open() will bring it back once the it is actually needed. in cap11xx_i2c_probe()
473 error = input_register_device(priv->idev); in cap11xx_i2c_probe()
480 return -ENXIO; in cap11xx_i2c_probe()
527 MODULE_AUTHOR("Daniel Mack <linux@zonque.org>");