Lines Matching +full:touchscreen +full:- +full:fuzz +full:- +full:y

1 // SPDX-License-Identifier: GPL-2.0
2 // Melfas MMS114/MMS136/MMS152 touchscreen device driver
12 #include <linux/input/touchscreen.h>
42 /* Touchscreen absolute values */
93 struct i2c_client *client = data->client; in __mms114_read_reg()
102 xfer[0].addr = client->addr; in __mms114_read_reg()
103 xfer[0].flags = client->flags & I2C_M_TEN; in __mms114_read_reg()
108 xfer[1].addr = client->addr; in __mms114_read_reg()
109 xfer[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD; in __mms114_read_reg()
113 error = i2c_transfer(client->adapter, xfer, 2); in __mms114_read_reg()
115 dev_err(&client->dev, in __mms114_read_reg()
117 return error < 0 ? error : -EIO; in __mms114_read_reg()
130 return data->cache_mode_control; in mms114_read_reg()
139 struct i2c_client *client = data->client; in mms114_write_reg()
148 dev_err(&client->dev, in mms114_write_reg()
150 return error < 0 ? error : -EIO; in mms114_write_reg()
155 data->cache_mode_control = val; in mms114_write_reg()
162 struct i2c_client *client = data->client; in mms114_process_mt()
163 struct input_dev *input_dev = data->input_dev; in mms114_process_mt()
166 unsigned int y; in mms114_process_mt() local
168 if (touch->id > MMS114_MAX_TOUCH) { in mms114_process_mt()
169 dev_err(&client->dev, "Wrong touch id (%d)\n", touch->id); in mms114_process_mt()
173 id = touch->id - 1; in mms114_process_mt()
174 x = touch->x_lo | touch->x_hi << 8; in mms114_process_mt()
175 y = touch->y_lo | touch->y_hi << 8; in mms114_process_mt()
177 dev_dbg(&client->dev, in mms114_process_mt()
178 "id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n", in mms114_process_mt()
179 id, touch->type, touch->pressed, in mms114_process_mt()
180 x, y, touch->width, touch->strength); in mms114_process_mt()
183 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed); in mms114_process_mt()
185 if (touch->pressed) { in mms114_process_mt()
186 touchscreen_report_pos(input_dev, &data->props, x, y, true); in mms114_process_mt()
187 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width); in mms114_process_mt()
188 input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength); in mms114_process_mt()
195 struct i2c_client *client = data->client; in mms114_process_touchkey()
196 struct input_dev *input_dev = data->input_dev; in mms114_process_touchkey()
199 if (touch->id == 0) in mms114_process_touchkey()
202 if (touch->id > data->num_keycodes) { in mms114_process_touchkey()
203 dev_err(&client->dev, "Wrong touch id for touchkey (%d)\n", in mms114_process_touchkey()
204 touch->id); in mms114_process_touchkey()
208 keycode_id = touch->id - 1; in mms114_process_touchkey()
209 dev_dbg(&client->dev, "keycode id: %d, pressed: %d\n", keycode_id, in mms114_process_touchkey()
210 touch->pressed); in mms114_process_touchkey()
212 input_report_key(input_dev, data->keycodes[keycode_id], touch->pressed); in mms114_process_touchkey()
218 struct i2c_client *client = data->client; in mms114_interrupt()
219 struct input_dev *input_dev = data->input_dev; in mms114_interrupt()
226 mutex_lock(&input_dev->mutex); in mms114_interrupt()
228 mutex_unlock(&input_dev->mutex); in mms114_interrupt()
231 mutex_unlock(&input_dev->mutex); in mms114_interrupt()
238 if (data->type == TYPE_MMS134S || data->type == TYPE_MMS136) in mms114_interrupt()
259 dev_err(&client->dev, "Wrong touch type (%d)\n", in mms114_interrupt()
265 input_mt_report_pointer_emulation(data->input_dev, true); in mms114_interrupt()
266 input_sync(data->input_dev); in mms114_interrupt()
291 struct device *dev = &data->client->dev; in mms114_get_version()
296 switch (data->type) { in mms114_get_version()
311 group = i2c_smbus_read_byte_data(data->client, in mms114_get_version()
337 const struct touchscreen_properties *props = &data->props; in mms114_setup_regs()
346 if (data->type != TYPE_MMS114 && data->type != TYPE_MMS134S && in mms114_setup_regs()
347 data->type != TYPE_MMS136) in mms114_setup_regs()
354 val = (props->max_x >> 8) & 0xf; in mms114_setup_regs()
355 val |= ((props->max_y >> 8) & 0xf) << 4; in mms114_setup_regs()
360 val = props->max_x & 0xff; in mms114_setup_regs()
365 val = props->max_x & 0xff; in mms114_setup_regs()
370 if (data->contact_threshold) { in mms114_setup_regs()
372 data->contact_threshold); in mms114_setup_regs()
377 if (data->moving_threshold) { in mms114_setup_regs()
379 data->moving_threshold); in mms114_setup_regs()
389 struct i2c_client *client = data->client; in mms114_start()
392 error = regulator_enable(data->core_reg); in mms114_start()
394 dev_err(&client->dev, "Failed to enable avdd: %d\n", error); in mms114_start()
398 error = regulator_enable(data->io_reg); in mms114_start()
400 dev_err(&client->dev, "Failed to enable vdd: %d\n", error); in mms114_start()
401 regulator_disable(data->core_reg); in mms114_start()
409 regulator_disable(data->io_reg); in mms114_start()
410 regulator_disable(data->core_reg); in mms114_start()
414 enable_irq(client->irq); in mms114_start()
421 struct i2c_client *client = data->client; in mms114_stop()
424 disable_irq(client->irq); in mms114_stop()
426 error = regulator_disable(data->io_reg); in mms114_stop()
428 dev_warn(&client->dev, "Failed to disable vdd: %d\n", error); in mms114_stop()
430 error = regulator_disable(data->core_reg); in mms114_stop()
432 dev_warn(&client->dev, "Failed to disable avdd: %d\n", error); in mms114_stop()
451 struct device *dev = &data->client->dev; in mms114_parse_legacy_bindings()
452 struct touchscreen_properties *props = &data->props; in mms114_parse_legacy_bindings()
454 if (device_property_read_u32(dev, "x-size", &props->max_x)) { in mms114_parse_legacy_bindings()
455 dev_dbg(dev, "failed to get legacy x-size property\n"); in mms114_parse_legacy_bindings()
456 return -EINVAL; in mms114_parse_legacy_bindings()
459 if (device_property_read_u32(dev, "y-size", &props->max_y)) { in mms114_parse_legacy_bindings()
460 dev_dbg(dev, "failed to get legacy y-size property\n"); in mms114_parse_legacy_bindings()
461 return -EINVAL; in mms114_parse_legacy_bindings()
464 device_property_read_u32(dev, "contact-threshold", in mms114_parse_legacy_bindings()
465 &data->contact_threshold); in mms114_parse_legacy_bindings()
466 device_property_read_u32(dev, "moving-threshold", in mms114_parse_legacy_bindings()
467 &data->moving_threshold); in mms114_parse_legacy_bindings()
469 if (device_property_read_bool(dev, "x-invert")) in mms114_parse_legacy_bindings()
470 props->invert_x = true; in mms114_parse_legacy_bindings()
471 if (device_property_read_bool(dev, "y-invert")) in mms114_parse_legacy_bindings()
472 props->invert_y = true; in mms114_parse_legacy_bindings()
474 props->swap_x_y = false; in mms114_parse_legacy_bindings()
487 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in mms114_probe()
488 dev_err(&client->dev, "Not supported I2C adapter\n"); in mms114_probe()
489 return -ENODEV; in mms114_probe()
492 data = devm_kzalloc(&client->dev, sizeof(struct mms114_data), in mms114_probe()
494 input_dev = devm_input_allocate_device(&client->dev); in mms114_probe()
496 dev_err(&client->dev, "Failed to allocate memory\n"); in mms114_probe()
497 return -ENOMEM; in mms114_probe()
500 data->client = client; in mms114_probe()
501 data->input_dev = input_dev; in mms114_probe()
503 match_data = device_get_match_data(&client->dev); in mms114_probe()
505 return -EINVAL; in mms114_probe()
507 data->type = (enum mms_type)match_data; in mms114_probe()
509 data->num_keycodes = device_property_count_u32(&client->dev, in mms114_probe()
511 if (data->num_keycodes == -EINVAL) { in mms114_probe()
512 data->num_keycodes = 0; in mms114_probe()
513 } else if (data->num_keycodes < 0) { in mms114_probe()
514 dev_err(&client->dev, in mms114_probe()
516 data->num_keycodes); in mms114_probe()
517 return data->num_keycodes; in mms114_probe()
518 } else if (data->num_keycodes > MMS114_MAX_TOUCHKEYS) { in mms114_probe()
519 dev_warn(&client->dev, in mms114_probe()
521 data->num_keycodes, MMS114_MAX_TOUCHKEYS); in mms114_probe()
522 data->num_keycodes = MMS114_MAX_TOUCHKEYS; in mms114_probe()
525 if (data->num_keycodes > 0) { in mms114_probe()
526 error = device_property_read_u32_array(&client->dev, in mms114_probe()
528 data->keycodes, in mms114_probe()
529 data->num_keycodes); in mms114_probe()
531 dev_err(&client->dev, in mms114_probe()
537 input_dev->keycode = data->keycodes; in mms114_probe()
538 input_dev->keycodemax = data->num_keycodes; in mms114_probe()
539 input_dev->keycodesize = sizeof(data->keycodes[0]); in mms114_probe()
540 for (i = 0; i < data->num_keycodes; i++) in mms114_probe()
542 EV_KEY, data->keycodes[i]); in mms114_probe()
551 touchscreen_parse_properties(input_dev, true, &data->props); in mms114_probe()
552 if (!data->props.max_x || !data->props.max_y) { in mms114_probe()
553 dev_dbg(&client->dev, in mms114_probe()
554 "missing X/Y size properties, trying legacy bindings\n"); in mms114_probe()
560 0, data->props.max_x, 0, 0); in mms114_probe()
562 0, data->props.max_y, 0, 0); in mms114_probe()
565 if (data->type == TYPE_MMS114 || data->type == TYPE_MMS134S || in mms114_probe()
566 data->type == TYPE_MMS136) { in mms114_probe()
568 * The firmware handles movement and pressure fuzz, so in mms114_probe()
571 data->moving_threshold = input_abs_get_fuzz(input_dev, in mms114_probe()
573 data->contact_threshold = input_abs_get_fuzz(input_dev, in mms114_probe()
580 input_dev->name = devm_kasprintf(&client->dev, GFP_KERNEL, in mms114_probe()
581 "MELFAS MMS%d Touchscreen", in mms114_probe()
582 data->type); in mms114_probe()
583 if (!input_dev->name) in mms114_probe()
584 return -ENOMEM; in mms114_probe()
586 input_dev->id.bustype = BUS_I2C; in mms114_probe()
587 input_dev->dev.parent = &client->dev; in mms114_probe()
588 input_dev->open = mms114_input_open; in mms114_probe()
589 input_dev->close = mms114_input_close; in mms114_probe()
599 data->core_reg = devm_regulator_get(&client->dev, "avdd"); in mms114_probe()
600 if (IS_ERR(data->core_reg)) { in mms114_probe()
601 error = PTR_ERR(data->core_reg); in mms114_probe()
602 dev_err(&client->dev, in mms114_probe()
607 data->io_reg = devm_regulator_get(&client->dev, "vdd"); in mms114_probe()
608 if (IS_ERR(data->io_reg)) { in mms114_probe()
609 error = PTR_ERR(data->io_reg); in mms114_probe()
610 dev_err(&client->dev, in mms114_probe()
615 error = devm_request_threaded_irq(&client->dev, client->irq, in mms114_probe()
618 dev_name(&client->dev), data); in mms114_probe()
620 dev_err(&client->dev, "Failed to register interrupt\n"); in mms114_probe()
624 error = input_register_device(data->input_dev); in mms114_probe()
626 dev_err(&client->dev, "Failed to register input device\n"); in mms114_probe()
637 struct input_dev *input_dev = data->input_dev; in mms114_suspend()
649 mutex_lock(&input_dev->mutex); in mms114_suspend()
652 mutex_unlock(&input_dev->mutex); in mms114_suspend()
661 struct input_dev *input_dev = data->input_dev; in mms114_resume()
664 mutex_lock(&input_dev->mutex); in mms114_resume()
668 mutex_unlock(&input_dev->mutex); in mms114_resume()
672 mutex_unlock(&input_dev->mutex); in mms114_resume()
722 MODULE_DESCRIPTION("MELFAS mms114 Touchscreen driver");