diff options
-rw-r--r-- | Documentation/i2c/busses/i2c-taos-evm | 46 | ||||
-rw-r--r-- | drivers/i2c/busses/Kconfig | 16 | ||||
-rw-r--r-- | drivers/i2c/busses/Makefile | 1 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-taos-evm.c | 330 | ||||
-rw-r--r-- | include/linux/serio.h | 1 |
5 files changed, 394 insertions, 0 deletions
diff --git a/Documentation/i2c/busses/i2c-taos-evm b/Documentation/i2c/busses/i2c-taos-evm new file mode 100644 index 000000000000..9146e33be6dd --- /dev/null +++ b/Documentation/i2c/busses/i2c-taos-evm | |||
@@ -0,0 +1,46 @@ | |||
1 | Kernel driver i2c-taos-evm | ||
2 | |||
3 | Author: Jean Delvare <khali@linux-fr.org> | ||
4 | |||
5 | This is a driver for the evaluation modules for TAOS I2C/SMBus chips. | ||
6 | The modules include an SMBus master with limited capabilities, which can | ||
7 | be controlled over the serial port. Virtually all evaluation modules | ||
8 | are supported, but a few lines of code need to be added for each new | ||
9 | module to instantiate the right I2C chip on the bus. Obviously, a driver | ||
10 | for the chip in question is also needed. | ||
11 | |||
12 | Currently supported devices are: | ||
13 | |||
14 | * TAOS TSL2550 EVM | ||
15 | |||
16 | For addtional information on TAOS products, please see | ||
17 | http://www.taosinc.com/ | ||
18 | |||
19 | |||
20 | Using this driver | ||
21 | ----------------- | ||
22 | |||
23 | In order to use this driver, you'll need the serport driver, and the | ||
24 | inputattach tool, which is part of the input-utils package. The following | ||
25 | commands will tell the kernel that you have a TAOS EVM on the first | ||
26 | serial port: | ||
27 | |||
28 | # modprobe serport | ||
29 | # inputattach --taos-evm /dev/ttyS0 | ||
30 | |||
31 | |||
32 | Technical details | ||
33 | ----------------- | ||
34 | |||
35 | Only 4 SMBus transaction types are supported by the TAOS evaluation | ||
36 | modules: | ||
37 | * Receive Byte | ||
38 | * Send Byte | ||
39 | * Read Byte | ||
40 | * Write Byte | ||
41 | |||
42 | The communication protocol is text-based and pretty simple. It is | ||
43 | described in a PDF document on the CD which comes with the evaluation | ||
44 | module. The communication is rather slow, because the serial port has | ||
45 | to operate at 1200 bps. However, I don't think this is a big concern in | ||
46 | practice, as these modules are meant for evaluation and testing only. | ||
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 165c1266fff7..c093b0700158 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -513,6 +513,22 @@ config I2C_SIS96X | |||
513 | This driver can also be built as a module. If so, the module | 513 | This driver can also be built as a module. If so, the module |
514 | will be called i2c-sis96x. | 514 | will be called i2c-sis96x. |
515 | 515 | ||
516 | config I2C_TAOS_EVM | ||
517 | tristate "TAOS evaluation module" | ||
518 | depends on EXPERIMENTAL | ||
519 | select SERIO | ||
520 | select SERIO_SERPORT | ||
521 | default n | ||
522 | help | ||
523 | This supports TAOS evaluation modules on serial port. In order to | ||
524 | use this driver, you will need the inputattach tool, which is part | ||
525 | of the input-utils package. | ||
526 | |||
527 | If unsure, say N. | ||
528 | |||
529 | This support is also available as a module. If so, the module | ||
530 | will be called i2c-taos-evm. | ||
531 | |||
516 | config I2C_STUB | 532 | config I2C_STUB |
517 | tristate "I2C/SMBus Test Stub" | 533 | tristate "I2C/SMBus Test Stub" |
518 | depends on EXPERIMENTAL && m | 534 | depends on EXPERIMENTAL && m |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 14d1432f698b..a49c0a386aee 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -44,6 +44,7 @@ obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o | |||
44 | obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o | 44 | obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o |
45 | obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o | 45 | obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o |
46 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o | 46 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o |
47 | obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o | ||
47 | obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o | 48 | obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o |
48 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o | 49 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o |
49 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o | 50 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o |
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c new file mode 100644 index 000000000000..1b0cfd5472fd --- /dev/null +++ b/drivers/i2c/busses/i2c-taos-evm.c | |||
@@ -0,0 +1,330 @@ | |||
1 | /* | ||
2 | * Driver for the TAOS evaluation modules | ||
3 | * These devices include an I2C master which can be controlled over the | ||
4 | * serial port. | ||
5 | * | ||
6 | * Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; version 2 of the License. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/delay.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/input.h> | ||
27 | #include <linux/serio.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/i2c.h> | ||
30 | |||
31 | #define TAOS_BUFFER_SIZE 63 | ||
32 | |||
33 | #define TAOS_STATE_INIT 0 | ||
34 | #define TAOS_STATE_IDLE 1 | ||
35 | #define TAOS_STATE_SEND 2 | ||
36 | #define TAOS_STATE_RECV 3 | ||
37 | |||
38 | #define TAOS_CMD_RESET 0x12 | ||
39 | |||
40 | static DECLARE_WAIT_QUEUE_HEAD(wq); | ||
41 | |||
42 | struct taos_data { | ||
43 | struct i2c_adapter adapter; | ||
44 | struct i2c_client *client; | ||
45 | int state; | ||
46 | u8 addr; /* last used address */ | ||
47 | unsigned char buffer[TAOS_BUFFER_SIZE]; | ||
48 | unsigned int pos; /* position inside the buffer */ | ||
49 | }; | ||
50 | |||
51 | /* TAOS TSL2550 EVM */ | ||
52 | static struct i2c_board_info tsl2550_info = { | ||
53 | I2C_BOARD_INFO("tsl2550", 0x39), | ||
54 | .type = "tsl2550", | ||
55 | }; | ||
56 | |||
57 | /* Instantiate i2c devices based on the adapter name */ | ||
58 | static struct i2c_client *taos_instantiate_device(struct i2c_adapter *adapter) | ||
59 | { | ||
60 | if (!strncmp(adapter->name, "TAOS TSL2550 EVM", 16)) { | ||
61 | dev_info(&adapter->dev, "Instantiating device %s at 0x%02x\n", | ||
62 | tsl2550_info.driver_name, tsl2550_info.addr); | ||
63 | return i2c_new_device(adapter, &tsl2550_info); | ||
64 | } | ||
65 | |||
66 | return NULL; | ||
67 | } | ||
68 | |||
69 | static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr, | ||
70 | unsigned short flags, char read_write, u8 command, | ||
71 | int size, union i2c_smbus_data *data) | ||
72 | { | ||
73 | struct serio *serio = adapter->algo_data; | ||
74 | struct taos_data *taos = serio_get_drvdata(serio); | ||
75 | char *p; | ||
76 | |||
77 | /* Encode our transaction. "@" is for the device address, "$" for the | ||
78 | SMBus command and "#" for the data. */ | ||
79 | p = taos->buffer; | ||
80 | |||
81 | /* The device remembers the last used address, no need to send it | ||
82 | again if it's the same */ | ||
83 | if (addr != taos->addr) | ||
84 | p += sprintf(p, "@%02X", addr); | ||
85 | |||
86 | switch (size) { | ||
87 | case I2C_SMBUS_BYTE: | ||
88 | if (read_write == I2C_SMBUS_WRITE) | ||
89 | sprintf(p, "$#%02X", command); | ||
90 | else | ||
91 | sprintf(p, "$"); | ||
92 | break; | ||
93 | case I2C_SMBUS_BYTE_DATA: | ||
94 | if (read_write == I2C_SMBUS_WRITE) | ||
95 | sprintf(p, "$%02X#%02X", command, data->byte); | ||
96 | else | ||
97 | sprintf(p, "$%02X", command); | ||
98 | break; | ||
99 | default: | ||
100 | dev_dbg(&adapter->dev, "Unsupported transaction size %d\n", | ||
101 | size); | ||
102 | return -EINVAL; | ||
103 | } | ||
104 | |||
105 | /* Send the transaction to the TAOS EVM */ | ||
106 | dev_dbg(&adapter->dev, "Command buffer: %s\n", taos->buffer); | ||
107 | taos->pos = 0; | ||
108 | taos->state = TAOS_STATE_SEND; | ||
109 | serio_write(serio, taos->buffer[0]); | ||
110 | wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, | ||
111 | msecs_to_jiffies(250)); | ||
112 | if (taos->state != TAOS_STATE_IDLE) { | ||
113 | dev_err(&adapter->dev, "Transaction failed " | ||
114 | "(state=%d, pos=%d)\n", taos->state, taos->pos); | ||
115 | taos->addr = 0; | ||
116 | return -EIO; | ||
117 | } | ||
118 | taos->addr = addr; | ||
119 | |||
120 | /* Start the transaction and read the answer */ | ||
121 | taos->pos = 0; | ||
122 | taos->state = TAOS_STATE_RECV; | ||
123 | serio_write(serio, read_write == I2C_SMBUS_WRITE ? '>' : '<'); | ||
124 | wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, | ||
125 | msecs_to_jiffies(150)); | ||
126 | if (taos->state != TAOS_STATE_IDLE | ||
127 | || taos->pos != 6) { | ||
128 | dev_err(&adapter->dev, "Transaction timeout (pos=%d)\n", | ||
129 | taos->pos); | ||
130 | return -EIO; | ||
131 | } | ||
132 | dev_dbg(&adapter->dev, "Answer buffer: %s\n", taos->buffer); | ||
133 | |||
134 | /* Interpret the returned string */ | ||
135 | p = taos->buffer + 2; | ||
136 | p[3] = '\0'; | ||
137 | if (!strcmp(p, "NAK")) | ||
138 | return -ENODEV; | ||
139 | |||
140 | if (read_write == I2C_SMBUS_WRITE) { | ||
141 | if (!strcmp(p, "ACK")) | ||
142 | return 0; | ||
143 | } else { | ||
144 | if (p[0] == 'x') { | ||
145 | data->byte = simple_strtol(p + 1, NULL, 16); | ||
146 | return 0; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | return -EIO; | ||
151 | } | ||
152 | |||
153 | static u32 taos_smbus_func(struct i2c_adapter *adapter) | ||
154 | { | ||
155 | return I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA; | ||
156 | } | ||
157 | |||
158 | static const struct i2c_algorithm taos_algorithm = { | ||
159 | .smbus_xfer = taos_smbus_xfer, | ||
160 | .functionality = taos_smbus_func, | ||
161 | }; | ||
162 | |||
163 | static irqreturn_t taos_interrupt(struct serio *serio, unsigned char data, | ||
164 | unsigned int flags) | ||
165 | { | ||
166 | struct taos_data *taos = serio_get_drvdata(serio); | ||
167 | |||
168 | switch (taos->state) { | ||
169 | case TAOS_STATE_INIT: | ||
170 | taos->buffer[taos->pos++] = data; | ||
171 | if (data == ':' | ||
172 | || taos->pos == TAOS_BUFFER_SIZE - 1) { | ||
173 | taos->buffer[taos->pos] = '\0'; | ||
174 | taos->state = TAOS_STATE_IDLE; | ||
175 | wake_up_interruptible(&wq); | ||
176 | } | ||
177 | break; | ||
178 | case TAOS_STATE_SEND: | ||
179 | if (taos->buffer[++taos->pos]) | ||
180 | serio_write(serio, taos->buffer[taos->pos]); | ||
181 | else { | ||
182 | taos->state = TAOS_STATE_IDLE; | ||
183 | wake_up_interruptible(&wq); | ||
184 | } | ||
185 | break; | ||
186 | case TAOS_STATE_RECV: | ||
187 | taos->buffer[taos->pos++] = data; | ||
188 | if (data == ']') { | ||
189 | taos->buffer[taos->pos] = '\0'; | ||
190 | taos->state = TAOS_STATE_IDLE; | ||
191 | wake_up_interruptible(&wq); | ||
192 | } | ||
193 | break; | ||
194 | } | ||
195 | |||
196 | return IRQ_HANDLED; | ||
197 | } | ||
198 | |||
199 | /* Extract the adapter name from the buffer received after reset. | ||
200 | The buffer is modified and a pointer inside the buffer is returned. */ | ||
201 | static char *taos_adapter_name(char *buffer) | ||
202 | { | ||
203 | char *start, *end; | ||
204 | |||
205 | start = strstr(buffer, "TAOS "); | ||
206 | if (!start) | ||
207 | return NULL; | ||
208 | |||
209 | end = strchr(start, '\r'); | ||
210 | if (!end) | ||
211 | return NULL; | ||
212 | *end = '\0'; | ||
213 | |||
214 | return start; | ||
215 | } | ||
216 | |||
217 | static int taos_connect(struct serio *serio, struct serio_driver *drv) | ||
218 | { | ||
219 | struct taos_data *taos; | ||
220 | struct i2c_adapter *adapter; | ||
221 | char *name; | ||
222 | int err; | ||
223 | |||
224 | taos = kzalloc(sizeof(struct taos_data), GFP_KERNEL); | ||
225 | if (!taos) { | ||
226 | err = -ENOMEM; | ||
227 | goto exit; | ||
228 | } | ||
229 | taos->state = TAOS_STATE_INIT; | ||
230 | serio_set_drvdata(serio, taos); | ||
231 | |||
232 | err = serio_open(serio, drv); | ||
233 | if (err) | ||
234 | goto exit_kfree; | ||
235 | |||
236 | adapter = &taos->adapter; | ||
237 | adapter->owner = THIS_MODULE; | ||
238 | adapter->algo = &taos_algorithm; | ||
239 | adapter->algo_data = serio; | ||
240 | adapter->dev.parent = &serio->dev; | ||
241 | |||
242 | /* Reset the TAOS evaluation module to identify it */ | ||
243 | serio_write(serio, TAOS_CMD_RESET); | ||
244 | wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, | ||
245 | msecs_to_jiffies(2000)); | ||
246 | |||
247 | if (taos->state != TAOS_STATE_IDLE) { | ||
248 | err = -ENODEV; | ||
249 | dev_dbg(&serio->dev, "TAOS EVM reset failed (state=%d, " | ||
250 | "pos=%d)\n", taos->state, taos->pos); | ||
251 | goto exit_close; | ||
252 | } | ||
253 | |||
254 | name = taos_adapter_name(taos->buffer); | ||
255 | if (!name) { | ||
256 | err = -ENODEV; | ||
257 | dev_err(&serio->dev, "TAOS EVM identification failed\n"); | ||
258 | goto exit_close; | ||
259 | } | ||
260 | strlcpy(adapter->name, name, sizeof(adapter->name)); | ||
261 | |||
262 | err = i2c_add_adapter(adapter); | ||
263 | if (err) | ||
264 | goto exit_close; | ||
265 | dev_dbg(&serio->dev, "Connected to TAOS EVM\n"); | ||
266 | |||
267 | taos->client = taos_instantiate_device(adapter); | ||
268 | return 0; | ||
269 | |||
270 | exit_close: | ||
271 | serio_close(serio); | ||
272 | exit_kfree: | ||
273 | serio_set_drvdata(serio, NULL); | ||
274 | kfree(taos); | ||
275 | exit: | ||
276 | return err; | ||
277 | } | ||
278 | |||
279 | static void taos_disconnect(struct serio *serio) | ||
280 | { | ||
281 | struct taos_data *taos = serio_get_drvdata(serio); | ||
282 | |||
283 | if (taos->client) | ||
284 | i2c_unregister_device(taos->client); | ||
285 | i2c_del_adapter(&taos->adapter); | ||
286 | serio_close(serio); | ||
287 | serio_set_drvdata(serio, NULL); | ||
288 | kfree(taos); | ||
289 | |||
290 | dev_dbg(&serio->dev, "Disconnected from TAOS EVM\n"); | ||
291 | } | ||
292 | |||
293 | static struct serio_device_id taos_serio_ids[] = { | ||
294 | { | ||
295 | .type = SERIO_RS232, | ||
296 | .proto = SERIO_TAOSEVM, | ||
297 | .id = SERIO_ANY, | ||
298 | .extra = SERIO_ANY, | ||
299 | }, | ||
300 | { 0 } | ||
301 | }; | ||
302 | MODULE_DEVICE_TABLE(serio, taos_serio_ids); | ||
303 | |||
304 | static struct serio_driver taos_drv = { | ||
305 | .driver = { | ||
306 | .name = "taos-evm", | ||
307 | }, | ||
308 | .description = "TAOS evaluation module driver", | ||
309 | .id_table = taos_serio_ids, | ||
310 | .connect = taos_connect, | ||
311 | .disconnect = taos_disconnect, | ||
312 | .interrupt = taos_interrupt, | ||
313 | }; | ||
314 | |||
315 | static int __init taos_init(void) | ||
316 | { | ||
317 | return serio_register_driver(&taos_drv); | ||
318 | } | ||
319 | |||
320 | static void __exit taos_exit(void) | ||
321 | { | ||
322 | serio_unregister_driver(&taos_drv); | ||
323 | } | ||
324 | |||
325 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | ||
326 | MODULE_DESCRIPTION("TAOS evaluation module driver"); | ||
327 | MODULE_LICENSE("GPL"); | ||
328 | |||
329 | module_init(taos_init); | ||
330 | module_exit(taos_exit); | ||
diff --git a/include/linux/serio.h b/include/linux/serio.h index 1ebf0455e224..d9377ce9ffd1 100644 --- a/include/linux/serio.h +++ b/include/linux/serio.h | |||
@@ -209,5 +209,6 @@ static inline void serio_unpin_driver(struct serio *serio) | |||
209 | #define SERIO_PENMOUNT 0x31 | 209 | #define SERIO_PENMOUNT 0x31 |
210 | #define SERIO_TOUCHRIGHT 0x32 | 210 | #define SERIO_TOUCHRIGHT 0x32 |
211 | #define SERIO_TOUCHWIN 0x33 | 211 | #define SERIO_TOUCHWIN 0x33 |
212 | #define SERIO_TAOSEVM 0x34 | ||
212 | 213 | ||
213 | #endif | 214 | #endif |