]>
Commit | Line | Data |
---|---|---|
19302bad WJS |
1 | /* |
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. | |
6 | * | |
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. | |
11 | * | |
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 | |
15 | */ | |
16 | ||
17 | #define XR_SET_MAP_XR2280X 5 | |
18 | #define XR_GET_MAP_XR2280X 5 | |
19 | ||
20 | #define XR_SET_MAP_XR21B142X 0 | |
21 | #define XR_GET_MAP_XR21B142X 0 | |
22 | ||
23 | #define XR_SET_MAP_XR21V141X 0 | |
24 | #define XR_GET_MAP_XR21V141X 1 | |
25 | ||
26 | #define XR_SET_MAP_XR21B1411 0 | |
27 | #define XR_GET_MAP_XR21B1411 1 | |
28 | ||
29 | ||
30 | int xr_usb_serial_set_reg(struct xr_usb_serial *xr_usb_serial,int regnum, int value) | |
31 | { | |
32 | int result; | |
33 | int channel = 0; | |
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) | |
36 | { | |
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 */ | |
44 | NULL, /* data */ | |
45 | 0, /* size */ | |
46 | 5000); /* timeout */ | |
47 | ||
48 | } | |
49 | else if((xr_usb_serial->DeviceProduct == 0x1410) || | |
50 | (xr_usb_serial->DeviceProduct == 0x1412) || | |
51 | (xr_usb_serial->DeviceProduct == 0x1414)) | |
52 | { | |
53 | ||
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 */ | |
62 | NULL, /* data */ | |
63 | 0, /* size */ | |
64 | 5000); /* timeout */ | |
65 | } | |
66 | else if(xr_usb_serial->DeviceProduct == 0x1411) | |
67 | { | |
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 */ | |
73 | regnum , /* index */ | |
74 | NULL, /* data */ | |
75 | 0, /* size */ | |
76 | 5000); /* timeout */ | |
77 | } | |
78 | else if((xr_usb_serial->DeviceProduct == 0x1420)|| | |
79 | (xr_usb_serial->DeviceProduct == 0x1422)|| | |
80 | (xr_usb_serial->DeviceProduct == 0x1424)) | |
81 | ||
82 | { | |
83 | ||
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 */ | |
91 | NULL, /* data */ | |
92 | 0, /* size */ | |
93 | 5000); /* timeout */ | |
94 | } | |
95 | else | |
96 | { | |
97 | result = -1; | |
98 | } | |
99 | if(result < 0) | |
100 | dev_dbg(&xr_usb_serial->control->dev, "%s Error:%d\n", __func__,result); | |
101 | return result; | |
102 | ||
103 | ||
104 | } | |
105 | int xr_usb_serial_set_reg_ext(struct xr_usb_serial *xr_usb_serial,int channel,int regnum, int value) | |
106 | { | |
107 | int result; | |
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) | |
111 | { | |
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 */ | |
118 | NULL, /* data */ | |
119 | 0, /* size */ | |
120 | 5000); /* timeout */ | |
121 | ||
122 | } | |
123 | else if((xr_usb_serial->DeviceProduct == 0x1410) || | |
124 | (xr_usb_serial->DeviceProduct == 0x1412) || | |
125 | (xr_usb_serial->DeviceProduct == 0x1414)) | |
126 | { | |
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 */ | |
133 | NULL, /* data */ | |
134 | 0, /* size */ | |
135 | 5000); /* timeout */ | |
136 | } | |
137 | else if(xr_usb_serial->DeviceProduct == 0x1411) | |
138 | { | |
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 */ | |
144 | regnum , /* index */ | |
145 | NULL, /* data */ | |
146 | 0, /* size */ | |
147 | 5000); /* timeout */ | |
148 | } | |
149 | else if((xr_usb_serial->DeviceProduct == 0x1420)|| | |
150 | (xr_usb_serial->DeviceProduct == 0x1422)|| | |
151 | (xr_usb_serial->DeviceProduct == 0x1424)) | |
152 | { | |
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 */ | |
159 | NULL, /* data */ | |
160 | 0, /* size */ | |
161 | 5000); /* timeout */ | |
162 | } | |
163 | else | |
164 | { | |
165 | result = -1; | |
166 | } | |
167 | if(result < 0) | |
168 | dev_dbg(&xr_usb_serial->control->dev, "%s Error:%d\n", __func__,result); | |
169 | return result; | |
170 | ||
171 | ||
172 | } | |
173 | ||
174 | int xr_usb_serial_get_reg(struct xr_usb_serial *xr_usb_serial,int regnum, short *value) | |
175 | { | |
176 | int result; | |
177 | int channel = 0; | |
178 | ||
179 | if((xr_usb_serial->DeviceProduct&0xfff0) == 0x1400) | |
180 | { | |
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 */ | |
188 | value, /* data */ | |
189 | 2, /* size */ | |
190 | 5000); /* timeout */ | |
191 | ||
192 | ||
193 | ||
194 | } | |
195 | else if((xr_usb_serial->DeviceProduct == 0x1410) || | |
196 | (xr_usb_serial->DeviceProduct == 0x1412) || | |
197 | (xr_usb_serial->DeviceProduct == 0x1414)) | |
198 | { | |
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 */ | |
207 | value, /* data */ | |
208 | 1, /* size */ | |
209 | 5000); /* timeout */ | |
210 | } | |
211 | else if(xr_usb_serial->DeviceProduct == 0x1411) | |
212 | { | |
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 */ | |
218 | regnum, /* index */ | |
219 | value, /* data */ | |
220 | 2, /* size */ | |
221 | 5000); /* timeout */ | |
222 | } | |
223 | else if((xr_usb_serial->DeviceProduct == 0x1420)|| | |
224 | (xr_usb_serial->DeviceProduct == 0x1422)|| | |
225 | (xr_usb_serial->DeviceProduct == 0x1424)) | |
226 | ||
227 | { | |
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 */ | |
235 | value, /* data */ | |
236 | 2, /* size */ | |
237 | 5000); /* timeout */ | |
238 | } | |
239 | else | |
240 | { | |
241 | result = -1; | |
242 | } | |
243 | ||
244 | if(result < 0) | |
245 | dev_dbg(&xr_usb_serial->control->dev, "%s channel:%d Reg 0x%x Error:%d\n", __func__,channel,regnum,result); | |
246 | else | |
247 | dev_dbg(&xr_usb_serial->control->dev, "%s channel:%d 0x%x = 0x%04x\n", __func__,channel,regnum, *value); | |
248 | ||
249 | return result; | |
250 | ||
251 | } | |
252 | ||
253 | ||
254 | int xr_usb_serial_get_reg_ext(struct xr_usb_serial *xr_usb_serial,int channel,int regnum, short *value) | |
255 | { | |
256 | int result; | |
257 | int XR2280xaddr = XR2280x_FUNC_MGR_OFFSET + regnum; | |
258 | if((xr_usb_serial->DeviceProduct&0xfff0) == 0x1400) | |
259 | { | |
260 | ||
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 */ | |
267 | value, /* data */ | |
268 | 2, /* size */ | |
269 | 5000); /* timeout */ | |
270 | ||
271 | ||
272 | ||
273 | } | |
274 | else if((xr_usb_serial->DeviceProduct == 0x1410) || | |
275 | (xr_usb_serial->DeviceProduct == 0x1412) || | |
276 | (xr_usb_serial->DeviceProduct == 0x1414)) | |
277 | { | |
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 */ | |
286 | 1, /* size */ | |
287 | 5000); /* timeout */ | |
288 | dev_dbg(&xr_usb_serial->control->dev, "xr_usb_serial_get_reg_ext reg:%x\n",reg_value); | |
289 | *value = reg_value; | |
290 | } | |
291 | else if(xr_usb_serial->DeviceProduct == 0x1411) | |
292 | { | |
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 */ | |
299 | value, /* data */ | |
300 | 2, /* size */ | |
301 | 5000); /* timeout */ | |
302 | } | |
303 | else if((xr_usb_serial->DeviceProduct == 0x1420)|| | |
304 | (xr_usb_serial->DeviceProduct == 0x1422)|| | |
305 | (xr_usb_serial->DeviceProduct == 0x1424)) | |
306 | { | |
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 */ | |
313 | value, /* data */ | |
314 | 2, /* size */ | |
315 | 5000); /* timeout */ | |
316 | } | |
317 | else | |
318 | { | |
319 | result = -1; | |
320 | } | |
321 | ||
322 | if(result < 0) | |
323 | dev_dbg(&xr_usb_serial->control->dev, "%s Error:%d\n", __func__,result); | |
324 | else | |
325 | dev_dbg(&xr_usb_serial->control->dev, "%s channel:%d 0x%x = 0x%04x\n", __func__,channel,regnum, *value); | |
326 | ||
327 | return result; | |
328 | ||
329 | } | |
330 | ||
331 | struct xr21v141x_baud_rate | |
332 | { | |
333 | unsigned int tx; | |
334 | unsigned int rx0; | |
335 | unsigned int rx1; | |
336 | }; | |
337 | ||
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 }, | |
371 | }; | |
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 | |
379 | ||
380 | static int xr21v141x_set_baud_rate(struct xr_usb_serial *xr_usb_serial, unsigned int rate) | |
381 | { | |
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; | |
386 | ||
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); | |
388 | ||
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); | |
396 | ||
397 | return 0; | |
398 | } | |
399 | /* devices aren't required to support these requests. | |
400 | * the cdc xr_usb_serial descriptor tells whether they do... | |
401 | */ | |
402 | int xr_usb_serial_set_control(struct xr_usb_serial *xr_usb_serial, unsigned int control) | |
403 | { | |
404 | int ret = 0; | |
405 | ||
406 | if((xr_usb_serial->DeviceProduct == 0x1410) || | |
407 | (xr_usb_serial->DeviceProduct == 0x1412) || | |
408 | (xr_usb_serial->DeviceProduct == 0x1414)) | |
409 | { | |
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); | |
412 | else | |
413 | xr_usb_serial_set_reg(xr_usb_serial,xr_usb_serial->reg_map.uart_gpio_set_addr, 0x08); | |
414 | ||
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); | |
417 | else | |
418 | xr_usb_serial_set_reg(xr_usb_serial,xr_usb_serial->reg_map.uart_gpio_set_addr, 0x20); | |
419 | } | |
420 | else | |
421 | { | |
422 | ret = xr_usb_serial_ctrl_msg(xr_usb_serial, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0); | |
423 | } | |
424 | ||
425 | return ret; | |
426 | } | |
427 | ||
428 | int xr_usb_serial_set_line(struct xr_usb_serial *xr_usb_serial, struct usb_cdc_line_coding* line) | |
429 | { | |
430 | int ret = 0; | |
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)) | |
437 | { | |
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) ); | |
445 | ||
446 | } | |
447 | else | |
448 | { | |
449 | ret = xr_usb_serial_ctrl_msg(xr_usb_serial, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line)); | |
450 | } | |
451 | return ret; | |
452 | } | |
453 | int xr_usb_serial_set_flow_mode(struct xr_usb_serial *xr_usb_serial, | |
454 | struct tty_struct *tty, unsigned int cflag) | |
455 | { | |
456 | unsigned int flow; | |
457 | unsigned int gpio_mode; | |
458 | ||
459 | if (cflag & CRTSCTS) | |
460 | { | |
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; | |
464 | } | |
465 | else if (I_IXOFF(tty) || I_IXON(tty)) | |
466 | { | |
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; | |
472 | ||
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); | |
475 | } | |
476 | else | |
477 | { | |
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; | |
481 | } | |
a61ca106 DW |
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); | |
486 | } else { | |
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); | |
490 | } | |
19302bad WJS |
491 | return 0; |
492 | ||
493 | ||
494 | } | |
495 | ||
496 | int xr_usb_serial_send_break(struct xr_usb_serial *xr_usb_serial, int state) | |
497 | { | |
498 | int ret = 0; | |
499 | if((xr_usb_serial->DeviceProduct == 0x1410)|| | |
500 | (xr_usb_serial->DeviceProduct == 0x1412)|| | |
501 | (xr_usb_serial->DeviceProduct == 0x1414)) | |
502 | { | |
503 | if(state) | |
504 | ret = xr_usb_serial_set_reg(xr_usb_serial,xr_usb_serial->reg_map.tx_break_addr,0xffff); | |
505 | else | |
506 | ret = xr_usb_serial_set_reg(xr_usb_serial,xr_usb_serial->reg_map.tx_break_addr,0); | |
507 | } | |
508 | else | |
509 | { | |
510 | ret = xr_usb_serial_ctrl_msg(xr_usb_serial, USB_CDC_REQ_SEND_BREAK, state, NULL, 0); | |
511 | } | |
512 | return ret; | |
513 | } | |
514 | ||
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 | |
519 | ||
520 | int xr_usb_serial_enable(struct xr_usb_serial *xr_usb_serial) | |
521 | { | |
522 | int ret = 0; | |
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)) | |
527 | { | |
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); | |
531 | } | |
532 | else | |
533 | { | |
534 | ret = xr_usb_serial_set_reg(xr_usb_serial,xr_usb_serial->reg_map.uart_enable_addr,UART_ENABLE_TX | UART_ENABLE_RX); | |
535 | } | |
536 | ||
537 | return ret; | |
538 | } | |
539 | int xr_usb_serial_disable(struct xr_usb_serial *xr_usb_serial) | |
540 | { | |
541 | int ret = 0; | |
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)) | |
547 | { | |
548 | ret = xr_usb_serial_set_reg_ext(xr_usb_serial,URM_REG_BLOCK,URM_ENABLE_BASE + channel,URM_ENABLE_0_TX); | |
549 | } | |
550 | ||
551 | return ret; | |
552 | } | |
553 | int xr_usb_serial_set_loopback(struct xr_usb_serial *xr_usb_serial, int channel) | |
554 | { | |
555 | int ret = 0; | |
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); | |
560 | return ret; | |
561 | } | |
562 | ||
563 | ||
564 | static int xr_usb_serial_tiocmget(struct xr_usb_serial *xr_usb_serial) | |
565 | ||
566 | { | |
567 | short data; | |
568 | int result; | |
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); | |
571 | if (result) | |
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); | |
573 | else | |
574 | return -EFAULT; | |
575 | } | |
576 | static int xr_usb_serial_tiocmset(struct xr_usb_serial *xr_usb_serial, | |
577 | ||
578 | unsigned int set, unsigned int clear) | |
579 | ||
580 | { | |
581 | unsigned int newctrl = 0; | |
582 | newctrl = xr_usb_serial->ctrlout; | |
583 | ||
584 | set = (set & TIOCM_DTR ? XR_USB_SERIAL_CTRL_DTR : 0) | (set & TIOCM_RTS ? XR_USB_SERIAL_CTRL_RTS : 0); | |
585 | ||
586 | clear = (clear & TIOCM_DTR ? XR_USB_SERIAL_CTRL_DTR : 0) | (clear & TIOCM_RTS ? XR_USB_SERIAL_CTRL_RTS : 0); | |
587 | ||
588 | newctrl = (newctrl & ~clear) | set; | |
589 | ||
590 | if (xr_usb_serial->ctrlout == newctrl) | |
591 | return 0; | |
592 | ||
593 | xr_usb_serial->ctrlout = newctrl; | |
594 | ||
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); | |
597 | else | |
598 | xr_usb_serial_set_reg(xr_usb_serial, xr_usb_serial->reg_map.uart_gpio_set_addr, 0x08); | |
599 | ||
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); | |
602 | else | |
603 | xr_usb_serial_set_reg(xr_usb_serial, xr_usb_serial->reg_map.uart_gpio_set_addr, 0x20); | |
604 | ||
605 | return 0; | |
606 | } | |
607 | ||
608 | ||
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; | |
613 | ||
614 | static void init_xr21b140x_reg_map(void) | |
615 | { | |
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; | |
629 | } | |
630 | ||
631 | static void init_xr21b1411_reg_map(void) | |
632 | { | |
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; | |
645 | } | |
646 | ||
647 | static void init_xr21v141x_reg_map(void) | |
648 | { | |
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; | |
661 | } | |
662 | static void init_xr21b142x_reg_map(void) | |
663 | { | |
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; | |
677 | } | |
678 | ||
679 | int xr_usb_serial_pre_setup(struct xr_usb_serial *xr_usb_serial) | |
680 | { | |
681 | int ret = 0; | |
682 | ||
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) | |
688 | { | |
689 | memcpy(&(xr_usb_serial->reg_map),&xr21b140x_reg_map,sizeof(struct reg_addr_map)); | |
690 | ||
691 | } | |
692 | else if(xr_usb_serial->DeviceProduct == 0x1411) | |
693 | { | |
694 | memcpy(&(xr_usb_serial->reg_map),&xr21b1411_reg_map,sizeof(struct reg_addr_map)); | |
695 | } | |
696 | else if((xr_usb_serial->DeviceProduct == 0x1410)|| | |
697 | (xr_usb_serial->DeviceProduct == 0x1412)|| | |
698 | (xr_usb_serial->DeviceProduct == 0x1414)) | |
699 | { | |
700 | memcpy(&(xr_usb_serial->reg_map),&xr21v141x_reg_map,sizeof(struct reg_addr_map)); | |
701 | } | |
702 | else if((xr_usb_serial->DeviceProduct == 0x1420)|| | |
703 | (xr_usb_serial->DeviceProduct == 0x1422)|| | |
704 | (xr_usb_serial->DeviceProduct == 0x1424)) | |
705 | { | |
706 | memcpy(&(xr_usb_serial->reg_map),&xr21b142x_reg_map,sizeof(struct reg_addr_map)); | |
707 | } | |
708 | else | |
709 | { | |
710 | ret = -1; | |
711 | } | |
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); | |
714 | ||
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); | |
718 | ||
719 | return ret; | |
720 | ||
721 | } | |
722 | ||
723 | ||
724 |