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