Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * TSC2005 touchscreen driver |
| 3 | * |
| 4 | * Copyright (C) 2006-2010 Nokia Corporation |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 5 | * Copyright (C) 2015 QWERTY Embedded Design |
| 6 | * Copyright (C) 2015 EMAC Inc. |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 7 | * |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 8 | * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com> |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 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. |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/input.h> |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 23 | #include <linux/spi/spi.h> |
Sebastian Reichel | 273cf48 | 2015-07-27 17:27:25 -0700 | [diff] [blame] | 24 | #include <linux/regmap.h> |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 25 | #include "tsc200x-core.h" |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 26 | |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 27 | static int tsc2005_cmd(struct device *dev, u8 cmd) |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 28 | { |
Michael Welling | ef3b98c | 2015-11-02 17:51:49 -0800 | [diff] [blame] | 29 | u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd; |
Dmitry Torokhov | 9a6e180 | 2011-03-16 22:10:52 -0700 | [diff] [blame] | 30 | struct spi_transfer xfer = { |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 31 | .tx_buf = &tx, |
| 32 | .len = 1, |
| 33 | .bits_per_word = 8, |
Dmitry Torokhov | 9a6e180 | 2011-03-16 22:10:52 -0700 | [diff] [blame] | 34 | }; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 35 | struct spi_message msg; |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 36 | struct spi_device *spi = to_spi_device(dev); |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 37 | int error; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 38 | |
| 39 | spi_message_init(&msg); |
| 40 | spi_message_add_tail(&xfer, &msg); |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 41 | |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 42 | error = spi_sync(spi, &msg); |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 43 | if (error) { |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 44 | dev_err(dev, "%s: failed, command: %x, spi error: %d\n", |
Dmitry Torokhov | 71f8004 | 2011-03-16 22:11:25 -0700 | [diff] [blame] | 45 | __func__, cmd, error); |
| 46 | return error; |
| 47 | } |
| 48 | |
| 49 | return 0; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 52 | static int tsc2005_probe(struct spi_device *spi) |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 53 | { |
Dmitry Torokhov | 99bb892 | 2011-03-16 22:09:38 -0700 | [diff] [blame] | 54 | int error; |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 55 | |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 56 | 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 Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 60 | |
Dmitry Torokhov | 99bb892 | 2011-03-16 22:09:38 -0700 | [diff] [blame] | 61 | error = spi_setup(spi); |
| 62 | if (error) |
| 63 | return error; |
| 64 | |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 65 | return tsc200x_probe(&spi->dev, spi->irq, BUS_SPI, |
| 66 | devm_regmap_init_spi(spi, &tsc200x_regmap_config), |
| 67 | tsc2005_cmd); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 70 | static int tsc2005_remove(struct spi_device *spi) |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 71 | { |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 72 | return tsc200x_remove(&spi->dev); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 75 | static struct spi_driver tsc2005_driver = { |
Dmitry Torokhov | 3ff8ff5 | 2011-03-16 22:08:26 -0700 | [diff] [blame] | 76 | .driver = { |
| 77 | .name = "tsc2005", |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 78 | .pm = &tsc200x_pm_ops, |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 79 | }, |
Dmitry Torokhov | 3ff8ff5 | 2011-03-16 22:08:26 -0700 | [diff] [blame] | 80 | .probe = tsc2005_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 81 | .remove = tsc2005_remove, |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 82 | }; |
Axel Lin | ca83922 | 2012-03-16 23:05:26 -0700 | [diff] [blame] | 83 | module_spi_driver(tsc2005_driver); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 84 | |
Michael Welling | 6ac2438 | 2015-11-02 17:45:51 -0800 | [diff] [blame] | 85 | MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>"); |
Dmitry Torokhov | b88aa49 | 2011-03-16 22:09:03 -0700 | [diff] [blame] | 86 | MODULE_DESCRIPTION("TSC2005 Touchscreen Driver"); |
Lauri Leukkunen | 37bd446 | 2011-03-16 22:07:36 -0700 | [diff] [blame] | 87 | MODULE_LICENSE("GPL"); |
Pali Rohár | 938789f | 2013-02-16 22:01:44 -0800 | [diff] [blame] | 88 | MODULE_ALIAS("spi:tsc2005"); |