xref: /linux/drivers/input/touchscreen/tsc2005.c (revision dec1c62e91ba268ab2a6e339d4d7a59287d5eba1)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * TSC2005 touchscreen driver
4  *
5  * Copyright (C) 2006-2010 Nokia Corporation
6  * Copyright (C) 2015 QWERTY Embedded Design
7  * Copyright (C) 2015 EMAC Inc.
8  *
9  * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
10  */
11 
12 #include <linux/input.h>
13 #include <linux/module.h>
14 #include <linux/of.h>
15 #include <linux/spi/spi.h>
16 #include <linux/regmap.h>
17 #include "tsc200x-core.h"
18 
19 static const struct input_id tsc2005_input_id = {
20 	.bustype = BUS_SPI,
21 	.product = 2005,
22 };
23 
24 static int tsc2005_cmd(struct device *dev, u8 cmd)
25 {
26 	u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
27 	struct spi_transfer xfer = {
28 		.tx_buf         = &tx,
29 		.len            = 1,
30 		.bits_per_word  = 8,
31 	};
32 	struct spi_message msg;
33 	struct spi_device *spi = to_spi_device(dev);
34 	int error;
35 
36 	spi_message_init(&msg);
37 	spi_message_add_tail(&xfer, &msg);
38 
39 	error = spi_sync(spi, &msg);
40 	if (error) {
41 		dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
42 			__func__, cmd, error);
43 		return error;
44 	}
45 
46 	return 0;
47 }
48 
49 static int tsc2005_probe(struct spi_device *spi)
50 {
51 	int error;
52 
53 	spi->mode = SPI_MODE_0;
54 	spi->bits_per_word = 8;
55 	if (!spi->max_speed_hz)
56 		spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
57 
58 	error = spi_setup(spi);
59 	if (error)
60 		return error;
61 
62 	return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
63 			     devm_regmap_init_spi(spi, &tsc200x_regmap_config),
64 			     tsc2005_cmd);
65 }
66 
67 static void tsc2005_remove(struct spi_device *spi)
68 {
69 	tsc200x_remove(&spi->dev);
70 }
71 
72 #ifdef CONFIG_OF
73 static const struct of_device_id tsc2005_of_match[] = {
74 	{ .compatible = "ti,tsc2005" },
75 	{ /* sentinel */ }
76 };
77 MODULE_DEVICE_TABLE(of, tsc2005_of_match);
78 #endif
79 
80 static struct spi_driver tsc2005_driver = {
81 	.driver	= {
82 		.name	= "tsc2005",
83 		.of_match_table = of_match_ptr(tsc2005_of_match),
84 		.pm	= &tsc200x_pm_ops,
85 	},
86 	.probe	= tsc2005_probe,
87 	.remove	= tsc2005_remove,
88 };
89 module_spi_driver(tsc2005_driver);
90 
91 MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
92 MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
93 MODULE_LICENSE("GPL");
94 MODULE_ALIAS("spi:tsc2005");
95