hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/input/touchscreen/pixcir_i2c_ts.c
....@@ -1,33 +1,76 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for Pixcir I2C touchscreen controllers.
34 *
45 * Copyright (C) 2010-2011 Pixcir, Inc.
5
- *
6
- * This software is licensed under the terms of the GNU General Public
7
- * License version 2, as published by the Free Software Foundation, and
8
- * may be copied, distributed, and modified under those terms.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
146 */
157
8
+#include <asm/unaligned.h>
169 #include <linux/delay.h>
17
-#include <linux/module.h>
18
-#include <linux/interrupt.h>
19
-#include <linux/slab.h>
10
+#include <linux/gpio/consumer.h>
2011 #include <linux/i2c.h>
2112 #include <linux/input.h>
2213 #include <linux/input/mt.h>
2314 #include <linux/input/touchscreen.h>
24
-#include <linux/gpio.h>
25
-#include <linux/gpio/consumer.h>
15
+#include <linux/interrupt.h>
2616 #include <linux/of_device.h>
27
-#include <linux/platform_data/pixcir_i2c_ts.h>
28
-#include <asm/unaligned.h>
17
+#include <linux/module.h>
18
+#include <linux/slab.h>
2919
3020 #define PIXCIR_MAX_SLOTS 5 /* Max fingers supported by driver */
21
+
22
+/*
23
+ * Register map
24
+ */
25
+#define PIXCIR_REG_POWER_MODE 51
26
+#define PIXCIR_REG_INT_MODE 52
27
+
28
+/*
29
+ * Power modes:
30
+ * active: max scan speed
31
+ * idle: lower scan speed with automatic transition to active on touch
32
+ * halt: datasheet says sleep but this is more like halt as the chip
33
+ * clocks are cut and it can only be brought out of this mode
34
+ * using the RESET pin.
35
+ */
36
+enum pixcir_power_mode {
37
+ PIXCIR_POWER_ACTIVE,
38
+ PIXCIR_POWER_IDLE,
39
+ PIXCIR_POWER_HALT,
40
+};
41
+
42
+#define PIXCIR_POWER_MODE_MASK 0x03
43
+#define PIXCIR_POWER_ALLOW_IDLE (1UL << 2)
44
+
45
+/*
46
+ * Interrupt modes:
47
+ * periodical: interrupt is asserted periodicaly
48
+ * diff coordinates: interrupt is asserted when coordinates change
49
+ * level on touch: interrupt level asserted during touch
50
+ * pulse on touch: interrupt pulse asserted during touch
51
+ *
52
+ */
53
+enum pixcir_int_mode {
54
+ PIXCIR_INT_PERIODICAL,
55
+ PIXCIR_INT_DIFF_COORD,
56
+ PIXCIR_INT_LEVEL_TOUCH,
57
+ PIXCIR_INT_PULSE_TOUCH,
58
+};
59
+
60
+#define PIXCIR_INT_MODE_MASK 0x03
61
+#define PIXCIR_INT_ENABLE (1UL << 3)
62
+#define PIXCIR_INT_POL_HIGH (1UL << 2)
63
+
64
+/**
65
+ * struct pixcir_i2c_chip_data - chip related data
66
+ * @max_fingers: Max number of fingers reported simultaneously by h/w
67
+ * @has_hw_ids: Hardware supports finger tracking IDs
68
+ *
69
+ */
70
+struct pixcir_i2c_chip_data {
71
+ u8 max_fingers;
72
+ bool has_hw_ids;
73
+};
3174
3275 struct pixcir_i2c_ts_data {
3376 struct i2c_client *client;
....@@ -38,7 +81,6 @@
3881 struct gpio_desc *gpio_wake;
3982 const struct pixcir_i2c_chip_data *chip;
4083 struct touchscreen_properties prop;
41
- int max_fingers; /* Max fingers supported in this instance */
4284 bool running;
4385 };
4486
....@@ -62,7 +104,7 @@
62104 memset(report, 0, sizeof(struct pixcir_report_data));
63105
64106 i = chip->has_hw_ids ? 1 : 0;
65
- readsize = 2 + tsdata->max_fingers * (4 + i);
107
+ readsize = 2 + tsdata->chip->max_fingers * (4 + i);
66108 if (readsize > sizeof(rdbuf))
67109 readsize = sizeof(rdbuf);
68110
....@@ -83,8 +125,8 @@
83125 }
84126
85127 touch = rdbuf[0] & 0x7;
86
- if (touch > tsdata->max_fingers)
87
- touch = tsdata->max_fingers;
128
+ if (touch > tsdata->chip->max_fingers)
129
+ touch = tsdata->chip->max_fingers;
88130
89131 report->num_touches = touch;
90132 bufptr = &rdbuf[2];
....@@ -200,7 +242,7 @@
200242
201243 ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_POWER_MODE);
202244 if (ret < 0) {
203
- dev_err(dev, "%s: can't read reg 0x%x : %d\n",
245
+ dev_err(dev, "%s: can't read reg %d : %d\n",
204246 __func__, PIXCIR_REG_POWER_MODE, ret);
205247 return ret;
206248 }
....@@ -213,7 +255,7 @@
213255
214256 ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_POWER_MODE, ret);
215257 if (ret < 0) {
216
- dev_err(dev, "%s: can't write reg 0x%x : %d\n",
258
+ dev_err(dev, "%s: can't write reg %d : %d\n",
217259 __func__, PIXCIR_REG_POWER_MODE, ret);
218260 return ret;
219261 }
....@@ -239,7 +281,7 @@
239281
240282 ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_INT_MODE);
241283 if (ret < 0) {
242
- dev_err(dev, "%s: can't read reg 0x%x : %d\n",
284
+ dev_err(dev, "%s: can't read reg %d : %d\n",
243285 __func__, PIXCIR_REG_INT_MODE, ret);
244286 return ret;
245287 }
....@@ -254,7 +296,7 @@
254296
255297 ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_INT_MODE, ret);
256298 if (ret < 0) {
257
- dev_err(dev, "%s: can't write reg 0x%x : %d\n",
299
+ dev_err(dev, "%s: can't write reg %d : %d\n",
258300 __func__, PIXCIR_REG_INT_MODE, ret);
259301 return ret;
260302 }
....@@ -272,7 +314,7 @@
272314
273315 ret = i2c_smbus_read_byte_data(ts->client, PIXCIR_REG_INT_MODE);
274316 if (ret < 0) {
275
- dev_err(dev, "%s: can't read reg 0x%x : %d\n",
317
+ dev_err(dev, "%s: can't read reg %d : %d\n",
276318 __func__, PIXCIR_REG_INT_MODE, ret);
277319 return ret;
278320 }
....@@ -284,7 +326,7 @@
284326
285327 ret = i2c_smbus_write_byte_data(ts->client, PIXCIR_REG_INT_MODE, ret);
286328 if (ret < 0) {
287
- dev_err(dev, "%s: can't write reg 0x%x : %d\n",
329
+ dev_err(dev, "%s: can't write reg %d : %d\n",
288330 __func__, PIXCIR_REG_INT_MODE, ret);
289331 return ret;
290332 }
....@@ -420,31 +462,9 @@
420462 static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops,
421463 pixcir_i2c_ts_suspend, pixcir_i2c_ts_resume);
422464
423
-#ifdef CONFIG_OF
424
-static const struct of_device_id pixcir_of_match[];
425
-
426
-static int pixcir_parse_dt(struct device *dev,
427
- struct pixcir_i2c_ts_data *tsdata)
428
-{
429
- tsdata->chip = of_device_get_match_data(dev);
430
- if (!tsdata->chip)
431
- return -EINVAL;
432
-
433
- return 0;
434
-}
435
-#else
436
-static int pixcir_parse_dt(struct device *dev,
437
- struct pixcir_i2c_ts_data *tsdata)
438
-{
439
- return -EINVAL;
440
-}
441
-#endif
442
-
443465 static int pixcir_i2c_ts_probe(struct i2c_client *client,
444466 const struct i2c_device_id *id)
445467 {
446
- const struct pixcir_ts_platform_data *pdata =
447
- dev_get_platdata(&client->dev);
448468 struct device *dev = &client->dev;
449469 struct pixcir_i2c_ts_data *tsdata;
450470 struct input_dev *input;
....@@ -454,19 +474,11 @@
454474 if (!tsdata)
455475 return -ENOMEM;
456476
457
- if (pdata) {
458
- tsdata->chip = &pdata->chip;
459
- } else if (dev->of_node) {
460
- error = pixcir_parse_dt(dev, tsdata);
461
- if (error)
462
- return error;
463
- } else {
464
- dev_err(dev, "platform data not defined\n");
465
- return -EINVAL;
466
- }
467
-
468
- if (!tsdata->chip->max_fingers) {
469
- dev_err(dev, "Invalid max_fingers in chip data\n");
477
+ tsdata->chip = device_get_match_data(dev);
478
+ if (!tsdata->chip && id)
479
+ tsdata->chip = (const void *)id->driver_data;
480
+ if (!tsdata->chip) {
481
+ dev_err(dev, "can't locate chip data\n");
470482 return -EINVAL;
471483 }
472484
....@@ -483,30 +495,17 @@
483495 input->id.bustype = BUS_I2C;
484496 input->open = pixcir_input_open;
485497 input->close = pixcir_input_close;
486
- input->dev.parent = dev;
487498
488
- if (pdata) {
489
- input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0);
490
- input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->y_max, 0, 0);
491
- } else {
492
- input_set_capability(input, EV_ABS, ABS_MT_POSITION_X);
493
- input_set_capability(input, EV_ABS, ABS_MT_POSITION_Y);
494
- touchscreen_parse_properties(input, true, &tsdata->prop);
495
- if (!input_abs_get_max(input, ABS_MT_POSITION_X) ||
496
- !input_abs_get_max(input, ABS_MT_POSITION_Y)) {
497
- dev_err(dev, "Touchscreen size is not specified\n");
498
- return -EINVAL;
499
- }
499
+ input_set_capability(input, EV_ABS, ABS_MT_POSITION_X);
500
+ input_set_capability(input, EV_ABS, ABS_MT_POSITION_Y);
501
+ touchscreen_parse_properties(input, true, &tsdata->prop);
502
+ if (!input_abs_get_max(input, ABS_MT_POSITION_X) ||
503
+ !input_abs_get_max(input, ABS_MT_POSITION_Y)) {
504
+ dev_err(dev, "Touchscreen size is not specified\n");
505
+ return -EINVAL;
500506 }
501507
502
- tsdata->max_fingers = tsdata->chip->max_fingers;
503
- if (tsdata->max_fingers > PIXCIR_MAX_SLOTS) {
504
- tsdata->max_fingers = PIXCIR_MAX_SLOTS;
505
- dev_info(dev, "Limiting maximum fingers to %d\n",
506
- tsdata->max_fingers);
507
- }
508
-
509
- error = input_mt_init_slots(input, tsdata->max_fingers,
508
+ error = input_mt_init_slots(input, tsdata->chip->max_fingers,
510509 INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
511510 if (error) {
512511 dev_err(dev, "Error initializing Multi-Touch slots\n");
....@@ -518,7 +517,9 @@
518517 tsdata->gpio_attb = devm_gpiod_get(dev, "attb", GPIOD_IN);
519518 if (IS_ERR(tsdata->gpio_attb)) {
520519 error = PTR_ERR(tsdata->gpio_attb);
521
- dev_err(dev, "Failed to request ATTB gpio: %d\n", error);
520
+ if (error != -EPROBE_DEFER)
521
+ dev_err(dev, "Failed to request ATTB gpio: %d\n",
522
+ error);
522523 return error;
523524 }
524525
....@@ -526,7 +527,9 @@
526527 GPIOD_OUT_LOW);
527528 if (IS_ERR(tsdata->gpio_reset)) {
528529 error = PTR_ERR(tsdata->gpio_reset);
529
- dev_err(dev, "Failed to request RESET gpio: %d\n", error);
530
+ if (error != -EPROBE_DEFER)
531
+ dev_err(dev, "Failed to request RESET gpio: %d\n",
532
+ error);
530533 return error;
531534 }
532535
....@@ -582,14 +585,6 @@
582585 return 0;
583586 }
584587
585
-static const struct i2c_device_id pixcir_i2c_ts_id[] = {
586
- { "pixcir_ts", 0 },
587
- { "pixcir_tangoc", 0 },
588
- { }
589
-};
590
-MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id);
591
-
592
-#ifdef CONFIG_OF
593588 static const struct pixcir_i2c_chip_data pixcir_ts_data = {
594589 .max_fingers = 2,
595590 /* no hw id support */
....@@ -600,6 +595,14 @@
600595 .has_hw_ids = true,
601596 };
602597
598
+static const struct i2c_device_id pixcir_i2c_ts_id[] = {
599
+ { "pixcir_ts", (unsigned long) &pixcir_ts_data },
600
+ { "pixcir_tangoc", (unsigned long) &pixcir_tangoc_data },
601
+ { }
602
+};
603
+MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id);
604
+
605
+#ifdef CONFIG_OF
603606 static const struct of_device_id pixcir_of_match[] = {
604607 { .compatible = "pixcir,pixcir_ts", .data = &pixcir_ts_data },
605608 { .compatible = "pixcir,pixcir_tangoc", .data = &pixcir_tangoc_data },