blob: e02b69f40ad8ab103024071623d1165629b9b8b9 [file] [log] [blame]
Lauri Leukkunen37bd4462011-03-16 22:07:36 -07001/*
2 * TSC2005 touchscreen driver
3 *
4 * Copyright (C) 2006-2010 Nokia Corporation
Michael Welling6ac24382015-11-02 17:45:51 -08005 * Copyright (C) 2015 QWERTY Embedded Design
6 * Copyright (C) 2015 EMAC Inc.
Lauri Leukkunen37bd4462011-03-16 22:07:36 -07007 *
Michael Welling6ac24382015-11-02 17:45:51 -08008 * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
Lauri Leukkunen37bd4462011-03-16 22:07:36 -07009 *
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 Leukkunen37bd4462011-03-16 22:07:36 -070019 */
20
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070021#include <linux/input.h>
Dmitry Torokhov449aa832017-02-10 15:12:20 -080022#include <linux/module.h>
23#include <linux/of.h>
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070024#include <linux/spi/spi.h>
Sebastian Reichel273cf482015-07-27 17:27:25 -070025#include <linux/regmap.h>
Michael Welling6ac24382015-11-02 17:45:51 -080026#include "tsc200x-core.h"
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070027
Michael Wellinge9003c92016-07-20 10:02:07 -070028static const struct input_id tsc2005_input_id = {
29 .bustype = BUS_SPI,
30 .product = 2005,
31};
32
Michael Welling6ac24382015-11-02 17:45:51 -080033static int tsc2005_cmd(struct device *dev, u8 cmd)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070034{
Michael Wellingef3b98c2015-11-02 17:51:49 -080035 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070036 struct spi_transfer xfer = {
Michael Welling6ac24382015-11-02 17:45:51 -080037 .tx_buf = &tx,
38 .len = 1,
39 .bits_per_word = 8,
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070040 };
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070041 struct spi_message msg;
Michael Welling6ac24382015-11-02 17:45:51 -080042 struct spi_device *spi = to_spi_device(dev);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070043 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070044
45 spi_message_init(&msg);
46 spi_message_add_tail(&xfer, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070047
Michael Welling6ac24382015-11-02 17:45:51 -080048 error = spi_sync(spi, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070049 if (error) {
Michael Welling6ac24382015-11-02 17:45:51 -080050 dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
Dmitry Torokhov71f80042011-03-16 22:11:25 -070051 __func__, cmd, error);
52 return error;
53 }
54
55 return 0;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070056}
57
Bill Pemberton5298cc42012-11-23 21:38:25 -080058static int tsc2005_probe(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070059{
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070060 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070061
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070062 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 Leukkunen37bd4462011-03-16 22:07:36 -070066
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070067 error = spi_setup(spi);
68 if (error)
69 return error;
70
Michael Wellinge9003c92016-07-20 10:02:07 -070071 return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
Michael Welling6ac24382015-11-02 17:45:51 -080072 devm_regmap_init_spi(spi, &tsc200x_regmap_config),
73 tsc2005_cmd);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070074}
75
Bill Pembertone2619cf2012-11-23 21:50:47 -080076static int tsc2005_remove(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070077{
Michael Welling6ac24382015-11-02 17:45:51 -080078 return tsc200x_remove(&spi->dev);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070079}
80
Dmitry Torokhov449aa832017-02-10 15:12:20 -080081#ifdef CONFIG_OF
82static const struct of_device_id tsc2005_of_match[] = {
83 { .compatible = "ti,tsc2005" },
84 { /* sentinel */ }
85};
86MODULE_DEVICE_TABLE(of, tsc2005_of_match);
87#endif
88
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070089static struct spi_driver tsc2005_driver = {
Dmitry Torokhov3ff8ff52011-03-16 22:08:26 -070090 .driver = {
91 .name = "tsc2005",
Dmitry Torokhov449aa832017-02-10 15:12:20 -080092 .of_match_table = of_match_ptr(tsc2005_of_match),
Michael Welling6ac24382015-11-02 17:45:51 -080093 .pm = &tsc200x_pm_ops,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070094 },
Dmitry Torokhov3ff8ff52011-03-16 22:08:26 -070095 .probe = tsc2005_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -080096 .remove = tsc2005_remove,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070097};
Axel Linca839222012-03-16 23:05:26 -070098module_spi_driver(tsc2005_driver);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070099
Michael Welling6ac24382015-11-02 17:45:51 -0800100MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
Dmitry Torokhovb88aa492011-03-16 22:09:03 -0700101MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
Lauri Leukkunen37bd4462011-03-16 22:07:36 -0700102MODULE_LICENSE("GPL");
Pali Rohár938789f2013-02-16 22:01:44 -0800103MODULE_ALIAS("spi:tsc2005");