^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) * TSC2004 touchscreen driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2015 QWERTY Embedded Design
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2015 EMAC Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "tsc200x-core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static const struct input_id tsc2004_input_id = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .bustype = BUS_I2C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .product = 2004,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int tsc2004_cmd(struct device *dev, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) s32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct i2c_client *i2c = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) data = i2c_smbus_write_byte(i2c, tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (data < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) dev_err(dev, "%s: failed, command: %x i2c error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) __func__, cmd, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int tsc2004_probe(struct i2c_client *i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return tsc200x_probe(&i2c->dev, i2c->irq, &tsc2004_input_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) devm_regmap_init_i2c(i2c, &tsc200x_regmap_config),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) tsc2004_cmd);
^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) static int tsc2004_remove(struct i2c_client *i2c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return tsc200x_remove(&i2c->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static const struct i2c_device_id tsc2004_idtable[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) { "tsc2004", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) MODULE_DEVICE_TABLE(i2c, tsc2004_idtable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static const struct of_device_id tsc2004_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) { .compatible = "ti,tsc2004" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) MODULE_DEVICE_TABLE(of, tsc2004_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static struct i2c_driver tsc2004_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .name = "tsc2004",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .of_match_table = of_match_ptr(tsc2004_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .pm = &tsc200x_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .id_table = tsc2004_idtable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .probe = tsc2004_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .remove = tsc2004_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) module_i2c_driver(tsc2004_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) MODULE_DESCRIPTION("TSC2004 Touchscreen Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) MODULE_LICENSE("GPL");