Lines Matching +full:touchscreen +full:- +full:min +full:- +full:pressure

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012-2013 MundoReader S.L.
89 int pressure; member
99 * @access_mutex serialize i2c-access, to keep multipart reads together
137 struct i2c_client *client = ts->client; in zforce_command()
141 dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd); in zforce_command()
147 mutex_lock(&ts->access_mutex); in zforce_command()
149 mutex_unlock(&ts->access_mutex); in zforce_command()
151 dev_err(&client->dev, "i2c send data request error: %d\n", ret); in zforce_command()
160 gpiod_set_value_cansleep(ts->gpio_rst, 1); in zforce_reset_assert()
165 gpiod_set_value_cansleep(ts->gpio_rst, 0); in zforce_reset_deassert()
170 struct i2c_client *client = ts->client; in zforce_send_wait()
173 ret = mutex_trylock(&ts->command_mutex); in zforce_send_wait()
175 dev_err(&client->dev, "already waiting for a command\n"); in zforce_send_wait()
176 return -EBUSY; in zforce_send_wait()
179 dev_dbg(&client->dev, "sending %d bytes for command 0x%x\n", in zforce_send_wait()
182 ts->command_waiting = buf[2]; in zforce_send_wait()
184 mutex_lock(&ts->access_mutex); in zforce_send_wait()
186 mutex_unlock(&ts->access_mutex); in zforce_send_wait()
188 dev_err(&client->dev, "i2c send data request error: %d\n", ret); in zforce_send_wait()
192 dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]); in zforce_send_wait()
194 if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) { in zforce_send_wait()
195 ret = -ETIME; in zforce_send_wait()
199 ret = ts->command_result; in zforce_send_wait()
202 mutex_unlock(&ts->command_mutex); in zforce_send_wait()
208 struct i2c_client *client = ts->client; in zforce_command_wait()
212 dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd); in zforce_command_wait()
220 dev_err(&client->dev, "i2c send data request error: %d\n", ret); in zforce_command_wait()
229 struct i2c_client *client = ts->client; in zforce_resolution()
234 dev_dbg(&client->dev, "set resolution to (%d,%d)\n", x, y); in zforce_resolution()
242 struct i2c_client *client = ts->client; in zforce_scan_frequency()
248 dev_dbg(&client->dev, in zforce_scan_frequency()
257 struct i2c_client *client = ts->client; in zforce_setconfig()
261 dev_dbg(&client->dev, "set config to (%d)\n", b1); in zforce_setconfig()
268 struct i2c_client *client = ts->client; in zforce_start()
269 const struct zforce_ts_platdata *pdata = ts->pdata; in zforce_start()
272 dev_dbg(&client->dev, "starting device\n"); in zforce_start()
276 dev_err(&client->dev, "Unable to initialize, %d\n", ret); in zforce_start()
280 ret = zforce_resolution(ts, pdata->x_max, pdata->y_max); in zforce_start()
282 dev_err(&client->dev, "Unable to set resolution, %d\n", ret); in zforce_start()
288 dev_err(&client->dev, "Unable to set scan frequency, %d\n", in zforce_start()
295 dev_err(&client->dev, "Unable to set config\n"); in zforce_start()
302 dev_err(&client->dev, "Unable to request data\n"); in zforce_start()
321 struct i2c_client *client = ts->client; in zforce_stop()
324 dev_dbg(&client->dev, "stopping device\n"); in zforce_stop()
329 dev_err(&client->dev, "could not deactivate device, %d\n", in zforce_stop()
339 struct i2c_client *client = ts->client; in zforce_touch_event()
340 const struct zforce_ts_platdata *pdata = ts->pdata; in zforce_touch_event()
346 dev_warn(&client->dev, in zforce_touch_event()
358 if (point.coord_x > pdata->x_max || in zforce_touch_event()
359 point.coord_y > pdata->y_max) { in zforce_touch_event()
360 dev_warn(&client->dev, "coordinates (%d,%d) invalid\n", in zforce_touch_event()
371 point.area_minor = min(payload[9 * i + 6], in zforce_touch_event()
375 point.pressure = payload[9 * i + 8]; in zforce_touch_event()
378 dev_dbg(&client->dev, in zforce_touch_event()
379 …"point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n", in zforce_touch_event()
381 point.pressure, point.prblty, in zforce_touch_event()
387 input_mt_slot(ts->input, point.id - 1); in zforce_touch_event()
389 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, in zforce_touch_event()
393 input_report_abs(ts->input, ABS_MT_POSITION_X, in zforce_touch_event()
395 input_report_abs(ts->input, ABS_MT_POSITION_Y, in zforce_touch_event()
397 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, in zforce_touch_event()
399 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR, in zforce_touch_event()
401 input_report_abs(ts->input, ABS_MT_ORIENTATION, in zforce_touch_event()
407 input_mt_sync_frame(ts->input); in zforce_touch_event()
409 input_mt_report_finger_count(ts->input, num); in zforce_touch_event()
411 input_sync(ts->input); in zforce_touch_event()
418 struct i2c_client *client = ts->client; in zforce_read_packet()
421 mutex_lock(&ts->access_mutex); in zforce_read_packet()
426 dev_err(&client->dev, "error reading header: %d\n", ret); in zforce_read_packet()
431 dev_err(&client->dev, "invalid frame start: %d\n", buf[0]); in zforce_read_packet()
432 ret = -EIO; in zforce_read_packet()
437 dev_err(&client->dev, "invalid payload length: %d\n", in zforce_read_packet()
439 ret = -EIO; in zforce_read_packet()
446 dev_err(&client->dev, "error reading payload: %d\n", ret); in zforce_read_packet()
450 dev_dbg(&client->dev, "read %d bytes for response command 0x%x\n", in zforce_read_packet()
454 mutex_unlock(&ts->access_mutex); in zforce_read_packet()
460 struct i2c_client *client = ts->client; in zforce_complete()
462 if (ts->command_waiting == cmd) { in zforce_complete()
463 dev_dbg(&client->dev, "completing command 0x%x\n", cmd); in zforce_complete()
464 ts->command_result = result; in zforce_complete()
465 complete(&ts->command_done); in zforce_complete()
467 dev_dbg(&client->dev, "command %d not for us\n", cmd); in zforce_complete()
474 struct i2c_client *client = ts->client; in zforce_irq()
476 if (ts->suspended && device_may_wakeup(&client->dev)) in zforce_irq()
477 pm_wakeup_event(&client->dev, 500); in zforce_irq()
485 struct i2c_client *client = ts->client; in zforce_irq_thread()
492 * Due to the level-interrupt we will get re-triggered later. in zforce_irq_thread()
494 if (ts->suspended) { in zforce_irq_thread()
499 dev_dbg(&client->dev, "handling interrupt\n"); in zforce_irq_thread()
502 if (!ts->suspending && device_may_wakeup(&client->dev)) in zforce_irq_thread()
503 pm_stay_awake(&client->dev); in zforce_irq_thread()
507 * - the optional interrupt GPIO isn't specified in zforce_irq_thread()
510 * - the GPIO isn't active any more in zforce_irq_thread()
517 dev_err(&client->dev, in zforce_irq_thread()
527 * Always report touch-events received while in zforce_irq_thread()
530 if (ts->suspending && device_may_wakeup(&client->dev)) in zforce_irq_thread()
531 pm_wakeup_event(&client->dev, 500); in zforce_irq_thread()
536 ts->boot_complete = payload[RESPONSE_DATA]; in zforce_irq_thread()
554 ts->version_major = (payload[RESPONSE_DATA + 1] << 8) | in zforce_irq_thread()
556 ts->version_minor = (payload[RESPONSE_DATA + 3] << 8) | in zforce_irq_thread()
558 ts->version_build = (payload[RESPONSE_DATA + 5] << 8) | in zforce_irq_thread()
560 ts->version_rev = (payload[RESPONSE_DATA + 7] << 8) | in zforce_irq_thread()
562 dev_dbg(&ts->client->dev, in zforce_irq_thread()
564 ts->version_major, ts->version_minor, in zforce_irq_thread()
565 ts->version_build, ts->version_rev); in zforce_irq_thread()
571 dev_err(&ts->client->dev, "invalid command: 0x%x\n", in zforce_irq_thread()
576 dev_err(&ts->client->dev, in zforce_irq_thread()
581 } while (gpiod_get_value_cansleep(ts->gpio_int)); in zforce_irq_thread()
583 if (!ts->suspending && device_may_wakeup(&client->dev)) in zforce_irq_thread()
584 pm_relax(&client->dev); in zforce_irq_thread()
586 dev_dbg(&client->dev, "finished interrupt\n"); in zforce_irq_thread()
601 struct i2c_client *client = ts->client; in zforce_input_close()
606 dev_warn(&client->dev, "stopping zforce failed\n"); in zforce_input_close()
615 struct input_dev *input = ts->input; in zforce_suspend()
618 mutex_lock(&input->mutex); in zforce_suspend()
619 ts->suspending = true; in zforce_suspend()
625 if (device_may_wakeup(&client->dev)) { in zforce_suspend()
626 dev_dbg(&client->dev, "suspend while being a wakeup source\n"); in zforce_suspend()
629 if (!input->users) { in zforce_suspend()
635 enable_irq_wake(client->irq); in zforce_suspend()
636 } else if (input->users) { in zforce_suspend()
637 dev_dbg(&client->dev, in zforce_suspend()
644 disable_irq(client->irq); in zforce_suspend()
647 ts->suspended = true; in zforce_suspend()
650 ts->suspending = false; in zforce_suspend()
651 mutex_unlock(&input->mutex); in zforce_suspend()
660 struct input_dev *input = ts->input; in zforce_resume()
663 mutex_lock(&input->mutex); in zforce_resume()
665 ts->suspended = false; in zforce_resume()
667 if (device_may_wakeup(&client->dev)) { in zforce_resume()
668 dev_dbg(&client->dev, "resume from being a wakeup source\n"); in zforce_resume()
670 disable_irq_wake(client->irq); in zforce_resume()
673 if (!input->users) { in zforce_resume()
678 } else if (input->users) { in zforce_resume()
679 dev_dbg(&client->dev, "resume without being a wakeup source\n"); in zforce_resume()
681 enable_irq(client->irq); in zforce_resume()
689 mutex_unlock(&input->mutex); in zforce_resume()
704 if (!IS_ERR(ts->reg_vdd)) in zforce_reset()
705 regulator_disable(ts->reg_vdd); in zforce_reset()
711 struct device_node *np = dev->of_node; in zforce_parse_dt()
714 return ERR_PTR(-ENOENT); in zforce_parse_dt()
719 return ERR_PTR(-ENOMEM); in zforce_parse_dt()
722 if (of_property_read_u32(np, "x-size", &pdata->x_max)) { in zforce_parse_dt()
723 dev_err(dev, "failed to get x-size property\n"); in zforce_parse_dt()
724 return ERR_PTR(-EINVAL); in zforce_parse_dt()
727 if (of_property_read_u32(np, "y-size", &pdata->y_max)) { in zforce_parse_dt()
728 dev_err(dev, "failed to get y-size property\n"); in zforce_parse_dt()
729 return ERR_PTR(-EINVAL); in zforce_parse_dt()
738 const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev); in zforce_probe()
744 pdata = zforce_parse_dt(&client->dev); in zforce_probe()
749 ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL); in zforce_probe()
751 return -ENOMEM; in zforce_probe()
753 ts->gpio_rst = devm_gpiod_get_optional(&client->dev, "reset", in zforce_probe()
755 if (IS_ERR(ts->gpio_rst)) { in zforce_probe()
756 ret = PTR_ERR(ts->gpio_rst); in zforce_probe()
757 dev_err(&client->dev, in zforce_probe()
762 if (ts->gpio_rst) { in zforce_probe()
763 ts->gpio_int = devm_gpiod_get_optional(&client->dev, "irq", in zforce_probe()
765 if (IS_ERR(ts->gpio_int)) { in zforce_probe()
766 ret = PTR_ERR(ts->gpio_int); in zforce_probe()
767 dev_err(&client->dev, in zforce_probe()
778 ts->gpio_int = devm_gpiod_get_index(&client->dev, NULL, 0, in zforce_probe()
780 if (IS_ERR(ts->gpio_int)) { in zforce_probe()
781 ret = PTR_ERR(ts->gpio_int); in zforce_probe()
782 dev_err(&client->dev, in zforce_probe()
788 ts->gpio_rst = devm_gpiod_get_index(&client->dev, NULL, 1, in zforce_probe()
790 if (IS_ERR(ts->gpio_rst)) { in zforce_probe()
791 ret = PTR_ERR(ts->gpio_rst); in zforce_probe()
792 dev_err(&client->dev, in zforce_probe()
798 ts->reg_vdd = devm_regulator_get_optional(&client->dev, "vdd"); in zforce_probe()
799 if (IS_ERR(ts->reg_vdd)) { in zforce_probe()
800 ret = PTR_ERR(ts->reg_vdd); in zforce_probe()
801 if (ret == -EPROBE_DEFER) in zforce_probe()
804 ret = regulator_enable(ts->reg_vdd); in zforce_probe()
815 ret = devm_add_action(&client->dev, zforce_reset, ts); in zforce_probe()
817 dev_err(&client->dev, "failed to register reset action, %d\n", in zforce_probe()
821 if (!IS_ERR(ts->reg_vdd)) in zforce_probe()
822 regulator_disable(ts->reg_vdd); in zforce_probe()
827 snprintf(ts->phys, sizeof(ts->phys), in zforce_probe()
828 "%s/input0", dev_name(&client->dev)); in zforce_probe()
830 input_dev = devm_input_allocate_device(&client->dev); in zforce_probe()
832 dev_err(&client->dev, "could not allocate input device\n"); in zforce_probe()
833 return -ENOMEM; in zforce_probe()
836 mutex_init(&ts->access_mutex); in zforce_probe()
837 mutex_init(&ts->command_mutex); in zforce_probe()
839 ts->pdata = pdata; in zforce_probe()
840 ts->client = client; in zforce_probe()
841 ts->input = input_dev; in zforce_probe()
843 input_dev->name = "Neonode zForce touchscreen"; in zforce_probe()
844 input_dev->phys = ts->phys; in zforce_probe()
845 input_dev->id.bustype = BUS_I2C; in zforce_probe()
847 input_dev->open = zforce_input_open; in zforce_probe()
848 input_dev->close = zforce_input_close; in zforce_probe()
850 __set_bit(EV_KEY, input_dev->evbit); in zforce_probe()
851 __set_bit(EV_SYN, input_dev->evbit); in zforce_probe()
852 __set_bit(EV_ABS, input_dev->evbit); in zforce_probe()
856 pdata->x_max, 0, 0); in zforce_probe()
858 pdata->y_max, 0, 0); in zforce_probe()
867 input_set_drvdata(ts->input, ts); in zforce_probe()
869 init_completion(&ts->command_done); in zforce_probe()
878 ret = devm_request_threaded_irq(&client->dev, client->irq, in zforce_probe()
881 input_dev->name, ts); in zforce_probe()
883 dev_err(&client->dev, "irq %d request failed\n", client->irq); in zforce_probe()
892 ts->command_waiting = NOTIFICATION_BOOTCOMPLETE; in zforce_probe()
893 if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) in zforce_probe()
894 dev_warn(&client->dev, "bootcomplete timed out\n"); in zforce_probe()
899 dev_err(&client->dev, "unable to initialize, %d\n", ret); in zforce_probe()
906 dev_err(&client->dev, "couldn't get status, %d\n", ret); in zforce_probe()
916 device_set_wakeup_capable(&client->dev, true); in zforce_probe()
920 dev_err(&client->dev, "could not register input device, %d\n", in zforce_probe()
929 { "zforce-ts", 0 },
944 .name = "zforce-ts",
955 MODULE_DESCRIPTION("zForce TouchScreen Driver");