xref: /linux/drivers/input/touchscreen/tsc2005.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
237bd4469SLauri Leukkunen /*
337bd4469SLauri Leukkunen  * TSC2005 touchscreen driver
437bd4469SLauri Leukkunen  *
537bd4469SLauri Leukkunen  * Copyright (C) 2006-2010 Nokia Corporation
66ac24381SMichael Welling  * Copyright (C) 2015 QWERTY Embedded Design
76ac24381SMichael Welling  * Copyright (C) 2015 EMAC Inc.
837bd4469SLauri Leukkunen  *
96ac24381SMichael Welling  * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
1037bd4469SLauri Leukkunen  */
1137bd4469SLauri Leukkunen 
1237bd4469SLauri Leukkunen #include <linux/input.h>
13449aa83eSDmitry Torokhov #include <linux/module.h>
14449aa83eSDmitry Torokhov #include <linux/of.h>
1537bd4469SLauri Leukkunen #include <linux/spi/spi.h>
16273cf48aSSebastian Reichel #include <linux/regmap.h>
176ac24381SMichael Welling #include "tsc200x-core.h"
1837bd4469SLauri Leukkunen 
19e9003c9cSMichael Welling static const struct input_id tsc2005_input_id = {
20e9003c9cSMichael Welling 	.bustype = BUS_SPI,
21e9003c9cSMichael Welling 	.product = 2005,
22e9003c9cSMichael Welling };
23e9003c9cSMichael Welling 
tsc2005_cmd(struct device * dev,u8 cmd)246ac24381SMichael Welling static int tsc2005_cmd(struct device *dev, u8 cmd)
2537bd4469SLauri Leukkunen {
26ef3b98c2SMichael Welling 	u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
279a6e180aSDmitry Torokhov 	struct spi_transfer xfer = {
289a6e180aSDmitry Torokhov 		.tx_buf         = &tx,
299a6e180aSDmitry Torokhov 		.len            = 1,
309a6e180aSDmitry Torokhov 		.bits_per_word  = 8,
319a6e180aSDmitry Torokhov 	};
3237bd4469SLauri Leukkunen 	struct spi_message msg;
336ac24381SMichael Welling 	struct spi_device *spi = to_spi_device(dev);
3471f80045SDmitry Torokhov 	int error;
3537bd4469SLauri Leukkunen 
3637bd4469SLauri Leukkunen 	spi_message_init(&msg);
3737bd4469SLauri Leukkunen 	spi_message_add_tail(&xfer, &msg);
3871f80045SDmitry Torokhov 
396ac24381SMichael Welling 	error = spi_sync(spi, &msg);
4071f80045SDmitry Torokhov 	if (error) {
416ac24381SMichael Welling 		dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
4271f80045SDmitry Torokhov 			__func__, cmd, error);
4371f80045SDmitry Torokhov 		return error;
4437bd4469SLauri Leukkunen 	}
4537bd4469SLauri Leukkunen 
4671f80045SDmitry Torokhov 	return 0;
4771f80045SDmitry Torokhov }
4871f80045SDmitry Torokhov 
tsc2005_probe(struct spi_device * spi)495298cc4cSBill Pemberton static int tsc2005_probe(struct spi_device *spi)
5037bd4469SLauri Leukkunen {
5199bb892dSDmitry Torokhov 	int error;
5237bd4469SLauri Leukkunen 
5337bd4469SLauri Leukkunen 	spi->mode = SPI_MODE_0;
5437bd4469SLauri Leukkunen 	spi->bits_per_word = 8;
5537bd4469SLauri Leukkunen 	if (!spi->max_speed_hz)
5637bd4469SLauri Leukkunen 		spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
5737bd4469SLauri Leukkunen 
5899bb892dSDmitry Torokhov 	error = spi_setup(spi);
5999bb892dSDmitry Torokhov 	if (error)
6099bb892dSDmitry Torokhov 		return error;
6199bb892dSDmitry Torokhov 
62e9003c9cSMichael Welling 	return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
636ac24381SMichael Welling 			     devm_regmap_init_spi(spi, &tsc200x_regmap_config),
646ac24381SMichael Welling 			     tsc2005_cmd);
6537bd4469SLauri Leukkunen }
6637bd4469SLauri Leukkunen 
67449aa83eSDmitry Torokhov #ifdef CONFIG_OF
68449aa83eSDmitry Torokhov static const struct of_device_id tsc2005_of_match[] = {
69449aa83eSDmitry Torokhov 	{ .compatible = "ti,tsc2005" },
70449aa83eSDmitry Torokhov 	{ /* sentinel */ }
71449aa83eSDmitry Torokhov };
72449aa83eSDmitry Torokhov MODULE_DEVICE_TABLE(of, tsc2005_of_match);
73449aa83eSDmitry Torokhov #endif
74449aa83eSDmitry Torokhov 
7537bd4469SLauri Leukkunen static struct spi_driver tsc2005_driver = {
7637bd4469SLauri Leukkunen 	.driver	= {
7737bd4469SLauri Leukkunen 		.name		= "tsc2005",
78*97f2bedbSDmitry Torokhov 		.dev_groups	= tsc200x_groups,
79449aa83eSDmitry Torokhov 		.of_match_table	= of_match_ptr(tsc2005_of_match),
806470215bSJonathan Cameron 		.pm		= pm_sleep_ptr(&tsc200x_pm_ops),
8137bd4469SLauri Leukkunen 	},
8237bd4469SLauri Leukkunen 	.probe	= tsc2005_probe,
8337bd4469SLauri Leukkunen };
84ca83922eSAxel Lin module_spi_driver(tsc2005_driver);
8537bd4469SLauri Leukkunen 
866ac24381SMichael Welling MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
87b88aa494SDmitry Torokhov MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
8837bd4469SLauri Leukkunen MODULE_LICENSE("GPL");
89938789feSPali Rohár MODULE_ALIAS("spi:tsc2005");
90