blob: b9f593dfd2ef8368223e5d7d7d9ca06856afcc8d [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 Welling6ac24382015-11-02 17:45:51 -080027static int tsc2005_cmd(struct device *dev, u8 cmd)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070028{
Michael Wellingef3b98c2015-11-02 17:51:49 -080029 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070030 struct spi_transfer xfer = {
Michael Welling6ac24382015-11-02 17:45:51 -080031 .tx_buf = &tx,
32 .len = 1,
33 .bits_per_word = 8,
Dmitry Torokhov9a6e1802011-03-16 22:10:52 -070034 };
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070035 struct spi_message msg;
Michael Welling6ac24382015-11-02 17:45:51 -080036 struct spi_device *spi = to_spi_device(dev);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070037 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070038
39 spi_message_init(&msg);
40 spi_message_add_tail(&xfer, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070041
Michael Welling6ac24382015-11-02 17:45:51 -080042 error = spi_sync(spi, &msg);
Dmitry Torokhov71f80042011-03-16 22:11:25 -070043 if (error) {
Michael Welling6ac24382015-11-02 17:45:51 -080044 dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
Dmitry Torokhov71f80042011-03-16 22:11:25 -070045 __func__, cmd, error);
46 return error;
47 }
48
49 return 0;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070050}
51
Bill Pemberton5298cc42012-11-23 21:38:25 -080052static int tsc2005_probe(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070053{
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070054 int error;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070055
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070056 spi->mode = SPI_MODE_0;
57 spi->bits_per_word = 8;
58 if (!spi->max_speed_hz)
59 spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070060
Dmitry Torokhov99bb8922011-03-16 22:09:38 -070061 error = spi_setup(spi);
62 if (error)
63 return error;
64
Michael Welling6ac24382015-11-02 17:45:51 -080065 return tsc200x_probe(&spi->dev, spi->irq, BUS_SPI,
66 devm_regmap_init_spi(spi, &tsc200x_regmap_config),
67 tsc2005_cmd);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070068}
69
Bill Pembertone2619cf2012-11-23 21:50:47 -080070static int tsc2005_remove(struct spi_device *spi)
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070071{
Michael Welling6ac24382015-11-02 17:45:51 -080072 return tsc200x_remove(&spi->dev);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070073}
74
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070075static struct spi_driver tsc2005_driver = {
Dmitry Torokhov3ff8ff52011-03-16 22:08:26 -070076 .driver = {
77 .name = "tsc2005",
Michael Welling6ac24382015-11-02 17:45:51 -080078 .pm = &tsc200x_pm_ops,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070079 },
Dmitry Torokhov3ff8ff52011-03-16 22:08:26 -070080 .probe = tsc2005_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -080081 .remove = tsc2005_remove,
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070082};
Axel Linca839222012-03-16 23:05:26 -070083module_spi_driver(tsc2005_driver);
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070084
Michael Welling6ac24382015-11-02 17:45:51 -080085MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
Dmitry Torokhovb88aa492011-03-16 22:09:03 -070086MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
Lauri Leukkunen37bd4462011-03-16 22:07:36 -070087MODULE_LICENSE("GPL");
Pali Rohár938789f2013-02-16 22:01:44 -080088MODULE_ALIAS("spi:tsc2005");