2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #define XR_SET_MAP_XR2280X 5
18 #define XR_GET_MAP_XR2280X 5
20 #define XR_SET_MAP_XR21B142X 0
21 #define XR_GET_MAP_XR21B142X 0
23 #define XR_SET_MAP_XR21V141X 0
24 #define XR_GET_MAP_XR21V141X 1
26 #define XR_SET_MAP_XR21B1411 0
27 #define XR_GET_MAP_XR21B1411 1
30 int xr_usb_serial_set_reg(struct xr_usb_serial
*xr_usb_serial
,int regnum
, int value
)
34 dev_dbg(&xr_usb_serial
->control
->dev
, "%s Channel:%d 0x%02x = 0x%02x\n", __func__
,channel
,regnum
, value
);
35 if((xr_usb_serial
->DeviceProduct
&0xfff0) == 0x1400)
37 int XR2280xaddr
= XR2280x_FUNC_MGR_OFFSET
+ regnum
;
38 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
39 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
40 XR_SET_MAP_XR2280X
, /* request */
41 USB_DIR_OUT
| USB_TYPE_VENDOR
, /* request_type */
42 value
, /* request value */
43 XR2280xaddr
, /* index */
49 else if((xr_usb_serial
->DeviceProduct
== 0x1410) ||
50 (xr_usb_serial
->DeviceProduct
== 0x1412) ||
51 (xr_usb_serial
->DeviceProduct
== 0x1414))
54 if(xr_usb_serial
->channel
)
55 channel
= xr_usb_serial
->channel
- 1;
56 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
57 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
58 XR_SET_MAP_XR21V141X
, /* request */
59 USB_DIR_OUT
| USB_TYPE_VENDOR
, /* request_type */
60 value
, /* request value */
61 regnum
| (channel
<< 8), /* index */
66 else if(xr_usb_serial
->DeviceProduct
== 0x1411)
68 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
69 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
70 XR_SET_MAP_XR21B1411
, /* request */
71 USB_DIR_OUT
| USB_TYPE_VENDOR
, /* request_type */
72 value
, /* request value */
78 else if((xr_usb_serial
->DeviceProduct
== 0x1420)||
79 (xr_usb_serial
->DeviceProduct
== 0x1422)||
80 (xr_usb_serial
->DeviceProduct
== 0x1424))
84 channel
= (xr_usb_serial
->channel
- 4)*2;
85 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
86 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
87 XR_SET_MAP_XR21B142X
, /* request */
88 USB_DIR_OUT
| USB_TYPE_VENDOR
| 1, /* request_type */
89 value
, /* request value */
90 regnum
| (channel
<< 8), /* index */
100 dev_dbg(&xr_usb_serial
->control
->dev
, "%s Error:%d\n", __func__
,result
);
105 int xr_usb_serial_set_reg_ext(struct xr_usb_serial
*xr_usb_serial
,int channel
,int regnum
, int value
)
108 int XR2280xaddr
= XR2280x_FUNC_MGR_OFFSET
+ regnum
;
109 dev_dbg(&xr_usb_serial
->control
->dev
, "%s channel:%d 0x%02x = 0x%02x\n", __func__
,channel
,regnum
, value
);
110 if((xr_usb_serial
->DeviceProduct
&0xfff0) == 0x1400)
112 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
113 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
114 XR_SET_MAP_XR2280X
, /* request */
115 USB_DIR_OUT
| USB_TYPE_VENDOR
, /* request_type */
116 value
, /* request value */
117 XR2280xaddr
, /* index */
123 else if((xr_usb_serial
->DeviceProduct
== 0x1410) ||
124 (xr_usb_serial
->DeviceProduct
== 0x1412) ||
125 (xr_usb_serial
->DeviceProduct
== 0x1414))
127 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
128 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
129 XR_SET_MAP_XR21V141X
, /* request */
130 USB_DIR_OUT
| USB_TYPE_VENDOR
, /* request_type */
131 value
, /* request value */
132 regnum
| (channel
<< 8), /* index */
137 else if(xr_usb_serial
->DeviceProduct
== 0x1411)
139 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
140 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
141 XR_SET_MAP_XR21B1411
, /* request */
142 USB_DIR_OUT
| USB_TYPE_VENDOR
, /* request_type */
143 value
, /* request value */
149 else if((xr_usb_serial
->DeviceProduct
== 0x1420)||
150 (xr_usb_serial
->DeviceProduct
== 0x1422)||
151 (xr_usb_serial
->DeviceProduct
== 0x1424))
153 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
154 usb_sndctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
155 XR_SET_MAP_XR21B142X
, /* request */
156 USB_DIR_OUT
| USB_TYPE_VENDOR
| 1, /* request_type */
157 value
, /* request value */
158 regnum
| (channel
<< 8), /* index */
168 dev_dbg(&xr_usb_serial
->control
->dev
, "%s Error:%d\n", __func__
,result
);
174 int xr_usb_serial_get_reg(struct xr_usb_serial
*xr_usb_serial
,int regnum
, short *value
)
179 if((xr_usb_serial
->DeviceProduct
&0xfff0) == 0x1400)
181 int XR2280xaddr
= XR2280x_FUNC_MGR_OFFSET
+ regnum
;
182 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
183 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
184 XR_GET_MAP_XR2280X
, /* request */
185 USB_DIR_IN
| USB_TYPE_VENDOR
, /* request_type */
186 0, /* request value */
187 XR2280xaddr
, /* index */
195 else if((xr_usb_serial
->DeviceProduct
== 0x1410) ||
196 (xr_usb_serial
->DeviceProduct
== 0x1412) ||
197 (xr_usb_serial
->DeviceProduct
== 0x1414))
199 if(xr_usb_serial
->channel
)
200 channel
= xr_usb_serial
->channel
-1;
201 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
202 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
203 XR_GET_MAP_XR21V141X
, /* request */
204 USB_DIR_IN
| USB_TYPE_VENDOR
, /* request_type */
205 0, /* request value */
206 regnum
| (channel
<< 8), /* index */
211 else if(xr_usb_serial
->DeviceProduct
== 0x1411)
213 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
214 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
215 XR_GET_MAP_XR21B1411
, /* request */
216 USB_DIR_IN
| USB_TYPE_VENDOR
, /* request_type */
217 0, /* request value */
223 else if((xr_usb_serial
->DeviceProduct
== 0x1420)||
224 (xr_usb_serial
->DeviceProduct
== 0x1422)||
225 (xr_usb_serial
->DeviceProduct
== 0x1424))
228 channel
= (xr_usb_serial
->channel
-4)*2;
229 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
230 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
231 XR_GET_MAP_XR21B142X
, /* request */
232 USB_DIR_IN
| USB_TYPE_VENDOR
| 1, /* request_type */
233 0, /* request value */
234 regnum
| (channel
<< 8), /* index */
245 dev_dbg(&xr_usb_serial
->control
->dev
, "%s channel:%d Reg 0x%x Error:%d\n", __func__
,channel
,regnum
,result
);
247 dev_dbg(&xr_usb_serial
->control
->dev
, "%s channel:%d 0x%x = 0x%04x\n", __func__
,channel
,regnum
, *value
);
254 int xr_usb_serial_get_reg_ext(struct xr_usb_serial
*xr_usb_serial
,int channel
,int regnum
, short *value
)
257 int XR2280xaddr
= XR2280x_FUNC_MGR_OFFSET
+ regnum
;
258 if((xr_usb_serial
->DeviceProduct
&0xfff0) == 0x1400)
261 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
262 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
263 XR_GET_MAP_XR2280X
, /* request */
264 USB_DIR_IN
| USB_TYPE_VENDOR
, /* request_type */
265 0, /* request value */
266 XR2280xaddr
, /* index */
274 else if((xr_usb_serial
->DeviceProduct
== 0x1410) ||
275 (xr_usb_serial
->DeviceProduct
== 0x1412) ||
276 (xr_usb_serial
->DeviceProduct
== 0x1414))
278 unsigned char reg_value
= 0;
279 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
280 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
281 XR_GET_MAP_XR21V141X
, /* request */
282 USB_DIR_IN
| USB_TYPE_VENDOR
, /* request_type */
283 0, /* request value */
284 regnum
| (channel
<< 8), /* index */
285 ®_value
, /* data */
288 dev_dbg(&xr_usb_serial
->control
->dev
, "xr_usb_serial_get_reg_ext reg:%x\n",reg_value
);
291 else if(xr_usb_serial
->DeviceProduct
== 0x1411)
293 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
294 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
295 XR_GET_MAP_XR21B1411
, /* request */
296 USB_DIR_IN
| USB_TYPE_VENDOR
, /* request_type */
297 0, /* request value */
298 regnum
| (channel
<< 8), /* index */
303 else if((xr_usb_serial
->DeviceProduct
== 0x1420)||
304 (xr_usb_serial
->DeviceProduct
== 0x1422)||
305 (xr_usb_serial
->DeviceProduct
== 0x1424))
307 result
= usb_control_msg(xr_usb_serial
->dev
, /* usb device */
308 usb_rcvctrlpipe(xr_usb_serial
->dev
, 0), /* endpoint pipe */
309 XR_GET_MAP_XR21B142X
, /* request */
310 USB_DIR_IN
| USB_TYPE_VENDOR
| 1, /* request_type */
311 0, /* request value */
312 regnum
| (channel
<< 8), /* index */
323 dev_dbg(&xr_usb_serial
->control
->dev
, "%s Error:%d\n", __func__
,result
);
325 dev_dbg(&xr_usb_serial
->control
->dev
, "%s channel:%d 0x%x = 0x%04x\n", __func__
,channel
,regnum
, *value
);
331 struct xr21v141x_baud_rate
338 static struct xr21v141x_baud_rate xr21v141x_baud_rates
[] = {
339 { 0x000, 0x000, 0x000 },
340 { 0x000, 0x000, 0x000 },
341 { 0x100, 0x000, 0x100 },
342 { 0x020, 0x400, 0x020 },
343 { 0x010, 0x100, 0x010 },
344 { 0x208, 0x040, 0x208 },
345 { 0x104, 0x820, 0x108 },
346 { 0x844, 0x210, 0x884 },
347 { 0x444, 0x110, 0x444 },
348 { 0x122, 0x888, 0x224 },
349 { 0x912, 0x448, 0x924 },
350 { 0x492, 0x248, 0x492 },
351 { 0x252, 0x928, 0x292 },
352 { 0X94A, 0X4A4, 0XA52 },
353 { 0X52A, 0XAA4, 0X54A },
354 { 0XAAA, 0x954, 0X4AA },
355 { 0XAAA, 0x554, 0XAAA },
356 { 0x555, 0XAD4, 0X5AA },
357 { 0XB55, 0XAB4, 0X55A },
358 { 0X6B5, 0X5AC, 0XB56 },
359 { 0X5B5, 0XD6C, 0X6D6 },
360 { 0XB6D, 0XB6A, 0XDB6 },
361 { 0X76D, 0X6DA, 0XBB6 },
362 { 0XEDD, 0XDDA, 0X76E },
363 { 0XDDD, 0XBBA, 0XEEE },
364 { 0X7BB, 0XF7A, 0XDDE },
365 { 0XF7B, 0XEF6, 0X7DE },
366 { 0XDF7, 0XBF6, 0XF7E },
367 { 0X7F7, 0XFEE, 0XEFE },
368 { 0XFDF, 0XFBE, 0X7FE },
369 { 0XF7F, 0XEFE, 0XFFE },
370 { 0XFFF, 0XFFE, 0XFFD },
372 #define UART_CLOCK_DIVISOR_0 0x004
373 #define UART_CLOCK_DIVISOR_1 0x005
374 #define UART_CLOCK_DIVISOR_2 0x006
375 #define UART_TX_CLOCK_MASK_0 0x007
376 #define UART_TX_CLOCK_MASK_1 0x008
377 #define UART_RX_CLOCK_MASK_0 0x009
378 #define UART_RX_CLOCK_MASK_1 0x00a
380 static int xr21v141x_set_baud_rate(struct xr_usb_serial
*xr_usb_serial
, unsigned int rate
)
382 unsigned int divisor
= 48000000 / rate
;
383 unsigned int i
= ((32 * 48000000) / rate
) & 0x1f;
384 unsigned int tx_mask
= xr21v141x_baud_rates
[i
].tx
;
385 unsigned int rx_mask
= (divisor
& 1) ? xr21v141x_baud_rates
[i
].rx1
: xr21v141x_baud_rates
[i
].rx0
;
387 dev_dbg(&xr_usb_serial
->control
->dev
, "Setting baud rate to %d: i=%u div=%u tx=%03x rx=%03x\n", rate
, i
, divisor
, tx_mask
, rx_mask
);
389 xr_usb_serial_set_reg(xr_usb_serial
,UART_CLOCK_DIVISOR_0
, (divisor
>> 0) & 0xff);
390 xr_usb_serial_set_reg(xr_usb_serial
,UART_CLOCK_DIVISOR_1
, (divisor
>> 8) & 0xff);
391 xr_usb_serial_set_reg(xr_usb_serial
,UART_CLOCK_DIVISOR_2
, (divisor
>> 16) & 0xff);
392 xr_usb_serial_set_reg(xr_usb_serial
,UART_TX_CLOCK_MASK_0
, (tx_mask
>> 0) & 0xff);
393 xr_usb_serial_set_reg(xr_usb_serial
,UART_TX_CLOCK_MASK_1
, (tx_mask
>> 8) & 0xff);
394 xr_usb_serial_set_reg(xr_usb_serial
,UART_RX_CLOCK_MASK_0
, (rx_mask
>> 0) & 0xff);
395 xr_usb_serial_set_reg(xr_usb_serial
,UART_RX_CLOCK_MASK_1
, (rx_mask
>> 8) & 0xff);
399 /* devices aren't required to support these requests.
400 * the cdc xr_usb_serial descriptor tells whether they do...
402 int xr_usb_serial_set_control(struct xr_usb_serial
*xr_usb_serial
, unsigned int control
)
406 if((xr_usb_serial
->DeviceProduct
== 0x1410) ||
407 (xr_usb_serial
->DeviceProduct
== 0x1412) ||
408 (xr_usb_serial
->DeviceProduct
== 0x1414))
410 if (control
& XR_USB_SERIAL_CTRL_DTR
)
411 xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_gpio_clr_addr
, 0x08);
413 xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_gpio_set_addr
, 0x08);
415 if (control
& XR_USB_SERIAL_CTRL_RTS
)
416 xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_gpio_clr_addr
, 0x20);
418 xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_gpio_set_addr
, 0x20);
422 ret
= xr_usb_serial_ctrl_msg(xr_usb_serial
, USB_CDC_REQ_SET_CONTROL_LINE_STATE
, control
, NULL
, 0);
428 int xr_usb_serial_set_line(struct xr_usb_serial
*xr_usb_serial
, struct usb_cdc_line_coding
* line
)
431 unsigned int format_size
;
432 unsigned int format_parity
;
433 unsigned int format_stop
;
434 if((xr_usb_serial
->DeviceProduct
== 0x1410) ||
435 (xr_usb_serial
->DeviceProduct
== 0x1412) ||
436 (xr_usb_serial
->DeviceProduct
== 0x1414))
438 xr21v141x_set_baud_rate(xr_usb_serial
,line
->dwDTERate
);
439 format_size
= line
->bDataBits
;
440 format_parity
= line
->bParityType
;
441 format_stop
= line
->bCharFormat
;
442 xr_usb_serial_set_reg(xr_usb_serial
,
443 xr_usb_serial
->reg_map
.uart_format_addr
,
444 (format_size
<< 0) | (format_parity
<< 4) | (format_stop
<< 7) );
449 ret
= xr_usb_serial_ctrl_msg(xr_usb_serial
, USB_CDC_REQ_SET_LINE_CODING
, 0, line
, sizeof *(line
));
453 int xr_usb_serial_set_flow_mode(struct xr_usb_serial
*xr_usb_serial
,
454 struct tty_struct
*tty
, unsigned int cflag
)
457 unsigned int gpio_mode
;
461 dev_dbg(&xr_usb_serial
->control
->dev
, "xr_usb_serial_set_flow_mode:hardware\n");
462 flow
= UART_FLOW_MODE_HW
;
463 gpio_mode
= UART_GPIO_MODE_SEL_RTS_CTS
;
465 else if (I_IXOFF(tty
) || I_IXON(tty
))
467 unsigned char start_char
= START_CHAR(tty
);
468 unsigned char stop_char
= STOP_CHAR(tty
);
469 dev_dbg(&xr_usb_serial
->control
->dev
, "xr_usb_serial_set_flow_mode:software\n");
470 flow
= UART_FLOW_MODE_SW
;
471 gpio_mode
= UART_GPIO_MODE_SEL_GPIO
;
473 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_xon_char_addr
, start_char
);
474 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_xoff_char_addr
, stop_char
);
478 dev_dbg(&xr_usb_serial
->control
->dev
, "xr_usb_serial_set_flow_mode:none\n");
479 flow
= UART_FLOW_MODE_NONE
;
480 gpio_mode
= UART_GPIO_MODE_SEL_GPIO
;
482 // rs485,rs422 FD/HD mode
483 if (xr_usb_serial
->rs485_422_en
) {
484 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_flow_addr
, 0x00);
485 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_mode_addr
, 0x0B);
487 //rs232, default mode
488 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_flow_addr
, flow
);
489 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_mode_addr
, gpio_mode
);
496 int xr_usb_serial_send_break(struct xr_usb_serial
*xr_usb_serial
, int state
)
499 if((xr_usb_serial
->DeviceProduct
== 0x1410)||
500 (xr_usb_serial
->DeviceProduct
== 0x1412)||
501 (xr_usb_serial
->DeviceProduct
== 0x1414))
504 ret
= xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.tx_break_addr
,0xffff);
506 ret
= xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.tx_break_addr
,0);
510 ret
= xr_usb_serial_ctrl_msg(xr_usb_serial
, USB_CDC_REQ_SEND_BREAK
, state
, NULL
, 0);
515 #define URM_REG_BLOCK 4
516 #define URM_ENABLE_BASE 0x010
517 #define URM_ENABLE_0_TX 0x001
518 #define URM_ENABLE_0_RX 0x002
520 int xr_usb_serial_enable(struct xr_usb_serial
*xr_usb_serial
)
523 int channel
= xr_usb_serial
->channel
;
524 if((xr_usb_serial
->DeviceProduct
== 0x1410)||
525 (xr_usb_serial
->DeviceProduct
== 0x1412)||
526 (xr_usb_serial
->DeviceProduct
== 0x1414))
528 ret
= xr_usb_serial_set_reg_ext(xr_usb_serial
,URM_REG_BLOCK
,URM_ENABLE_BASE
+ channel
,URM_ENABLE_0_TX
);
529 ret
= xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_enable_addr
,UART_ENABLE_TX
| UART_ENABLE_RX
);
530 ret
= xr_usb_serial_set_reg_ext(xr_usb_serial
,URM_REG_BLOCK
,URM_ENABLE_BASE
+ channel
,URM_ENABLE_0_TX
| URM_ENABLE_0_RX
);
534 ret
= xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_enable_addr
,UART_ENABLE_TX
| UART_ENABLE_RX
);
539 int xr_usb_serial_disable(struct xr_usb_serial
*xr_usb_serial
)
542 int channel
= xr_usb_serial
->channel
;
543 ret
= xr_usb_serial_set_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_enable_addr
,0);
544 if((xr_usb_serial
->DeviceProduct
== 0x1410)||
545 (xr_usb_serial
->DeviceProduct
== 0x1412)||
546 (xr_usb_serial
->DeviceProduct
== 0x1414))
548 ret
= xr_usb_serial_set_reg_ext(xr_usb_serial
,URM_REG_BLOCK
,URM_ENABLE_BASE
+ channel
,URM_ENABLE_0_TX
);
553 int xr_usb_serial_set_loopback(struct xr_usb_serial
*xr_usb_serial
, int channel
)
556 xr_usb_serial_disable(xr_usb_serial
);
557 ret
= xr_usb_serial_set_reg_ext(xr_usb_serial
,channel
,
558 xr_usb_serial
->reg_map
.uart_loopback_addr
,0x07);
559 xr_usb_serial_enable(xr_usb_serial
);
564 static int xr_usb_serial_tiocmget(struct xr_usb_serial
*xr_usb_serial
)
569 result
= xr_usb_serial_get_reg(xr_usb_serial
,xr_usb_serial
->reg_map
.uart_gpio_status_addr
, &data
);
570 dev_dbg(&xr_usb_serial
->control
->dev
, "xr_usb_serial_tiocmget uart_gpio_status_addr:0x%04x\n",data
);
572 return ((data
& 0x8) ? 0: TIOCM_DTR
) | ((data
& 0x20) ? 0:TIOCM_RTS
) | ((data
& 0x4) ? 0:TIOCM_DSR
) | ((data
& 0x1) ? 0 : TIOCM_RI
) | ((data
& 0x2) ? 0:TIOCM_CD
) | ((data
& 0x10) ? 0 : TIOCM_CTS
);
576 static int xr_usb_serial_tiocmset(struct xr_usb_serial
*xr_usb_serial
,
578 unsigned int set
, unsigned int clear
)
581 unsigned int newctrl
= 0;
582 newctrl
= xr_usb_serial
->ctrlout
;
584 set
= (set
& TIOCM_DTR
? XR_USB_SERIAL_CTRL_DTR
: 0) | (set
& TIOCM_RTS
? XR_USB_SERIAL_CTRL_RTS
: 0);
586 clear
= (clear
& TIOCM_DTR
? XR_USB_SERIAL_CTRL_DTR
: 0) | (clear
& TIOCM_RTS
? XR_USB_SERIAL_CTRL_RTS
: 0);
588 newctrl
= (newctrl
& ~clear
) | set
;
590 if (xr_usb_serial
->ctrlout
== newctrl
)
593 xr_usb_serial
->ctrlout
= newctrl
;
595 if (newctrl
& XR_USB_SERIAL_CTRL_DTR
)
596 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_clr_addr
, 0x08);
598 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_set_addr
, 0x08);
600 if (newctrl
& XR_USB_SERIAL_CTRL_RTS
)
601 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_clr_addr
, 0x20);
603 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_set_addr
, 0x20);
609 static struct reg_addr_map xr21b140x_reg_map
;
610 static struct reg_addr_map xr21b1411_reg_map
;
611 static struct reg_addr_map xr21v141x_reg_map
;
612 static struct reg_addr_map xr21b142x_reg_map
;
614 static void init_xr21b140x_reg_map(void)
616 xr21b140x_reg_map
.uart_enable_addr
= 0x00;
617 xr21b140x_reg_map
.uart_format_addr
= 0x05;
618 xr21b140x_reg_map
.uart_flow_addr
= 0x06;
619 xr21b140x_reg_map
.uart_loopback_addr
= 0x16;
620 xr21b140x_reg_map
.uart_xon_char_addr
= 0x07;
621 xr21b140x_reg_map
.uart_xoff_char_addr
= 0x08;
622 xr21b140x_reg_map
.uart_gpio_mode_addr
= 0x0c;
623 xr21b140x_reg_map
.uart_gpio_dir_addr
= 0x0d;
624 xr21b140x_reg_map
.uart_gpio_set_addr
= 0x0e;
625 xr21b140x_reg_map
.uart_gpio_clr_addr
= 0x0f;
626 xr21b140x_reg_map
.uart_gpio_status_addr
= 0x10;
627 xr21b140x_reg_map
.tx_break_addr
= 0x0a;
628 xr21b140x_reg_map
.uart_custom_driver
= 0x41;
631 static void init_xr21b1411_reg_map(void)
633 xr21b1411_reg_map
.uart_enable_addr
= 0xc00;
634 xr21b1411_reg_map
.uart_flow_addr
= 0xc06;
635 xr21b1411_reg_map
.uart_loopback_addr
= 0xc16;
636 xr21b1411_reg_map
.uart_xon_char_addr
= 0xc07;
637 xr21b1411_reg_map
.uart_xoff_char_addr
= 0xc08;
638 xr21b1411_reg_map
.uart_gpio_mode_addr
= 0xc0c;
639 xr21b1411_reg_map
.uart_gpio_dir_addr
= 0xc0d;
640 xr21b1411_reg_map
.uart_gpio_set_addr
= 0xc0e;
641 xr21b1411_reg_map
.uart_gpio_clr_addr
= 0xc0f;
642 xr21b1411_reg_map
.uart_gpio_status_addr
= 0xc10;
643 xr21b1411_reg_map
.tx_break_addr
= 0xc0a;
644 xr21b1411_reg_map
.uart_custom_driver
= 0x20d;
647 static void init_xr21v141x_reg_map(void)
649 xr21v141x_reg_map
.uart_enable_addr
= 0x03;
650 xr21v141x_reg_map
.uart_format_addr
= 0x0b;
651 xr21v141x_reg_map
.uart_flow_addr
= 0x0c;
652 xr21v141x_reg_map
.uart_loopback_addr
= 0x12;
653 xr21v141x_reg_map
.uart_xon_char_addr
= 0x10;
654 xr21v141x_reg_map
.uart_xoff_char_addr
= 0x11;
655 xr21v141x_reg_map
.uart_gpio_mode_addr
= 0x1a;
656 xr21v141x_reg_map
.uart_gpio_dir_addr
= 0x1b;
657 xr21v141x_reg_map
.uart_gpio_set_addr
= 0x1d;
658 xr21v141x_reg_map
.uart_gpio_clr_addr
= 0x1e;
659 xr21v141x_reg_map
.uart_gpio_status_addr
= 0x1f;
660 xr21v141x_reg_map
.tx_break_addr
= 0x14;
662 static void init_xr21b142x_reg_map(void)
664 xr21b142x_reg_map
.uart_enable_addr
= 0x00;
665 xr21b142x_reg_map
.uart_flow_addr
= 0x06;
666 xr21b142x_reg_map
.uart_loopback_addr
= 0x16;
667 xr21b142x_reg_map
.uart_xon_char_addr
= 0x07;
668 xr21b142x_reg_map
.uart_xoff_char_addr
= 0x08;
669 xr21b142x_reg_map
.uart_gpio_mode_addr
= 0x0c;
670 xr21b142x_reg_map
.uart_gpio_dir_addr
= 0x0d;
671 xr21b142x_reg_map
.uart_gpio_set_addr
= 0x0e;
672 xr21b142x_reg_map
.uart_gpio_clr_addr
= 0x0f;
673 xr21b142x_reg_map
.uart_gpio_status_addr
= 0x10;
674 xr21b140x_reg_map
.tx_break_addr
= 0x0a;
675 xr21b140x_reg_map
.uart_custom_driver
= 0x60;
676 xr21b140x_reg_map
.uart_low_latency
= 0x46;
679 int xr_usb_serial_pre_setup(struct xr_usb_serial
*xr_usb_serial
)
683 init_xr21b140x_reg_map();
684 init_xr21b1411_reg_map();
685 init_xr21v141x_reg_map();
686 init_xr21b142x_reg_map();
687 if((xr_usb_serial
->DeviceProduct
&0xfff0) == 0x1400)
689 memcpy(&(xr_usb_serial
->reg_map
),&xr21b140x_reg_map
,sizeof(struct reg_addr_map
));
692 else if(xr_usb_serial
->DeviceProduct
== 0x1411)
694 memcpy(&(xr_usb_serial
->reg_map
),&xr21b1411_reg_map
,sizeof(struct reg_addr_map
));
696 else if((xr_usb_serial
->DeviceProduct
== 0x1410)||
697 (xr_usb_serial
->DeviceProduct
== 0x1412)||
698 (xr_usb_serial
->DeviceProduct
== 0x1414))
700 memcpy(&(xr_usb_serial
->reg_map
),&xr21v141x_reg_map
,sizeof(struct reg_addr_map
));
702 else if((xr_usb_serial
->DeviceProduct
== 0x1420)||
703 (xr_usb_serial
->DeviceProduct
== 0x1422)||
704 (xr_usb_serial
->DeviceProduct
== 0x1424))
706 memcpy(&(xr_usb_serial
->reg_map
),&xr21b142x_reg_map
,sizeof(struct reg_addr_map
));
712 if(xr_usb_serial
->reg_map
.uart_custom_driver
)
713 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_custom_driver
, 1);
715 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_mode_addr
, 0);
716 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_dir_addr
, 0x28);
717 xr_usb_serial_set_reg(xr_usb_serial
, xr_usb_serial
->reg_map
.uart_gpio_set_addr
, UART_GPIO_SET_DTR
| UART_GPIO_SET_RTS
);