Lines Matching +full:button +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org>
26 #define DRV_NAME "gpio-keys-polled"
45 const struct gpio_keys_button *button, in gpio_keys_button_event() argument
49 unsigned int type = button->type ?: EV_KEY; in gpio_keys_button_event()
53 input_event(input, type, button->code, button->value); in gpio_keys_button_event()
54 __set_bit(button->code, bdev->rel_axis_seen); in gpio_keys_button_event()
58 input_event(input, type, button->code, button->value); in gpio_keys_button_event()
59 __set_bit(button->code, bdev->abs_axis_seen); in gpio_keys_button_event()
62 input_event(input, type, button->code, state); in gpio_keys_button_event()
68 const struct gpio_keys_button *button, in gpio_keys_polled_check_state() argument
73 state = gpiod_get_value_cansleep(bdata->gpiod); in gpio_keys_polled_check_state()
75 dev_err(input->dev.parent, in gpio_keys_polled_check_state()
78 gpio_keys_button_event(input, button, state); in gpio_keys_polled_check_state()
80 if (state != bdata->last_state) { in gpio_keys_polled_check_state()
81 bdata->count = 0; in gpio_keys_polled_check_state()
82 bdata->last_state = state; in gpio_keys_polled_check_state()
90 const struct gpio_keys_platform_data *pdata = bdev->pdata; in gpio_keys_polled_poll()
93 memset(bdev->rel_axis_seen, 0, sizeof(bdev->rel_axis_seen)); in gpio_keys_polled_poll()
94 memset(bdev->abs_axis_seen, 0, sizeof(bdev->abs_axis_seen)); in gpio_keys_polled_poll()
96 for (i = 0; i < pdata->nbuttons; i++) { in gpio_keys_polled_poll()
97 struct gpio_keys_button_data *bdata = &bdev->data[i]; in gpio_keys_polled_poll()
99 if (bdata->count < bdata->threshold) { in gpio_keys_polled_poll()
100 bdata->count++; in gpio_keys_polled_poll()
101 gpio_keys_button_event(input, &pdata->buttons[i], in gpio_keys_polled_poll()
102 bdata->last_state); in gpio_keys_polled_poll()
104 gpio_keys_polled_check_state(input, &pdata->buttons[i], in gpio_keys_polled_poll()
109 for_each_set_bit(i, input->relbit, REL_CNT) { in gpio_keys_polled_poll()
110 if (!test_bit(i, bdev->rel_axis_seen)) in gpio_keys_polled_poll()
114 for_each_set_bit(i, input->absbit, ABS_CNT) { in gpio_keys_polled_poll()
115 if (!test_bit(i, bdev->abs_axis_seen)) in gpio_keys_polled_poll()
125 const struct gpio_keys_platform_data *pdata = bdev->pdata; in gpio_keys_polled_open()
127 if (pdata->enable) in gpio_keys_polled_open()
128 pdata->enable(bdev->dev); in gpio_keys_polled_open()
136 const struct gpio_keys_platform_data *pdata = bdev->pdata; in gpio_keys_polled_close()
138 if (pdata->disable) in gpio_keys_polled_close()
139 pdata->disable(bdev->dev); in gpio_keys_polled_close()
146 struct gpio_keys_button *button; in gpio_keys_polled_get_devtree_pdata() local
151 return ERR_PTR(-EINVAL); in gpio_keys_polled_get_devtree_pdata()
153 pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * sizeof(*button), in gpio_keys_polled_get_devtree_pdata()
156 return ERR_PTR(-ENOMEM); in gpio_keys_polled_get_devtree_pdata()
158 button = (struct gpio_keys_button *)(pdata + 1); in gpio_keys_polled_get_devtree_pdata()
160 pdata->buttons = button; in gpio_keys_polled_get_devtree_pdata()
161 pdata->nbuttons = nbuttons; in gpio_keys_polled_get_devtree_pdata()
163 pdata->rep = device_property_present(dev, "autorepeat"); in gpio_keys_polled_get_devtree_pdata()
164 device_property_read_u32(dev, "poll-interval", &pdata->poll_interval); in gpio_keys_polled_get_devtree_pdata()
166 device_property_read_string(dev, "label", &pdata->name); in gpio_keys_polled_get_devtree_pdata()
170 &button->code)) { in gpio_keys_polled_get_devtree_pdata()
171 dev_err(dev, "button without keycode\n"); in gpio_keys_polled_get_devtree_pdata()
172 return ERR_PTR(-EINVAL); in gpio_keys_polled_get_devtree_pdata()
175 fwnode_property_read_string(child, "label", &button->desc); in gpio_keys_polled_get_devtree_pdata()
177 if (fwnode_property_read_u32(child, "linux,input-type", in gpio_keys_polled_get_devtree_pdata()
178 &button->type)) in gpio_keys_polled_get_devtree_pdata()
179 button->type = EV_KEY; in gpio_keys_polled_get_devtree_pdata()
181 if (fwnode_property_read_u32(child, "linux,input-value", in gpio_keys_polled_get_devtree_pdata()
182 (u32 *)&button->value)) in gpio_keys_polled_get_devtree_pdata()
183 button->value = 1; in gpio_keys_polled_get_devtree_pdata()
185 button->wakeup = in gpio_keys_polled_get_devtree_pdata()
186 fwnode_property_read_bool(child, "wakeup-source") || in gpio_keys_polled_get_devtree_pdata()
188 fwnode_property_read_bool(child, "gpio-key,wakeup"); in gpio_keys_polled_get_devtree_pdata()
190 if (fwnode_property_read_u32(child, "debounce-interval", in gpio_keys_polled_get_devtree_pdata()
191 &button->debounce_interval)) in gpio_keys_polled_get_devtree_pdata()
192 button->debounce_interval = 5; in gpio_keys_polled_get_devtree_pdata()
194 button++; in gpio_keys_polled_get_devtree_pdata()
205 for (i = 0; i < pdata->nbuttons; i++) { in gpio_keys_polled_set_abs_params()
206 const struct gpio_keys_button *button = &pdata->buttons[i]; in gpio_keys_polled_set_abs_params() local
208 if (button->type != EV_ABS || button->code != code) in gpio_keys_polled_set_abs_params()
211 if (button->value < min) in gpio_keys_polled_set_abs_params()
212 min = button->value; in gpio_keys_polled_set_abs_params()
213 if (button->value > max) in gpio_keys_polled_set_abs_params()
214 max = button->value; in gpio_keys_polled_set_abs_params()
221 { .compatible = "gpio-keys-polled", },
228 struct device *dev = &pdev->dev; in gpio_keys_polled_probe()
242 if (!pdata->poll_interval) { in gpio_keys_polled_probe()
244 return -EINVAL; in gpio_keys_polled_probe()
247 bdev = devm_kzalloc(dev, struct_size(bdev, data, pdata->nbuttons), in gpio_keys_polled_probe()
251 return -ENOMEM; in gpio_keys_polled_probe()
257 return -ENOMEM; in gpio_keys_polled_probe()
262 input->name = pdata->name ?: pdev->name; in gpio_keys_polled_probe()
263 input->phys = DRV_NAME"/input0"; in gpio_keys_polled_probe()
265 input->id.bustype = BUS_HOST; in gpio_keys_polled_probe()
266 input->id.vendor = 0x0001; in gpio_keys_polled_probe()
267 input->id.product = 0x0001; in gpio_keys_polled_probe()
268 input->id.version = 0x0100; in gpio_keys_polled_probe()
270 input->open = gpio_keys_polled_open; in gpio_keys_polled_probe()
271 input->close = gpio_keys_polled_close; in gpio_keys_polled_probe()
273 __set_bit(EV_KEY, input->evbit); in gpio_keys_polled_probe()
274 if (pdata->rep) in gpio_keys_polled_probe()
275 __set_bit(EV_REP, input->evbit); in gpio_keys_polled_probe()
277 for (i = 0; i < pdata->nbuttons; i++) { in gpio_keys_polled_probe()
278 const struct gpio_keys_button *button = &pdata->buttons[i]; in gpio_keys_polled_probe() local
279 struct gpio_keys_button_data *bdata = &bdev->data[i]; in gpio_keys_polled_probe()
280 unsigned int type = button->type ?: EV_KEY; in gpio_keys_polled_probe()
282 if (button->wakeup) { in gpio_keys_polled_probe()
285 return -EINVAL; in gpio_keys_polled_probe()
293 return -EINVAL; in gpio_keys_polled_probe()
296 bdata->gpiod = devm_fwnode_gpiod_get(dev, child, in gpio_keys_polled_probe()
298 button->desc); in gpio_keys_polled_probe()
299 if (IS_ERR(bdata->gpiod)) { in gpio_keys_polled_probe()
301 return dev_err_probe(dev, PTR_ERR(bdata->gpiod), in gpio_keys_polled_probe()
304 } else if (gpio_is_valid(button->gpio)) { in gpio_keys_polled_probe()
311 if (button->active_low) in gpio_keys_polled_probe()
314 error = devm_gpio_request_one(dev, button->gpio, in gpio_keys_polled_probe()
315 flags, button->desc ? : DRV_NAME); in gpio_keys_polled_probe()
319 button->gpio); in gpio_keys_polled_probe()
321 bdata->gpiod = gpio_to_desc(button->gpio); in gpio_keys_polled_probe()
322 if (!bdata->gpiod) { in gpio_keys_polled_probe()
325 button->gpio); in gpio_keys_polled_probe()
326 return -EINVAL; in gpio_keys_polled_probe()
330 bdata->last_state = -1; in gpio_keys_polled_probe()
331 bdata->threshold = DIV_ROUND_UP(button->debounce_interval, in gpio_keys_polled_probe()
332 pdata->poll_interval); in gpio_keys_polled_probe()
334 input_set_capability(input, type, button->code); in gpio_keys_polled_probe()
337 button->code); in gpio_keys_polled_probe()
342 bdev->input = input; in gpio_keys_polled_probe()
343 bdev->dev = dev; in gpio_keys_polled_probe()
344 bdev->pdata = pdata; in gpio_keys_polled_probe()
352 input_set_poll_interval(input, pdata->poll_interval); in gpio_keys_polled_probe()
362 for (i = 0; i < pdata->nbuttons; i++) in gpio_keys_polled_probe()
363 gpio_keys_polled_check_state(input, &pdata->buttons[i], in gpio_keys_polled_probe()
364 &bdev->data[i]); in gpio_keys_polled_probe()