Lines Matching +full:input +full:- +full:wakeup

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012-2013 MundoReader S.L.
16 #include <linux/input.h>
17 #include <linux/input/mt.h>
18 #include <linux/input/touchscreen.h>
95 * @input the input device
96 * @suspending in the process of going to suspend (don't emit wakeup
106 struct input_dev *input; member
130 struct i2c_client *client = ts->client; in zforce_command()
134 dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd); in zforce_command()
142 dev_err(&client->dev, "i2c send data request error: %d\n", ret); in zforce_command()
151 struct i2c_client *client = ts->client; in zforce_send_wait()
154 dev_dbg(&client->dev, "sending %d bytes for command 0x%x\n", in zforce_send_wait()
157 ts->command_waiting = buf[2]; in zforce_send_wait()
161 dev_err(&client->dev, "i2c send data request error: %d\n", ret); in zforce_send_wait()
165 dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]); in zforce_send_wait()
167 if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) in zforce_send_wait()
168 return -ETIME; in zforce_send_wait()
170 ret = ts->command_result; in zforce_send_wait()
176 struct i2c_client *client = ts->client; in zforce_command_wait()
180 dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd); in zforce_command_wait()
188 dev_err(&client->dev, "i2c send data request error: %d\n", in zforce_command_wait()
198 struct i2c_client *client = ts->client; in zforce_resolution()
203 dev_dbg(&client->dev, "set resolution to (%d,%d)\n", x, y); in zforce_resolution()
211 struct i2c_client *client = ts->client; in zforce_scan_frequency()
217 dev_dbg(&client->dev, in zforce_scan_frequency()
226 struct i2c_client *client = ts->client; in zforce_setconfig()
230 dev_dbg(&client->dev, "set config to (%d)\n", b1); in zforce_setconfig()
237 struct i2c_client *client = ts->client; in zforce_start()
240 dev_dbg(&client->dev, "starting device\n"); in zforce_start()
244 dev_err(&client->dev, "Unable to initialize, %d\n", error); in zforce_start()
248 error = zforce_resolution(ts, ts->prop.max_x, ts->prop.max_y); in zforce_start()
250 dev_err(&client->dev, "Unable to set resolution, %d\n", error); in zforce_start()
256 dev_err(&client->dev, "Unable to set scan frequency, %d\n", in zforce_start()
263 dev_err(&client->dev, "Unable to set config\n"); in zforce_start()
270 dev_err(&client->dev, "Unable to request data\n"); in zforce_start()
289 struct i2c_client *client = ts->client; in zforce_stop()
292 dev_dbg(&client->dev, "stopping device\n"); in zforce_stop()
297 dev_err(&client->dev, "could not deactivate device, %d\n", in zforce_stop()
307 struct i2c_client *client = ts->client; in zforce_touch_event()
314 dev_warn(&client->dev, in zforce_touch_event()
326 if (point.coord_x > ts->prop.max_x || in zforce_touch_event()
327 point.coord_y > ts->prop.max_y) { in zforce_touch_event()
328 dev_warn(&client->dev, "coordinates (%d,%d) invalid\n", in zforce_touch_event()
344 dev_dbg(&client->dev, in zforce_touch_event()
353 input_mt_slot(ts->input, point.id - 1); in zforce_touch_event()
355 if (input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, in zforce_touch_event()
357 touchscreen_report_pos(ts->input, &ts->prop, in zforce_touch_event()
360 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, in zforce_touch_event()
362 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR, in zforce_touch_event()
364 input_report_abs(ts->input, ABS_MT_ORIENTATION, in zforce_touch_event()
370 input_mt_sync_frame(ts->input); in zforce_touch_event()
372 input_mt_report_finger_count(ts->input, num); in zforce_touch_event()
374 input_sync(ts->input); in zforce_touch_event()
381 struct i2c_client *client = ts->client; in zforce_read_packet()
387 dev_err(&client->dev, "error reading header: %d\n", ret); in zforce_read_packet()
392 dev_err(&client->dev, "invalid frame start: %d\n", buf[0]); in zforce_read_packet()
393 return -EIO; in zforce_read_packet()
397 dev_err(&client->dev, "invalid payload length: %d\n", in zforce_read_packet()
399 return -EIO; in zforce_read_packet()
405 dev_err(&client->dev, "error reading payload: %d\n", ret); in zforce_read_packet()
409 dev_dbg(&client->dev, "read %d bytes for response command 0x%x\n", in zforce_read_packet()
417 struct i2c_client *client = ts->client; in zforce_complete()
419 if (ts->command_waiting == cmd) { in zforce_complete()
420 dev_dbg(&client->dev, "completing command 0x%x\n", cmd); in zforce_complete()
421 ts->command_result = result; in zforce_complete()
422 complete(&ts->command_done); in zforce_complete()
424 dev_dbg(&client->dev, "command %d not for us\n", cmd); in zforce_complete()
431 struct i2c_client *client = ts->client; in zforce_irq()
433 if (ts->suspended && device_may_wakeup(&client->dev)) in zforce_irq()
434 pm_wakeup_event(&client->dev, 500); in zforce_irq()
442 struct i2c_client *client = ts->client; in zforce_irq_thread()
450 * Due to the level-interrupt we will get re-triggered later. in zforce_irq_thread()
452 if (ts->suspended) { in zforce_irq_thread()
457 dev_dbg(&client->dev, "handling interrupt\n"); in zforce_irq_thread()
459 /* Don't emit wakeup events from commands run by zforce_suspend */ in zforce_irq_thread()
460 suspending = READ_ONCE(ts->suspending); in zforce_irq_thread()
461 if (!suspending && device_may_wakeup(&client->dev)) in zforce_irq_thread()
462 pm_stay_awake(&client->dev); in zforce_irq_thread()
466 * - the optional interrupt GPIO isn't specified in zforce_irq_thread()
469 * - the GPIO isn't active any more in zforce_irq_thread()
476 dev_err(&client->dev, in zforce_irq_thread()
486 * Always report touch-events received while in zforce_irq_thread()
487 * suspending, when being a wakeup source in zforce_irq_thread()
489 if (suspending && device_may_wakeup(&client->dev)) in zforce_irq_thread()
490 pm_wakeup_event(&client->dev, 500); in zforce_irq_thread()
495 ts->boot_complete = payload[RESPONSE_DATA]; in zforce_irq_thread()
513 ts->version_major = in zforce_irq_thread()
515 ts->version_minor = in zforce_irq_thread()
517 ts->version_build = in zforce_irq_thread()
519 ts->version_rev = in zforce_irq_thread()
522 dev_dbg(&ts->client->dev, in zforce_irq_thread()
524 ts->version_major, ts->version_minor, in zforce_irq_thread()
525 ts->version_build, ts->version_rev); in zforce_irq_thread()
531 dev_err(&ts->client->dev, "invalid command: 0x%x\n", in zforce_irq_thread()
536 dev_err(&ts->client->dev, in zforce_irq_thread()
541 } while (gpiod_get_value_cansleep(ts->gpio_int)); in zforce_irq_thread()
543 if (!suspending && device_may_wakeup(&client->dev)) in zforce_irq_thread()
544 pm_relax(&client->dev); in zforce_irq_thread()
546 dev_dbg(&client->dev, "finished interrupt\n"); in zforce_irq_thread()
561 struct i2c_client *client = ts->client; in zforce_input_close()
566 dev_warn(&client->dev, "stopping zforce failed\n"); in zforce_input_close()
571 struct i2c_client *client = ts->client; in __zforce_suspend()
572 struct input_dev *input = ts->input; in __zforce_suspend() local
575 guard(mutex)(&input->mutex); in __zforce_suspend()
578 * When configured as a wakeup source device should always wake in __zforce_suspend()
581 if (device_may_wakeup(&client->dev)) { in __zforce_suspend()
582 dev_dbg(&client->dev, "suspend while being a wakeup source\n"); in __zforce_suspend()
584 /* Need to start device, if not open, to be a wakeup source. */ in __zforce_suspend()
585 if (!input_device_enabled(input)) { in __zforce_suspend()
591 enable_irq_wake(client->irq); in __zforce_suspend()
592 } else if (input_device_enabled(input)) { in __zforce_suspend()
593 dev_dbg(&client->dev, in __zforce_suspend()
594 "suspend without being a wakeup source\n"); in __zforce_suspend()
600 disable_irq(client->irq); in __zforce_suspend()
603 ts->suspended = true; in __zforce_suspend()
613 WRITE_ONCE(ts->suspending, true); in zforce_suspend()
619 WRITE_ONCE(ts->suspending, false); in zforce_suspend()
628 struct input_dev *input = ts->input; in zforce_resume() local
631 guard(mutex)(&input->mutex); in zforce_resume()
633 ts->suspended = false; in zforce_resume()
635 if (device_may_wakeup(&client->dev)) { in zforce_resume()
636 dev_dbg(&client->dev, "resume from being a wakeup source\n"); in zforce_resume()
638 disable_irq_wake(client->irq); in zforce_resume()
641 if (!input_device_enabled(input)) { in zforce_resume()
646 } else if (input_device_enabled(input)) { in zforce_resume()
647 dev_dbg(&client->dev, "resume without being a wakeup source\n"); in zforce_resume()
649 enable_irq(client->irq); in zforce_resume()
665 gpiod_set_value_cansleep(ts->gpio_rst, 1); in zforce_reset()
674 device_property_read_u32(&ts->client->dev, "x-size", &x_max); in zforce_ts_parse_legacy_properties()
675 input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, x_max, 0, 0); in zforce_ts_parse_legacy_properties()
677 device_property_read_u32(&ts->client->dev, "y-size", &y_max); in zforce_ts_parse_legacy_properties()
678 input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, y_max, 0, 0); in zforce_ts_parse_legacy_properties()
687 ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL); in zforce_probe()
689 return -ENOMEM; in zforce_probe()
691 ts->gpio_rst = devm_gpiod_get_optional(&client->dev, "reset", in zforce_probe()
693 error = PTR_ERR_OR_ZERO(ts->gpio_rst); in zforce_probe()
695 return dev_err_probe(&client->dev, error, in zforce_probe()
698 if (ts->gpio_rst) { in zforce_probe()
699 ts->gpio_int = devm_gpiod_get_optional(&client->dev, "irq", in zforce_probe()
701 error = PTR_ERR_OR_ZERO(ts->gpio_int); in zforce_probe()
703 return dev_err_probe(&client->dev, error, in zforce_probe()
712 ts->gpio_int = devm_gpiod_get_index(&client->dev, NULL, 0, in zforce_probe()
715 error = PTR_ERR_OR_ZERO(ts->gpio_int); in zforce_probe()
717 return dev_err_probe(&client->dev, error, in zforce_probe()
721 ts->gpio_rst = devm_gpiod_get_index(&client->dev, NULL, 1, in zforce_probe()
723 error = PTR_ERR_OR_ZERO(ts->gpio_rst); in zforce_probe()
725 return dev_err_probe(&client->dev, error, in zforce_probe()
729 error = devm_regulator_get_enable(&client->dev, "vdd"); in zforce_probe()
731 return dev_err_probe(&client->dev, error, in zforce_probe()
740 error = devm_add_action_or_reset(&client->dev, zforce_reset, ts); in zforce_probe()
742 return dev_err_probe(&client->dev, error, in zforce_probe()
745 snprintf(ts->phys, sizeof(ts->phys), in zforce_probe()
746 "%s/input0", dev_name(&client->dev)); in zforce_probe()
748 input_dev = devm_input_allocate_device(&client->dev); in zforce_probe()
750 return dev_err_probe(&client->dev, -ENOMEM, in zforce_probe()
751 "could not allocate input device\n"); in zforce_probe()
753 ts->client = client; in zforce_probe()
754 ts->input = input_dev; in zforce_probe()
756 input_dev->name = "Neonode zForce touchscreen"; in zforce_probe()
757 input_dev->phys = ts->phys; in zforce_probe()
758 input_dev->id.bustype = BUS_I2C; in zforce_probe()
760 input_dev->open = zforce_input_open; in zforce_probe()
761 input_dev->close = zforce_input_close; in zforce_probe()
764 touchscreen_parse_properties(input_dev, true, &ts->prop); in zforce_probe()
765 if (ts->prop.max_x == 0 || ts->prop.max_y == 0) in zforce_probe()
766 return dev_err_probe(&client->dev, -EINVAL, "no size specified"); in zforce_probe()
779 input_set_drvdata(ts->input, ts); in zforce_probe()
781 init_completion(&ts->command_done); in zforce_probe()
790 error = devm_request_threaded_irq(&client->dev, client->irq, in zforce_probe()
792 IRQF_ONESHOT, input_dev->name, ts); in zforce_probe()
794 return dev_err_probe(&client->dev, error, in zforce_probe()
795 "irq %d request failed\n", client->irq); in zforce_probe()
800 gpiod_set_value_cansleep(ts->gpio_rst, 0); in zforce_probe()
802 ts->command_waiting = NOTIFICATION_BOOTCOMPLETE; in zforce_probe()
803 if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) in zforce_probe()
804 dev_warn(&client->dev, "bootcomplete timed out\n"); in zforce_probe()
809 return dev_err_probe(&client->dev, error, "unable to initialize\n"); in zforce_probe()
814 dev_err_probe(&client->dev, error, "couldn't get status\n"); in zforce_probe()
824 device_set_wakeup_capable(&client->dev, true); in zforce_probe()
828 return dev_err_probe(&client->dev, error, in zforce_probe()
829 "could not register input device\n"); in zforce_probe()
835 { "zforce-ts" },
850 .name = "zforce-ts",