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
152 return ERR_PTR(-EINVAL); in gpio_keys_polled_get_devtree_pdata()
154 pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * sizeof(*button), in gpio_keys_polled_get_devtree_pdata()
157 return ERR_PTR(-ENOMEM); in gpio_keys_polled_get_devtree_pdata()
159 button = (struct gpio_keys_button *)(pdata + 1); in gpio_keys_polled_get_devtree_pdata()
161 pdata->buttons = button; in gpio_keys_polled_get_devtree_pdata()
162 pdata->nbuttons = nbuttons; in gpio_keys_polled_get_devtree_pdata()
164 pdata->rep = device_property_present(dev, "autorepeat"); in gpio_keys_polled_get_devtree_pdata()
165 device_property_read_u32(dev, "poll-interval", &pdata->poll_interval); in gpio_keys_polled_get_devtree_pdata()
167 device_property_read_string(dev, "label", &pdata->name); in gpio_keys_polled_get_devtree_pdata()
171 &button->code)) { in gpio_keys_polled_get_devtree_pdata()
172 dev_err(dev, "button without keycode\n"); in gpio_keys_polled_get_devtree_pdata()
174 return ERR_PTR(-EINVAL); in gpio_keys_polled_get_devtree_pdata()
177 fwnode_property_read_string(child, "label", &button->desc); in gpio_keys_polled_get_devtree_pdata()
179 if (fwnode_property_read_u32(child, "linux,input-type", in gpio_keys_polled_get_devtree_pdata()
180 &button->type)) in gpio_keys_polled_get_devtree_pdata()
181 button->type = EV_KEY; in gpio_keys_polled_get_devtree_pdata()
183 if (fwnode_property_read_u32(child, "linux,input-value", in gpio_keys_polled_get_devtree_pdata()
184 (u32 *)&button->value)) in gpio_keys_polled_get_devtree_pdata()
185 button->value = 1; in gpio_keys_polled_get_devtree_pdata()
187 button->wakeup = in gpio_keys_polled_get_devtree_pdata()
188 fwnode_property_read_bool(child, "wakeup-source") || in gpio_keys_polled_get_devtree_pdata()
190 fwnode_property_read_bool(child, "gpio-key,wakeup"); in gpio_keys_polled_get_devtree_pdata()
192 if (fwnode_property_read_u32(child, "debounce-interval", in gpio_keys_polled_get_devtree_pdata()
193 &button->debounce_interval)) in gpio_keys_polled_get_devtree_pdata()
194 button->debounce_interval = 5; in gpio_keys_polled_get_devtree_pdata()
196 button++; in gpio_keys_polled_get_devtree_pdata()
207 for (i = 0; i < pdata->nbuttons; i++) { in gpio_keys_polled_set_abs_params()
208 const struct gpio_keys_button *button = &pdata->buttons[i]; in gpio_keys_polled_set_abs_params() local
210 if (button->type != EV_ABS || button->code != code) in gpio_keys_polled_set_abs_params()
213 if (button->value < min) in gpio_keys_polled_set_abs_params()
214 min = button->value; in gpio_keys_polled_set_abs_params()
215 if (button->value > max) in gpio_keys_polled_set_abs_params()
216 max = button->value; in gpio_keys_polled_set_abs_params()
223 { .compatible = "gpio-keys-polled", },
230 struct device *dev = &pdev->dev; in gpio_keys_polled_probe()
244 if (!pdata->poll_interval) { in gpio_keys_polled_probe()
246 return -EINVAL; in gpio_keys_polled_probe()
249 bdev = devm_kzalloc(dev, struct_size(bdev, data, pdata->nbuttons), in gpio_keys_polled_probe()
253 return -ENOMEM; in gpio_keys_polled_probe()
259 return -ENOMEM; in gpio_keys_polled_probe()
264 input->name = pdata->name ?: pdev->name; in gpio_keys_polled_probe()
265 input->phys = DRV_NAME"/input0"; in gpio_keys_polled_probe()
267 input->id.bustype = BUS_HOST; in gpio_keys_polled_probe()
268 input->id.vendor = 0x0001; in gpio_keys_polled_probe()
269 input->id.product = 0x0001; in gpio_keys_polled_probe()
270 input->id.version = 0x0100; in gpio_keys_polled_probe()
272 input->open = gpio_keys_polled_open; in gpio_keys_polled_probe()
273 input->close = gpio_keys_polled_close; in gpio_keys_polled_probe()
275 __set_bit(EV_KEY, input->evbit); in gpio_keys_polled_probe()
276 if (pdata->rep) in gpio_keys_polled_probe()
277 __set_bit(EV_REP, input->evbit); in gpio_keys_polled_probe()
279 for (i = 0; i < pdata->nbuttons; i++) { in gpio_keys_polled_probe()
280 const struct gpio_keys_button *button = &pdata->buttons[i]; in gpio_keys_polled_probe() local
281 struct gpio_keys_button_data *bdata = &bdev->data[i]; in gpio_keys_polled_probe()
282 unsigned int type = button->type ?: EV_KEY; in gpio_keys_polled_probe()
284 if (button->wakeup) { in gpio_keys_polled_probe()
287 return -EINVAL; in gpio_keys_polled_probe()
295 return -EINVAL; in gpio_keys_polled_probe()
298 bdata->gpiod = devm_fwnode_gpiod_get(dev, child, in gpio_keys_polled_probe()
300 button->desc); in gpio_keys_polled_probe()
301 if (IS_ERR(bdata->gpiod)) { in gpio_keys_polled_probe()
303 return dev_err_probe(dev, PTR_ERR(bdata->gpiod), in gpio_keys_polled_probe()
306 } else if (gpio_is_valid(button->gpio)) { in gpio_keys_polled_probe()
313 if (button->active_low) in gpio_keys_polled_probe()
316 error = devm_gpio_request_one(dev, button->gpio, in gpio_keys_polled_probe()
317 flags, button->desc ? : DRV_NAME); in gpio_keys_polled_probe()
321 button->gpio, error); in gpio_keys_polled_probe()
325 bdata->gpiod = gpio_to_desc(button->gpio); in gpio_keys_polled_probe()
326 if (!bdata->gpiod) { in gpio_keys_polled_probe()
329 button->gpio); in gpio_keys_polled_probe()
330 return -EINVAL; in gpio_keys_polled_probe()
334 bdata->last_state = -1; in gpio_keys_polled_probe()
335 bdata->threshold = DIV_ROUND_UP(button->debounce_interval, in gpio_keys_polled_probe()
336 pdata->poll_interval); in gpio_keys_polled_probe()
338 input_set_capability(input, type, button->code); in gpio_keys_polled_probe()
341 button->code); in gpio_keys_polled_probe()
346 bdev->input = input; in gpio_keys_polled_probe()
347 bdev->dev = dev; in gpio_keys_polled_probe()
348 bdev->pdata = pdata; in gpio_keys_polled_probe()
356 input_set_poll_interval(input, pdata->poll_interval); in gpio_keys_polled_probe()
366 for (i = 0; i < pdata->nbuttons; i++) in gpio_keys_polled_probe()
367 gpio_keys_polled_check_state(input, &pdata->buttons[i], in gpio_keys_polled_probe()
368 &bdev->data[i]); in gpio_keys_polled_probe()