blob: f2c5f0e47f77dd6ab177adec2bb102ed0da5dd08 [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/module.h>
22#include <linux/input.h>
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070023#include <linux/spi/spi.h>
Sebastian Reichel273cf482015-07-27 17:27:25 -070024#include <linux/regmap.h>
Michael Welling6ac24382015-11-02 17:45:51 -080025#include "tsc200x-core.h"
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070026
Michael Wellinge9003c92016-07-20 10:02:07 -070027static const struct input_id tsc2005_input_id = {
28 .bustype = BUS_SPI,
29 .product = 2005,
30};
31
Michael Welling6ac24382015-11-02 17:45:51 -080032static int tsc2005_cmd(struct device *dev, u8 cmd)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070033{
Michael Wellingef3b98c2015-11-02 17:51:49 -080034 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070035 struct spi_transfer xfer = {
Michael Welling6ac24382015-11-02 17:45:51 -080036 .tx_buf = &tx,
37 .len = 1,
38 .bits_per_word = 8,
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070039 };
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070040 struct spi_message msg;
Michael Welling6ac24382015-11-02 17:45:51 -080041 struct spi_device *spi = to_spi_device(dev);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070042 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070043
44 spi_message_init(&msg);
45 spi_message_add_tail(&xfer, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070046
Michael Welling6ac24382015-11-02 17:45:51 -080047 error = spi_sync(spi, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070048 if (error) {
Michael Welling6ac24382015-11-02 17:45:51 -080049 dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
Dmitry Torokhov71f80042011-03-16 22:11:25 -070050 __func__, cmd, error);
51 return error;
52 }
53
54 return 0;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070055}
56
Bill Pemberton5298cc42012-11-23 21:38:25 -080057static int tsc2005_probe(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070058{
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070059 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070060
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070061 spi->mode = SPI_MODE_0;
62 spi->bits_per_word = 8;
63 if (!spi->max_speed_hz)
64 spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070065
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070066 error = spi_setup(spi);
67 if (error)
68 return error;
69
Michael Wellinge9003c92016-07-20 10:02:07 -070070 return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
Michael Welling6ac24382015-11-02 17:45:51 -080071 devm_regmap_init_spi(spi, &tsc200x_regmap_config),
72 tsc2005_cmd);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070073}
74
Bill Pembertone2619cf2012-11-23 21:50:47 -080075static int tsc2005_remove(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070076{
Michael Welling6ac24382015-11-02 17:45:51 -080077 return tsc200x_remove(&spi->dev);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070078}
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",
Michael Welling6ac24382015-11-02 17:45:51 -080083 .pm = &tsc200x_pm_ops,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070084 },
Dmitry Torokhov3ff8ff52011-03-16 22:08:26 -070085 .probe = tsc2005_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -080086 .remove = tsc2005_remove,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070087};
Axel Linca839222012-03-16 23:05:26 -070088module_spi_driver(tsc2005_driver);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070089
Michael Welling6ac24382015-11-02 17:45:51 -080090MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
Dmitry Torokhovb88aa492011-03-16 22:09:03 -070091MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070092MODULE_LICENSE("GPL");
Pali Rohár938789f2013-02-16 22:01:44 -080093MODULE_ALIAS("spi:tsc2005");