0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/input.h>
0013 #include <linux/module.h>
0014 #include <linux/of.h>
0015 #include <linux/spi/spi.h>
0016 #include <linux/regmap.h>
0017 #include "tsc200x-core.h"
0018
0019 static const struct input_id tsc2005_input_id = {
0020 .bustype = BUS_SPI,
0021 .product = 2005,
0022 };
0023
0024 static int tsc2005_cmd(struct device *dev, u8 cmd)
0025 {
0026 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
0027 struct spi_transfer xfer = {
0028 .tx_buf = &tx,
0029 .len = 1,
0030 .bits_per_word = 8,
0031 };
0032 struct spi_message msg;
0033 struct spi_device *spi = to_spi_device(dev);
0034 int error;
0035
0036 spi_message_init(&msg);
0037 spi_message_add_tail(&xfer, &msg);
0038
0039 error = spi_sync(spi, &msg);
0040 if (error) {
0041 dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
0042 __func__, cmd, error);
0043 return error;
0044 }
0045
0046 return 0;
0047 }
0048
0049 static int tsc2005_probe(struct spi_device *spi)
0050 {
0051 int error;
0052
0053 spi->mode = SPI_MODE_0;
0054 spi->bits_per_word = 8;
0055 if (!spi->max_speed_hz)
0056 spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
0057
0058 error = spi_setup(spi);
0059 if (error)
0060 return error;
0061
0062 return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
0063 devm_regmap_init_spi(spi, &tsc200x_regmap_config),
0064 tsc2005_cmd);
0065 }
0066
0067 static void tsc2005_remove(struct spi_device *spi)
0068 {
0069 tsc200x_remove(&spi->dev);
0070 }
0071
0072 #ifdef CONFIG_OF
0073 static const struct of_device_id tsc2005_of_match[] = {
0074 { .compatible = "ti,tsc2005" },
0075 { }
0076 };
0077 MODULE_DEVICE_TABLE(of, tsc2005_of_match);
0078 #endif
0079
0080 static struct spi_driver tsc2005_driver = {
0081 .driver = {
0082 .name = "tsc2005",
0083 .of_match_table = of_match_ptr(tsc2005_of_match),
0084 .pm = &tsc200x_pm_ops,
0085 },
0086 .probe = tsc2005_probe,
0087 .remove = tsc2005_remove,
0088 };
0089 module_spi_driver(tsc2005_driver);
0090
0091 MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
0092 MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
0093 MODULE_LICENSE("GPL");
0094 MODULE_ALIAS("spi:tsc2005");