Lines Matching +full:linux +full:- +full:keycodes

1 // SPDX-License-Identifier: GPL-2.0-only
9 * Copyright (c) 2006-2012 MStar Semiconductor, Inc.
14 #include <linux/delay.h>
15 #include <linux/gpio/consumer.h>
16 #include <linux/i2c.h>
17 #include <linux/input.h>
18 #include <linux/input/mt.h>
19 #include <linux/input/touchscreen.h>
20 #include <linux/interrupt.h>
21 #include <linux/kernel.h>
22 #include <linux/mod_devicetable.h>
23 #include <linux/module.h>
24 #include <linux/property.h>
25 #include <linux/regulator/consumer.h>
26 #include <linux/slab.h>
78 u32 keycodes[MAX_BUTTONS]; member
90 return (u8)((-sum) & 0xFF); in msg2638_checksum()
101 for (i = 0; i < msg2638->num_keycodes; ++i) in msg2138_report_keys()
102 input_report_key(msg2638->input_dev, msg2638->keycodes[i], in msg2138_report_keys()
109 struct i2c_client *client = msg2638->client; in msg2138_ts_irq_handler()
110 struct input_dev *input = msg2638->input_dev; in msg2138_ts_irq_handler()
115 .addr = client->addr, in msg2138_ts_irq_handler()
125 ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); in msg2138_ts_irq_handler()
127 dev_err(&client->dev, in msg2138_ts_irq_handler()
129 ret < 0 ? ret : -EIO); in msg2138_ts_irq_handler()
133 if (msg2638_checksum((u8 *)&touch_event, len - 1) != in msg2138_ts_irq_handler()
135 dev_err(&client->dev, "Failed checksum!\n"); in msg2138_ts_irq_handler()
142 /* Ignore non-pressed finger data, but check for key code */ in msg2138_ts_irq_handler()
143 if (p0->xy_hi == 0xFF && p0->x_low == 0xFF && p0->y_low == 0xFF) { in msg2138_ts_irq_handler()
144 if (p1->xy_hi == 0xFF && p1->y_low == 0xFF) in msg2138_ts_irq_handler()
145 msg2138_report_keys(msg2638, p1->x_low); in msg2138_ts_irq_handler()
149 x = ((p0->xy_hi & 0xF0) << 4) | p0->x_low; in msg2138_ts_irq_handler()
150 y = ((p0->xy_hi & 0x0F) << 8) | p0->y_low; in msg2138_ts_irq_handler()
154 touchscreen_report_pos(input, &msg2638->prop, x, y, true); in msg2138_ts_irq_handler()
156 /* Ignore non-pressed finger data */ in msg2138_ts_irq_handler()
157 if (p1->xy_hi == 0xFF && p1->x_low == 0xFF && p1->y_low == 0xFF) in msg2138_ts_irq_handler()
161 delta_x = ((p1->xy_hi & 0xF0) << 4) | p1->x_low; in msg2138_ts_irq_handler()
162 delta_y = ((p1->xy_hi & 0x0F) << 8) | p1->y_low; in msg2138_ts_irq_handler()
173 touchscreen_report_pos(input, &msg2638->prop, x, y, true); in msg2138_ts_irq_handler()
176 input_mt_sync_frame(msg2638->input_dev); in msg2138_ts_irq_handler()
177 input_sync(msg2638->input_dev); in msg2138_ts_irq_handler()
186 struct i2c_client *client = msg2638->client; in msg2638_ts_irq_handler()
187 struct input_dev *input = msg2638->input_dev; in msg2638_ts_irq_handler()
192 .addr = client->addr, in msg2638_ts_irq_handler()
203 ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); in msg2638_ts_irq_handler()
205 dev_err(&client->dev, in msg2638_ts_irq_handler()
207 ret < 0 ? ret : -EIO); in msg2638_ts_irq_handler()
214 if (msg2638_checksum((u8 *)&touch_event, len - 1) != in msg2638_ts_irq_handler()
216 dev_err(&client->dev, "Failed checksum!\n"); in msg2638_ts_irq_handler()
220 for (i = 0; i < msg2638->max_fingers; i++) { in msg2638_ts_irq_handler()
223 /* Ignore non-pressed finger data */ in msg2638_ts_irq_handler()
224 if (p->xy_hi == 0xFF && p->x_low == 0xFF && p->y_low == 0xFF) in msg2638_ts_irq_handler()
227 x = (((p->xy_hi & 0xF0) << 4) | p->x_low); in msg2638_ts_irq_handler()
228 y = (((p->xy_hi & 0x0F) << 8) | p->y_low); in msg2638_ts_irq_handler()
232 touchscreen_report_pos(input, &msg2638->prop, x, y, true); in msg2638_ts_irq_handler()
235 input_mt_sync_frame(msg2638->input_dev); in msg2638_ts_irq_handler()
236 input_sync(msg2638->input_dev); in msg2638_ts_irq_handler()
244 gpiod_set_value_cansleep(msg2638->reset_gpiod, 1); in msg2638_reset()
246 gpiod_set_value_cansleep(msg2638->reset_gpiod, 0); in msg2638_reset()
254 error = regulator_bulk_enable(ARRAY_SIZE(msg2638->supplies), in msg2638_start()
255 msg2638->supplies); in msg2638_start()
257 dev_err(&msg2638->client->dev, in msg2638_start()
266 enable_irq(msg2638->client->irq); in msg2638_start()
275 disable_irq(msg2638->client->irq); in msg2638_stop()
277 error = regulator_bulk_disable(ARRAY_SIZE(msg2638->supplies), in msg2638_stop()
278 msg2638->supplies); in msg2638_stop()
280 dev_err(&msg2638->client->dev, in msg2638_stop()
304 struct device *dev = &msg2638->client->dev; in msg2638_init_input_dev()
312 return -ENOMEM; in msg2638_init_input_dev()
316 msg2638->input_dev = input_dev; in msg2638_init_input_dev()
318 input_dev->name = "MStar TouchScreen"; in msg2638_init_input_dev()
319 input_dev->phys = "input/ts"; in msg2638_init_input_dev()
320 input_dev->id.bustype = BUS_I2C; in msg2638_init_input_dev()
321 input_dev->open = msg2638_input_open; in msg2638_init_input_dev()
322 input_dev->close = msg2638_input_close; in msg2638_init_input_dev()
324 if (msg2638->num_keycodes) { in msg2638_init_input_dev()
325 input_dev->keycode = msg2638->keycodes; in msg2638_init_input_dev()
326 input_dev->keycodemax = msg2638->num_keycodes; in msg2638_init_input_dev()
327 input_dev->keycodesize = sizeof(msg2638->keycodes[0]); in msg2638_init_input_dev()
328 for (i = 0; i < msg2638->num_keycodes; i++) in msg2638_init_input_dev()
330 EV_KEY, msg2638->keycodes[i]); in msg2638_init_input_dev()
336 touchscreen_parse_properties(input_dev, true, &msg2638->prop); in msg2638_init_input_dev()
337 if (!msg2638->prop.max_x || !msg2638->prop.max_y) { in msg2638_init_input_dev()
338 dev_err(dev, "touchscreen-size-x and/or touchscreen-size-y not set in properties\n"); in msg2638_init_input_dev()
339 return -EINVAL; in msg2638_init_input_dev()
342 error = input_mt_init_slots(input_dev, msg2638->max_fingers, in msg2638_init_input_dev()
361 struct device *dev = &client->dev; in msg2638_ts_probe()
365 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in msg2638_ts_probe()
367 return -ENXIO; in msg2638_ts_probe()
372 return -ENOMEM; in msg2638_ts_probe()
374 msg2638->client = client; in msg2638_ts_probe()
377 chip_data = device_get_match_data(&client->dev); in msg2638_ts_probe()
378 if (!chip_data || !chip_data->max_fingers) { in msg2638_ts_probe()
380 return -EINVAL; in msg2638_ts_probe()
383 msg2638->max_fingers = chip_data->max_fingers; in msg2638_ts_probe()
385 msg2638->supplies[0].supply = "vdd"; in msg2638_ts_probe()
386 msg2638->supplies[1].supply = "vddio"; in msg2638_ts_probe()
387 error = devm_regulator_bulk_get(dev, ARRAY_SIZE(msg2638->supplies), in msg2638_ts_probe()
388 msg2638->supplies); in msg2638_ts_probe()
394 msg2638->reset_gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in msg2638_ts_probe()
395 if (IS_ERR(msg2638->reset_gpiod)) { in msg2638_ts_probe()
396 error = PTR_ERR(msg2638->reset_gpiod); in msg2638_ts_probe()
401 msg2638->num_keycodes = device_property_count_u32(dev, in msg2638_ts_probe()
402 "linux,keycodes"); in msg2638_ts_probe()
403 if (msg2638->num_keycodes == -EINVAL) { in msg2638_ts_probe()
404 msg2638->num_keycodes = 0; in msg2638_ts_probe()
405 } else if (msg2638->num_keycodes < 0) { in msg2638_ts_probe()
406 dev_err(dev, "Unable to parse linux,keycodes property: %d\n", in msg2638_ts_probe()
407 msg2638->num_keycodes); in msg2638_ts_probe()
408 return msg2638->num_keycodes; in msg2638_ts_probe()
409 } else if (msg2638->num_keycodes > ARRAY_SIZE(msg2638->keycodes)) { in msg2638_ts_probe()
410 dev_warn(dev, "Found %d linux,keycodes but max is %zd, ignoring the rest\n", in msg2638_ts_probe()
411 msg2638->num_keycodes, ARRAY_SIZE(msg2638->keycodes)); in msg2638_ts_probe()
412 msg2638->num_keycodes = ARRAY_SIZE(msg2638->keycodes); in msg2638_ts_probe()
415 if (msg2638->num_keycodes > 0) { in msg2638_ts_probe()
416 error = device_property_read_u32_array(dev, "linux,keycodes", in msg2638_ts_probe()
417 msg2638->keycodes, in msg2638_ts_probe()
418 msg2638->num_keycodes); in msg2638_ts_probe()
420 dev_err(dev, "Unable to read linux,keycodes values: %d\n", in msg2638_ts_probe()
426 error = devm_request_threaded_irq(dev, client->irq, in msg2638_ts_probe()
427 NULL, chip_data->irq_handler, in msg2638_ts_probe()
429 client->name, msg2638); in msg2638_ts_probe()
449 mutex_lock(&msg2638->input_dev->mutex); in msg2638_suspend()
451 if (input_device_enabled(msg2638->input_dev)) in msg2638_suspend()
454 mutex_unlock(&msg2638->input_dev->mutex); in msg2638_suspend()
465 mutex_lock(&msg2638->input_dev->mutex); in msg2638_resume()
467 if (input_device_enabled(msg2638->input_dev)) in msg2638_resume()
470 mutex_unlock(&msg2638->input_dev->mutex); in msg2638_resume()
497 .name = "MStar-TS",