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

1 // SPDX-License-Identifier: GPL-2.0
2 // Melfas MMS114/MMS152 touchscreen device driver
13 #include <linux/input/touchscreen.h>
43 /* Touchscreen absolute values */
87 struct i2c_client *client = data->client; in __mms114_read_reg()
96 xfer[0].addr = client->addr; in __mms114_read_reg()
97 xfer[0].flags = client->flags & I2C_M_TEN; in __mms114_read_reg()
102 xfer[1].addr = client->addr; in __mms114_read_reg()
103 xfer[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD; in __mms114_read_reg()
107 error = i2c_transfer(client->adapter, xfer, 2); in __mms114_read_reg()
109 dev_err(&client->dev, in __mms114_read_reg()
111 return error < 0 ? error : -EIO; in __mms114_read_reg()
124 return data->cache_mode_control; in mms114_read_reg()
133 struct i2c_client *client = data->client; in mms114_write_reg()
142 dev_err(&client->dev, in mms114_write_reg()
144 return error < 0 ? error : -EIO; in mms114_write_reg()
149 data->cache_mode_control = val; in mms114_write_reg()
156 struct i2c_client *client = data->client; in mms114_process_mt()
157 struct input_dev *input_dev = data->input_dev; in mms114_process_mt()
160 unsigned int y; in mms114_process_mt() local
162 if (touch->id > MMS114_MAX_TOUCH) { in mms114_process_mt()
163 dev_err(&client->dev, "Wrong touch id (%d)\n", touch->id); in mms114_process_mt()
167 if (touch->type != MMS114_TYPE_TOUCHSCREEN) { in mms114_process_mt()
168 dev_err(&client->dev, "Wrong touch type (%d)\n", touch->type); in mms114_process_mt()
172 id = touch->id - 1; in mms114_process_mt()
173 x = touch->x_lo | touch->x_hi << 8; in mms114_process_mt()
174 y = touch->y_lo | touch->y_hi << 8; in mms114_process_mt()
176 dev_dbg(&client->dev, in mms114_process_mt()
177 "id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n", in mms114_process_mt()
178 id, touch->type, touch->pressed, in mms114_process_mt()
179 x, y, touch->width, touch->strength); in mms114_process_mt()
182 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed); in mms114_process_mt()
184 if (touch->pressed) { in mms114_process_mt()
185 touchscreen_report_pos(input_dev, &data->props, x, y, true); in mms114_process_mt()
186 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width); in mms114_process_mt()
187 input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength); in mms114_process_mt()
194 struct input_dev *input_dev = data->input_dev; in mms114_interrupt()
201 mutex_lock(&input_dev->mutex); in mms114_interrupt()
202 if (!input_dev->users) { in mms114_interrupt()
203 mutex_unlock(&input_dev->mutex); in mms114_interrupt()
206 mutex_unlock(&input_dev->mutex); in mms114_interrupt()
222 input_mt_report_pointer_emulation(data->input_dev, true); in mms114_interrupt()
223 input_sync(data->input_dev); in mms114_interrupt()
248 struct device *dev = &data->client->dev; in mms114_get_version()
253 switch (data->type) { in mms114_get_version()
268 group = i2c_smbus_read_byte_data(data->client, in mms114_get_version()
292 const struct touchscreen_properties *props = &data->props; in mms114_setup_regs()
301 if (data->type != TYPE_MMS114) in mms114_setup_regs()
308 val = (props->max_x >> 8) & 0xf; in mms114_setup_regs()
309 val |= ((props->max_y >> 8) & 0xf) << 4; in mms114_setup_regs()
314 val = props->max_x & 0xff; in mms114_setup_regs()
319 val = props->max_x & 0xff; in mms114_setup_regs()
324 if (data->contact_threshold) { in mms114_setup_regs()
326 data->contact_threshold); in mms114_setup_regs()
331 if (data->moving_threshold) { in mms114_setup_regs()
333 data->moving_threshold); in mms114_setup_regs()
343 struct i2c_client *client = data->client; in mms114_start()
346 error = regulator_enable(data->core_reg); in mms114_start()
348 dev_err(&client->dev, "Failed to enable avdd: %d\n", error); in mms114_start()
352 error = regulator_enable(data->io_reg); in mms114_start()
354 dev_err(&client->dev, "Failed to enable vdd: %d\n", error); in mms114_start()
355 regulator_disable(data->core_reg); in mms114_start()
363 regulator_disable(data->io_reg); in mms114_start()
364 regulator_disable(data->core_reg); in mms114_start()
368 enable_irq(client->irq); in mms114_start()
375 struct i2c_client *client = data->client; in mms114_stop()
378 disable_irq(client->irq); in mms114_stop()
380 error = regulator_disable(data->io_reg); in mms114_stop()
382 dev_warn(&client->dev, "Failed to disable vdd: %d\n", error); in mms114_stop()
384 error = regulator_disable(data->core_reg); in mms114_stop()
386 dev_warn(&client->dev, "Failed to disable avdd: %d\n", error); in mms114_stop()
405 struct device *dev = &data->client->dev; in mms114_parse_legacy_bindings()
406 struct touchscreen_properties *props = &data->props; in mms114_parse_legacy_bindings()
408 if (device_property_read_u32(dev, "x-size", &props->max_x)) { in mms114_parse_legacy_bindings()
409 dev_dbg(dev, "failed to get legacy x-size property\n"); in mms114_parse_legacy_bindings()
410 return -EINVAL; in mms114_parse_legacy_bindings()
413 if (device_property_read_u32(dev, "y-size", &props->max_y)) { in mms114_parse_legacy_bindings()
414 dev_dbg(dev, "failed to get legacy y-size property\n"); in mms114_parse_legacy_bindings()
415 return -EINVAL; in mms114_parse_legacy_bindings()
418 device_property_read_u32(dev, "contact-threshold", in mms114_parse_legacy_bindings()
419 &data->contact_threshold); in mms114_parse_legacy_bindings()
420 device_property_read_u32(dev, "moving-threshold", in mms114_parse_legacy_bindings()
421 &data->moving_threshold); in mms114_parse_legacy_bindings()
423 if (device_property_read_bool(dev, "x-invert")) in mms114_parse_legacy_bindings()
424 props->invert_x = true; in mms114_parse_legacy_bindings()
425 if (device_property_read_bool(dev, "y-invert")) in mms114_parse_legacy_bindings()
426 props->invert_y = true; in mms114_parse_legacy_bindings()
428 props->swap_x_y = false; in mms114_parse_legacy_bindings()
441 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in mms114_probe()
442 dev_err(&client->dev, "Not supported I2C adapter\n"); in mms114_probe()
443 return -ENODEV; in mms114_probe()
446 data = devm_kzalloc(&client->dev, sizeof(struct mms114_data), in mms114_probe()
448 input_dev = devm_input_allocate_device(&client->dev); in mms114_probe()
450 dev_err(&client->dev, "Failed to allocate memory\n"); in mms114_probe()
451 return -ENOMEM; in mms114_probe()
454 data->client = client; in mms114_probe()
455 data->input_dev = input_dev; in mms114_probe()
457 match_data = device_get_match_data(&client->dev); in mms114_probe()
459 return -EINVAL; in mms114_probe()
461 data->type = (enum mms_type)match_data; in mms114_probe()
469 touchscreen_parse_properties(input_dev, true, &data->props); in mms114_probe()
470 if (!data->props.max_x || !data->props.max_y) { in mms114_probe()
471 dev_dbg(&client->dev, in mms114_probe()
472 "missing X/Y size properties, trying legacy bindings\n"); in mms114_probe()
478 0, data->props.max_x, 0, 0); in mms114_probe()
480 0, data->props.max_y, 0, 0); in mms114_probe()
483 if (data->type == TYPE_MMS114) { in mms114_probe()
485 * The firmware handles movement and pressure fuzz, so in mms114_probe()
488 data->moving_threshold = input_abs_get_fuzz(input_dev, in mms114_probe()
490 data->contact_threshold = input_abs_get_fuzz(input_dev, in mms114_probe()
497 input_dev->name = devm_kasprintf(&client->dev, GFP_KERNEL, in mms114_probe()
498 "MELFAS MMS%d Touchscreen", in mms114_probe()
499 data->type); in mms114_probe()
500 if (!input_dev->name) in mms114_probe()
501 return -ENOMEM; in mms114_probe()
503 input_dev->id.bustype = BUS_I2C; in mms114_probe()
504 input_dev->dev.parent = &client->dev; in mms114_probe()
505 input_dev->open = mms114_input_open; in mms114_probe()
506 input_dev->close = mms114_input_close; in mms114_probe()
516 data->core_reg = devm_regulator_get(&client->dev, "avdd"); in mms114_probe()
517 if (IS_ERR(data->core_reg)) { in mms114_probe()
518 error = PTR_ERR(data->core_reg); in mms114_probe()
519 dev_err(&client->dev, in mms114_probe()
524 data->io_reg = devm_regulator_get(&client->dev, "vdd"); in mms114_probe()
525 if (IS_ERR(data->io_reg)) { in mms114_probe()
526 error = PTR_ERR(data->io_reg); in mms114_probe()
527 dev_err(&client->dev, in mms114_probe()
532 error = devm_request_threaded_irq(&client->dev, client->irq, in mms114_probe()
534 dev_name(&client->dev), data); in mms114_probe()
536 dev_err(&client->dev, "Failed to register interrupt\n"); in mms114_probe()
539 disable_irq(client->irq); in mms114_probe()
541 error = input_register_device(data->input_dev); in mms114_probe()
543 dev_err(&client->dev, "Failed to register input device\n"); in mms114_probe()
554 struct input_dev *input_dev = data->input_dev; in mms114_suspend()
566 mutex_lock(&input_dev->mutex); in mms114_suspend()
567 if (input_dev->users) in mms114_suspend()
569 mutex_unlock(&input_dev->mutex); in mms114_suspend()
578 struct input_dev *input_dev = data->input_dev; in mms114_resume()
581 mutex_lock(&input_dev->mutex); in mms114_resume()
582 if (input_dev->users) { in mms114_resume()
585 mutex_unlock(&input_dev->mutex); in mms114_resume()
589 mutex_unlock(&input_dev->mutex); in mms114_resume()
633 MODULE_DESCRIPTION("MELFAS mms114 Touchscreen driver");