1 /* 2 * AD7879-1/AD7889-1 touchscreen (I2C bus) 3 * 4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc. 5 * 6 * Licensed under the GPL-2 or later. 7 */ 8 9 #include <linux/input.h> /* BUS_I2C */ 10 #include <linux/i2c.h> 11 #include <linux/module.h> 12 #include <linux/types.h> 13 #include <linux/of.h> 14 #include <linux/pm.h> 15 #include <linux/regmap.h> 16 17 #include "ad7879.h" 18 19 #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */ 20 21 static const struct regmap_config ad7879_i2c_regmap_config = { 22 .reg_bits = 8, 23 .val_bits = 16, 24 .max_register = 15, 25 }; 26 27 static int ad7879_i2c_probe(struct i2c_client *client, 28 const struct i2c_device_id *id) 29 { 30 struct ad7879 *ts; 31 struct regmap *regmap; 32 33 if (!i2c_check_functionality(client->adapter, 34 I2C_FUNC_SMBUS_WORD_DATA)) { 35 dev_err(&client->dev, "SMBUS Word Data not Supported\n"); 36 return -EIO; 37 } 38 39 regmap = devm_regmap_init_i2c(client, &ad7879_i2c_regmap_config); 40 if (IS_ERR(regmap)) 41 return PTR_ERR(regmap); 42 43 ts = ad7879_probe(&client->dev, regmap, client->irq, 44 BUS_I2C, AD7879_DEVID); 45 if (IS_ERR(ts)) 46 return PTR_ERR(ts); 47 48 i2c_set_clientdata(client, ts); 49 50 return 0; 51 } 52 53 static int ad7879_i2c_remove(struct i2c_client *client) 54 { 55 struct ad7879 *ts = i2c_get_clientdata(client); 56 57 ad7879_remove(ts); 58 59 return 0; 60 } 61 62 static const struct i2c_device_id ad7879_id[] = { 63 { "ad7879", 0 }, 64 { "ad7889", 0 }, 65 { } 66 }; 67 MODULE_DEVICE_TABLE(i2c, ad7879_id); 68 69 #ifdef CONFIG_OF 70 static const struct of_device_id ad7879_i2c_dt_ids[] = { 71 { .compatible = "adi,ad7879-1", }, 72 { } 73 }; 74 MODULE_DEVICE_TABLE(of, ad7879_i2c_dt_ids); 75 #endif 76 77 static struct i2c_driver ad7879_i2c_driver = { 78 .driver = { 79 .name = "ad7879", 80 .pm = &ad7879_pm_ops, 81 .of_match_table = of_match_ptr(ad7879_i2c_dt_ids), 82 }, 83 .probe = ad7879_i2c_probe, 84 .remove = ad7879_i2c_remove, 85 .id_table = ad7879_id, 86 }; 87 88 module_i2c_driver(ad7879_i2c_driver); 89 90 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 91 MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver"); 92 MODULE_LICENSE("GPL"); 93