Commit | Line | Data |
---|---|---|
37bd4469 LL |
1 | /* |
2 | * TSC2005 touchscreen driver | |
3 | * | |
4 | * Copyright (C) 2006-2010 Nokia Corporation | |
6ac24381 MW |
5 | * Copyright (C) 2015 QWERTY Embedded Design |
6 | * Copyright (C) 2015 EMAC Inc. | |
37bd4469 | 7 | * |
6ac24381 | 8 | * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com> |
37bd4469 LL |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
37bd4469 LL |
19 | */ |
20 | ||
37bd4469 | 21 | #include <linux/input.h> |
449aa83e DT |
22 | #include <linux/module.h> |
23 | #include <linux/of.h> | |
37bd4469 | 24 | #include <linux/spi/spi.h> |
273cf48a | 25 | #include <linux/regmap.h> |
6ac24381 | 26 | #include "tsc200x-core.h" |
37bd4469 | 27 | |
e9003c9c MW |
28 | static const struct input_id tsc2005_input_id = { |
29 | .bustype = BUS_SPI, | |
30 | .product = 2005, | |
31 | }; | |
32 | ||
6ac24381 | 33 | static int tsc2005_cmd(struct device *dev, u8 cmd) |
37bd4469 | 34 | { |
ef3b98c2 | 35 | u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd; |
9a6e180a | 36 | struct spi_transfer xfer = { |
6ac24381 MW |
37 | .tx_buf = &tx, |
38 | .len = 1, | |
39 | .bits_per_word = 8, | |
9a6e180a | 40 | }; |
37bd4469 | 41 | struct spi_message msg; |
6ac24381 | 42 | struct spi_device *spi = to_spi_device(dev); |
71f80045 | 43 | int error; |
37bd4469 LL |
44 | |
45 | spi_message_init(&msg); | |
46 | spi_message_add_tail(&xfer, &msg); | |
71f80045 | 47 | |
6ac24381 | 48 | error = spi_sync(spi, &msg); |
71f80045 | 49 | if (error) { |
6ac24381 | 50 | dev_err(dev, "%s: failed, command: %x, spi error: %d\n", |
71f80045 DT |
51 | __func__, cmd, error); |
52 | return error; | |
53 | } | |
54 | ||
55 | return 0; | |
37bd4469 LL |
56 | } |
57 | ||
5298cc4c | 58 | static int tsc2005_probe(struct spi_device *spi) |
37bd4469 | 59 | { |
99bb892d | 60 | int error; |
37bd4469 | 61 | |
99bb892d DT |
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; | |
37bd4469 | 66 | |
99bb892d DT |
67 | error = spi_setup(spi); |
68 | if (error) | |
69 | return error; | |
37bd4469 | 70 | |
e9003c9c | 71 | return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id, |
6ac24381 MW |
72 | devm_regmap_init_spi(spi, &tsc200x_regmap_config), |
73 | tsc2005_cmd); | |
37bd4469 LL |
74 | } |
75 | ||
e2619cf7 | 76 | static int tsc2005_remove(struct spi_device *spi) |
37bd4469 | 77 | { |
6ac24381 | 78 | return tsc200x_remove(&spi->dev); |
37bd4469 | 79 | } |
37bd4469 | 80 | |
449aa83e DT |
81 | #ifdef CONFIG_OF |
82 | static const struct of_device_id tsc2005_of_match[] = { | |
83 | { .compatible = "ti,tsc2005" }, | |
84 | { /* sentinel */ } | |
85 | }; | |
86 | MODULE_DEVICE_TABLE(of, tsc2005_of_match); | |
87 | #endif | |
88 | ||
37bd4469 | 89 | static struct spi_driver tsc2005_driver = { |
3ff8ff53 DT |
90 | .driver = { |
91 | .name = "tsc2005", | |
449aa83e | 92 | .of_match_table = of_match_ptr(tsc2005_of_match), |
6ac24381 | 93 | .pm = &tsc200x_pm_ops, |
37bd4469 | 94 | }, |
3ff8ff53 | 95 | .probe = tsc2005_probe, |
1cb0aa88 | 96 | .remove = tsc2005_remove, |
37bd4469 | 97 | }; |
ca83922e | 98 | module_spi_driver(tsc2005_driver); |
37bd4469 | 99 | |
6ac24381 | 100 | MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>"); |
b88aa494 | 101 | MODULE_DESCRIPTION("TSC2005 Touchscreen Driver"); |
37bd4469 | 102 | MODULE_LICENSE("GPL"); |
938789fe | 103 | MODULE_ALIAS("spi:tsc2005"); |