Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * TSC2005 touchscreen driver
 4 *
 5 * Copyright (C) 2006-2010 Nokia Corporation
 6 * Copyright (C) 2015 QWERTY Embedded Design
 7 * Copyright (C) 2015 EMAC Inc.
 8 *
 9 * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
 
 
 
 
 
 
 
 
 
 
10 */
11
12#include <linux/input.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/spi/spi.h>
16#include <linux/regmap.h>
17#include "tsc200x-core.h"
18
19static const struct input_id tsc2005_input_id = {
20	.bustype = BUS_SPI,
21	.product = 2005,
22};
23
24static int tsc2005_cmd(struct device *dev, u8 cmd)
25{
26	u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
27	struct spi_transfer xfer = {
28		.tx_buf         = &tx,
29		.len            = 1,
30		.bits_per_word  = 8,
31	};
32	struct spi_message msg;
33	struct spi_device *spi = to_spi_device(dev);
34	int error;
35
36	spi_message_init(&msg);
37	spi_message_add_tail(&xfer, &msg);
38
39	error = spi_sync(spi, &msg);
40	if (error) {
41		dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
42			__func__, cmd, error);
43		return error;
44	}
45
46	return 0;
47}
48
49static int tsc2005_probe(struct spi_device *spi)
50{
51	int error;
52
53	spi->mode = SPI_MODE_0;
54	spi->bits_per_word = 8;
55	if (!spi->max_speed_hz)
56		spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
57
58	error = spi_setup(spi);
59	if (error)
60		return error;
61
62	return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
63			     devm_regmap_init_spi(spi, &tsc200x_regmap_config),
64			     tsc2005_cmd);
65}
66
67#ifdef CONFIG_OF
68static const struct of_device_id tsc2005_of_match[] = {
69	{ .compatible = "ti,tsc2005" },
70	{ /* sentinel */ }
71};
72MODULE_DEVICE_TABLE(of, tsc2005_of_match);
73#endif
74
75static struct spi_driver tsc2005_driver = {
76	.driver	= {
77		.name		= "tsc2005",
78		.dev_groups	= tsc200x_groups,
79		.of_match_table	= of_match_ptr(tsc2005_of_match),
80		.pm		= pm_sleep_ptr(&tsc200x_pm_ops),
81	},
82	.probe	= tsc2005_probe,
 
83};
84module_spi_driver(tsc2005_driver);
85
86MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
87MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
88MODULE_LICENSE("GPL");
89MODULE_ALIAS("spi:tsc2005");
v4.6
 
 1/*
 2 * TSC2005 touchscreen driver
 3 *
 4 * Copyright (C) 2006-2010 Nokia Corporation
 5 * Copyright (C) 2015 QWERTY Embedded Design
 6 * Copyright (C) 2015 EMAC Inc.
 7 *
 8 * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
 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.
19 */
20
 
21#include <linux/module.h>
22#include <linux/input.h>
23#include <linux/spi/spi.h>
24#include <linux/regmap.h>
25#include "tsc200x-core.h"
26
 
 
 
 
 
27static int tsc2005_cmd(struct device *dev, u8 cmd)
28{
29	u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
30	struct spi_transfer xfer = {
31		.tx_buf         = &tx,
32		.len            = 1,
33		.bits_per_word  = 8,
34	};
35	struct spi_message msg;
36	struct spi_device *spi = to_spi_device(dev);
37	int error;
38
39	spi_message_init(&msg);
40	spi_message_add_tail(&xfer, &msg);
41
42	error = spi_sync(spi, &msg);
43	if (error) {
44		dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
45			__func__, cmd, error);
46		return error;
47	}
48
49	return 0;
50}
51
52static int tsc2005_probe(struct spi_device *spi)
53{
54	int error;
55
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;
60
61	error = spi_setup(spi);
62	if (error)
63		return error;
64
65	return tsc200x_probe(&spi->dev, spi->irq, BUS_SPI,
66			     devm_regmap_init_spi(spi, &tsc200x_regmap_config),
67			     tsc2005_cmd);
68}
69
70static int tsc2005_remove(struct spi_device *spi)
71{
72	return tsc200x_remove(&spi->dev);
73}
 
 
 
74
75static struct spi_driver tsc2005_driver = {
76	.driver	= {
77		.name	= "tsc2005",
78		.pm	= &tsc200x_pm_ops,
 
 
79	},
80	.probe	= tsc2005_probe,
81	.remove	= tsc2005_remove,
82};
83module_spi_driver(tsc2005_driver);
84
85MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
86MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
87MODULE_LICENSE("GPL");
88MODULE_ALIAS("spi:tsc2005");