]>
Commit | Line | Data |
---|---|---|
60a8fc01 AD |
1 | /* |
2 | * Infinity Unlimited USB Phoenix driver | |
3 | * | |
4 | * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com) | |
5 | * | |
6 | * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás) | |
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; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * And tested with help of WB Electronics | |
14 | * | |
15 | */ | |
16 | #include <linux/kernel.h> | |
17 | #include <linux/errno.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/slab.h> | |
20 | #include <linux/tty.h> | |
21 | #include <linux/tty_driver.h> | |
22 | #include <linux/tty_flip.h> | |
23 | #include <linux/serial.h> | |
24 | #include <linux/module.h> | |
25 | #include <linux/moduleparam.h> | |
26 | #include <linux/spinlock.h> | |
27 | #include <linux/uaccess.h> | |
28 | #include <linux/usb.h> | |
29 | #include <linux/usb/serial.h> | |
30 | #include "iuu_phoenix.h" | |
31 | #include <linux/random.h> | |
32 | ||
33 | ||
34 | #ifdef CONFIG_USB_SERIAL_DEBUG | |
35 | static int debug = 1; | |
36 | #else | |
37 | static int debug; | |
38 | #endif | |
39 | ||
40 | /* | |
41 | * Version Information | |
42 | */ | |
43 | #define DRIVER_VERSION "v0.5" | |
44 | #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" | |
45 | ||
46 | static struct usb_device_id id_table[] = { | |
47 | {USB_DEVICE(IUU_USB_VENDOR_ID, IUU_USB_PRODUCT_ID)}, | |
48 | {} /* Terminating entry */ | |
49 | }; | |
50 | MODULE_DEVICE_TABLE(usb, id_table); | |
51 | ||
52 | static struct usb_driver iuu_driver = { | |
53 | .name = "iuu_phoenix", | |
54 | .probe = usb_serial_probe, | |
55 | .disconnect = usb_serial_disconnect, | |
56 | .id_table = id_table, | |
57 | .no_dynamic_id = 1, | |
58 | }; | |
59 | ||
60 | /* turbo parameter */ | |
61 | static int boost = 100; | |
62 | static int clockmode = 1; | |
63 | static int cdmode = 1; | |
64 | static int iuu_cardin; | |
65 | static int iuu_cardout; | |
66 | static int xmas; | |
67 | ||
68 | static void read_rxcmd_callback(struct urb *urb); | |
69 | ||
70 | struct iuu_private { | |
71 | spinlock_t lock; /* store irq state */ | |
72 | wait_queue_head_t delta_msr_wait; | |
73 | u8 line_control; | |
74 | u8 line_status; | |
75 | u8 termios_initialized; | |
76 | int tiostatus; /* store IUART SIGNAL for tiocmget call */ | |
77 | u8 reset; /* if 1 reset is needed */ | |
78 | int poll; /* number of poll */ | |
79 | u8 *writebuf; /* buffer for writing to device */ | |
80 | int writelen; /* num of byte to write to device */ | |
81 | u8 *buf; /* used for initialize speed */ | |
82 | u8 *dbgbuf; /* debug buffer */ | |
83 | u8 len; | |
84 | }; | |
85 | ||
86 | ||
87 | static void iuu_free_buf(struct iuu_private *priv) | |
88 | { | |
89 | kfree(priv->buf); | |
90 | kfree(priv->dbgbuf); | |
91 | kfree(priv->writebuf); | |
92 | } | |
93 | ||
94 | static int iuu_alloc_buf(struct iuu_private *priv) | |
95 | { | |
96 | priv->buf = kzalloc(256, GFP_KERNEL); | |
97 | priv->dbgbuf = kzalloc(256, GFP_KERNEL); | |
98 | priv->writebuf = kzalloc(256, GFP_KERNEL); | |
99 | if (!priv->buf || !priv->dbgbuf || !priv->writebuf) { | |
100 | iuu_free_buf(priv); | |
441b62c1 | 101 | dbg("%s problem allocation buffer", __func__); |
60a8fc01 AD |
102 | return -ENOMEM; |
103 | } | |
441b62c1 | 104 | dbg("%s - Privates buffers allocation success", __func__); |
60a8fc01 AD |
105 | return 0; |
106 | } | |
107 | ||
108 | static int iuu_startup(struct usb_serial *serial) | |
109 | { | |
110 | struct iuu_private *priv; | |
111 | priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL); | |
441b62c1 | 112 | dbg("%s- priv allocation success", __func__); |
60a8fc01 AD |
113 | if (!priv) |
114 | return -ENOMEM; | |
115 | if (iuu_alloc_buf(priv)) { | |
116 | kfree(priv); | |
117 | return -ENOMEM; | |
118 | } | |
119 | spin_lock_init(&priv->lock); | |
120 | init_waitqueue_head(&priv->delta_msr_wait); | |
121 | usb_set_serial_port_data(serial->port[0], priv); | |
122 | return 0; | |
123 | } | |
124 | ||
125 | /* Shutdown function */ | |
126 | static void iuu_shutdown(struct usb_serial *serial) | |
127 | { | |
128 | struct usb_serial_port *port = serial->port[0]; | |
129 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
130 | if (!port) | |
131 | return; | |
132 | ||
441b62c1 | 133 | dbg("%s", __func__); |
60a8fc01 AD |
134 | |
135 | if (priv) { | |
136 | iuu_free_buf(priv); | |
441b62c1 | 137 | dbg("%s - I will free all", __func__); |
60a8fc01 AD |
138 | usb_set_serial_port_data(port, NULL); |
139 | ||
441b62c1 | 140 | dbg("%s - priv is not anymore in port structure", __func__); |
60a8fc01 AD |
141 | kfree(priv); |
142 | ||
441b62c1 | 143 | dbg("%s priv is now kfree", __func__); |
60a8fc01 AD |
144 | } |
145 | } | |
146 | ||
95da310e | 147 | static int iuu_tiocmset(struct tty_struct *tty, struct file *file, |
60a8fc01 AD |
148 | unsigned int set, unsigned int clear) |
149 | { | |
95da310e | 150 | struct usb_serial_port *port = tty->driver_data; |
60a8fc01 | 151 | struct iuu_private *priv = usb_get_serial_port_data(port); |
7b1fc8bc | 152 | unsigned long flags; |
60a8fc01 | 153 | |
7b1fc8bc | 154 | /* FIXME: locking on tiomstatus */ |
441b62c1 | 155 | dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __func__, |
60a8fc01 | 156 | port->number, set, clear); |
7b1fc8bc AC |
157 | |
158 | spin_lock_irqsave(&priv->lock, flags); | |
60a8fc01 AD |
159 | if (set & TIOCM_RTS) |
160 | priv->tiostatus = TIOCM_RTS; | |
161 | ||
162 | if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) { | |
441b62c1 | 163 | dbg("%s TIOCMSET RESET called !!!", __func__); |
60a8fc01 | 164 | priv->reset = 1; |
60a8fc01 | 165 | } |
7b1fc8bc | 166 | spin_unlock_irqrestore(&priv->lock, flags); |
60a8fc01 AD |
167 | return 0; |
168 | } | |
169 | ||
170 | /* This is used to provide a carrier detect mechanism | |
171 | * When a card is present, the response is 0x00 | |
172 | * When no card , the reader respond with TIOCM_CD | |
173 | * This is known as CD autodetect mechanism | |
174 | */ | |
95da310e | 175 | static int iuu_tiocmget(struct tty_struct *tty, struct file *file) |
60a8fc01 | 176 | { |
95da310e | 177 | struct usb_serial_port *port = tty->driver_data; |
60a8fc01 | 178 | struct iuu_private *priv = usb_get_serial_port_data(port); |
7b1fc8bc AC |
179 | unsigned long flags; |
180 | int rc; | |
181 | ||
182 | spin_lock_irqsave(&priv->lock, flags); | |
183 | rc = priv->tiostatus; | |
184 | spin_unlock_irqrestore(&priv->lock, flags); | |
185 | ||
186 | return rc; | |
60a8fc01 AD |
187 | } |
188 | ||
189 | static void iuu_rxcmd(struct urb *urb) | |
190 | { | |
cdc97792 | 191 | struct usb_serial_port *port = urb->context; |
60a8fc01 | 192 | int result; |
50de36f7 GKH |
193 | int status = urb->status; |
194 | ||
441b62c1 | 195 | dbg("%s - enter", __func__); |
60a8fc01 | 196 | |
50de36f7 GKH |
197 | if (status) { |
198 | dbg("%s - status = %d", __func__, status); | |
60a8fc01 AD |
199 | /* error stop all */ |
200 | return; | |
201 | } | |
202 | ||
203 | ||
204 | memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1); | |
205 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | |
206 | usb_sndbulkpipe(port->serial->dev, | |
207 | port->bulk_out_endpointAddress), | |
208 | port->write_urb->transfer_buffer, 1, | |
209 | read_rxcmd_callback, port); | |
210 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | |
211 | } | |
212 | ||
213 | static int iuu_reset(struct usb_serial_port *port, u8 wt) | |
214 | { | |
215 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
216 | int result; | |
217 | char *buf_ptr = port->write_urb->transfer_buffer; | |
441b62c1 | 218 | dbg("%s - enter", __func__); |
60a8fc01 AD |
219 | |
220 | /* Prepare the reset sequence */ | |
221 | ||
222 | *buf_ptr++ = IUU_RST_SET; | |
223 | *buf_ptr++ = IUU_DELAY_MS; | |
224 | *buf_ptr++ = wt; | |
225 | *buf_ptr = IUU_RST_CLEAR; | |
226 | ||
227 | /* send the sequence */ | |
228 | ||
229 | usb_fill_bulk_urb(port->write_urb, | |
230 | port->serial->dev, | |
231 | usb_sndbulkpipe(port->serial->dev, | |
232 | port->bulk_out_endpointAddress), | |
233 | port->write_urb->transfer_buffer, 4, iuu_rxcmd, port); | |
234 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | |
235 | priv->reset = 0; | |
236 | return result; | |
237 | } | |
238 | ||
239 | /* Status Function | |
240 | * Return value is | |
241 | * 0x00 = no card | |
242 | * 0x01 = smartcard | |
243 | * 0x02 = sim card | |
244 | */ | |
245 | static void iuu_update_status_callback(struct urb *urb) | |
246 | { | |
cdc97792 | 247 | struct usb_serial_port *port = urb->context; |
60a8fc01 AD |
248 | struct iuu_private *priv = usb_get_serial_port_data(port); |
249 | u8 *st; | |
50de36f7 GKH |
250 | int status = urb->status; |
251 | ||
441b62c1 | 252 | dbg("%s - enter", __func__); |
60a8fc01 | 253 | |
50de36f7 GKH |
254 | if (status) { |
255 | dbg("%s - status = %d", __func__, status); | |
60a8fc01 AD |
256 | /* error stop all */ |
257 | return; | |
258 | } | |
259 | ||
260 | st = urb->transfer_buffer; | |
441b62c1 | 261 | dbg("%s - enter", __func__); |
60a8fc01 AD |
262 | if (urb->actual_length == 1) { |
263 | switch (st[0]) { | |
264 | case 0x1: | |
265 | priv->tiostatus = iuu_cardout; | |
266 | break; | |
267 | case 0x0: | |
268 | priv->tiostatus = iuu_cardin; | |
269 | break; | |
270 | default: | |
271 | priv->tiostatus = iuu_cardin; | |
272 | } | |
273 | } | |
274 | iuu_rxcmd(urb); | |
275 | } | |
276 | ||
277 | static void iuu_status_callback(struct urb *urb) | |
278 | { | |
cdc97792 | 279 | struct usb_serial_port *port = urb->context; |
60a8fc01 | 280 | int result; |
50de36f7 | 281 | int status = urb->status; |
60a8fc01 | 282 | |
50de36f7 | 283 | dbg("%s - status = %d", __func__, status); |
60a8fc01 AD |
284 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, |
285 | usb_rcvbulkpipe(port->serial->dev, | |
286 | port->bulk_in_endpointAddress), | |
287 | port->read_urb->transfer_buffer, 256, | |
288 | iuu_update_status_callback, port); | |
289 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | |
290 | } | |
291 | ||
292 | static int iuu_status(struct usb_serial_port *port) | |
293 | { | |
294 | int result; | |
295 | ||
441b62c1 | 296 | dbg("%s - enter", __func__); |
60a8fc01 AD |
297 | |
298 | memset(port->write_urb->transfer_buffer, IUU_GET_STATE_REGISTER, 1); | |
299 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | |
300 | usb_sndbulkpipe(port->serial->dev, | |
301 | port->bulk_out_endpointAddress), | |
302 | port->write_urb->transfer_buffer, 1, | |
303 | iuu_status_callback, port); | |
304 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | |
305 | return result; | |
306 | ||
307 | } | |
308 | ||
309 | static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count) | |
310 | { | |
311 | int status; | |
312 | struct usb_serial *serial = port->serial; | |
313 | int actual = 0; | |
314 | ||
441b62c1 | 315 | dbg("%s - enter", __func__); |
60a8fc01 AD |
316 | |
317 | /* send the data out the bulk port */ | |
318 | ||
319 | status = | |
320 | usb_bulk_msg(serial->dev, | |
321 | usb_sndbulkpipe(serial->dev, | |
322 | port->bulk_out_endpointAddress), buf, | |
323 | count, &actual, HZ * 1); | |
324 | ||
9e8e2d2a | 325 | if (status != IUU_OPERATION_OK) |
441b62c1 | 326 | dbg("%s - error = %2x", __func__, status); |
9e8e2d2a | 327 | else |
441b62c1 | 328 | dbg("%s - write OK !", __func__); |
60a8fc01 AD |
329 | return status; |
330 | } | |
331 | ||
332 | static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count) | |
333 | { | |
334 | int status; | |
335 | struct usb_serial *serial = port->serial; | |
336 | int actual = 0; | |
337 | ||
441b62c1 | 338 | dbg("%s - enter", __func__); |
60a8fc01 AD |
339 | |
340 | /* send the data out the bulk port */ | |
341 | ||
342 | status = | |
343 | usb_bulk_msg(serial->dev, | |
344 | usb_rcvbulkpipe(serial->dev, | |
345 | port->bulk_in_endpointAddress), buf, | |
346 | count, &actual, HZ * 1); | |
347 | ||
9e8e2d2a | 348 | if (status != IUU_OPERATION_OK) |
441b62c1 | 349 | dbg("%s - error = %2x", __func__, status); |
9e8e2d2a | 350 | else |
441b62c1 | 351 | dbg("%s - read OK !", __func__); |
60a8fc01 AD |
352 | return status; |
353 | } | |
354 | ||
355 | static int iuu_led(struct usb_serial_port *port, unsigned int R, | |
356 | unsigned int G, unsigned int B, u8 f) | |
357 | { | |
358 | int status; | |
359 | u8 *buf; | |
360 | buf = kmalloc(8, GFP_KERNEL); | |
361 | if (!buf) | |
362 | return -ENOMEM; | |
363 | ||
441b62c1 | 364 | dbg("%s - enter", __func__); |
60a8fc01 AD |
365 | |
366 | buf[0] = IUU_SET_LED; | |
367 | buf[1] = R & 0xFF; | |
368 | buf[2] = (R >> 8) & 0xFF; | |
369 | buf[3] = G & 0xFF; | |
370 | buf[4] = (G >> 8) & 0xFF; | |
371 | buf[5] = B & 0xFF; | |
372 | buf[6] = (B >> 8) & 0xFF; | |
373 | buf[7] = f; | |
374 | status = bulk_immediate(port, buf, 8); | |
375 | kfree(buf); | |
376 | if (status != IUU_OPERATION_OK) | |
441b62c1 | 377 | dbg("%s - led error status = %2x", __func__, status); |
60a8fc01 | 378 | else |
441b62c1 | 379 | dbg("%s - led OK !", __func__); |
60a8fc01 AD |
380 | return IUU_OPERATION_OK; |
381 | } | |
382 | ||
383 | static void iuu_rgbf_fill_buffer(u8 *buf, u8 r1, u8 r2, u8 g1, u8 g2, u8 b1, | |
384 | u8 b2, u8 freq) | |
385 | { | |
386 | *buf++ = IUU_SET_LED; | |
387 | *buf++ = r1; | |
388 | *buf++ = r2; | |
389 | *buf++ = g1; | |
390 | *buf++ = g2; | |
391 | *buf++ = b1; | |
392 | *buf++ = b2; | |
393 | *buf = freq; | |
394 | } | |
395 | ||
396 | static void iuu_led_activity_on(struct urb *urb) | |
397 | { | |
cdc97792 | 398 | struct usb_serial_port *port = urb->context; |
60a8fc01 AD |
399 | int result; |
400 | char *buf_ptr = port->write_urb->transfer_buffer; | |
401 | *buf_ptr++ = IUU_SET_LED; | |
402 | if (xmas == 1) { | |
403 | get_random_bytes(buf_ptr, 6); | |
404 | *(buf_ptr+7) = 1; | |
405 | } else { | |
406 | iuu_rgbf_fill_buffer(buf_ptr, 255, 255, 0, 0, 0, 0, 255); | |
407 | } | |
408 | ||
409 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | |
410 | usb_sndbulkpipe(port->serial->dev, | |
411 | port->bulk_out_endpointAddress), | |
412 | port->write_urb->transfer_buffer, 8 , | |
413 | iuu_rxcmd, port); | |
414 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | |
415 | } | |
416 | ||
417 | static void iuu_led_activity_off(struct urb *urb) | |
418 | { | |
cdc97792 | 419 | struct usb_serial_port *port = urb->context; |
60a8fc01 AD |
420 | int result; |
421 | char *buf_ptr = port->write_urb->transfer_buffer; | |
422 | if (xmas == 1) { | |
423 | iuu_rxcmd(urb); | |
424 | return; | |
425 | } else { | |
426 | *buf_ptr++ = IUU_SET_LED; | |
427 | iuu_rgbf_fill_buffer(buf_ptr, 0, 0, 255, 255, 0, 0, 255); | |
428 | } | |
429 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | |
430 | usb_sndbulkpipe(port->serial->dev, | |
431 | port->bulk_out_endpointAddress), | |
432 | port->write_urb->transfer_buffer, 8 , | |
433 | iuu_rxcmd, port); | |
434 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | |
435 | } | |
436 | ||
437 | ||
438 | ||
439 | static int iuu_clk(struct usb_serial_port *port, int dwFrq) | |
440 | { | |
441 | int status; | |
442 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
443 | int Count = 0; | |
444 | u8 FrqGenAdr = 0x69; | |
445 | u8 DIV = 0; /* 8bit */ | |
446 | u8 XDRV = 0; /* 8bit */ | |
447 | u8 PUMP = 0; /* 3bit */ | |
448 | u8 PBmsb = 0; /* 2bit */ | |
449 | u8 PBlsb = 0; /* 8bit */ | |
450 | u8 PO = 0; /* 1bit */ | |
451 | u8 Q = 0; /* 7bit */ | |
452 | /* 24bit = 3bytes */ | |
453 | unsigned int P = 0; | |
454 | unsigned int P2 = 0; | |
455 | int frq = (int)dwFrq; | |
456 | ||
441b62c1 | 457 | dbg("%s - enter", __func__); |
60a8fc01 AD |
458 | |
459 | if (frq == 0) { | |
460 | priv->buf[Count++] = IUU_UART_WRITE_I2C; | |
461 | priv->buf[Count++] = FrqGenAdr << 1; | |
462 | priv->buf[Count++] = 0x09; | |
463 | priv->buf[Count++] = 0x00; | |
464 | ||
465 | status = bulk_immediate(port, (u8 *) priv->buf, Count); | |
466 | if (status != 0) { | |
441b62c1 | 467 | dbg("%s - write error ", __func__); |
60a8fc01 AD |
468 | return status; |
469 | } | |
470 | } else if (frq == 3579000) { | |
471 | DIV = 100; | |
472 | P = 1193; | |
473 | Q = 40; | |
474 | XDRV = 0; | |
475 | } else if (frq == 3680000) { | |
476 | DIV = 105; | |
477 | P = 161; | |
478 | Q = 5; | |
479 | XDRV = 0; | |
480 | } else if (frq == 6000000) { | |
481 | DIV = 66; | |
482 | P = 66; | |
483 | Q = 2; | |
484 | XDRV = 0x28; | |
485 | } else { | |
486 | unsigned int result = 0; | |
487 | unsigned int tmp = 0; | |
488 | unsigned int check; | |
489 | unsigned int check2; | |
490 | char found = 0x00; | |
491 | unsigned int lQ = 2; | |
492 | unsigned int lP = 2055; | |
493 | unsigned int lDiv = 4; | |
494 | ||
495 | for (lQ = 2; lQ <= 47 && !found; lQ++) | |
496 | for (lP = 2055; lP >= 8 && !found; lP--) | |
497 | for (lDiv = 4; lDiv <= 127 && !found; lDiv++) { | |
498 | tmp = (12000000 / lDiv) * (lP / lQ); | |
499 | if (abs((int)(tmp - frq)) < | |
500 | abs((int)(frq - result))) { | |
501 | check2 = (12000000 / lQ); | |
502 | if (check2 < 250000) | |
503 | continue; | |
504 | check = (12000000 / lQ) * lP; | |
505 | if (check > 400000000) | |
506 | continue; | |
507 | if (check < 100000000) | |
508 | continue; | |
509 | if (lDiv < 4 || lDiv > 127) | |
510 | continue; | |
511 | result = tmp; | |
512 | P = lP; | |
513 | DIV = lDiv; | |
514 | Q = lQ; | |
515 | if (result == frq) | |
516 | found = 0x01; | |
517 | } | |
518 | } | |
519 | } | |
520 | P2 = ((P - PO) / 2) - 4; | |
521 | DIV = DIV; | |
522 | PUMP = 0x04; | |
523 | PBmsb = (P2 >> 8 & 0x03); | |
524 | PBlsb = P2 & 0xFF; | |
525 | PO = (P >> 10) & 0x01; | |
526 | Q = Q - 2; | |
527 | ||
528 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
529 | priv->buf[Count++] = FrqGenAdr << 1; | |
530 | priv->buf[Count++] = 0x09; | |
531 | priv->buf[Count++] = 0x20; /* Adr = 0x09 */ | |
532 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
533 | priv->buf[Count++] = FrqGenAdr << 1; | |
534 | priv->buf[Count++] = 0x0C; | |
535 | priv->buf[Count++] = DIV; /* Adr = 0x0C */ | |
536 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
537 | priv->buf[Count++] = FrqGenAdr << 1; | |
538 | priv->buf[Count++] = 0x12; | |
539 | priv->buf[Count++] = XDRV; /* Adr = 0x12 */ | |
540 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
541 | priv->buf[Count++] = FrqGenAdr << 1; | |
542 | priv->buf[Count++] = 0x13; | |
543 | priv->buf[Count++] = 0x6B; /* Adr = 0x13 */ | |
544 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
545 | priv->buf[Count++] = FrqGenAdr << 1; | |
546 | priv->buf[Count++] = 0x40; | |
547 | priv->buf[Count++] = (0xC0 | ((PUMP & 0x07) << 2)) | | |
548 | (PBmsb & 0x03); /* Adr = 0x40 */ | |
549 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
550 | priv->buf[Count++] = FrqGenAdr << 1; | |
551 | priv->buf[Count++] = 0x41; | |
552 | priv->buf[Count++] = PBlsb; /* Adr = 0x41 */ | |
553 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
554 | priv->buf[Count++] = FrqGenAdr << 1; | |
555 | priv->buf[Count++] = 0x42; | |
556 | priv->buf[Count++] = Q | (((PO & 0x01) << 7)); /* Adr = 0x42 */ | |
557 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
558 | priv->buf[Count++] = FrqGenAdr << 1; | |
559 | priv->buf[Count++] = 0x44; | |
560 | priv->buf[Count++] = (char)0xFF; /* Adr = 0x44 */ | |
561 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
562 | priv->buf[Count++] = FrqGenAdr << 1; | |
563 | priv->buf[Count++] = 0x45; | |
564 | priv->buf[Count++] = (char)0xFE; /* Adr = 0x45 */ | |
565 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
566 | priv->buf[Count++] = FrqGenAdr << 1; | |
567 | priv->buf[Count++] = 0x46; | |
568 | priv->buf[Count++] = 0x7F; /* Adr = 0x46 */ | |
569 | priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ | |
570 | priv->buf[Count++] = FrqGenAdr << 1; | |
571 | priv->buf[Count++] = 0x47; | |
572 | priv->buf[Count++] = (char)0x84; /* Adr = 0x47 */ | |
573 | ||
574 | status = bulk_immediate(port, (u8 *) priv->buf, Count); | |
575 | if (status != IUU_OPERATION_OK) | |
441b62c1 | 576 | dbg("%s - write error ", __func__); |
60a8fc01 AD |
577 | return status; |
578 | } | |
579 | ||
580 | static int iuu_uart_flush(struct usb_serial_port *port) | |
581 | { | |
582 | int i; | |
583 | int status; | |
584 | u8 rxcmd = IUU_UART_RX; | |
585 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
586 | ||
441b62c1 | 587 | dbg("%s - enter", __func__); |
60a8fc01 AD |
588 | |
589 | if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0) | |
590 | return -EIO; | |
591 | ||
592 | for (i = 0; i < 2; i++) { | |
593 | status = bulk_immediate(port, &rxcmd, 1); | |
594 | if (status != IUU_OPERATION_OK) { | |
441b62c1 | 595 | dbg("%s - uart_flush_write error", __func__); |
60a8fc01 AD |
596 | return status; |
597 | } | |
598 | ||
599 | status = read_immediate(port, &priv->len, 1); | |
600 | if (status != IUU_OPERATION_OK) { | |
441b62c1 | 601 | dbg("%s - uart_flush_read error", __func__); |
60a8fc01 AD |
602 | return status; |
603 | } | |
604 | ||
605 | if (priv->len > 0) { | |
441b62c1 | 606 | dbg("%s - uart_flush datalen is : %i ", __func__, |
60a8fc01 AD |
607 | priv->len); |
608 | status = read_immediate(port, priv->buf, priv->len); | |
609 | if (status != IUU_OPERATION_OK) { | |
441b62c1 | 610 | dbg("%s - uart_flush_read error", __func__); |
60a8fc01 AD |
611 | return status; |
612 | } | |
613 | } | |
614 | } | |
441b62c1 | 615 | dbg("%s - uart_flush_read OK!", __func__); |
60a8fc01 AD |
616 | iuu_led(port, 0, 0xF000, 0, 0xFF); |
617 | return status; | |
618 | } | |
619 | ||
620 | static void read_buf_callback(struct urb *urb) | |
621 | { | |
cdc97792 | 622 | struct usb_serial_port *port = urb->context; |
60a8fc01 AD |
623 | unsigned char *data = urb->transfer_buffer; |
624 | struct tty_struct *tty; | |
50de36f7 | 625 | int status = urb->status; |
60a8fc01 | 626 | |
50de36f7 GKH |
627 | dbg("%s - status = %d", __func__, status); |
628 | ||
629 | if (status) { | |
630 | if (status == -EPROTO) { | |
60a8fc01 AD |
631 | /* reschedule needed */ |
632 | } | |
633 | return; | |
634 | } | |
635 | ||
441b62c1 | 636 | dbg("%s - %i chars to write", __func__, urb->actual_length); |
4a90f09b | 637 | tty = tty_port_tty_get(&port->port); |
60a8fc01 | 638 | if (data == NULL) |
441b62c1 | 639 | dbg("%s - data is NULL !!!", __func__); |
60a8fc01 AD |
640 | if (tty && urb->actual_length && data) { |
641 | tty_insert_flip_string(tty, data, urb->actual_length); | |
642 | tty_flip_buffer_push(tty); | |
643 | } | |
4a90f09b | 644 | tty_kref_put(tty); |
60a8fc01 AD |
645 | iuu_led_activity_on(urb); |
646 | } | |
647 | ||
648 | static int iuu_bulk_write(struct usb_serial_port *port) | |
649 | { | |
650 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
8594303a | 651 | unsigned long flags; |
60a8fc01 AD |
652 | int result; |
653 | int i; | |
654 | char *buf_ptr = port->write_urb->transfer_buffer; | |
441b62c1 | 655 | dbg("%s - enter", __func__); |
60a8fc01 AD |
656 | |
657 | *buf_ptr++ = IUU_UART_ESC; | |
658 | *buf_ptr++ = IUU_UART_TX; | |
659 | *buf_ptr++ = priv->writelen; | |
660 | ||
661 | memcpy(buf_ptr, priv->writebuf, | |
662 | priv->writelen); | |
663 | if (debug == 1) { | |
664 | for (i = 0; i < priv->writelen; i++) | |
665 | sprintf(priv->dbgbuf + i*2 , | |
666 | "%02X", priv->writebuf[i]); | |
667 | priv->dbgbuf[priv->writelen+i*2] = 0; | |
441b62c1 | 668 | dbg("%s - writing %i chars : %s", __func__, |
60a8fc01 AD |
669 | priv->writelen, priv->dbgbuf); |
670 | } | |
671 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | |
672 | usb_sndbulkpipe(port->serial->dev, | |
673 | port->bulk_out_endpointAddress), | |
674 | port->write_urb->transfer_buffer, priv->writelen + 3, | |
675 | iuu_rxcmd, port); | |
676 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | |
677 | spin_lock_irqsave(&priv->lock, flags); | |
678 | priv->writelen = 0; | |
679 | spin_unlock_irqrestore(&priv->lock, flags); | |
680 | usb_serial_port_softint(port); | |
681 | return result; | |
682 | } | |
683 | ||
684 | static int iuu_read_buf(struct usb_serial_port *port, int len) | |
685 | { | |
686 | int result; | |
441b62c1 | 687 | dbg("%s - enter", __func__); |
60a8fc01 AD |
688 | |
689 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, | |
690 | usb_rcvbulkpipe(port->serial->dev, | |
691 | port->bulk_in_endpointAddress), | |
692 | port->read_urb->transfer_buffer, len, | |
693 | read_buf_callback, port); | |
694 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | |
695 | return result; | |
696 | } | |
697 | ||
698 | static void iuu_uart_read_callback(struct urb *urb) | |
699 | { | |
cdc97792 | 700 | struct usb_serial_port *port = urb->context; |
60a8fc01 | 701 | struct iuu_private *priv = usb_get_serial_port_data(port); |
8594303a | 702 | unsigned long flags; |
50de36f7 | 703 | int status = urb->status; |
60a8fc01 AD |
704 | int error = 0; |
705 | int len = 0; | |
706 | unsigned char *data = urb->transfer_buffer; | |
707 | priv->poll++; | |
708 | ||
441b62c1 | 709 | dbg("%s - enter", __func__); |
60a8fc01 | 710 | |
50de36f7 GKH |
711 | if (status) { |
712 | dbg("%s - status = %d", __func__, status); | |
60a8fc01 AD |
713 | /* error stop all */ |
714 | return; | |
715 | } | |
716 | if (data == NULL) | |
441b62c1 | 717 | dbg("%s - data is NULL !!!", __func__); |
60a8fc01 AD |
718 | |
719 | if (urb->actual_length == 1 && data != NULL) | |
720 | len = (int) data[0]; | |
721 | ||
722 | if (urb->actual_length > 1) { | |
441b62c1 | 723 | dbg("%s - urb->actual_length = %i", __func__, |
60a8fc01 AD |
724 | urb->actual_length); |
725 | error = 1; | |
726 | return; | |
727 | } | |
728 | /* if len > 0 call readbuf */ | |
729 | ||
730 | if (len > 0 && error == 0) { | |
731 | dbg("%s - call read buf - len to read is %i ", | |
441b62c1 | 732 | __func__, len); |
60a8fc01 AD |
733 | status = iuu_read_buf(port, len); |
734 | return; | |
735 | } | |
736 | /* need to update status ? */ | |
737 | if (priv->poll > 99) { | |
738 | status = iuu_status(port); | |
739 | priv->poll = 0; | |
740 | return; | |
741 | } | |
742 | ||
743 | /* reset waiting ? */ | |
744 | ||
745 | if (priv->reset == 1) { | |
746 | status = iuu_reset(port, 0xC); | |
747 | return; | |
748 | } | |
749 | /* Writebuf is waiting */ | |
750 | spin_lock_irqsave(&priv->lock, flags); | |
751 | if (priv->writelen > 0) { | |
752 | spin_unlock_irqrestore(&priv->lock, flags); | |
753 | status = iuu_bulk_write(port); | |
754 | return; | |
755 | } | |
756 | spin_unlock_irqrestore(&priv->lock, flags); | |
757 | /* if nothing to write call again rxcmd */ | |
441b62c1 | 758 | dbg("%s - rxcmd recall", __func__); |
60a8fc01 | 759 | iuu_led_activity_off(urb); |
60a8fc01 AD |
760 | } |
761 | ||
95da310e AC |
762 | static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port, |
763 | const u8 *buf, int count) | |
60a8fc01 AD |
764 | { |
765 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
8594303a | 766 | unsigned long flags; |
441b62c1 | 767 | dbg("%s - enter", __func__); |
60a8fc01 AD |
768 | |
769 | if (count > 256) | |
770 | return -ENOMEM; | |
771 | ||
772 | spin_lock_irqsave(&priv->lock, flags); | |
773 | if (priv->writelen > 0) { | |
774 | /* buffer already filled but not commited */ | |
775 | spin_unlock_irqrestore(&priv->lock, flags); | |
9e8e2d2a | 776 | return 0; |
60a8fc01 AD |
777 | } |
778 | /* fill the buffer */ | |
779 | memcpy(priv->writebuf, buf, count); | |
780 | priv->writelen = count; | |
781 | spin_unlock_irqrestore(&priv->lock, flags); | |
782 | ||
9e8e2d2a | 783 | return count; |
60a8fc01 AD |
784 | } |
785 | ||
786 | static void read_rxcmd_callback(struct urb *urb) | |
787 | { | |
cdc97792 | 788 | struct usb_serial_port *port = urb->context; |
60a8fc01 | 789 | int result; |
50de36f7 | 790 | int status = urb->status; |
60a8fc01 | 791 | |
50de36f7 | 792 | dbg("%s - status = %d", __func__, status); |
60a8fc01 | 793 | |
50de36f7 | 794 | if (status) { |
60a8fc01 AD |
795 | /* error stop all */ |
796 | return; | |
797 | } | |
798 | ||
799 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, | |
800 | usb_rcvbulkpipe(port->serial->dev, | |
801 | port->bulk_in_endpointAddress), | |
802 | port->read_urb->transfer_buffer, 256, | |
803 | iuu_uart_read_callback, port); | |
804 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | |
441b62c1 | 805 | dbg("%s - submit result = %d", __func__, result); |
60a8fc01 AD |
806 | return; |
807 | } | |
808 | ||
809 | static int iuu_uart_on(struct usb_serial_port *port) | |
810 | { | |
811 | int status; | |
812 | u8 *buf; | |
813 | ||
814 | buf = kmalloc(sizeof(u8) * 4, GFP_KERNEL); | |
815 | ||
816 | if (!buf) | |
817 | return -ENOMEM; | |
818 | ||
819 | buf[0] = IUU_UART_ENABLE; | |
820 | buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF); | |
821 | buf[2] = (u8) (0x00FF & IUU_BAUD_9600); | |
822 | buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN); | |
823 | ||
824 | status = bulk_immediate(port, buf, 4); | |
825 | if (status != IUU_OPERATION_OK) { | |
441b62c1 | 826 | dbg("%s - uart_on error", __func__); |
60a8fc01 AD |
827 | goto uart_enable_failed; |
828 | } | |
829 | /* iuu_reset() the card after iuu_uart_on() */ | |
830 | status = iuu_uart_flush(port); | |
831 | if (status != IUU_OPERATION_OK) | |
441b62c1 | 832 | dbg("%s - uart_flush error", __func__); |
60a8fc01 AD |
833 | uart_enable_failed: |
834 | kfree(buf); | |
835 | return status; | |
836 | } | |
837 | ||
838 | /* Diables the IUU UART (a.k.a. the Phoenix voiderface) */ | |
839 | static int iuu_uart_off(struct usb_serial_port *port) | |
840 | { | |
841 | int status; | |
842 | u8 *buf; | |
843 | buf = kmalloc(1, GFP_KERNEL); | |
844 | if (!buf) | |
845 | return -ENOMEM; | |
846 | buf[0] = IUU_UART_DISABLE; | |
847 | ||
848 | status = bulk_immediate(port, buf, 1); | |
849 | if (status != IUU_OPERATION_OK) | |
441b62c1 | 850 | dbg("%s - uart_off error", __func__); |
60a8fc01 AD |
851 | |
852 | kfree(buf); | |
853 | return status; | |
854 | } | |
855 | ||
856 | static int iuu_uart_baud(struct usb_serial_port *port, u32 baud, | |
857 | u32 *actual, u8 parity) | |
858 | { | |
859 | int status; | |
860 | u8 *dataout; | |
861 | u8 DataCount = 0; | |
862 | u8 T1Frekvens = 0; | |
863 | u8 T1reload = 0; | |
864 | unsigned int T1FrekvensHZ = 0; | |
865 | ||
866 | dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL); | |
867 | ||
868 | if (!dataout) | |
869 | return -ENOMEM; | |
870 | ||
871 | if (baud < 1200 || baud > 230400) { | |
872 | kfree(dataout); | |
873 | return IUU_INVALID_PARAMETER; | |
874 | } | |
875 | if (baud > 977) { | |
876 | T1Frekvens = 3; | |
877 | T1FrekvensHZ = 500000; | |
878 | } | |
879 | ||
880 | if (baud > 3906) { | |
881 | T1Frekvens = 2; | |
882 | T1FrekvensHZ = 2000000; | |
883 | } | |
884 | ||
885 | if (baud > 11718) { | |
886 | T1Frekvens = 1; | |
887 | T1FrekvensHZ = 6000000; | |
888 | } | |
889 | ||
890 | if (baud > 46875) { | |
891 | T1Frekvens = 0; | |
892 | T1FrekvensHZ = 24000000; | |
893 | } | |
894 | ||
895 | T1reload = 256 - (u8) (T1FrekvensHZ / (baud * 2)); | |
896 | ||
897 | /* magic number here: ENTER_FIRMWARE_UPDATE; */ | |
898 | dataout[DataCount++] = IUU_UART_ESC; | |
899 | /* magic number here: CHANGE_BAUD; */ | |
900 | dataout[DataCount++] = IUU_UART_CHANGE; | |
901 | dataout[DataCount++] = T1Frekvens; | |
902 | dataout[DataCount++] = T1reload; | |
903 | ||
904 | *actual = (T1FrekvensHZ / (256 - T1reload)) / 2; | |
905 | ||
906 | switch (parity & 0x0F) { | |
907 | case IUU_PARITY_NONE: | |
908 | dataout[DataCount++] = 0x00; | |
909 | break; | |
910 | case IUU_PARITY_EVEN: | |
911 | dataout[DataCount++] = 0x01; | |
912 | break; | |
913 | case IUU_PARITY_ODD: | |
914 | dataout[DataCount++] = 0x02; | |
915 | break; | |
916 | case IUU_PARITY_MARK: | |
917 | dataout[DataCount++] = 0x03; | |
918 | break; | |
919 | case IUU_PARITY_SPACE: | |
920 | dataout[DataCount++] = 0x04; | |
921 | break; | |
922 | default: | |
923 | kfree(dataout); | |
924 | return IUU_INVALID_PARAMETER; | |
925 | break; | |
926 | } | |
927 | ||
928 | switch (parity & 0xF0) { | |
929 | case IUU_ONE_STOP_BIT: | |
930 | dataout[DataCount - 1] |= IUU_ONE_STOP_BIT; | |
931 | break; | |
932 | ||
933 | case IUU_TWO_STOP_BITS: | |
934 | dataout[DataCount - 1] |= IUU_TWO_STOP_BITS; | |
935 | break; | |
936 | default: | |
937 | kfree(dataout); | |
938 | return IUU_INVALID_PARAMETER; | |
939 | break; | |
940 | } | |
941 | ||
942 | status = bulk_immediate(port, dataout, DataCount); | |
943 | if (status != IUU_OPERATION_OK) | |
441b62c1 | 944 | dbg("%s - uart_off error", __func__); |
60a8fc01 AD |
945 | kfree(dataout); |
946 | return status; | |
947 | } | |
948 | ||
949 | static int set_control_lines(struct usb_device *dev, u8 value) | |
950 | { | |
951 | return 0; | |
952 | } | |
953 | ||
95da310e AC |
954 | static void iuu_close(struct tty_struct *tty, |
955 | struct usb_serial_port *port, struct file *filp) | |
60a8fc01 AD |
956 | { |
957 | /* iuu_led (port,255,0,0,0); */ | |
958 | struct usb_serial *serial; | |
959 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
960 | unsigned long flags; | |
961 | unsigned int c_cflag; | |
962 | ||
963 | serial = port->serial; | |
964 | if (!serial) | |
965 | return; | |
966 | ||
441b62c1 | 967 | dbg("%s - port %d", __func__, port->number); |
60a8fc01 AD |
968 | |
969 | iuu_uart_off(port); | |
970 | if (serial->dev) { | |
95da310e AC |
971 | if (tty) { |
972 | c_cflag = tty->termios->c_cflag; | |
60a8fc01 AD |
973 | if (c_cflag & HUPCL) { |
974 | /* drop DTR and RTS */ | |
975 | priv = usb_get_serial_port_data(port); | |
976 | spin_lock_irqsave(&priv->lock, flags); | |
977 | priv->line_control = 0; | |
978 | spin_unlock_irqrestore(&priv->lock, flags); | |
979 | set_control_lines(port->serial->dev, 0); | |
980 | } | |
981 | } | |
982 | /* free writebuf */ | |
983 | /* shutdown our urbs */ | |
441b62c1 | 984 | dbg("%s - shutting down urbs", __func__); |
60a8fc01 AD |
985 | usb_kill_urb(port->write_urb); |
986 | usb_kill_urb(port->read_urb); | |
987 | usb_kill_urb(port->interrupt_in_urb); | |
988 | msleep(1000); | |
989 | /* wait one second to free all buffers */ | |
990 | iuu_led(port, 0, 0, 0xF000, 0xFF); | |
991 | msleep(1000); | |
992 | usb_reset_device(port->serial->dev); | |
993 | } | |
994 | } | |
995 | ||
95da310e AC |
996 | static int iuu_open(struct tty_struct *tty, |
997 | struct usb_serial_port *port, struct file *filp) | |
60a8fc01 AD |
998 | { |
999 | struct usb_serial *serial = port->serial; | |
1000 | u8 *buf; | |
1001 | int result; | |
1002 | u32 actual; | |
1003 | unsigned long flags; | |
1004 | struct iuu_private *priv = usb_get_serial_port_data(port); | |
1005 | ||
441b62c1 | 1006 | dbg("%s - port %d", __func__, port->number); |
60a8fc01 AD |
1007 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
1008 | usb_clear_halt(serial->dev, port->read_urb->pipe); | |
1009 | ||
1010 | buf = kmalloc(10, GFP_KERNEL); | |
1011 | if (buf == NULL) | |
1012 | return -ENOMEM; | |
1013 | ||
1014 | /* fixup the endpoint buffer size */ | |
1015 | kfree(port->bulk_out_buffer); | |
1016 | port->bulk_out_buffer = kmalloc(512, GFP_KERNEL); | |
1017 | port->bulk_out_size = 512; | |
1018 | kfree(port->bulk_in_buffer); | |
1019 | port->bulk_in_buffer = kmalloc(512, GFP_KERNEL); | |
1020 | port->bulk_in_size = 512; | |
1021 | ||
1022 | if (!port->bulk_out_buffer || !port->bulk_in_buffer) { | |
1023 | kfree(port->bulk_out_buffer); | |
1024 | kfree(port->bulk_in_buffer); | |
1025 | kfree(buf); | |
1026 | return -ENOMEM; | |
1027 | } | |
1028 | ||
1029 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | |
1030 | usb_sndbulkpipe(port->serial->dev, | |
1031 | port->bulk_out_endpointAddress), | |
1032 | port->bulk_out_buffer, 512, | |
1033 | NULL, NULL); | |
1034 | ||
1035 | ||
1036 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, | |
1037 | usb_rcvbulkpipe(port->serial->dev, | |
1038 | port->bulk_in_endpointAddress), | |
1039 | port->bulk_in_buffer, 512, | |
1040 | NULL, NULL); | |
1041 | ||
1042 | /* set the termios structure */ | |
1043 | spin_lock_irqsave(&priv->lock, flags); | |
95da310e AC |
1044 | if (tty && !priv->termios_initialized) { |
1045 | *(tty->termios) = tty_std_termios; | |
1046 | tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 | |
1047 | | TIOCM_CTS | CSTOPB | PARENB; | |
1048 | tty->termios->c_ispeed = 9600; | |
1049 | tty->termios->c_ospeed = 9600; | |
1050 | tty->termios->c_lflag = 0; | |
1051 | tty->termios->c_oflag = 0; | |
1052 | tty->termios->c_iflag = 0; | |
60a8fc01 | 1053 | priv->termios_initialized = 1; |
60a8fc01 AD |
1054 | priv->poll = 0; |
1055 | } | |
1056 | spin_unlock_irqrestore(&priv->lock, flags); | |
1057 | ||
1058 | /* initialize writebuf */ | |
1059 | #define FISH(a, b, c, d) do { \ | |
1060 | result = usb_control_msg(port->serial->dev, \ | |
1061 | usb_rcvctrlpipe(port->serial->dev, 0), \ | |
1062 | b, a, c, d, buf, 1, 1000); \ | |
1063 | dbg("0x%x:0x%x:0x%x:0x%x %d - %x", a, b, c, d, result, \ | |
1064 | buf[0]); } while (0); | |
1065 | ||
1066 | #define SOUP(a, b, c, d) do { \ | |
1067 | result = usb_control_msg(port->serial->dev, \ | |
1068 | usb_sndctrlpipe(port->serial->dev, 0), \ | |
1069 | b, a, c, d, NULL, 0, 1000); \ | |
1070 | dbg("0x%x:0x%x:0x%x:0x%x %d", a, b, c, d, result); } while (0) | |
1071 | ||
1072 | /* This is not UART related but IUU USB driver related or something */ | |
1073 | /* like that. Basically no IUU will accept any commands from the USB */ | |
1074 | /* host unless it has received the following message */ | |
1075 | /* sprintf(buf ,"%c%c%c%c",0x03,0x02,0x02,0x0); */ | |
1076 | ||
1077 | SOUP(0x03, 0x02, 0x02, 0x0); | |
1078 | kfree(buf); | |
1079 | iuu_led(port, 0xF000, 0xF000, 0, 0xFF); | |
1080 | iuu_uart_on(port); | |
1081 | if (boost < 100) | |
1082 | boost = 100; | |
1083 | switch (clockmode) { | |
1084 | case 2: /* 3.680 Mhz */ | |
1085 | iuu_clk(port, IUU_CLK_3680000 * boost / 100); | |
1086 | result = | |
1087 | iuu_uart_baud(port, 9600 * boost / 100, &actual, | |
1088 | IUU_PARITY_EVEN); | |
1089 | break; | |
1090 | case 3: /* 6.00 Mhz */ | |
1091 | iuu_clk(port, IUU_CLK_6000000 * boost / 100); | |
1092 | result = | |
1093 | iuu_uart_baud(port, 16457 * boost / 100, &actual, | |
1094 | IUU_PARITY_EVEN); | |
1095 | break; | |
1096 | default: /* 3.579 Mhz */ | |
1097 | iuu_clk(port, IUU_CLK_3579000 * boost / 100); | |
1098 | result = | |
1099 | iuu_uart_baud(port, 9600 * boost / 100, &actual, | |
1100 | IUU_PARITY_EVEN); | |
1101 | } | |
1102 | ||
1103 | /* set the cardin cardout signals */ | |
1104 | switch (cdmode) { | |
1105 | case 0: | |
1106 | iuu_cardin = 0; | |
1107 | iuu_cardout = 0; | |
1108 | break; | |
1109 | case 1: | |
1110 | iuu_cardin = TIOCM_CD; | |
1111 | iuu_cardout = 0; | |
1112 | break; | |
1113 | case 2: | |
1114 | iuu_cardin = 0; | |
1115 | iuu_cardout = TIOCM_CD; | |
1116 | break; | |
1117 | case 3: | |
1118 | iuu_cardin = TIOCM_DSR; | |
1119 | iuu_cardout = 0; | |
1120 | break; | |
1121 | case 4: | |
1122 | iuu_cardin = 0; | |
1123 | iuu_cardout = TIOCM_DSR; | |
1124 | break; | |
1125 | case 5: | |
1126 | iuu_cardin = TIOCM_CTS; | |
1127 | iuu_cardout = 0; | |
1128 | break; | |
1129 | case 6: | |
1130 | iuu_cardin = 0; | |
1131 | iuu_cardout = TIOCM_CTS; | |
1132 | break; | |
1133 | case 7: | |
1134 | iuu_cardin = TIOCM_RNG; | |
1135 | iuu_cardout = 0; | |
1136 | break; | |
1137 | case 8: | |
1138 | iuu_cardin = 0; | |
1139 | iuu_cardout = TIOCM_RNG; | |
1140 | } | |
1141 | ||
1142 | iuu_uart_flush(port); | |
1143 | ||
441b62c1 | 1144 | dbg("%s - initialization done", __func__); |
60a8fc01 AD |
1145 | |
1146 | memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1); | |
1147 | usb_fill_bulk_urb(port->write_urb, port->serial->dev, | |
1148 | usb_sndbulkpipe(port->serial->dev, | |
1149 | port->bulk_out_endpointAddress), | |
1150 | port->write_urb->transfer_buffer, 1, | |
1151 | read_rxcmd_callback, port); | |
1152 | result = usb_submit_urb(port->write_urb, GFP_KERNEL); | |
1153 | ||
1154 | if (result) { | |
1155 | dev_err(&port->dev, "%s - failed submitting read urb," | |
441b62c1 | 1156 | " error %d\n", __func__, result); |
95da310e | 1157 | iuu_close(tty, port, NULL); |
60a8fc01 AD |
1158 | return -EPROTO; |
1159 | } else { | |
441b62c1 | 1160 | dbg("%s - rxcmd OK", __func__); |
60a8fc01 AD |
1161 | } |
1162 | return result; | |
1163 | } | |
1164 | ||
1165 | static struct usb_serial_driver iuu_device = { | |
1166 | .driver = { | |
1167 | .owner = THIS_MODULE, | |
1168 | .name = "iuu_phoenix", | |
1169 | }, | |
1170 | .id_table = id_table, | |
60a8fc01 AD |
1171 | .num_ports = 1, |
1172 | .open = iuu_open, | |
1173 | .close = iuu_close, | |
1174 | .write = iuu_uart_write, | |
1175 | .read_bulk_callback = iuu_uart_read_callback, | |
1176 | .tiocmget = iuu_tiocmget, | |
1177 | .tiocmset = iuu_tiocmset, | |
1178 | .attach = iuu_startup, | |
1179 | .shutdown = iuu_shutdown, | |
1180 | }; | |
1181 | ||
1182 | static int __init iuu_init(void) | |
1183 | { | |
1184 | int retval; | |
1185 | retval = usb_serial_register(&iuu_device); | |
1186 | if (retval) | |
1187 | goto failed_usb_serial_register; | |
1188 | retval = usb_register(&iuu_driver); | |
1189 | if (retval) | |
1190 | goto failed_usb_register; | |
c197a8db GKH |
1191 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
1192 | DRIVER_DESC "\n"); | |
60a8fc01 AD |
1193 | return 0; |
1194 | failed_usb_register: | |
1195 | usb_serial_deregister(&iuu_device); | |
1196 | failed_usb_serial_register: | |
1197 | return retval; | |
1198 | } | |
1199 | ||
1200 | static void __exit iuu_exit(void) | |
1201 | { | |
1202 | usb_deregister(&iuu_driver); | |
1203 | usb_serial_deregister(&iuu_device); | |
1204 | } | |
1205 | ||
1206 | module_init(iuu_init); | |
1207 | module_exit(iuu_exit); | |
1208 | ||
1209 | MODULE_AUTHOR("Alain Degreffe eczema@ecze.com"); | |
1210 | ||
1211 | MODULE_DESCRIPTION(DRIVER_DESC); | |
1212 | MODULE_LICENSE("GPL"); | |
1213 | ||
1214 | MODULE_VERSION(DRIVER_VERSION); | |
1215 | module_param(debug, bool, S_IRUGO | S_IWUSR); | |
1216 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | |
1217 | ||
1218 | module_param(xmas, bool, S_IRUGO | S_IWUSR); | |
1219 | MODULE_PARM_DESC(xmas, "xmas color enabled or not"); | |
1220 | ||
1221 | module_param(boost, int, S_IRUGO | S_IWUSR); | |
1222 | MODULE_PARM_DESC(boost, "overclock boost percent 100 to 500"); | |
1223 | ||
1224 | module_param(clockmode, int, S_IRUGO | S_IWUSR); | |
1225 | MODULE_PARM_DESC(clockmode, "1=3Mhz579,2=3Mhz680,3=6Mhz"); | |
1226 | ||
1227 | module_param(cdmode, int, S_IRUGO | S_IWUSR); | |
1228 | MODULE_PARM_DESC(cdmode, "Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, " | |
1229 | "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING"); |