diff options
author | Mike Frysinger <vapier@gentoo.org> | 2010-06-30 04:40:52 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-07-03 16:13:03 -0400 |
commit | 4397c98a8a60ba029f2d0051d0cbafe600f05d8c (patch) | |
tree | 8aed8bdd4b811051fc877b1f08e7b68d343a12e4 /drivers | |
parent | 7cd7a82d16ad5a711338c1baf2316f24121d93aa (diff) |
Input: ad7879 - split bus logic out
The ad7879 driver is using the old bus method of only supporting one
at a time (I2C or SPI). So refactor it like the other input drivers
that support multiple busses simultaneously.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 37 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 2 | ||||
-rw-r--r-- | drivers/input/touchscreen/ad7879-i2c.c | 140 | ||||
-rw-r--r-- | drivers/input/touchscreen/ad7879-spi.c | 190 | ||||
-rw-r--r-- | drivers/input/touchscreen/ad7879.c | 500 | ||||
-rw-r--r-- | drivers/input/touchscreen/ad7879.h | 30 |
6 files changed, 484 insertions, 415 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index e835f04bc0d0..ff18d896ea6d 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -55,37 +55,36 @@ config TOUCHSCREEN_AD7877 | |||
55 | To compile this driver as a module, choose M here: the | 55 | To compile this driver as a module, choose M here: the |
56 | module will be called ad7877. | 56 | module will be called ad7877. |
57 | 57 | ||
58 | config TOUCHSCREEN_AD7879_I2C | 58 | config TOUCHSCREEN_AD7879 |
59 | tristate "AD7879 based touchscreens: AD7879-1 I2C Interface" | 59 | tristate "Analog Devices AD7879-1/AD7889-1 touchscreen interface" |
60 | depends on I2C | ||
61 | select TOUCHSCREEN_AD7879 | ||
62 | help | 60 | help |
63 | Say Y here if you have a touchscreen interface using the | 61 | Say Y here if you want to support a touchscreen interface using |
64 | AD7879-1/AD7889-1 controller, and your board-specific | 62 | the AD7879-1/AD7889-1 controller. |
65 | initialization code includes that in its table of I2C devices. | ||
66 | 63 | ||
67 | If unsure, say N (but it's safe to say "Y"). | 64 | You should select a bus connection too. |
68 | 65 | ||
69 | To compile this driver as a module, choose M here: the | 66 | To compile this driver as a module, choose M here: the |
70 | module will be called ad7879. | 67 | module will be called ad7879. |
71 | 68 | ||
69 | config TOUCHSCREEN_AD7879_I2C | ||
70 | tristate "support I2C bus connection" | ||
71 | depends on TOUCHSCREEN_AD7879 && I2C | ||
72 | help | ||
73 | Say Y here if you have AD7879-1/AD7889-1 hooked to an I2C bus. | ||
74 | |||
75 | To compile this driver as a module, choose M here: the | ||
76 | module will be called ad7879-i2c. | ||
77 | |||
72 | config TOUCHSCREEN_AD7879_SPI | 78 | config TOUCHSCREEN_AD7879_SPI |
73 | tristate "AD7879 based touchscreens: AD7879 SPI Interface" | 79 | tristate "support SPI bus connection" |
74 | depends on SPI_MASTER && TOUCHSCREEN_AD7879_I2C = n | 80 | depends on TOUCHSCREEN_AD7879 && SPI_MASTER |
75 | select TOUCHSCREEN_AD7879 | ||
76 | help | 81 | help |
77 | Say Y here if you have a touchscreen interface using the | 82 | Say Y here if you have AD7879-1/AD7889-1 hooked to a SPI bus. |
78 | AD7879/AD7889 controller, and your board-specific initialization | ||
79 | code includes that in its table of SPI devices. | ||
80 | 83 | ||
81 | If unsure, say N (but it's safe to say "Y"). | 84 | If unsure, say N (but it's safe to say "Y"). |
82 | 85 | ||
83 | To compile this driver as a module, choose M here: the | 86 | To compile this driver as a module, choose M here: the |
84 | module will be called ad7879. | 87 | module will be called ad7879-spi. |
85 | |||
86 | config TOUCHSCREEN_AD7879 | ||
87 | tristate | ||
88 | default n | ||
89 | 88 | ||
90 | config TOUCHSCREEN_BITSY | 89 | config TOUCHSCREEN_BITSY |
91 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" | 90 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 497964a7a214..9efdd4424757 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -9,6 +9,8 @@ wm97xx-ts-y := wm97xx-core.o | |||
9 | obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o | 9 | obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o |
10 | obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o | 10 | obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o |
11 | obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o | 11 | obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o |
12 | obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o | ||
13 | obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o | ||
12 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o | 14 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o |
13 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o | 15 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o |
14 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o | 16 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o |
diff --git a/drivers/input/touchscreen/ad7879-i2c.c b/drivers/input/touchscreen/ad7879-i2c.c new file mode 100644 index 000000000000..85dfdd27df5a --- /dev/null +++ b/drivers/input/touchscreen/ad7879-i2c.c | |||
@@ -0,0 +1,140 @@ | |||
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 | |||
14 | #include "ad7879.h" | ||
15 | |||
16 | #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */ | ||
17 | |||
18 | #ifdef CONFIG_PM | ||
19 | static int ad7879_i2c_suspend(struct i2c_client *client, pm_message_t message) | ||
20 | { | ||
21 | struct ad7879 *ts = i2c_get_clientdata(client); | ||
22 | |||
23 | ad7879_disable(ts); | ||
24 | |||
25 | return 0; | ||
26 | } | ||
27 | |||
28 | static int ad7879_i2c_resume(struct i2c_client *client) | ||
29 | { | ||
30 | struct ad7879 *ts = i2c_get_clientdata(client); | ||
31 | |||
32 | ad7879_enable(ts); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | #else | ||
37 | # define ad7879_i2c_suspend NULL | ||
38 | # define ad7879_i2c_resume NULL | ||
39 | #endif | ||
40 | |||
41 | /* All registers are word-sized. | ||
42 | * AD7879 uses a high-byte first convention. | ||
43 | */ | ||
44 | static int ad7879_i2c_read(struct device *dev, u8 reg) | ||
45 | { | ||
46 | struct i2c_client *client = to_i2c_client(dev); | ||
47 | |||
48 | return swab16(i2c_smbus_read_word_data(client, reg)); | ||
49 | } | ||
50 | |||
51 | static int ad7879_i2c_multi_read(struct device *dev, | ||
52 | u8 first_reg, u8 count, u16 *buf) | ||
53 | { | ||
54 | u8 idx; | ||
55 | |||
56 | for (idx = 0; idx < count; ++idx) | ||
57 | buf[idx] = ad7879_i2c_read(dev, first_reg + idx); | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val) | ||
63 | { | ||
64 | struct i2c_client *client = to_i2c_client(dev); | ||
65 | |||
66 | return i2c_smbus_write_word_data(client, reg, swab16(val)); | ||
67 | } | ||
68 | |||
69 | static const struct ad7879_bus_ops ad7879_i2c_bus_ops = { | ||
70 | .bustype = BUS_I2C, | ||
71 | .read = ad7879_i2c_read, | ||
72 | .multi_read = ad7879_i2c_multi_read, | ||
73 | .write = ad7879_i2c_write, | ||
74 | }; | ||
75 | |||
76 | static int __devinit ad7879_i2c_probe(struct i2c_client *client, | ||
77 | const struct i2c_device_id *id) | ||
78 | { | ||
79 | struct ad7879 *ts; | ||
80 | |||
81 | if (!i2c_check_functionality(client->adapter, | ||
82 | I2C_FUNC_SMBUS_WORD_DATA)) { | ||
83 | dev_err(&client->dev, "SMBUS Word Data not Supported\n"); | ||
84 | return -EIO; | ||
85 | } | ||
86 | |||
87 | ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq, | ||
88 | &ad7879_i2c_bus_ops); | ||
89 | if (IS_ERR(ts)) | ||
90 | return PTR_ERR(ts); | ||
91 | |||
92 | i2c_set_clientdata(client, ts); | ||
93 | |||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | static int __devexit ad7879_i2c_remove(struct i2c_client *client) | ||
98 | { | ||
99 | struct ad7879 *ts = i2c_get_clientdata(client); | ||
100 | |||
101 | ad7879_remove(ts); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | static const struct i2c_device_id ad7879_id[] = { | ||
107 | { "ad7879", 0 }, | ||
108 | { "ad7889", 0 }, | ||
109 | { } | ||
110 | }; | ||
111 | MODULE_DEVICE_TABLE(i2c, ad7879_id); | ||
112 | |||
113 | static struct i2c_driver ad7879_i2c_driver = { | ||
114 | .driver = { | ||
115 | .name = "ad7879", | ||
116 | .owner = THIS_MODULE, | ||
117 | }, | ||
118 | .probe = ad7879_i2c_probe, | ||
119 | .remove = __devexit_p(ad7879_i2c_remove), | ||
120 | .suspend = ad7879_i2c_suspend, | ||
121 | .resume = ad7879_i2c_resume, | ||
122 | .id_table = ad7879_id, | ||
123 | }; | ||
124 | |||
125 | static int __init ad7879_i2c_init(void) | ||
126 | { | ||
127 | return i2c_add_driver(&ad7879_i2c_driver); | ||
128 | } | ||
129 | module_init(ad7879_i2c_init); | ||
130 | |||
131 | static void __exit ad7879_i2c_exit(void) | ||
132 | { | ||
133 | i2c_del_driver(&ad7879_i2c_driver); | ||
134 | } | ||
135 | module_exit(ad7879_i2c_exit); | ||
136 | |||
137 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | ||
138 | MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver"); | ||
139 | MODULE_LICENSE("GPL"); | ||
140 | MODULE_ALIAS("i2c:ad7879"); | ||
diff --git a/drivers/input/touchscreen/ad7879-spi.c b/drivers/input/touchscreen/ad7879-spi.c new file mode 100644 index 000000000000..5d1e5a050332 --- /dev/null +++ b/drivers/input/touchscreen/ad7879-spi.c | |||
@@ -0,0 +1,190 @@ | |||
1 | /* | ||
2 | * AD7879/AD7889 touchscreen (SPI 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_SPI */ | ||
10 | #include <linux/spi/spi.h> | ||
11 | |||
12 | #include "ad7879.h" | ||
13 | |||
14 | #define AD7879_DEVID 0x7A /* AD7879/AD7889 */ | ||
15 | |||
16 | #define MAX_SPI_FREQ_HZ 5000000 | ||
17 | #define AD7879_CMD_MAGIC 0xE000 | ||
18 | #define AD7879_CMD_READ (1 << 10) | ||
19 | #define AD7879_CMD(reg) (AD7879_CMD_MAGIC | ((reg) & 0xF)) | ||
20 | #define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) | ||
21 | #define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) | ||
22 | |||
23 | #ifdef CONFIG_PM | ||
24 | static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message) | ||
25 | { | ||
26 | struct ad7879 *ts = spi_get_drvdata(spi); | ||
27 | |||
28 | ad7879_disable(ts); | ||
29 | |||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | static int ad7879_spi_resume(struct spi_device *spi) | ||
34 | { | ||
35 | struct ad7879 *ts = spi_get_drvdata(spi); | ||
36 | |||
37 | ad7879_enable(ts); | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | #else | ||
42 | # define ad7879_spi_suspend NULL | ||
43 | # define ad7879_spi_resume NULL | ||
44 | #endif | ||
45 | |||
46 | /* | ||
47 | * ad7879_read/write are only used for initial setup and for sysfs controls. | ||
48 | * The main traffic is done in ad7879_collect(). | ||
49 | */ | ||
50 | |||
51 | static int ad7879_spi_xfer(struct spi_device *spi, | ||
52 | u16 cmd, u8 count, u16 *tx_buf, u16 *rx_buf) | ||
53 | { | ||
54 | struct spi_message msg; | ||
55 | struct spi_transfer *xfers; | ||
56 | void *spi_data; | ||
57 | u16 *command; | ||
58 | u16 *_rx_buf = _rx_buf; /* shut gcc up */ | ||
59 | u8 idx; | ||
60 | int ret; | ||
61 | |||
62 | xfers = spi_data = kzalloc(sizeof(*xfers) * (count + 2), GFP_KERNEL); | ||
63 | if (!spi_data) | ||
64 | return -ENOMEM; | ||
65 | |||
66 | spi_message_init(&msg); | ||
67 | |||
68 | command = spi_data; | ||
69 | command[0] = cmd; | ||
70 | if (count == 1) { | ||
71 | /* ad7879_spi_{read,write} gave us buf on stack */ | ||
72 | command[1] = *tx_buf; | ||
73 | tx_buf = &command[1]; | ||
74 | _rx_buf = rx_buf; | ||
75 | rx_buf = &command[2]; | ||
76 | } | ||
77 | |||
78 | ++xfers; | ||
79 | xfers[0].tx_buf = command; | ||
80 | xfers[0].len = 2; | ||
81 | spi_message_add_tail(&xfers[0], &msg); | ||
82 | ++xfers; | ||
83 | |||
84 | for (idx = 0; idx < count; ++idx) { | ||
85 | if (rx_buf) | ||
86 | xfers[idx].rx_buf = &rx_buf[idx]; | ||
87 | if (tx_buf) | ||
88 | xfers[idx].tx_buf = &tx_buf[idx]; | ||
89 | xfers[idx].len = 2; | ||
90 | spi_message_add_tail(&xfers[idx], &msg); | ||
91 | } | ||
92 | |||
93 | ret = spi_sync(spi, &msg); | ||
94 | |||
95 | if (count == 1) | ||
96 | _rx_buf[0] = command[2]; | ||
97 | |||
98 | kfree(spi_data); | ||
99 | |||
100 | return ret; | ||
101 | } | ||
102 | |||
103 | static int ad7879_spi_multi_read(struct device *dev, | ||
104 | u8 first_reg, u8 count, u16 *buf) | ||
105 | { | ||
106 | struct spi_device *spi = to_spi_device(dev); | ||
107 | |||
108 | return ad7879_spi_xfer(spi, AD7879_READCMD(first_reg), count, NULL, buf); | ||
109 | } | ||
110 | |||
111 | static int ad7879_spi_read(struct device *dev, u8 reg) | ||
112 | { | ||
113 | struct spi_device *spi = to_spi_device(dev); | ||
114 | u16 ret, dummy; | ||
115 | |||
116 | return ad7879_spi_xfer(spi, AD7879_READCMD(reg), 1, &dummy, &ret) ? : ret; | ||
117 | } | ||
118 | |||
119 | static int ad7879_spi_write(struct device *dev, u8 reg, u16 val) | ||
120 | { | ||
121 | struct spi_device *spi = to_spi_device(dev); | ||
122 | u16 dummy; | ||
123 | |||
124 | return ad7879_spi_xfer(spi, AD7879_WRITECMD(reg), 1, &val, &dummy); | ||
125 | } | ||
126 | |||
127 | static const struct ad7879_bus_ops ad7879_spi_bus_ops = { | ||
128 | .bustype = BUS_SPI, | ||
129 | .read = ad7879_spi_read, | ||
130 | .multi_read = ad7879_spi_multi_read, | ||
131 | .write = ad7879_spi_write, | ||
132 | }; | ||
133 | |||
134 | static int __devinit ad7879_spi_probe(struct spi_device *spi) | ||
135 | { | ||
136 | struct ad7879 *ts; | ||
137 | |||
138 | /* don't exceed max specified SPI CLK frequency */ | ||
139 | if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) { | ||
140 | dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz); | ||
141 | return -EINVAL; | ||
142 | } | ||
143 | |||
144 | ts = ad7879_probe(&spi->dev, AD7879_DEVID, spi->irq, &ad7879_spi_bus_ops); | ||
145 | if (IS_ERR(ts)) | ||
146 | return PTR_ERR(ts); | ||
147 | |||
148 | spi_set_drvdata(spi, ts); | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static int __devexit ad7879_spi_remove(struct spi_device *spi) | ||
154 | { | ||
155 | struct ad7879 *ts = spi_get_drvdata(spi); | ||
156 | |||
157 | ad7879_remove(ts); | ||
158 | spi_set_drvdata(spi, NULL); | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | static struct spi_driver ad7879_spi_driver = { | ||
164 | .driver = { | ||
165 | .name = "ad7879", | ||
166 | .bus = &spi_bus_type, | ||
167 | .owner = THIS_MODULE, | ||
168 | }, | ||
169 | .probe = ad7879_spi_probe, | ||
170 | .remove = __devexit_p(ad7879_spi_remove), | ||
171 | .suspend = ad7879_spi_suspend, | ||
172 | .resume = ad7879_spi_resume, | ||
173 | }; | ||
174 | |||
175 | static int __init ad7879_spi_init(void) | ||
176 | { | ||
177 | return spi_register_driver(&ad7879_spi_driver); | ||
178 | } | ||
179 | module_init(ad7879_spi_init); | ||
180 | |||
181 | static void __exit ad7879_spi_exit(void) | ||
182 | { | ||
183 | spi_unregister_driver(&ad7879_spi_driver); | ||
184 | } | ||
185 | module_exit(ad7879_spi_exit); | ||
186 | |||
187 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | ||
188 | MODULE_DESCRIPTION("AD7879(-1) touchscreen SPI bus driver"); | ||
189 | MODULE_LICENSE("GPL"); | ||
190 | MODULE_ALIAS("spi:ad7879"); | ||
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c index f947457c858b..1de19691c4a3 100644 --- a/drivers/input/touchscreen/ad7879.c +++ b/drivers/input/touchscreen/ad7879.c | |||
@@ -1,25 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2008-2009 Michael Hennerich, Analog Devices Inc. | 2 | * AD7879/AD7889 based touchscreen and GPIO driver |
3 | * | 3 | * |
4 | * Description: AD7879/AD7889 based touchscreen, and GPIO driver | 4 | * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc. |
5 | * (I2C/SPI Interface) | ||
6 | * | 5 | * |
7 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | 6 | * Licensed under the GPL-2 or later. |
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, see the file COPYING, or write | ||
21 | * to the Free Software Foundation, Inc., | ||
22 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | * | 7 | * |
24 | * History: | 8 | * History: |
25 | * Copyright (c) 2005 David Brownell | 9 | * Copyright (c) 2005 David Brownell |
@@ -49,6 +33,7 @@ | |||
49 | #include <linux/gpio.h> | 33 | #include <linux/gpio.h> |
50 | 34 | ||
51 | #include <linux/spi/ad7879.h> | 35 | #include <linux/spi/ad7879.h> |
36 | #include "ad7879.h" | ||
52 | 37 | ||
53 | #define AD7879_REG_ZEROS 0 | 38 | #define AD7879_REG_ZEROS 0 |
54 | #define AD7879_REG_CTRL1 1 | 39 | #define AD7879_REG_CTRL1 1 |
@@ -119,29 +104,18 @@ enum { | |||
119 | #define MAX_12BIT ((1<<12)-1) | 104 | #define MAX_12BIT ((1<<12)-1) |
120 | #define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50) | 105 | #define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50) |
121 | 106 | ||
122 | #if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) | ||
123 | #define AD7879_DEVID 0x7A | ||
124 | typedef struct spi_device bus_device; | ||
125 | #elif defined(CONFIG_TOUCHSCREEN_AD7879_I2C) || defined(CONFIG_TOUCHSCREEN_AD7879_I2C_MODULE) | ||
126 | #define AD7879_DEVID 0x79 | ||
127 | typedef struct i2c_client bus_device; | ||
128 | #endif | ||
129 | |||
130 | struct ad7879 { | 107 | struct ad7879 { |
131 | bus_device *bus; | 108 | const struct ad7879_bus_ops *bops; |
109 | |||
110 | struct device *dev; | ||
132 | struct input_dev *input; | 111 | struct input_dev *input; |
133 | struct timer_list timer; | 112 | struct timer_list timer; |
134 | #ifdef CONFIG_GPIOLIB | 113 | #ifdef CONFIG_GPIOLIB |
135 | struct gpio_chip gc; | 114 | struct gpio_chip gc; |
136 | #endif | 115 | #endif |
116 | unsigned int irq; | ||
137 | struct mutex mutex; | 117 | struct mutex mutex; |
138 | bool disabled; /* P: mutex */ | 118 | bool disabled; /* P: mutex */ |
139 | |||
140 | #if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) | ||
141 | struct spi_message msg; | ||
142 | struct spi_transfer xfer[AD7879_NR_SENSE + 1]; | ||
143 | u16 cmd; | ||
144 | #endif | ||
145 | u16 conversion_data[AD7879_NR_SENSE]; | 119 | u16 conversion_data[AD7879_NR_SENSE]; |
146 | char phys[32]; | 120 | char phys[32]; |
147 | u8 first_conversion_delay; | 121 | u8 first_conversion_delay; |
@@ -156,9 +130,20 @@ struct ad7879 { | |||
156 | u16 cmd_crtl3; | 130 | u16 cmd_crtl3; |
157 | }; | 131 | }; |
158 | 132 | ||
159 | static int ad7879_read(bus_device *, u8); | 133 | static int ad7879_read(struct ad7879 *ts, u8 reg) |
160 | static int ad7879_write(bus_device *, u8, u16); | 134 | { |
161 | static void ad7879_collect(struct ad7879 *); | 135 | return ts->bops->read(ts->dev, reg); |
136 | } | ||
137 | |||
138 | static int ad7879_multi_read(struct ad7879 *ts, u8 first_reg, u8 count, u16 *buf) | ||
139 | { | ||
140 | return ts->bops->multi_read(ts->dev, first_reg, count, buf); | ||
141 | } | ||
142 | |||
143 | static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val) | ||
144 | { | ||
145 | return ts->bops->write(ts->dev, reg, val); | ||
146 | } | ||
162 | 147 | ||
163 | static void ad7879_report(struct ad7879 *ts) | 148 | static void ad7879_report(struct ad7879 *ts) |
164 | { | 149 | { |
@@ -173,12 +158,14 @@ static void ad7879_report(struct ad7879 *ts) | |||
173 | 158 | ||
174 | /* | 159 | /* |
175 | * The samples processed here are already preprocessed by the AD7879. | 160 | * The samples processed here are already preprocessed by the AD7879. |
176 | * The preprocessing function consists of a median and an averaging filter. | 161 | * The preprocessing function consists of a median and an averaging |
177 | * The combination of these two techniques provides a robust solution, | 162 | * filter. The combination of these two techniques provides a robust |
178 | * discarding the spurious noise in the signal and keeping only the data of interest. | 163 | * solution, discarding the spurious noise in the signal and keeping |
179 | * The size of both filters is programmable. (dev.platform_data, see linux/spi/ad7879.h) | 164 | * only the data of interest. The size of both filters is |
180 | * Other user-programmable conversion controls include variable acquisition time, | 165 | * programmable. (dev.platform_data, see linux/spi/ad7879.h) Other |
181 | * and first conversion delay. Up to 16 averages can be taken per conversion. | 166 | * user-programmable conversion controls include variable acquisition |
167 | * time, and first conversion delay. Up to 16 averages can be taken | ||
168 | * per conversion. | ||
182 | */ | 169 | */ |
183 | 170 | ||
184 | if (likely(x && z1)) { | 171 | if (likely(x && z1)) { |
@@ -213,7 +200,7 @@ static irqreturn_t ad7879_irq(int irq, void *handle) | |||
213 | { | 200 | { |
214 | struct ad7879 *ts = handle; | 201 | struct ad7879 *ts = handle; |
215 | 202 | ||
216 | ad7879_collect(ts); | 203 | ad7879_multi_read(ts, AD7879_REG_XPLUS, AD7879_NR_SENSE, ts->conversion_data); |
217 | ad7879_report(ts); | 204 | ad7879_report(ts); |
218 | 205 | ||
219 | mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); | 206 | mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); |
@@ -223,42 +210,44 @@ static irqreturn_t ad7879_irq(int irq, void *handle) | |||
223 | 210 | ||
224 | static void ad7879_setup(struct ad7879 *ts) | 211 | static void ad7879_setup(struct ad7879 *ts) |
225 | { | 212 | { |
226 | ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); | 213 | ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); |
227 | ad7879_write(ts->bus, AD7879_REG_CTRL3, ts->cmd_crtl3); | 214 | ad7879_write(ts, AD7879_REG_CTRL3, ts->cmd_crtl3); |
228 | ad7879_write(ts->bus, AD7879_REG_CTRL1, ts->cmd_crtl1); | 215 | ad7879_write(ts, AD7879_REG_CTRL1, ts->cmd_crtl1); |
229 | } | 216 | } |
230 | 217 | ||
231 | static void ad7879_disable(struct ad7879 *ts) | 218 | void ad7879_disable(struct ad7879 *ts) |
232 | { | 219 | { |
233 | mutex_lock(&ts->mutex); | 220 | mutex_lock(&ts->mutex); |
234 | 221 | ||
235 | if (!ts->disabled) { | 222 | if (!ts->disabled) { |
236 | 223 | ||
237 | ts->disabled = true; | 224 | ts->disabled = true; |
238 | disable_irq(ts->bus->irq); | 225 | disable_irq(ts->irq); |
239 | 226 | ||
240 | if (del_timer_sync(&ts->timer)) | 227 | if (del_timer_sync(&ts->timer)) |
241 | ad7879_ts_event_release(ts); | 228 | ad7879_ts_event_release(ts); |
242 | 229 | ||
243 | ad7879_write(ts->bus, AD7879_REG_CTRL2, | 230 | ad7879_write(ts, AD7879_REG_CTRL2, |
244 | AD7879_PM(AD7879_PM_SHUTDOWN)); | 231 | AD7879_PM(AD7879_PM_SHUTDOWN)); |
245 | } | 232 | } |
246 | 233 | ||
247 | mutex_unlock(&ts->mutex); | 234 | mutex_unlock(&ts->mutex); |
248 | } | 235 | } |
236 | EXPORT_SYMBOL(ad7879_disable); | ||
249 | 237 | ||
250 | static void ad7879_enable(struct ad7879 *ts) | 238 | void ad7879_enable(struct ad7879 *ts) |
251 | { | 239 | { |
252 | mutex_lock(&ts->mutex); | 240 | mutex_lock(&ts->mutex); |
253 | 241 | ||
254 | if (ts->disabled) { | 242 | if (ts->disabled) { |
255 | ad7879_setup(ts); | 243 | ad7879_setup(ts); |
256 | ts->disabled = false; | 244 | ts->disabled = false; |
257 | enable_irq(ts->bus->irq); | 245 | enable_irq(ts->irq); |
258 | } | 246 | } |
259 | 247 | ||
260 | mutex_unlock(&ts->mutex); | 248 | mutex_unlock(&ts->mutex); |
261 | } | 249 | } |
250 | EXPORT_SYMBOL(ad7879_enable); | ||
262 | 251 | ||
263 | static ssize_t ad7879_disable_show(struct device *dev, | 252 | static ssize_t ad7879_disable_show(struct device *dev, |
264 | struct device_attribute *attr, char *buf) | 253 | struct device_attribute *attr, char *buf) |
@@ -308,7 +297,7 @@ static int ad7879_gpio_direction_input(struct gpio_chip *chip, | |||
308 | 297 | ||
309 | mutex_lock(&ts->mutex); | 298 | mutex_lock(&ts->mutex); |
310 | ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; | 299 | ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; |
311 | err = ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); | 300 | err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); |
312 | mutex_unlock(&ts->mutex); | 301 | mutex_unlock(&ts->mutex); |
313 | 302 | ||
314 | return err; | 303 | return err; |
@@ -328,7 +317,7 @@ static int ad7879_gpio_direction_output(struct gpio_chip *chip, | |||
328 | else | 317 | else |
329 | ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; | 318 | ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; |
330 | 319 | ||
331 | err = ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); | 320 | err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); |
332 | mutex_unlock(&ts->mutex); | 321 | mutex_unlock(&ts->mutex); |
333 | 322 | ||
334 | return err; | 323 | return err; |
@@ -340,7 +329,7 @@ static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned gpio) | |||
340 | u16 val; | 329 | u16 val; |
341 | 330 | ||
342 | mutex_lock(&ts->mutex); | 331 | mutex_lock(&ts->mutex); |
343 | val = ad7879_read(ts->bus, AD7879_REG_CTRL2); | 332 | val = ad7879_read(ts, AD7879_REG_CTRL2); |
344 | mutex_unlock(&ts->mutex); | 333 | mutex_unlock(&ts->mutex); |
345 | 334 | ||
346 | return !!(val & AD7879_GPIO_DATA); | 335 | return !!(val & AD7879_GPIO_DATA); |
@@ -357,14 +346,13 @@ static void ad7879_gpio_set_value(struct gpio_chip *chip, | |||
357 | else | 346 | else |
358 | ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; | 347 | ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; |
359 | 348 | ||
360 | ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); | 349 | ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); |
361 | mutex_unlock(&ts->mutex); | 350 | mutex_unlock(&ts->mutex); |
362 | } | 351 | } |
363 | 352 | ||
364 | static int __devinit ad7879_gpio_add(struct device *dev) | 353 | static int ad7879_gpio_add(struct ad7879 *ts, |
354 | const struct ad7879_platform_data *pdata) | ||
365 | { | 355 | { |
366 | struct ad7879 *ts = dev_get_drvdata(dev); | ||
367 | struct ad7879_platform_data *pdata = dev->platform_data; | ||
368 | int ret = 0; | 356 | int ret = 0; |
369 | 357 | ||
370 | if (pdata->gpio_export) { | 358 | if (pdata->gpio_export) { |
@@ -377,72 +365,78 @@ static int __devinit ad7879_gpio_add(struct device *dev) | |||
377 | ts->gc.ngpio = 1; | 365 | ts->gc.ngpio = 1; |
378 | ts->gc.label = "AD7879-GPIO"; | 366 | ts->gc.label = "AD7879-GPIO"; |
379 | ts->gc.owner = THIS_MODULE; | 367 | ts->gc.owner = THIS_MODULE; |
380 | ts->gc.dev = dev; | 368 | ts->gc.dev = ts->dev; |
381 | 369 | ||
382 | ret = gpiochip_add(&ts->gc); | 370 | ret = gpiochip_add(&ts->gc); |
383 | if (ret) | 371 | if (ret) |
384 | dev_err(dev, "failed to register gpio %d\n", | 372 | dev_err(ts->dev, "failed to register gpio %d\n", |
385 | ts->gc.base); | 373 | ts->gc.base); |
386 | } | 374 | } |
387 | 375 | ||
388 | return ret; | 376 | return ret; |
389 | } | 377 | } |
390 | 378 | ||
391 | /* | 379 | static void ad7879_gpio_remove(struct ad7879 *ts) |
392 | * We mark ad7879_gpio_remove inline so there is a chance the code | ||
393 | * gets discarded when not needed. We can't do __devinit/__devexit | ||
394 | * markup since it is used in both probe and remove methods. | ||
395 | */ | ||
396 | static inline void ad7879_gpio_remove(struct device *dev) | ||
397 | { | 380 | { |
398 | struct ad7879 *ts = dev_get_drvdata(dev); | 381 | const struct ad7879_platform_data *pdata = ts->dev->platform_data; |
399 | struct ad7879_platform_data *pdata = dev->platform_data; | ||
400 | int ret; | 382 | int ret; |
401 | 383 | ||
402 | if (pdata->gpio_export) { | 384 | if (pdata->gpio_export) { |
403 | ret = gpiochip_remove(&ts->gc); | 385 | ret = gpiochip_remove(&ts->gc); |
404 | if (ret) | 386 | if (ret) |
405 | dev_err(dev, "failed to remove gpio %d\n", | 387 | dev_err(ts->dev, "failed to remove gpio %d\n", |
406 | ts->gc.base); | 388 | ts->gc.base); |
407 | } | 389 | } |
408 | } | 390 | } |
409 | #else | 391 | #else |
410 | static inline int ad7879_gpio_add(struct device *dev) | 392 | static inline int ad7879_gpio_add(struct ad7879 *ts, |
393 | const struct ad7879_platform_data *pdata) | ||
411 | { | 394 | { |
412 | return 0; | 395 | return 0; |
413 | } | 396 | } |
414 | 397 | ||
415 | static inline void ad7879_gpio_remove(struct device *dev) | 398 | static inline void ad7879_gpio_remove(struct ad7879 *ts) |
416 | { | 399 | { |
417 | } | 400 | } |
418 | #endif | 401 | #endif |
419 | 402 | ||
420 | static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) | 403 | struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq, |
404 | const struct ad7879_bus_ops *bops) | ||
421 | { | 405 | { |
406 | struct ad7879_platform_data *pdata = dev->platform_data; | ||
407 | struct ad7879 *ts; | ||
422 | struct input_dev *input_dev; | 408 | struct input_dev *input_dev; |
423 | struct ad7879_platform_data *pdata = bus->dev.platform_data; | ||
424 | int err; | 409 | int err; |
425 | u16 revid; | 410 | u16 revid; |
426 | 411 | ||
427 | if (!bus->irq) { | 412 | if (!irq) { |
428 | dev_err(&bus->dev, "no IRQ?\n"); | 413 | dev_err(dev, "no IRQ?\n"); |
429 | return -ENODEV; | 414 | err = -EINVAL; |
415 | goto err_out; | ||
430 | } | 416 | } |
431 | 417 | ||
432 | if (!pdata) { | 418 | if (!pdata) { |
433 | dev_err(&bus->dev, "no platform data?\n"); | 419 | dev_err(dev, "no platform data?\n"); |
434 | return -ENODEV; | 420 | err = -EINVAL; |
421 | goto err_out; | ||
435 | } | 422 | } |
436 | 423 | ||
424 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); | ||
437 | input_dev = input_allocate_device(); | 425 | input_dev = input_allocate_device(); |
438 | if (!input_dev) | 426 | if (!ts || !input_dev) { |
439 | return -ENOMEM; | 427 | err = -ENOMEM; |
428 | goto err_free_mem; | ||
429 | } | ||
440 | 430 | ||
431 | ts->bops = bops; | ||
432 | ts->dev = dev; | ||
441 | ts->input = input_dev; | 433 | ts->input = input_dev; |
442 | 434 | ||
443 | setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts); | 435 | setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts); |
444 | mutex_init(&ts->mutex); | 436 | mutex_init(&ts->mutex); |
445 | 437 | ||
438 | ts->irq = irq; | ||
439 | |||
446 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; | 440 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; |
447 | ts->pressure_max = pdata->pressure_max ? : ~0; | 441 | ts->pressure_max = pdata->pressure_max ? : ~0; |
448 | 442 | ||
@@ -452,11 +446,12 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) | |||
452 | ts->pen_down_acc_interval = pdata->pen_down_acc_interval; | 446 | ts->pen_down_acc_interval = pdata->pen_down_acc_interval; |
453 | ts->median = pdata->median; | 447 | ts->median = pdata->median; |
454 | 448 | ||
455 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&bus->dev)); | 449 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); |
456 | 450 | ||
457 | input_dev->name = "AD7879 Touchscreen"; | 451 | input_dev->name = "AD7879 Touchscreen"; |
458 | input_dev->phys = ts->phys; | 452 | input_dev->phys = ts->phys; |
459 | input_dev->dev.parent = &bus->dev; | 453 | input_dev->dev.parent = dev; |
454 | input_dev->id.bustype = bops->bustype; | ||
460 | 455 | ||
461 | __set_bit(EV_ABS, input_dev->evbit); | 456 | __set_bit(EV_ABS, input_dev->evbit); |
462 | __set_bit(ABS_X, input_dev->absbit); | 457 | __set_bit(ABS_X, input_dev->absbit); |
@@ -474,17 +469,18 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) | |||
474 | input_set_abs_params(input_dev, ABS_PRESSURE, | 469 | input_set_abs_params(input_dev, ABS_PRESSURE, |
475 | pdata->pressure_min, pdata->pressure_max, 0, 0); | 470 | pdata->pressure_min, pdata->pressure_max, 0, 0); |
476 | 471 | ||
477 | err = ad7879_write(bus, AD7879_REG_CTRL2, AD7879_RESET); | 472 | err = ad7879_write(ts, AD7879_REG_CTRL2, AD7879_RESET); |
478 | |||
479 | if (err < 0) { | 473 | if (err < 0) { |
480 | dev_err(&bus->dev, "Failed to write %s\n", input_dev->name); | 474 | dev_err(dev, "Failed to write %s\n", input_dev->name); |
481 | goto err_free_mem; | 475 | goto err_free_mem; |
482 | } | 476 | } |
483 | 477 | ||
484 | revid = ad7879_read(bus, AD7879_REG_REVID); | 478 | revid = ad7879_read(ts, AD7879_REG_REVID); |
485 | 479 | input_dev->id.product = (revid & 0xff); | |
486 | if ((revid & 0xFF) != AD7879_DEVID) { | 480 | input_dev->id.version = revid >> 8; |
487 | dev_err(&bus->dev, "Failed to probe %s\n", input_dev->name); | 481 | if (input_dev->id.product != devid) { |
482 | dev_err(dev, "Failed to probe %s (%x vs %x)\n", | ||
483 | input_dev->name, devid, revid); | ||
488 | err = -ENODEV; | 484 | err = -ENODEV; |
489 | goto err_free_mem; | 485 | goto err_free_mem; |
490 | } | 486 | } |
@@ -508,19 +504,19 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) | |||
508 | 504 | ||
509 | ad7879_setup(ts); | 505 | ad7879_setup(ts); |
510 | 506 | ||
511 | err = request_threaded_irq(bus->irq, NULL, ad7879_irq, | 507 | err = request_threaded_irq(ts->irq, NULL, ad7879_irq, |
512 | IRQF_TRIGGER_FALLING, | 508 | IRQF_TRIGGER_FALLING, |
513 | bus->dev.driver->name, ts); | 509 | dev_name(dev), ts); |
514 | if (err) { | 510 | if (err) { |
515 | dev_err(&bus->dev, "irq %d busy?\n", bus->irq); | 511 | dev_err(dev, "irq %d busy?\n", ts->irq); |
516 | goto err_free_mem; | 512 | goto err_free_mem; |
517 | } | 513 | } |
518 | 514 | ||
519 | err = sysfs_create_group(&bus->dev.kobj, &ad7879_attr_group); | 515 | err = sysfs_create_group(&dev->kobj, &ad7879_attr_group); |
520 | if (err) | 516 | if (err) |
521 | goto err_free_irq; | 517 | goto err_free_irq; |
522 | 518 | ||
523 | err = ad7879_gpio_add(&bus->dev); | 519 | err = ad7879_gpio_add(ts, pdata); |
524 | if (err) | 520 | if (err) |
525 | goto err_remove_attr; | 521 | goto err_remove_attr; |
526 | 522 | ||
@@ -528,321 +524,33 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) | |||
528 | if (err) | 524 | if (err) |
529 | goto err_remove_gpio; | 525 | goto err_remove_gpio; |
530 | 526 | ||
531 | dev_info(&bus->dev, "Rev.%d touchscreen, irq %d\n", | 527 | return ts; |
532 | revid >> 8, bus->irq); | ||
533 | |||
534 | return 0; | ||
535 | 528 | ||
536 | err_remove_gpio: | 529 | err_remove_gpio: |
537 | ad7879_gpio_remove(&bus->dev); | 530 | ad7879_gpio_remove(ts); |
538 | err_remove_attr: | 531 | err_remove_attr: |
539 | sysfs_remove_group(&bus->dev.kobj, &ad7879_attr_group); | 532 | sysfs_remove_group(&dev->kobj, &ad7879_attr_group); |
540 | err_free_irq: | 533 | err_free_irq: |
541 | free_irq(bus->irq, ts); | 534 | free_irq(ts->irq, ts); |
542 | err_free_mem: | 535 | err_free_mem: |
543 | input_free_device(input_dev); | 536 | input_free_device(input_dev); |
544 | 537 | kfree(ts); | |
545 | return err; | 538 | err_out: |
539 | return ERR_PTR(err); | ||
546 | } | 540 | } |
541 | EXPORT_SYMBOL(ad7879_probe); | ||
547 | 542 | ||
548 | static int __devexit ad7879_destroy(bus_device *bus, struct ad7879 *ts) | 543 | void ad7879_remove(struct ad7879 *ts) |
549 | { | 544 | { |
550 | ad7879_gpio_remove(&bus->dev); | 545 | ad7879_gpio_remove(ts); |
551 | ad7879_disable(ts); | 546 | ad7879_disable(ts); |
552 | sysfs_remove_group(&ts->bus->dev.kobj, &ad7879_attr_group); | 547 | sysfs_remove_group(&ts->dev->kobj, &ad7879_attr_group); |
553 | free_irq(ts->bus->irq, ts); | 548 | free_irq(ts->irq, ts); |
554 | input_unregister_device(ts->input); | 549 | input_unregister_device(ts->input); |
555 | dev_dbg(&bus->dev, "unregistered touchscreen\n"); | ||
556 | |||
557 | return 0; | ||
558 | } | ||
559 | |||
560 | #ifdef CONFIG_PM | ||
561 | static int ad7879_suspend(bus_device *bus, pm_message_t message) | ||
562 | { | ||
563 | struct ad7879 *ts = dev_get_drvdata(&bus->dev); | ||
564 | |||
565 | ad7879_disable(ts); | ||
566 | |||
567 | return 0; | ||
568 | } | ||
569 | |||
570 | static int ad7879_resume(bus_device *bus) | ||
571 | { | ||
572 | struct ad7879 *ts = dev_get_drvdata(&bus->dev); | ||
573 | |||
574 | ad7879_enable(ts); | ||
575 | |||
576 | return 0; | ||
577 | } | ||
578 | #else | ||
579 | #define ad7879_suspend NULL | ||
580 | #define ad7879_resume NULL | ||
581 | #endif | ||
582 | |||
583 | #if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) | ||
584 | #define MAX_SPI_FREQ_HZ 5000000 | ||
585 | #define AD7879_CMD_MAGIC 0xE000 | ||
586 | #define AD7879_CMD_READ (1 << 10) | ||
587 | #define AD7879_WRITECMD(reg) (AD7879_CMD_MAGIC | (reg & 0xF)) | ||
588 | #define AD7879_READCMD(reg) (AD7879_CMD_MAGIC | AD7879_CMD_READ | (reg & 0xF)) | ||
589 | |||
590 | struct ser_req { | ||
591 | u16 command; | ||
592 | u16 data; | ||
593 | struct spi_message msg; | ||
594 | struct spi_transfer xfer[2]; | ||
595 | }; | ||
596 | |||
597 | /* | ||
598 | * ad7879_read/write are only used for initial setup and for sysfs controls. | ||
599 | * The main traffic is done in ad7879_collect(). | ||
600 | */ | ||
601 | |||
602 | static int ad7879_read(struct spi_device *spi, u8 reg) | ||
603 | { | ||
604 | struct ser_req *req; | ||
605 | int status, ret; | ||
606 | |||
607 | req = kzalloc(sizeof *req, GFP_KERNEL); | ||
608 | if (!req) | ||
609 | return -ENOMEM; | ||
610 | |||
611 | spi_message_init(&req->msg); | ||
612 | |||
613 | req->command = (u16) AD7879_READCMD(reg); | ||
614 | req->xfer[0].tx_buf = &req->command; | ||
615 | req->xfer[0].len = 2; | ||
616 | |||
617 | req->xfer[1].rx_buf = &req->data; | ||
618 | req->xfer[1].len = 2; | ||
619 | |||
620 | spi_message_add_tail(&req->xfer[0], &req->msg); | ||
621 | spi_message_add_tail(&req->xfer[1], &req->msg); | ||
622 | |||
623 | status = spi_sync(spi, &req->msg); | ||
624 | ret = status ? : req->data; | ||
625 | |||
626 | kfree(req); | ||
627 | |||
628 | return ret; | ||
629 | } | ||
630 | |||
631 | static int ad7879_write(struct spi_device *spi, u8 reg, u16 val) | ||
632 | { | ||
633 | struct ser_req *req; | ||
634 | int status; | ||
635 | |||
636 | req = kzalloc(sizeof *req, GFP_KERNEL); | ||
637 | if (!req) | ||
638 | return -ENOMEM; | ||
639 | |||
640 | spi_message_init(&req->msg); | ||
641 | |||
642 | req->command = (u16) AD7879_WRITECMD(reg); | ||
643 | req->xfer[0].tx_buf = &req->command; | ||
644 | req->xfer[0].len = 2; | ||
645 | |||
646 | req->data = val; | ||
647 | req->xfer[1].tx_buf = &req->data; | ||
648 | req->xfer[1].len = 2; | ||
649 | |||
650 | spi_message_add_tail(&req->xfer[0], &req->msg); | ||
651 | spi_message_add_tail(&req->xfer[1], &req->msg); | ||
652 | |||
653 | status = spi_sync(spi, &req->msg); | ||
654 | |||
655 | kfree(req); | ||
656 | |||
657 | return status; | ||
658 | } | ||
659 | |||
660 | static void ad7879_collect(struct ad7879 *ts) | ||
661 | { | ||
662 | int status = spi_sync(ts->bus, &ts->msg); | ||
663 | |||
664 | if (status) | ||
665 | dev_err(&ts->bus->dev, "spi_sync --> %d\n", status); | ||
666 | } | ||
667 | |||
668 | static void ad7879_setup_ts_def_msg(struct ad7879 *ts) | ||
669 | { | ||
670 | struct spi_message *m; | ||
671 | int i; | ||
672 | |||
673 | ts->cmd = (u16) AD7879_READCMD(AD7879_REG_XPLUS); | ||
674 | |||
675 | m = &ts->msg; | ||
676 | spi_message_init(m); | ||
677 | ts->xfer[0].tx_buf = &ts->cmd; | ||
678 | ts->xfer[0].len = 2; | ||
679 | |||
680 | spi_message_add_tail(&ts->xfer[0], m); | ||
681 | |||
682 | for (i = 0; i < AD7879_NR_SENSE; i++) { | ||
683 | ts->xfer[i + 1].rx_buf = &ts->conversion_data[i]; | ||
684 | ts->xfer[i + 1].len = 2; | ||
685 | spi_message_add_tail(&ts->xfer[i + 1], m); | ||
686 | } | ||
687 | } | ||
688 | |||
689 | static int __devinit ad7879_probe(struct spi_device *spi) | ||
690 | { | ||
691 | struct ad7879 *ts; | ||
692 | int error; | ||
693 | |||
694 | /* don't exceed max specified SPI CLK frequency */ | ||
695 | if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) { | ||
696 | dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz); | ||
697 | return -EINVAL; | ||
698 | } | ||
699 | |||
700 | ts = kzalloc(sizeof(struct ad7879), GFP_KERNEL); | ||
701 | if (!ts) | ||
702 | return -ENOMEM; | ||
703 | |||
704 | dev_set_drvdata(&spi->dev, ts); | ||
705 | ts->bus = spi; | ||
706 | |||
707 | ad7879_setup_ts_def_msg(ts); | ||
708 | |||
709 | error = ad7879_construct(spi, ts); | ||
710 | if (error) { | ||
711 | dev_set_drvdata(&spi->dev, NULL); | ||
712 | kfree(ts); | ||
713 | } | ||
714 | |||
715 | return error; | ||
716 | } | ||
717 | |||
718 | static int __devexit ad7879_remove(struct spi_device *spi) | ||
719 | { | ||
720 | struct ad7879 *ts = dev_get_drvdata(&spi->dev); | ||
721 | |||
722 | ad7879_destroy(spi, ts); | ||
723 | dev_set_drvdata(&spi->dev, NULL); | ||
724 | kfree(ts); | 550 | kfree(ts); |
725 | |||
726 | return 0; | ||
727 | } | 551 | } |
728 | 552 | EXPORT_SYMBOL(ad7879_remove); | |
729 | static struct spi_driver ad7879_driver = { | ||
730 | .driver = { | ||
731 | .name = "ad7879", | ||
732 | .bus = &spi_bus_type, | ||
733 | .owner = THIS_MODULE, | ||
734 | }, | ||
735 | .probe = ad7879_probe, | ||
736 | .remove = __devexit_p(ad7879_remove), | ||
737 | .suspend = ad7879_suspend, | ||
738 | .resume = ad7879_resume, | ||
739 | }; | ||
740 | |||
741 | static int __init ad7879_init(void) | ||
742 | { | ||
743 | return spi_register_driver(&ad7879_driver); | ||
744 | } | ||
745 | module_init(ad7879_init); | ||
746 | |||
747 | static void __exit ad7879_exit(void) | ||
748 | { | ||
749 | spi_unregister_driver(&ad7879_driver); | ||
750 | } | ||
751 | module_exit(ad7879_exit); | ||
752 | |||
753 | #elif defined(CONFIG_TOUCHSCREEN_AD7879_I2C) || defined(CONFIG_TOUCHSCREEN_AD7879_I2C_MODULE) | ||
754 | |||
755 | /* All registers are word-sized. | ||
756 | * AD7879 uses a high-byte first convention. | ||
757 | */ | ||
758 | static int ad7879_read(struct i2c_client *client, u8 reg) | ||
759 | { | ||
760 | return swab16(i2c_smbus_read_word_data(client, reg)); | ||
761 | } | ||
762 | |||
763 | static int ad7879_write(struct i2c_client *client, u8 reg, u16 val) | ||
764 | { | ||
765 | return i2c_smbus_write_word_data(client, reg, swab16(val)); | ||
766 | } | ||
767 | |||
768 | static void ad7879_collect(struct ad7879 *ts) | ||
769 | { | ||
770 | int i; | ||
771 | |||
772 | for (i = 0; i < AD7879_NR_SENSE; i++) | ||
773 | ts->conversion_data[i] = ad7879_read(ts->bus, | ||
774 | AD7879_REG_XPLUS + i); | ||
775 | } | ||
776 | |||
777 | static int __devinit ad7879_probe(struct i2c_client *client, | ||
778 | const struct i2c_device_id *id) | ||
779 | { | ||
780 | struct ad7879 *ts; | ||
781 | int error; | ||
782 | |||
783 | if (!i2c_check_functionality(client->adapter, | ||
784 | I2C_FUNC_SMBUS_WORD_DATA)) { | ||
785 | dev_err(&client->dev, "SMBUS Word Data not Supported\n"); | ||
786 | return -EIO; | ||
787 | } | ||
788 | |||
789 | ts = kzalloc(sizeof(struct ad7879), GFP_KERNEL); | ||
790 | if (!ts) | ||
791 | return -ENOMEM; | ||
792 | |||
793 | i2c_set_clientdata(client, ts); | ||
794 | ts->bus = client; | ||
795 | |||
796 | error = ad7879_construct(client, ts); | ||
797 | if (error) | ||
798 | kfree(ts); | ||
799 | |||
800 | return error; | ||
801 | } | ||
802 | |||
803 | static int __devexit ad7879_remove(struct i2c_client *client) | ||
804 | { | ||
805 | struct ad7879 *ts = dev_get_drvdata(&client->dev); | ||
806 | |||
807 | ad7879_destroy(client, ts); | ||
808 | kfree(ts); | ||
809 | |||
810 | return 0; | ||
811 | } | ||
812 | |||
813 | static const struct i2c_device_id ad7879_id[] = { | ||
814 | { "ad7879", 0 }, | ||
815 | { "ad7889", 0 }, | ||
816 | { } | ||
817 | }; | ||
818 | MODULE_DEVICE_TABLE(i2c, ad7879_id); | ||
819 | |||
820 | static struct i2c_driver ad7879_driver = { | ||
821 | .driver = { | ||
822 | .name = "ad7879", | ||
823 | .owner = THIS_MODULE, | ||
824 | }, | ||
825 | .probe = ad7879_probe, | ||
826 | .remove = __devexit_p(ad7879_remove), | ||
827 | .suspend = ad7879_suspend, | ||
828 | .resume = ad7879_resume, | ||
829 | .id_table = ad7879_id, | ||
830 | }; | ||
831 | |||
832 | static int __init ad7879_init(void) | ||
833 | { | ||
834 | return i2c_add_driver(&ad7879_driver); | ||
835 | } | ||
836 | module_init(ad7879_init); | ||
837 | |||
838 | static void __exit ad7879_exit(void) | ||
839 | { | ||
840 | i2c_del_driver(&ad7879_driver); | ||
841 | } | ||
842 | module_exit(ad7879_exit); | ||
843 | #endif | ||
844 | 553 | ||
845 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | 554 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
846 | MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver"); | 555 | MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver"); |
847 | MODULE_LICENSE("GPL"); | 556 | MODULE_LICENSE("GPL"); |
848 | MODULE_ALIAS("spi:ad7879"); | ||
diff --git a/drivers/input/touchscreen/ad7879.h b/drivers/input/touchscreen/ad7879.h new file mode 100644 index 000000000000..169f155db3b9 --- /dev/null +++ b/drivers/input/touchscreen/ad7879.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | * AD7879/AD7889 touchscreen (bus interfaces) | ||
3 | * | ||
4 | * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc. | ||
5 | * | ||
6 | * Licensed under the GPL-2 or later. | ||
7 | */ | ||
8 | |||
9 | #ifndef _AD7879_H_ | ||
10 | #define _AD7879_H_ | ||
11 | |||
12 | #include <linux/types.h> | ||
13 | |||
14 | struct ad7879; | ||
15 | struct device; | ||
16 | |||
17 | struct ad7879_bus_ops { | ||
18 | u16 bustype; | ||
19 | int (*read)(struct device *dev, u8 reg); | ||
20 | int (*multi_read)(struct device *dev, u8 first_reg, u8 count, u16 *buf); | ||
21 | int (*write)(struct device *dev, u8 reg, u16 val); | ||
22 | }; | ||
23 | |||
24 | void ad7879_disable(struct ad7879 *); | ||
25 | void ad7879_enable(struct ad7879 *); | ||
26 | struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned irq, | ||
27 | const struct ad7879_bus_ops *bops); | ||
28 | void ad7879_remove(struct ad7879 *); | ||
29 | |||
30 | #endif | ||