1a748941cSMichael Welling /* 2a748941cSMichael Welling * TSC2004 touchscreen driver 3a748941cSMichael Welling * 4a748941cSMichael Welling * Copyright (C) 2015 QWERTY Embedded Design 5a748941cSMichael Welling * Copyright (C) 2015 EMAC Inc. 6a748941cSMichael Welling * 7a748941cSMichael Welling * This program is free software; you can redistribute it and/or modify 8a748941cSMichael Welling * it under the terms of the GNU General Public License as published by 9a748941cSMichael Welling * the Free Software Foundation; either version 2 of the License, or 10a748941cSMichael Welling * (at your option) any later version. 11a748941cSMichael Welling * 12a748941cSMichael Welling * This program is distributed in the hope that it will be useful, 13a748941cSMichael Welling * but WITHOUT ANY WARRANTY; without even the implied warranty of 14a748941cSMichael Welling * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15a748941cSMichael Welling * GNU General Public License for more details. 16a748941cSMichael Welling */ 17a748941cSMichael Welling 18a748941cSMichael Welling #include <linux/module.h> 19a748941cSMichael Welling #include <linux/input.h> 20a748941cSMichael Welling #include <linux/of.h> 21a748941cSMichael Welling #include <linux/i2c.h> 22a748941cSMichael Welling #include <linux/regmap.h> 23a748941cSMichael Welling #include "tsc200x-core.h" 24a748941cSMichael Welling 25e9003c9cSMichael Welling static const struct input_id tsc2004_input_id = { 26e9003c9cSMichael Welling .bustype = BUS_I2C, 27e9003c9cSMichael Welling .product = 2004, 28e9003c9cSMichael Welling }; 29e9003c9cSMichael Welling 30a748941cSMichael Welling static int tsc2004_cmd(struct device *dev, u8 cmd) 31a748941cSMichael Welling { 32a748941cSMichael Welling u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd; 33a748941cSMichael Welling s32 data; 34a748941cSMichael Welling struct i2c_client *i2c = to_i2c_client(dev); 35a748941cSMichael Welling 36a748941cSMichael Welling data = i2c_smbus_write_byte(i2c, tx); 37a748941cSMichael Welling if (data < 0) { 38a748941cSMichael Welling dev_err(dev, "%s: failed, command: %x i2c error: %d\n", 39a748941cSMichael Welling __func__, cmd, data); 40a748941cSMichael Welling return data; 41a748941cSMichael Welling } 42a748941cSMichael Welling 43a748941cSMichael Welling return 0; 44a748941cSMichael Welling } 45a748941cSMichael Welling 46a748941cSMichael Welling static int tsc2004_probe(struct i2c_client *i2c, 47a748941cSMichael Welling const struct i2c_device_id *id) 48a748941cSMichael Welling 49a748941cSMichael Welling { 50e9003c9cSMichael Welling return tsc200x_probe(&i2c->dev, i2c->irq, &tsc2004_input_id, 51a748941cSMichael Welling devm_regmap_init_i2c(i2c, &tsc200x_regmap_config), 52a748941cSMichael Welling tsc2004_cmd); 53a748941cSMichael Welling } 54a748941cSMichael Welling 55a748941cSMichael Welling static int tsc2004_remove(struct i2c_client *i2c) 56a748941cSMichael Welling { 57a748941cSMichael Welling return tsc200x_remove(&i2c->dev); 58a748941cSMichael Welling } 59a748941cSMichael Welling 60a748941cSMichael Welling static const struct i2c_device_id tsc2004_idtable[] = { 61a748941cSMichael Welling { "tsc2004", 0 }, 62a748941cSMichael Welling { } 63a748941cSMichael Welling }; 64a748941cSMichael Welling MODULE_DEVICE_TABLE(i2c, tsc2004_idtable); 65a748941cSMichael Welling 66a748941cSMichael Welling #ifdef CONFIG_OF 67a748941cSMichael Welling static const struct of_device_id tsc2004_of_match[] = { 68a748941cSMichael Welling { .compatible = "ti,tsc2004" }, 69a748941cSMichael Welling { /* sentinel */ } 70a748941cSMichael Welling }; 71a748941cSMichael Welling MODULE_DEVICE_TABLE(of, tsc2004_of_match); 72a748941cSMichael Welling #endif 73a748941cSMichael Welling 74a748941cSMichael Welling static struct i2c_driver tsc2004_driver = { 75a748941cSMichael Welling .driver = { 76a748941cSMichael Welling .name = "tsc2004", 77a748941cSMichael Welling .of_match_table = of_match_ptr(tsc2004_of_match), 78a748941cSMichael Welling .pm = &tsc200x_pm_ops, 79a748941cSMichael Welling }, 80a748941cSMichael Welling .id_table = tsc2004_idtable, 81a748941cSMichael Welling .probe = tsc2004_probe, 82a748941cSMichael Welling .remove = tsc2004_remove, 83a748941cSMichael Welling }; 84a748941cSMichael Welling module_i2c_driver(tsc2004_driver); 85a748941cSMichael Welling 86a748941cSMichael Welling MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>"); 87a748941cSMichael Welling MODULE_DESCRIPTION("TSC2004 Touchscreen Driver"); 88a748941cSMichael Welling MODULE_LICENSE("GPL"); 89