Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 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> |
Mark Brown | d5dc9ac | 2011-01-06 23:01:02 -0800 | [diff] [blame] | 13 | #include <linux/pm.h> |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 14 | |
| 15 | #include "ad7879.h" |
| 16 | |
| 17 | #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */ |
| 18 | |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 19 | /* All registers are word-sized. |
| 20 | * AD7879 uses a high-byte first convention. |
| 21 | */ |
| 22 | static int ad7879_i2c_read(struct device *dev, u8 reg) |
| 23 | { |
| 24 | struct i2c_client *client = to_i2c_client(dev); |
| 25 | |
Jonathan Cameron | 75255b2 | 2011-11-29 11:23:27 -0800 | [diff] [blame] | 26 | return i2c_smbus_read_word_swapped(client, reg); |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static int ad7879_i2c_multi_read(struct device *dev, |
| 30 | u8 first_reg, u8 count, u16 *buf) |
| 31 | { |
Michael Hennerich | 16ea10a | 2010-06-30 14:51:09 -0700 | [diff] [blame] | 32 | struct i2c_client *client = to_i2c_client(dev); |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 33 | u8 idx; |
| 34 | |
Michael Hennerich | 16ea10a | 2010-06-30 14:51:09 -0700 | [diff] [blame] | 35 | i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf); |
| 36 | |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 37 | for (idx = 0; idx < count; ++idx) |
Michael Hennerich | 16ea10a | 2010-06-30 14:51:09 -0700 | [diff] [blame] | 38 | buf[idx] = swab16(buf[idx]); |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val) |
| 44 | { |
| 45 | struct i2c_client *client = to_i2c_client(dev); |
| 46 | |
Jonathan Cameron | 75255b2 | 2011-11-29 11:23:27 -0800 | [diff] [blame] | 47 | return i2c_smbus_write_word_swapped(client, reg, val); |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static const struct ad7879_bus_ops ad7879_i2c_bus_ops = { |
| 51 | .bustype = BUS_I2C, |
| 52 | .read = ad7879_i2c_read, |
| 53 | .multi_read = ad7879_i2c_multi_read, |
| 54 | .write = ad7879_i2c_write, |
| 55 | }; |
| 56 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 57 | static int ad7879_i2c_probe(struct i2c_client *client, |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 58 | const struct i2c_device_id *id) |
| 59 | { |
| 60 | struct ad7879 *ts; |
| 61 | |
| 62 | if (!i2c_check_functionality(client->adapter, |
| 63 | I2C_FUNC_SMBUS_WORD_DATA)) { |
| 64 | dev_err(&client->dev, "SMBUS Word Data not Supported\n"); |
| 65 | return -EIO; |
| 66 | } |
| 67 | |
| 68 | ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq, |
| 69 | &ad7879_i2c_bus_ops); |
| 70 | if (IS_ERR(ts)) |
| 71 | return PTR_ERR(ts); |
| 72 | |
| 73 | i2c_set_clientdata(client, ts); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 78 | static int ad7879_i2c_remove(struct i2c_client *client) |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 79 | { |
| 80 | struct ad7879 *ts = i2c_get_clientdata(client); |
| 81 | |
| 82 | ad7879_remove(ts); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static const struct i2c_device_id ad7879_id[] = { |
| 88 | { "ad7879", 0 }, |
| 89 | { "ad7889", 0 }, |
| 90 | { } |
| 91 | }; |
| 92 | MODULE_DEVICE_TABLE(i2c, ad7879_id); |
| 93 | |
| 94 | static struct i2c_driver ad7879_i2c_driver = { |
| 95 | .driver = { |
| 96 | .name = "ad7879", |
| 97 | .owner = THIS_MODULE, |
Dmitry Torokhov | 8672bd9 | 2011-11-14 00:32:09 -0800 | [diff] [blame] | 98 | .pm = &ad7879_pm_ops, |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 99 | }, |
| 100 | .probe = ad7879_i2c_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 101 | .remove = ad7879_i2c_remove, |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 102 | .id_table = ad7879_id, |
| 103 | }; |
| 104 | |
Axel Lin | 1b92c1c | 2012-03-16 23:05:41 -0700 | [diff] [blame] | 105 | module_i2c_driver(ad7879_i2c_driver); |
Mike Frysinger | 4397c98 | 2010-06-30 01:40:52 -0700 | [diff] [blame] | 106 | |
| 107 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
| 108 | MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver"); |
| 109 | MODULE_LICENSE("GPL"); |