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