Lines Matching +full:input +full:- +full:threshold
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Input driver for resistor ladder connected on ADC
11 #include <linux/input.h>
32 static void adc_keys_poll(struct input_dev *input) in adc_keys_poll() argument
34 struct adc_keys_state *st = input_get_drvdata(input); in adc_keys_poll()
39 ret = iio_read_channel_processed(st->channel, &value); in adc_keys_poll()
42 value = st->keyup_voltage; in adc_keys_poll()
44 for (i = 0; i < st->num_keys; i++) { in adc_keys_poll()
45 diff = abs(st->map[i].voltage - value); in adc_keys_poll()
48 keycode = st->map[i].keycode; in adc_keys_poll()
53 if (abs(st->keyup_voltage - value) < closest) in adc_keys_poll()
56 if (st->last_key && st->last_key != keycode) in adc_keys_poll()
57 input_report_key(input, st->last_key, 0); in adc_keys_poll()
60 input_report_key(input, keycode, 1); in adc_keys_poll()
62 input_sync(input); in adc_keys_poll()
63 st->last_key = keycode; in adc_keys_poll()
71 st->num_keys = device_get_child_node_count(dev); in adc_keys_load_keymap()
72 if (st->num_keys == 0) { in adc_keys_load_keymap()
74 return -EINVAL; in adc_keys_load_keymap()
77 map = devm_kmalloc_array(dev, st->num_keys, sizeof(*map), GFP_KERNEL); in adc_keys_load_keymap()
79 return -ENOMEM; in adc_keys_load_keymap()
83 if (fwnode_property_read_u32(child, "press-threshold-microvolt", in adc_keys_load_keymap()
86 return -EINVAL; in adc_keys_load_keymap()
93 return -EINVAL; in adc_keys_load_keymap()
99 st->map = map; in adc_keys_load_keymap()
105 struct device *dev = &pdev->dev; in adc_keys_probe()
107 struct input_dev *input; in adc_keys_probe() local
114 return -ENOMEM; in adc_keys_probe()
116 st->channel = devm_iio_channel_get(dev, "buttons"); in adc_keys_probe()
117 if (IS_ERR(st->channel)) in adc_keys_probe()
118 return PTR_ERR(st->channel); in adc_keys_probe()
120 if (!st->channel->indio_dev) in adc_keys_probe()
121 return -ENXIO; in adc_keys_probe()
123 error = iio_get_channel_type(st->channel, &type); in adc_keys_probe()
129 return -EINVAL; in adc_keys_probe()
132 if (device_property_read_u32(dev, "keyup-threshold-microvolt", in adc_keys_probe()
133 &st->keyup_voltage)) { in adc_keys_probe()
135 return -EINVAL; in adc_keys_probe()
137 st->keyup_voltage /= 1000; in adc_keys_probe()
143 input = devm_input_allocate_device(dev); in adc_keys_probe()
144 if (!input) { in adc_keys_probe()
145 dev_err(dev, "failed to allocate input device\n"); in adc_keys_probe()
146 return -ENOMEM; in adc_keys_probe()
149 input_set_drvdata(input, st); in adc_keys_probe()
151 input->name = pdev->name; in adc_keys_probe()
152 input->phys = "adc-keys/input0"; in adc_keys_probe()
154 input->id.bustype = BUS_HOST; in adc_keys_probe()
155 input->id.vendor = 0x0001; in adc_keys_probe()
156 input->id.product = 0x0001; in adc_keys_probe()
157 input->id.version = 0x0100; in adc_keys_probe()
159 __set_bit(EV_KEY, input->evbit); in adc_keys_probe()
160 for (i = 0; i < st->num_keys; i++) in adc_keys_probe()
161 __set_bit(st->map[i].keycode, input->keybit); in adc_keys_probe()
164 __set_bit(EV_REP, input->evbit); in adc_keys_probe()
167 error = input_setup_polling(input, adc_keys_poll); in adc_keys_probe()
173 if (!device_property_read_u32(dev, "poll-interval", &value)) in adc_keys_probe()
174 input_set_poll_interval(input, value); in adc_keys_probe()
176 error = input_register_device(input); in adc_keys_probe()
178 dev_err(dev, "Unable to register input device: %d\n", error); in adc_keys_probe()
187 { .compatible = "adc-keys", },
202 MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@free-electrons.com>");
203 MODULE_DESCRIPTION("Input driver for resistor ladder connected on ADC");