Merge branches 'pm-core', 'pm-clk', 'pm-domains' and 'pm-pci'
[deliverable/linux.git] / drivers / input / touchscreen / tsc2005.c
CommitLineData
37bd4469
LL
1/*
2 * TSC2005 touchscreen driver
3 *
4 * Copyright (C) 2006-2010 Nokia Corporation
6ac24381
MW
5 * Copyright (C) 2015 QWERTY Embedded Design
6 * Copyright (C) 2015 EMAC Inc.
37bd4469 7 *
6ac24381 8 * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
37bd4469
LL
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.
37bd4469
LL
19 */
20
37bd4469
LL
21#include <linux/module.h>
22#include <linux/input.h>
37bd4469 23#include <linux/spi/spi.h>
273cf48a 24#include <linux/regmap.h>
6ac24381 25#include "tsc200x-core.h"
37bd4469 26
e9003c9c
MW
27static const struct input_id tsc2005_input_id = {
28 .bustype = BUS_SPI,
29 .product = 2005,
30};
31
6ac24381 32static int tsc2005_cmd(struct device *dev, u8 cmd)
37bd4469 33{
ef3b98c2 34 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
9a6e180a 35 struct spi_transfer xfer = {
6ac24381
MW
36 .tx_buf = &tx,
37 .len = 1,
38 .bits_per_word = 8,
9a6e180a 39 };
37bd4469 40 struct spi_message msg;
6ac24381 41 struct spi_device *spi = to_spi_device(dev);
71f80045 42 int error;
37bd4469
LL
43
44 spi_message_init(&msg);
45 spi_message_add_tail(&xfer, &msg);
71f80045 46
6ac24381 47 error = spi_sync(spi, &msg);
71f80045 48 if (error) {
6ac24381 49 dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
71f80045
DT
50 __func__, cmd, error);
51 return error;
52 }
53
54 return 0;
37bd4469
LL
55}
56
5298cc4c 57static int tsc2005_probe(struct spi_device *spi)
37bd4469 58{
99bb892d 59 int error;
37bd4469 60
99bb892d
DT
61 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;
37bd4469 65
99bb892d
DT
66 error = spi_setup(spi);
67 if (error)
68 return error;
37bd4469 69
e9003c9c 70 return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
6ac24381
MW
71 devm_regmap_init_spi(spi, &tsc200x_regmap_config),
72 tsc2005_cmd);
37bd4469
LL
73}
74
e2619cf7 75static int tsc2005_remove(struct spi_device *spi)
37bd4469 76{
6ac24381 77 return tsc200x_remove(&spi->dev);
37bd4469 78}
37bd4469
LL
79
80static struct spi_driver tsc2005_driver = {
3ff8ff53
DT
81 .driver = {
82 .name = "tsc2005",
6ac24381 83 .pm = &tsc200x_pm_ops,
37bd4469 84 },
3ff8ff53 85 .probe = tsc2005_probe,
1cb0aa88 86 .remove = tsc2005_remove,
37bd4469 87};
ca83922e 88module_spi_driver(tsc2005_driver);
37bd4469 89
6ac24381 90MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
b88aa494 91MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
37bd4469 92MODULE_LICENSE("GPL");
938789fe 93MODULE_ALIAS("spi:tsc2005");
This page took 0.130091 seconds and 5 git commands to generate.