Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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