blob: 923496bbb368d5b248d9fc6f7f51ec1fe4664da0 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Lauri Leukkunen37bd4462011-03-16 22:07:36 -07002/*
3 * TSC2005 touchscreen driver
4 *
5 * Copyright (C) 2006-2010 Nokia Corporation
Michael Welling6ac24382015-11-02 17:45:51 -08006 * Copyright (C) 2015 QWERTY Embedded Design
7 * Copyright (C) 2015 EMAC Inc.
Lauri Leukkunen37bd4462011-03-16 22:07:36 -07008 *
Michael Welling6ac24382015-11-02 17:45:51 -08009 * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070010 */
11
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070012#include <linux/input.h>
Dmitry Torokhov449aa832017-02-10 15:12:20 -080013#include <linux/module.h>
14#include <linux/of.h>
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070015#include <linux/spi/spi.h>
Sebastian Reichel273cf482015-07-27 17:27:25 -070016#include <linux/regmap.h>
Michael Welling6ac24382015-11-02 17:45:51 -080017#include "tsc200x-core.h"
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070018
Michael Wellinge9003c92016-07-20 10:02:07 -070019static const struct input_id tsc2005_input_id = {
20 .bustype = BUS_SPI,
21 .product = 2005,
22};
23
Michael Welling6ac24382015-11-02 17:45:51 -080024static int tsc2005_cmd(struct device *dev, u8 cmd)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070025{
Michael Wellingef3b98c2015-11-02 17:51:49 -080026 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070027 struct spi_transfer xfer = {
Michael Welling6ac24382015-11-02 17:45:51 -080028 .tx_buf = &tx,
29 .len = 1,
30 .bits_per_word = 8,
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070031 };
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070032 struct spi_message msg;
Michael Welling6ac24382015-11-02 17:45:51 -080033 struct spi_device *spi = to_spi_device(dev);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070034 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070035
36 spi_message_init(&msg);
37 spi_message_add_tail(&xfer, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070038
Michael Welling6ac24382015-11-02 17:45:51 -080039 error = spi_sync(spi, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070040 if (error) {
Michael Welling6ac24382015-11-02 17:45:51 -080041 dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
Dmitry Torokhov71f80042011-03-16 22:11:25 -070042 __func__, cmd, error);
43 return error;
44 }
45
46 return 0;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070047}
48
Bill Pemberton5298cc42012-11-23 21:38:25 -080049static int tsc2005_probe(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070050{
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070051 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070052
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070053 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;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070057
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070058 error = spi_setup(spi);
59 if (error)
60 return error;
61
Michael Wellinge9003c92016-07-20 10:02:07 -070062 return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
Michael Welling6ac24382015-11-02 17:45:51 -080063 devm_regmap_init_spi(spi, &tsc200x_regmap_config),
64 tsc2005_cmd);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070065}
66
Bill Pembertone2619cf2012-11-23 21:50:47 -080067static int tsc2005_remove(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070068{
Michael Welling6ac24382015-11-02 17:45:51 -080069 return tsc200x_remove(&spi->dev);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070070}
71
Dmitry Torokhov449aa832017-02-10 15:12:20 -080072#ifdef CONFIG_OF
73static const struct of_device_id tsc2005_of_match[] = {
74 { .compatible = "ti,tsc2005" },
75 { /* sentinel */ }
76};
77MODULE_DEVICE_TABLE(of, tsc2005_of_match);
78#endif
79
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070080static struct spi_driver tsc2005_driver = {
Dmitry Torokhov3ff8ff52011-03-16 22:08:26 -070081 .driver = {
82 .name = "tsc2005",
Dmitry Torokhov449aa832017-02-10 15:12:20 -080083 .of_match_table = of_match_ptr(tsc2005_of_match),
Michael Welling6ac24382015-11-02 17:45:51 -080084 .pm = &tsc200x_pm_ops,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070085 },
Dmitry Torokhov3ff8ff52011-03-16 22:08:26 -070086 .probe = tsc2005_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -080087 .remove = tsc2005_remove,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070088};
Axel Linca839222012-03-16 23:05:26 -070089module_spi_driver(tsc2005_driver);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070090
Michael Welling6ac24382015-11-02 17:45:51 -080091MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
Dmitry Torokhovb88aa492011-03-16 22:09:03 -070092MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070093MODULE_LICENSE("GPL");
Pali Rohár938789f2013-02-16 22:01:44 -080094MODULE_ALIAS("spi:tsc2005");