Merge tag 'net-6.12-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[linux-2.6-block.git] / drivers / input / touchscreen / tsc2005.c
CommitLineData
c942fddf 1// SPDX-License-Identifier: GPL-2.0-or-later
37bd4469
LL
2/*
3 * TSC2005 touchscreen driver
4 *
5 * Copyright (C) 2006-2010 Nokia Corporation
6ac24381
MW
6 * Copyright (C) 2015 QWERTY Embedded Design
7 * Copyright (C) 2015 EMAC Inc.
37bd4469 8 *
6ac24381 9 * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
37bd4469
LL
10 */
11
37bd4469 12#include <linux/input.h>
449aa83e
DT
13#include <linux/module.h>
14#include <linux/of.h>
37bd4469 15#include <linux/spi/spi.h>
273cf48a 16#include <linux/regmap.h>
6ac24381 17#include "tsc200x-core.h"
37bd4469 18
e9003c9c
MW
19static const struct input_id tsc2005_input_id = {
20 .bustype = BUS_SPI,
21 .product = 2005,
22};
23
6ac24381 24static int tsc2005_cmd(struct device *dev, u8 cmd)
37bd4469 25{
ef3b98c2 26 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
9a6e180a 27 struct spi_transfer xfer = {
6ac24381
MW
28 .tx_buf = &tx,
29 .len = 1,
30 .bits_per_word = 8,
9a6e180a 31 };
37bd4469 32 struct spi_message msg;
6ac24381 33 struct spi_device *spi = to_spi_device(dev);
71f80045 34 int error;
37bd4469
LL
35
36 spi_message_init(&msg);
37 spi_message_add_tail(&xfer, &msg);
71f80045 38
6ac24381 39 error = spi_sync(spi, &msg);
71f80045 40 if (error) {
6ac24381 41 dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
71f80045
DT
42 __func__, cmd, error);
43 return error;
44 }
45
46 return 0;
37bd4469
LL
47}
48
5298cc4c 49static int tsc2005_probe(struct spi_device *spi)
37bd4469 50{
99bb892d 51 int error;
37bd4469 52
99bb892d
DT
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;
37bd4469 57
99bb892d
DT
58 error = spi_setup(spi);
59 if (error)
60 return error;
37bd4469 61
e9003c9c 62 return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
6ac24381
MW
63 devm_regmap_init_spi(spi, &tsc200x_regmap_config),
64 tsc2005_cmd);
37bd4469
LL
65}
66
449aa83e
DT
67#ifdef CONFIG_OF
68static const struct of_device_id tsc2005_of_match[] = {
69 { .compatible = "ti,tsc2005" },
70 { /* sentinel */ }
71};
72MODULE_DEVICE_TABLE(of, tsc2005_of_match);
73#endif
74
37bd4469 75static struct spi_driver tsc2005_driver = {
3ff8ff53 76 .driver = {
97f2bedb
DT
77 .name = "tsc2005",
78 .dev_groups = tsc200x_groups,
79 .of_match_table = of_match_ptr(tsc2005_of_match),
80 .pm = pm_sleep_ptr(&tsc200x_pm_ops),
37bd4469 81 },
3ff8ff53 82 .probe = tsc2005_probe,
37bd4469 83};
ca83922e 84module_spi_driver(tsc2005_driver);
37bd4469 85
6ac24381 86MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
b88aa494 87MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
37bd4469 88MODULE_LICENSE("GPL");
938789fe 89MODULE_ALIAS("spi:tsc2005");