Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * TSC2005 touchscreen driver |
| 3 | * |
| 4 | * Copyright (C) 2006-2010 Nokia Corporation |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 5 | * Copyright (C) 2015 QWERTY Embedded Design |
| 6 | * Copyright (C) 2015 EMAC Inc. |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 7 | * |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 8 | * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com> |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 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. |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 21 | #include <linux/input.h> |
Dmitry Torokhov | 449aa83 | 2017-02-10 15:12:20 -0800 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/of.h> |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 24 | #include <linux/spi/spi.h> |
Sebastian Reichel | 273cf48 | 2015-07-27 17:27:25 -0700 | [diff] [blame] | 25 | #include <linux/regmap.h> |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 26 | #include "tsc200x-core.h" |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 27 | |
Michael Welling | e9003c9 | 2016-07-20 10:02:07 -0700 | [diff] [blame] | 28 | static const struct input_id tsc2005_input_id = { |
| 29 | .bustype = BUS_SPI, |
| 30 | .product = 2005, |
| 31 | }; |
| 32 | |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 33 | static int tsc2005_cmd(struct device *dev, u8 cmd) |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 34 | { |
Michael Welling | ef3b98c | 2015-11-02 17:51:49 -0800 | [diff] [blame] | 35 | u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd; |
Dmitry Torokhov | 9a6e180 | 2011-03-16 22:10:52 -0700 | [diff] [blame] | 36 | struct spi_transfer xfer = { |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 37 | .tx_buf = &tx, |
| 38 | .len = 1, |
| 39 | .bits_per_word = 8, |
Dmitry Torokhov | 9a6e180 | 2011-03-16 22:10:52 -0700 | [diff] [blame] | 40 | }; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 41 | struct spi_message msg; |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 42 | struct spi_device *spi = to_spi_device(dev); |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 43 | int error; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 44 | |
| 45 | spi_message_init(&msg); |
| 46 | spi_message_add_tail(&xfer, &msg); |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 47 | |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 48 | error = spi_sync(spi, &msg); |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 49 | if (error) { |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 50 | dev_err(dev, "%s: failed, command: %x, spi error: %d\n", |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 51 | __func__, cmd, error); |
| 52 | return error; |
| 53 | } |
| 54 | |
| 55 | return 0; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 58 | static int tsc2005_probe(struct spi_device *spi) |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 59 | { |
Dmitry Torokhov | 99bb892 | 2011-03-16 22:09:38 -0700 | [diff] [blame] | 60 | int error; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 61 | |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 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; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 66 | |
Dmitry Torokhov | 99bb892 | 2011-03-16 22:09:38 -0700 | [diff] [blame] | 67 | error = spi_setup(spi); |
| 68 | if (error) |
| 69 | return error; |
| 70 | |
Michael Welling | e9003c9 | 2016-07-20 10:02:07 -0700 | [diff] [blame] | 71 | return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id, |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 72 | devm_regmap_init_spi(spi, &tsc200x_regmap_config), |
| 73 | tsc2005_cmd); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 76 | static int tsc2005_remove(struct spi_device *spi) |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 77 | { |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 78 | return tsc200x_remove(&spi->dev); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Dmitry Torokhov | 449aa83 | 2017-02-10 15:12:20 -0800 | [diff] [blame] | 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 | |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 89 | static struct spi_driver tsc2005_driver = { |
Dmitry Torokhov | 3ff8ff5 | 2011-03-16 22:08:26 -0700 | [diff] [blame] | 90 | .driver = { |
| 91 | .name = "tsc2005", |
Dmitry Torokhov | 449aa83 | 2017-02-10 15:12:20 -0800 | [diff] [blame] | 92 | .of_match_table = of_match_ptr(tsc2005_of_match), |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 93 | .pm = &tsc200x_pm_ops, |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 94 | }, |
Dmitry Torokhov | 3ff8ff5 | 2011-03-16 22:08:26 -0700 | [diff] [blame] | 95 | .probe = tsc2005_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 96 | .remove = tsc2005_remove, |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 97 | }; |
Axel Lin | ca83922 | 2012-03-16 23:05:26 -0700 | [diff] [blame] | 98 | module_spi_driver(tsc2005_driver); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 99 | |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 100 | MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>"); |
Dmitry Torokhov | b88aa49 | 2011-03-16 22:09:03 -0700 | [diff] [blame] | 101 | MODULE_DESCRIPTION("TSC2005 Touchscreen Driver"); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 102 | MODULE_LICENSE("GPL"); |
Pali Rohár | 938789f | 2013-02-16 22:01:44 -0800 | [diff] [blame] | 103 | MODULE_ALIAS("spi:tsc2005"); |