Lines Matching +full:calib +full:- +full:sensitivity
1 // SPDX-License-Identifier: GPL-2.0-only
178 return regmap_write(priv->regmap, in cap11xx_write_calib_sens_config_1()
180 (priv->calib_sensitivities[3] << 6) | in cap11xx_write_calib_sens_config_1()
181 (priv->calib_sensitivities[2] << 4) | in cap11xx_write_calib_sens_config_1()
182 (priv->calib_sensitivities[1] << 2) | in cap11xx_write_calib_sens_config_1()
183 priv->calib_sensitivities[0]); in cap11xx_write_calib_sens_config_1()
188 return regmap_write(priv->regmap, in cap11xx_write_calib_sens_config_2()
190 (priv->calib_sensitivities[7] << 6) | in cap11xx_write_calib_sens_config_2()
191 (priv->calib_sensitivities[6] << 4) | in cap11xx_write_calib_sens_config_2()
192 (priv->calib_sensitivities[5] << 2) | in cap11xx_write_calib_sens_config_2()
193 priv->calib_sensitivities[4]); in cap11xx_write_calib_sens_config_2()
198 struct device_node *node = priv->dev->of_node; in cap11xx_init_keys()
199 struct device *dev = priv->dev; in cap11xx_init_keys()
205 return -ENODEV; in cap11xx_init_keys()
208 if (!of_property_read_u32(node, "microchip,sensor-gain", &u32_val)) { in cap11xx_init_keys()
209 if (!priv->model->has_gain) { in cap11xx_init_keys()
211 "This model doesn't support 'sensor-gain'\n"); in cap11xx_init_keys()
213 priv->analog_gain = (u8)ilog2(u32_val); in cap11xx_init_keys()
215 error = regmap_update_bits(priv->regmap, in cap11xx_init_keys()
218 priv->analog_gain << CAP11XX_REG_MAIN_CONTROL_GAIN_SHIFT); in cap11xx_init_keys()
222 dev_err(dev, "Invalid sensor-gain value %u\n", u32_val); in cap11xx_init_keys()
223 return -EINVAL; in cap11xx_init_keys()
227 if (of_property_read_bool(node, "microchip,irq-active-high")) { in cap11xx_init_keys()
228 if (priv->model->has_irq_config) { in cap11xx_init_keys()
229 error = regmap_update_bits(priv->regmap, in cap11xx_init_keys()
237 "This model doesn't support 'irq-active-high'\n"); in cap11xx_init_keys()
241 if (!of_property_read_u32(node, "microchip,sensitivity-delta-sense", &u32_val)) { in cap11xx_init_keys()
243 dev_err(dev, "Invalid sensitivity-delta-sense value %u\n", u32_val); in cap11xx_init_keys()
244 return -EINVAL; in cap11xx_init_keys()
247 priv->sensitivity_delta_sense = (u8)ilog2(u32_val); in cap11xx_init_keys()
249 priv->sensitivity_delta_sense)); in cap11xx_init_keys()
251 error = regmap_update_bits(priv->regmap, in cap11xx_init_keys()
259 if (!of_property_read_u32_array(node, "microchip,input-threshold", in cap11xx_init_keys()
260 priv->thresholds, priv->model->num_channels)) { in cap11xx_init_keys()
261 for (i = 0; i < priv->model->num_channels; i++) { in cap11xx_init_keys()
262 if (priv->thresholds[i] > 127) { in cap11xx_init_keys()
263 dev_err(dev, "Invalid input-threshold value %u\n", in cap11xx_init_keys()
264 priv->thresholds[i]); in cap11xx_init_keys()
265 return -EINVAL; in cap11xx_init_keys()
268 error = regmap_write(priv->regmap, in cap11xx_init_keys()
270 priv->thresholds[i]); in cap11xx_init_keys()
276 if (!of_property_read_u32_array(node, "microchip,calib-sensitivity", in cap11xx_init_keys()
277 priv->calib_sensitivities, in cap11xx_init_keys()
278 priv->model->num_channels)) { in cap11xx_init_keys()
279 if (priv->model->has_sensitivity_control) { in cap11xx_init_keys()
280 for (i = 0; i < priv->model->num_channels; i++) { in cap11xx_init_keys()
281 if (!is_power_of_2(priv->calib_sensitivities[i]) || in cap11xx_init_keys()
282 priv->calib_sensitivities[i] > 4) { in cap11xx_init_keys()
283 dev_err(dev, "Invalid calib-sensitivity value %u\n", in cap11xx_init_keys()
284 priv->calib_sensitivities[i]); in cap11xx_init_keys()
285 return -EINVAL; in cap11xx_init_keys()
287 priv->calib_sensitivities[i] = ilog2(priv->calib_sensitivities[i]); in cap11xx_init_keys()
294 if (priv->model->num_channels > 4) { in cap11xx_init_keys()
301 "This model doesn't support 'calib-sensitivity'\n"); in cap11xx_init_keys()
305 for (i = 0; i < priv->model->num_channels; i++) { in cap11xx_init_keys()
306 if (!of_property_read_u32_index(node, "microchip,signal-guard", in cap11xx_init_keys()
309 return -EINVAL; in cap11xx_init_keys()
311 priv->signal_guard_inputs_mask |= 0x01 << i; in cap11xx_init_keys()
315 if (priv->signal_guard_inputs_mask) { in cap11xx_init_keys()
316 if (priv->model->has_signal_guard) { in cap11xx_init_keys()
317 error = regmap_write(priv->regmap, in cap11xx_init_keys()
319 priv->signal_guard_inputs_mask); in cap11xx_init_keys()
324 "This model doesn't support 'signal-guard'\n"); in cap11xx_init_keys()
329 for (i = 0; i < priv->model->num_channels; i++) in cap11xx_init_keys()
330 priv->keycodes[i] = KEY_A + i; in cap11xx_init_keys()
333 priv->keycodes, priv->model->num_channels); in cap11xx_init_keys()
336 error = regmap_write(priv->regmap, CAP11XX_REG_REPEAT_RATE, 0); in cap11xx_init_keys()
353 ret = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, 1, 0); in cap11xx_thread_func()
357 ret = regmap_read(priv->regmap, CAP11XX_REG_SENSOR_INPUT, &status); in cap11xx_thread_func()
361 for (i = 0; i < priv->idev->keycodemax; i++) in cap11xx_thread_func()
362 input_report_key(priv->idev, priv->keycodes[i], in cap11xx_thread_func()
365 input_sync(priv->idev); in cap11xx_thread_func()
376 if (IS_ENABLED(CONFIG_LEDS_CLASS) && priv->num_leds) in cap11xx_set_sleep()
379 return regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, in cap11xx_set_sleep()
403 struct cap11xx_priv *priv = led->priv; in cap11xx_led_set()
410 return regmap_update_bits(priv->regmap, in cap11xx_led_set()
412 BIT(led->reg), in cap11xx_led_set()
413 value ? BIT(led->reg) : 0); in cap11xx_led_set()
419 struct device_node *node = dev->of_node, *child; in cap11xx_init_leds()
428 return -EINVAL; in cap11xx_init_leds()
432 return -ENOMEM; in cap11xx_init_leds()
434 priv->leds = led; in cap11xx_init_leds()
436 error = regmap_update_bits(priv->regmap, in cap11xx_init_leds()
441 error = regmap_update_bits(priv->regmap, CAP11XX_REG_LED_DUTY_CYCLE_4, in cap11xx_init_leds()
451 led->cdev.name = in cap11xx_init_leds()
452 of_get_property(child, "label", NULL) ? : child->name; in cap11xx_init_leds()
453 led->cdev.default_trigger = in cap11xx_init_leds()
454 of_get_property(child, "linux,default-trigger", NULL); in cap11xx_init_leds()
455 led->cdev.flags = 0; in cap11xx_init_leds()
456 led->cdev.brightness_set_blocking = cap11xx_led_set; in cap11xx_init_leds()
457 led->cdev.max_brightness = 1; in cap11xx_init_leds()
458 led->cdev.brightness = LED_OFF; in cap11xx_init_leds()
463 return -EINVAL; in cap11xx_init_leds()
466 led->reg = reg; in cap11xx_init_leds()
467 led->priv = priv; in cap11xx_init_leds()
469 error = devm_led_classdev_register(dev, &led->cdev); in cap11xx_init_leds()
475 priv->num_leds++; in cap11xx_init_leds()
493 struct device *dev = &i2c_client->dev; in cap11xx_i2c_probe()
500 if (!id || !cap || !cap->num_channels) { in cap11xx_i2c_probe()
502 return -EINVAL; in cap11xx_i2c_probe()
506 struct_size(priv, keycodes, cap->num_channels), in cap11xx_i2c_probe()
509 return -ENOMEM; in cap11xx_i2c_probe()
511 priv->dev = dev; in cap11xx_i2c_probe()
513 priv->regmap = devm_regmap_init_i2c(i2c_client, &cap11xx_regmap_config); in cap11xx_i2c_probe()
514 if (IS_ERR(priv->regmap)) in cap11xx_i2c_probe()
515 return PTR_ERR(priv->regmap); in cap11xx_i2c_probe()
517 error = regmap_read(priv->regmap, CAP11XX_REG_PRODUCT_ID, &val); in cap11xx_i2c_probe()
521 if (val != cap->product_id) { in cap11xx_i2c_probe()
523 val, cap->product_id); in cap11xx_i2c_probe()
524 return -ENXIO; in cap11xx_i2c_probe()
527 error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val); in cap11xx_i2c_probe()
534 return -ENXIO; in cap11xx_i2c_probe()
537 error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev); in cap11xx_i2c_probe()
542 id->name, rev); in cap11xx_i2c_probe()
544 priv->model = cap; in cap11xx_i2c_probe()
547 id->name, rev); in cap11xx_i2c_probe()
553 priv->idev = devm_input_allocate_device(dev); in cap11xx_i2c_probe()
554 if (!priv->idev) in cap11xx_i2c_probe()
555 return -ENOMEM; in cap11xx_i2c_probe()
557 priv->idev->name = "CAP11XX capacitive touch sensor"; in cap11xx_i2c_probe()
558 priv->idev->id.bustype = BUS_I2C; in cap11xx_i2c_probe()
559 priv->idev->evbit[0] = BIT_MASK(EV_KEY); in cap11xx_i2c_probe()
561 if (of_property_read_bool(dev->of_node, "autorepeat")) in cap11xx_i2c_probe()
562 __set_bit(EV_REP, priv->idev->evbit); in cap11xx_i2c_probe()
564 for (i = 0; i < cap->num_channels; i++) in cap11xx_i2c_probe()
565 __set_bit(priv->keycodes[i], priv->idev->keybit); in cap11xx_i2c_probe()
567 __clear_bit(KEY_RESERVED, priv->idev->keybit); in cap11xx_i2c_probe()
569 priv->idev->keycode = priv->keycodes; in cap11xx_i2c_probe()
570 priv->idev->keycodesize = sizeof(priv->keycodes[0]); in cap11xx_i2c_probe()
571 priv->idev->keycodemax = cap->num_channels; in cap11xx_i2c_probe()
573 priv->idev->id.vendor = CAP11XX_MANUFACTURER_ID; in cap11xx_i2c_probe()
574 priv->idev->id.product = cap->product_id; in cap11xx_i2c_probe()
575 priv->idev->id.version = rev; in cap11xx_i2c_probe()
577 priv->idev->open = cap11xx_input_open; in cap11xx_i2c_probe()
578 priv->idev->close = cap11xx_input_close; in cap11xx_i2c_probe()
580 error = cap11xx_init_leds(dev, priv, cap->num_leds); in cap11xx_i2c_probe()
584 input_set_drvdata(priv->idev, priv); in cap11xx_i2c_probe()
588 * ->open() will bring it back once the it is actually needed. in cap11xx_i2c_probe()
592 error = input_register_device(priv->idev); in cap11xx_i2c_probe()
596 error = devm_request_threaded_irq(dev, i2c_client->irq, in cap11xx_i2c_probe()