ti_usb_3410_5052.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. /* vi: ts=8 sw=8
  2. *
  3. * TI 3410/5052 USB Serial Driver
  4. *
  5. * Copyright (C) 2004 Texas Instruments
  6. *
  7. * This driver is based on the Linux io_ti driver, which is
  8. * Copyright (C) 2000-2002 Inside Out Networks
  9. * Copyright (C) 2001-2002 Greg Kroah-Hartman
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * For questions or problems with this driver, contact Texas Instruments
  17. * technical support, or Al Borchers <alborchers@steinerpoint.com>, or
  18. * Peter Berger <pberger@brimson.com>.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/firmware.h>
  23. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/tty.h>
  26. #include <linux/tty_driver.h>
  27. #include <linux/tty_flip.h>
  28. #include <linux/module.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/ioctl.h>
  31. #include <linux/serial.h>
  32. #include <linux/kfifo.h>
  33. #include <linux/mutex.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/usb.h>
  36. #include <linux/usb/serial.h>
  37. #include "ti_usb_3410_5052.h"
  38. /* Defines */
  39. #define TI_DRIVER_VERSION "v0.10"
  40. #define TI_DRIVER_AUTHOR "Al Borchers <alborchers@steinerpoint.com>"
  41. #define TI_DRIVER_DESC "TI USB 3410/5052 Serial Driver"
  42. #define TI_FIRMWARE_BUF_SIZE 16284
  43. #define TI_WRITE_BUF_SIZE 1024
  44. #define TI_TRANSFER_TIMEOUT 2
  45. #define TI_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */
  46. /* supported setserial flags */
  47. #define TI_SET_SERIAL_FLAGS 0
  48. /* read urb states */
  49. #define TI_READ_URB_RUNNING 0
  50. #define TI_READ_URB_STOPPING 1
  51. #define TI_READ_URB_STOPPED 2
  52. #define TI_EXTRA_VID_PID_COUNT 5
  53. /* Structures */
  54. struct ti_port {
  55. int tp_is_open;
  56. __u8 tp_msr;
  57. __u8 tp_lsr;
  58. __u8 tp_shadow_mcr;
  59. __u8 tp_uart_mode; /* 232 or 485 modes */
  60. unsigned int tp_uart_base_addr;
  61. int tp_flags;
  62. int tp_closing_wait;/* in .01 secs */
  63. struct async_icount tp_icount;
  64. wait_queue_head_t tp_msr_wait; /* wait for msr change */
  65. wait_queue_head_t tp_write_wait;
  66. struct ti_device *tp_tdev;
  67. struct usb_serial_port *tp_port;
  68. spinlock_t tp_lock;
  69. int tp_read_urb_state;
  70. int tp_write_urb_in_use;
  71. struct kfifo write_fifo;
  72. };
  73. struct ti_device {
  74. struct mutex td_open_close_lock;
  75. int td_open_port_count;
  76. struct usb_serial *td_serial;
  77. int td_is_3410;
  78. int td_urb_error;
  79. };
  80. /* Function Declarations */
  81. static int ti_startup(struct usb_serial *serial);
  82. static void ti_release(struct usb_serial *serial);
  83. static int ti_open(struct tty_struct *tty, struct usb_serial_port *port);
  84. static void ti_close(struct usb_serial_port *port);
  85. static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
  86. const unsigned char *data, int count);
  87. static int ti_write_room(struct tty_struct *tty);
  88. static int ti_chars_in_buffer(struct tty_struct *tty);
  89. static void ti_throttle(struct tty_struct *tty);
  90. static void ti_unthrottle(struct tty_struct *tty);
  91. static int ti_ioctl(struct tty_struct *tty,
  92. unsigned int cmd, unsigned long arg);
  93. static int ti_get_icount(struct tty_struct *tty,
  94. struct serial_icounter_struct *icount);
  95. static void ti_set_termios(struct tty_struct *tty,
  96. struct usb_serial_port *port, struct ktermios *old_termios);
  97. static int ti_tiocmget(struct tty_struct *tty);
  98. static int ti_tiocmset(struct tty_struct *tty,
  99. unsigned int set, unsigned int clear);
  100. static void ti_break(struct tty_struct *tty, int break_state);
  101. static void ti_interrupt_callback(struct urb *urb);
  102. static void ti_bulk_in_callback(struct urb *urb);
  103. static void ti_bulk_out_callback(struct urb *urb);
  104. static void ti_recv(struct device *dev, struct tty_struct *tty,
  105. unsigned char *data, int length);
  106. static void ti_send(struct ti_port *tport);
  107. static int ti_set_mcr(struct ti_port *tport, unsigned int mcr);
  108. static int ti_get_lsr(struct ti_port *tport);
  109. static int ti_get_serial_info(struct ti_port *tport,
  110. struct serial_struct __user *ret_arg);
  111. static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
  112. struct serial_struct __user *new_arg);
  113. static void ti_handle_new_msr(struct ti_port *tport, __u8 msr);
  114. static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush);
  115. static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty);
  116. static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty);
  117. static int ti_command_out_sync(struct ti_device *tdev, __u8 command,
  118. __u16 moduleid, __u16 value, __u8 *data, int size);
  119. static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
  120. __u16 moduleid, __u16 value, __u8 *data, int size);
  121. static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev,
  122. unsigned long addr, __u8 mask, __u8 byte);
  123. static int ti_download_firmware(struct ti_device *tdev);
  124. /* Data */
  125. /* module parameters */
  126. static bool debug;
  127. static int closing_wait = TI_DEFAULT_CLOSING_WAIT;
  128. static ushort vendor_3410[TI_EXTRA_VID_PID_COUNT];
  129. static unsigned int vendor_3410_count;
  130. static ushort product_3410[TI_EXTRA_VID_PID_COUNT];
  131. static unsigned int product_3410_count;
  132. static ushort vendor_5052[TI_EXTRA_VID_PID_COUNT];
  133. static unsigned int vendor_5052_count;
  134. static ushort product_5052[TI_EXTRA_VID_PID_COUNT];
  135. static unsigned int product_5052_count;
  136. /* supported devices */
  137. /* the array dimension is the number of default entries plus */
  138. /* TI_EXTRA_VID_PID_COUNT user defined entries plus 1 terminating */
  139. /* null entry */
  140. static struct usb_device_id ti_id_table_3410[15+TI_EXTRA_VID_PID_COUNT+1] = {
  141. { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) },
  142. { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) },
  143. { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) },
  144. { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_NO_FW_PRODUCT_ID) },
  145. { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) },
  146. { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) },
  147. { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) },
  148. { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234MU_PRODUCT_ID) },
  149. { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBA_PRODUCT_ID) },
  150. { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBAOLD_PRODUCT_ID) },
  151. { USB_DEVICE(IBM_VENDOR_ID, IBM_4543_PRODUCT_ID) },
  152. { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) },
  153. { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) },
  154. { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) },
  155. { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) },
  156. };
  157. static struct usb_device_id ti_id_table_5052[5+TI_EXTRA_VID_PID_COUNT+1] = {
  158. { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) },
  159. { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) },
  160. { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) },
  161. { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) },
  162. };
  163. static struct usb_device_id ti_id_table_combined[19+2*TI_EXTRA_VID_PID_COUNT+1] = {
  164. { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) },
  165. { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) },
  166. { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) },
  167. { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_NO_FW_PRODUCT_ID) },
  168. { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) },
  169. { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) },
  170. { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) },
  171. { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234MU_PRODUCT_ID) },
  172. { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBA_PRODUCT_ID) },
  173. { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBAOLD_PRODUCT_ID) },
  174. { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) },
  175. { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) },
  176. { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) },
  177. { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) },
  178. { USB_DEVICE(IBM_VENDOR_ID, IBM_4543_PRODUCT_ID) },
  179. { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) },
  180. { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) },
  181. { USB_DEVICE(ABBOTT_VENDOR_ID, ABBOTT_PRODUCT_ID) },
  182. { USB_DEVICE(TI_VENDOR_ID, FRI2_PRODUCT_ID) },
  183. { }
  184. };
  185. static struct usb_serial_driver ti_1port_device = {
  186. .driver = {
  187. .owner = THIS_MODULE,
  188. .name = "ti_usb_3410_5052_1",
  189. },
  190. .description = "TI USB 3410 1 port adapter",
  191. .id_table = ti_id_table_3410,
  192. .num_ports = 1,
  193. .attach = ti_startup,
  194. .release = ti_release,
  195. .open = ti_open,
  196. .close = ti_close,
  197. .write = ti_write,
  198. .write_room = ti_write_room,
  199. .chars_in_buffer = ti_chars_in_buffer,
  200. .throttle = ti_throttle,
  201. .unthrottle = ti_unthrottle,
  202. .ioctl = ti_ioctl,
  203. .set_termios = ti_set_termios,
  204. .tiocmget = ti_tiocmget,
  205. .tiocmset = ti_tiocmset,
  206. .get_icount = ti_get_icount,
  207. .break_ctl = ti_break,
  208. .read_int_callback = ti_interrupt_callback,
  209. .read_bulk_callback = ti_bulk_in_callback,
  210. .write_bulk_callback = ti_bulk_out_callback,
  211. };
  212. static struct usb_serial_driver ti_2port_device = {
  213. .driver = {
  214. .owner = THIS_MODULE,
  215. .name = "ti_usb_3410_5052_2",
  216. },
  217. .description = "TI USB 5052 2 port adapter",
  218. .id_table = ti_id_table_5052,
  219. .num_ports = 2,
  220. .attach = ti_startup,
  221. .release = ti_release,
  222. .open = ti_open,
  223. .close = ti_close,
  224. .write = ti_write,
  225. .write_room = ti_write_room,
  226. .chars_in_buffer = ti_chars_in_buffer,
  227. .throttle = ti_throttle,
  228. .unthrottle = ti_unthrottle,
  229. .ioctl = ti_ioctl,
  230. .set_termios = ti_set_termios,
  231. .tiocmget = ti_tiocmget,
  232. .tiocmset = ti_tiocmset,
  233. .get_icount = ti_get_icount,
  234. .break_ctl = ti_break,
  235. .read_int_callback = ti_interrupt_callback,
  236. .read_bulk_callback = ti_bulk_in_callback,
  237. .write_bulk_callback = ti_bulk_out_callback,
  238. };
  239. static struct usb_serial_driver * const serial_drivers[] = {
  240. &ti_1port_device, &ti_2port_device, NULL
  241. };
  242. /* Module */
  243. MODULE_AUTHOR(TI_DRIVER_AUTHOR);
  244. MODULE_DESCRIPTION(TI_DRIVER_DESC);
  245. MODULE_VERSION(TI_DRIVER_VERSION);
  246. MODULE_LICENSE("GPL");
  247. MODULE_FIRMWARE("ti_3410.fw");
  248. MODULE_FIRMWARE("ti_5052.fw");
  249. MODULE_FIRMWARE("mts_cdma.fw");
  250. MODULE_FIRMWARE("mts_gsm.fw");
  251. MODULE_FIRMWARE("mts_edge.fw");
  252. MODULE_FIRMWARE("mts_mt9234mu.fw");
  253. MODULE_FIRMWARE("mts_mt9234zba.fw");
  254. module_param(debug, bool, S_IRUGO | S_IWUSR);
  255. MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes");
  256. module_param(closing_wait, int, S_IRUGO | S_IWUSR);
  257. MODULE_PARM_DESC(closing_wait,
  258. "Maximum wait for data to drain in close, in .01 secs, default is 4000");
  259. module_param_array(vendor_3410, ushort, &vendor_3410_count, S_IRUGO);
  260. MODULE_PARM_DESC(vendor_3410,
  261. "Vendor ids for 3410 based devices, 1-5 short integers");
  262. module_param_array(product_3410, ushort, &product_3410_count, S_IRUGO);
  263. MODULE_PARM_DESC(product_3410,
  264. "Product ids for 3410 based devices, 1-5 short integers");
  265. module_param_array(vendor_5052, ushort, &vendor_5052_count, S_IRUGO);
  266. MODULE_PARM_DESC(vendor_5052,
  267. "Vendor ids for 5052 based devices, 1-5 short integers");
  268. module_param_array(product_5052, ushort, &product_5052_count, S_IRUGO);
  269. MODULE_PARM_DESC(product_5052,
  270. "Product ids for 5052 based devices, 1-5 short integers");
  271. MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
  272. /* Functions */
  273. static int __init ti_init(void)
  274. {
  275. int i, j, c;
  276. int ret;
  277. /* insert extra vendor and product ids */
  278. c = ARRAY_SIZE(ti_id_table_combined) - 2 * TI_EXTRA_VID_PID_COUNT - 1;
  279. j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1;
  280. for (i = 0; i < min(vendor_3410_count, product_3410_count); i++, j++, c++) {
  281. ti_id_table_3410[j].idVendor = vendor_3410[i];
  282. ti_id_table_3410[j].idProduct = product_3410[i];
  283. ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
  284. ti_id_table_combined[c].idVendor = vendor_3410[i];
  285. ti_id_table_combined[c].idProduct = product_3410[i];
  286. ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
  287. }
  288. j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1;
  289. for (i = 0; i < min(vendor_5052_count, product_5052_count); i++, j++, c++) {
  290. ti_id_table_5052[j].idVendor = vendor_5052[i];
  291. ti_id_table_5052[j].idProduct = product_5052[i];
  292. ti_id_table_5052[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
  293. ti_id_table_combined[c].idVendor = vendor_5052[i];
  294. ti_id_table_combined[c].idProduct = product_5052[i];
  295. ti_id_table_combined[c].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
  296. }
  297. ret = usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, ti_id_table_combined);
  298. if (ret == 0)
  299. printk(KERN_INFO KBUILD_MODNAME ": " TI_DRIVER_VERSION ":"
  300. TI_DRIVER_DESC "\n");
  301. return ret;
  302. }
  303. static void __exit ti_exit(void)
  304. {
  305. usb_serial_deregister_drivers(serial_drivers);
  306. }
  307. module_init(ti_init);
  308. module_exit(ti_exit);
  309. static int ti_startup(struct usb_serial *serial)
  310. {
  311. struct ti_device *tdev;
  312. struct ti_port *tport;
  313. struct usb_device *dev = serial->dev;
  314. int status;
  315. int i;
  316. dev_dbg(&dev->dev,
  317. "%s - product 0x%4X, num configurations %d, configuration value %d",
  318. __func__, le16_to_cpu(dev->descriptor.idProduct),
  319. dev->descriptor.bNumConfigurations,
  320. dev->actconfig->desc.bConfigurationValue);
  321. /* create device structure */
  322. tdev = kzalloc(sizeof(struct ti_device), GFP_KERNEL);
  323. if (tdev == NULL) {
  324. dev_err(&dev->dev, "%s - out of memory\n", __func__);
  325. return -ENOMEM;
  326. }
  327. mutex_init(&tdev->td_open_close_lock);
  328. tdev->td_serial = serial;
  329. usb_set_serial_data(serial, tdev);
  330. /* determine device type */
  331. if (usb_match_id(serial->interface, ti_id_table_3410))
  332. tdev->td_is_3410 = 1;
  333. dev_dbg(&dev->dev, "%s - device type is %s\n", __func__,
  334. tdev->td_is_3410 ? "3410" : "5052");
  335. /* if we have only 1 configuration, download firmware */
  336. if (dev->descriptor.bNumConfigurations == 1) {
  337. status = ti_download_firmware(tdev);
  338. if (status != 0)
  339. goto free_tdev;
  340. /* 3410 must be reset, 5052 resets itself */
  341. if (tdev->td_is_3410) {
  342. msleep_interruptible(100);
  343. usb_reset_device(dev);
  344. }
  345. status = -ENODEV;
  346. goto free_tdev;
  347. }
  348. /* the second configuration must be set */
  349. if (dev->actconfig->desc.bConfigurationValue == TI_BOOT_CONFIG) {
  350. status = usb_driver_set_configuration(dev, TI_ACTIVE_CONFIG);
  351. status = status ? status : -ENODEV;
  352. goto free_tdev;
  353. }
  354. /* set up port structures */
  355. for (i = 0; i < serial->num_ports; ++i) {
  356. tport = kzalloc(sizeof(struct ti_port), GFP_KERNEL);
  357. if (tport == NULL) {
  358. dev_err(&dev->dev, "%s - out of memory\n", __func__);
  359. status = -ENOMEM;
  360. goto free_tports;
  361. }
  362. spin_lock_init(&tport->tp_lock);
  363. tport->tp_uart_base_addr = (i == 0 ?
  364. TI_UART1_BASE_ADDR : TI_UART2_BASE_ADDR);
  365. tport->tp_closing_wait = closing_wait;
  366. init_waitqueue_head(&tport->tp_msr_wait);
  367. init_waitqueue_head(&tport->tp_write_wait);
  368. if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE,
  369. GFP_KERNEL)) {
  370. dev_err(&dev->dev, "%s - out of memory\n", __func__);
  371. kfree(tport);
  372. status = -ENOMEM;
  373. goto free_tports;
  374. }
  375. tport->tp_port = serial->port[i];
  376. tport->tp_tdev = tdev;
  377. usb_set_serial_port_data(serial->port[i], tport);
  378. tport->tp_uart_mode = 0; /* default is RS232 */
  379. }
  380. return 0;
  381. free_tports:
  382. for (--i; i >= 0; --i) {
  383. tport = usb_get_serial_port_data(serial->port[i]);
  384. kfifo_free(&tport->write_fifo);
  385. kfree(tport);
  386. usb_set_serial_port_data(serial->port[i], NULL);
  387. }
  388. free_tdev:
  389. kfree(tdev);
  390. usb_set_serial_data(serial, NULL);
  391. return status;
  392. }
  393. static void ti_release(struct usb_serial *serial)
  394. {
  395. int i;
  396. struct ti_device *tdev = usb_get_serial_data(serial);
  397. struct ti_port *tport;
  398. for (i = 0; i < serial->num_ports; ++i) {
  399. tport = usb_get_serial_port_data(serial->port[i]);
  400. if (tport) {
  401. kfifo_free(&tport->write_fifo);
  402. kfree(tport);
  403. }
  404. }
  405. kfree(tdev);
  406. }
  407. static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
  408. {
  409. struct ti_port *tport = usb_get_serial_port_data(port);
  410. struct ti_device *tdev;
  411. struct usb_device *dev;
  412. struct urb *urb;
  413. int port_number;
  414. int status;
  415. __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINOUS |
  416. TI_PIPE_TIMEOUT_ENABLE |
  417. (TI_TRANSFER_TIMEOUT << 2));
  418. if (tport == NULL)
  419. return -ENODEV;
  420. dev = port->serial->dev;
  421. tdev = tport->tp_tdev;
  422. /* only one open on any port on a device at a time */
  423. if (mutex_lock_interruptible(&tdev->td_open_close_lock))
  424. return -ERESTARTSYS;
  425. port_number = port->number - port->serial->minor;
  426. memset(&(tport->tp_icount), 0x00, sizeof(tport->tp_icount));
  427. tport->tp_msr = 0;
  428. tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR);
  429. /* start interrupt urb the first time a port is opened on this device */
  430. if (tdev->td_open_port_count == 0) {
  431. dev_dbg(&port->dev, "%s - start interrupt in urb\n", __func__);
  432. urb = tdev->td_serial->port[0]->interrupt_in_urb;
  433. if (!urb) {
  434. dev_err(&port->dev, "%s - no interrupt urb\n", __func__);
  435. status = -EINVAL;
  436. goto release_lock;
  437. }
  438. urb->context = tdev;
  439. status = usb_submit_urb(urb, GFP_KERNEL);
  440. if (status) {
  441. dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __func__, status);
  442. goto release_lock;
  443. }
  444. }
  445. if (tty)
  446. ti_set_termios(tty, port, tty->termios);
  447. dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT\n", __func__);
  448. status = ti_command_out_sync(tdev, TI_OPEN_PORT,
  449. (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
  450. if (status) {
  451. dev_err(&port->dev, "%s - cannot send open command, %d\n",
  452. __func__, status);
  453. goto unlink_int_urb;
  454. }
  455. dev_dbg(&port->dev, "%s - sending TI_START_PORT\n", __func__);
  456. status = ti_command_out_sync(tdev, TI_START_PORT,
  457. (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
  458. if (status) {
  459. dev_err(&port->dev, "%s - cannot send start command, %d\n",
  460. __func__, status);
  461. goto unlink_int_urb;
  462. }
  463. dev_dbg(&port->dev, "%s - sending TI_PURGE_PORT\n", __func__);
  464. status = ti_command_out_sync(tdev, TI_PURGE_PORT,
  465. (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0);
  466. if (status) {
  467. dev_err(&port->dev, "%s - cannot clear input buffers, %d\n",
  468. __func__, status);
  469. goto unlink_int_urb;
  470. }
  471. status = ti_command_out_sync(tdev, TI_PURGE_PORT,
  472. (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0);
  473. if (status) {
  474. dev_err(&port->dev, "%s - cannot clear output buffers, %d\n",
  475. __func__, status);
  476. goto unlink_int_urb;
  477. }
  478. /* reset the data toggle on the bulk endpoints to work around bug in
  479. * host controllers where things get out of sync some times */
  480. usb_clear_halt(dev, port->write_urb->pipe);
  481. usb_clear_halt(dev, port->read_urb->pipe);
  482. if (tty)
  483. ti_set_termios(tty, port, tty->termios);
  484. dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT (2)\n", __func__);
  485. status = ti_command_out_sync(tdev, TI_OPEN_PORT,
  486. (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
  487. if (status) {
  488. dev_err(&port->dev, "%s - cannot send open command (2), %d\n",
  489. __func__, status);
  490. goto unlink_int_urb;
  491. }
  492. dev_dbg(&port->dev, "%s - sending TI_START_PORT (2)\n", __func__);
  493. status = ti_command_out_sync(tdev, TI_START_PORT,
  494. (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
  495. if (status) {
  496. dev_err(&port->dev, "%s - cannot send start command (2), %d\n",
  497. __func__, status);
  498. goto unlink_int_urb;
  499. }
  500. /* start read urb */
  501. dev_dbg(&port->dev, "%s - start read urb\n", __func__);
  502. urb = port->read_urb;
  503. if (!urb) {
  504. dev_err(&port->dev, "%s - no read urb\n", __func__);
  505. status = -EINVAL;
  506. goto unlink_int_urb;
  507. }
  508. tport->tp_read_urb_state = TI_READ_URB_RUNNING;
  509. urb->context = tport;
  510. status = usb_submit_urb(urb, GFP_KERNEL);
  511. if (status) {
  512. dev_err(&port->dev, "%s - submit read urb failed, %d\n",
  513. __func__, status);
  514. goto unlink_int_urb;
  515. }
  516. tport->tp_is_open = 1;
  517. ++tdev->td_open_port_count;
  518. goto release_lock;
  519. unlink_int_urb:
  520. if (tdev->td_open_port_count == 0)
  521. usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
  522. release_lock:
  523. mutex_unlock(&tdev->td_open_close_lock);
  524. dev_dbg(&port->dev, "%s - exit %d\n", __func__, status);
  525. return status;
  526. }
  527. static void ti_close(struct usb_serial_port *port)
  528. {
  529. struct ti_device *tdev;
  530. struct ti_port *tport;
  531. int port_number;
  532. int status;
  533. int do_unlock;
  534. tdev = usb_get_serial_data(port->serial);
  535. tport = usb_get_serial_port_data(port);
  536. if (tdev == NULL || tport == NULL)
  537. return;
  538. tport->tp_is_open = 0;
  539. ti_drain(tport, (tport->tp_closing_wait*HZ)/100, 1);
  540. usb_kill_urb(port->read_urb);
  541. usb_kill_urb(port->write_urb);
  542. tport->tp_write_urb_in_use = 0;
  543. port_number = port->number - port->serial->minor;
  544. dev_dbg(&port->dev, "%s - sending TI_CLOSE_PORT\n", __func__);
  545. status = ti_command_out_sync(tdev, TI_CLOSE_PORT,
  546. (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
  547. if (status)
  548. dev_err(&port->dev,
  549. "%s - cannot send close port command, %d\n"
  550. , __func__, status);
  551. /* if mutex_lock is interrupted, continue anyway */
  552. do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock);
  553. --tport->tp_tdev->td_open_port_count;
  554. if (tport->tp_tdev->td_open_port_count <= 0) {
  555. /* last port is closed, shut down interrupt urb */
  556. usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
  557. tport->tp_tdev->td_open_port_count = 0;
  558. }
  559. if (do_unlock)
  560. mutex_unlock(&tdev->td_open_close_lock);
  561. }
  562. static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
  563. const unsigned char *data, int count)
  564. {
  565. struct ti_port *tport = usb_get_serial_port_data(port);
  566. if (count == 0) {
  567. dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__);
  568. return 0;
  569. }
  570. if (tport == NULL || !tport->tp_is_open)
  571. return -ENODEV;
  572. count = kfifo_in_locked(&tport->write_fifo, data, count,
  573. &tport->tp_lock);
  574. ti_send(tport);
  575. return count;
  576. }
  577. static int ti_write_room(struct tty_struct *tty)
  578. {
  579. struct usb_serial_port *port = tty->driver_data;
  580. struct ti_port *tport = usb_get_serial_port_data(port);
  581. int room = 0;
  582. unsigned long flags;
  583. if (tport == NULL)
  584. return 0;
  585. spin_lock_irqsave(&tport->tp_lock, flags);
  586. room = kfifo_avail(&tport->write_fifo);
  587. spin_unlock_irqrestore(&tport->tp_lock, flags);
  588. dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
  589. return room;
  590. }
  591. static int ti_chars_in_buffer(struct tty_struct *tty)
  592. {
  593. struct usb_serial_port *port = tty->driver_data;
  594. struct ti_port *tport = usb_get_serial_port_data(port);
  595. int chars = 0;
  596. unsigned long flags;
  597. if (tport == NULL)
  598. return 0;
  599. spin_lock_irqsave(&tport->tp_lock, flags);
  600. chars = kfifo_len(&tport->write_fifo);
  601. spin_unlock_irqrestore(&tport->tp_lock, flags);
  602. dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
  603. return chars;
  604. }
  605. static void ti_throttle(struct tty_struct *tty)
  606. {
  607. struct usb_serial_port *port = tty->driver_data;
  608. struct ti_port *tport = usb_get_serial_port_data(port);
  609. if (tport == NULL)
  610. return;
  611. if (I_IXOFF(tty) || C_CRTSCTS(tty))
  612. ti_stop_read(tport, tty);
  613. }
  614. static void ti_unthrottle(struct tty_struct *tty)
  615. {
  616. struct usb_serial_port *port = tty->driver_data;
  617. struct ti_port *tport = usb_get_serial_port_data(port);
  618. int status;
  619. if (tport == NULL)
  620. return;
  621. if (I_IXOFF(tty) || C_CRTSCTS(tty)) {
  622. status = ti_restart_read(tport, tty);
  623. if (status)
  624. dev_err(&port->dev, "%s - cannot restart read, %d\n",
  625. __func__, status);
  626. }
  627. }
  628. static int ti_get_icount(struct tty_struct *tty,
  629. struct serial_icounter_struct *icount)
  630. {
  631. struct usb_serial_port *port = tty->driver_data;
  632. struct ti_port *tport = usb_get_serial_port_data(port);
  633. struct async_icount cnow = tport->tp_icount;
  634. dev_dbg(&port->dev, "%s - TIOCGICOUNT RX=%d, TX=%d\n", __func__,
  635. cnow.rx, cnow.tx);
  636. icount->cts = cnow.cts;
  637. icount->dsr = cnow.dsr;
  638. icount->rng = cnow.rng;
  639. icount->dcd = cnow.dcd;
  640. icount->rx = cnow.rx;
  641. icount->tx = cnow.tx;
  642. icount->frame = cnow.frame;
  643. icount->overrun = cnow.overrun;
  644. icount->parity = cnow.parity;
  645. icount->brk = cnow.brk;
  646. icount->buf_overrun = cnow.buf_overrun;
  647. return 0;
  648. }
  649. static int ti_ioctl(struct tty_struct *tty,
  650. unsigned int cmd, unsigned long arg)
  651. {
  652. struct usb_serial_port *port = tty->driver_data;
  653. struct ti_port *tport = usb_get_serial_port_data(port);
  654. struct async_icount cnow;
  655. struct async_icount cprev;
  656. dev_dbg(&port->dev, "%s - cmd = 0x%04X\n", __func__, cmd);
  657. if (tport == NULL)
  658. return -ENODEV;
  659. switch (cmd) {
  660. case TIOCGSERIAL:
  661. dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__);
  662. return ti_get_serial_info(tport,
  663. (struct serial_struct __user *)arg);
  664. case TIOCSSERIAL:
  665. dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__);
  666. return ti_set_serial_info(tty, tport,
  667. (struct serial_struct __user *)arg);
  668. case TIOCMIWAIT:
  669. dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
  670. cprev = tport->tp_icount;
  671. while (1) {
  672. interruptible_sleep_on(&tport->tp_msr_wait);
  673. if (signal_pending(current))
  674. return -ERESTARTSYS;
  675. cnow = tport->tp_icount;
  676. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  677. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
  678. return -EIO; /* no change => error */
  679. if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  680. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  681. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  682. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)))
  683. return 0;
  684. cprev = cnow;
  685. }
  686. break;
  687. }
  688. return -ENOIOCTLCMD;
  689. }
  690. static void ti_set_termios(struct tty_struct *tty,
  691. struct usb_serial_port *port, struct ktermios *old_termios)
  692. {
  693. struct ti_port *tport = usb_get_serial_port_data(port);
  694. struct ti_uart_config *config;
  695. tcflag_t cflag, iflag;
  696. int baud;
  697. int status;
  698. int port_number = port->number - port->serial->minor;
  699. unsigned int mcr;
  700. cflag = tty->termios->c_cflag;
  701. iflag = tty->termios->c_iflag;
  702. dev_dbg(&port->dev, "%s - cflag %08x, iflag %08x\n", __func__, cflag, iflag);
  703. dev_dbg(&port->dev, "%s - old clfag %08x, old iflag %08x\n", __func__,
  704. old_termios->c_cflag, old_termios->c_iflag);
  705. if (tport == NULL)
  706. return;
  707. config = kmalloc(sizeof(*config), GFP_KERNEL);
  708. if (!config) {
  709. dev_err(&port->dev, "%s - out of memory\n", __func__);
  710. return;
  711. }
  712. config->wFlags = 0;
  713. /* these flags must be set */
  714. config->wFlags |= TI_UART_ENABLE_MS_INTS;
  715. config->wFlags |= TI_UART_ENABLE_AUTO_START_DMA;
  716. config->bUartMode = (__u8)(tport->tp_uart_mode);
  717. switch (cflag & CSIZE) {
  718. case CS5:
  719. config->bDataBits = TI_UART_5_DATA_BITS;
  720. break;
  721. case CS6:
  722. config->bDataBits = TI_UART_6_DATA_BITS;
  723. break;
  724. case CS7:
  725. config->bDataBits = TI_UART_7_DATA_BITS;
  726. break;
  727. default:
  728. case CS8:
  729. config->bDataBits = TI_UART_8_DATA_BITS;
  730. break;
  731. }
  732. /* CMSPAR isn't supported by this driver */
  733. tty->termios->c_cflag &= ~CMSPAR;
  734. if (cflag & PARENB) {
  735. if (cflag & PARODD) {
  736. config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING;
  737. config->bParity = TI_UART_ODD_PARITY;
  738. } else {
  739. config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING;
  740. config->bParity = TI_UART_EVEN_PARITY;
  741. }
  742. } else {
  743. config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING;
  744. config->bParity = TI_UART_NO_PARITY;
  745. }
  746. if (cflag & CSTOPB)
  747. config->bStopBits = TI_UART_2_STOP_BITS;
  748. else
  749. config->bStopBits = TI_UART_1_STOP_BITS;
  750. if (cflag & CRTSCTS) {
  751. /* RTS flow control must be off to drop RTS for baud rate B0 */
  752. if ((cflag & CBAUD) != B0)
  753. config->wFlags |= TI_UART_ENABLE_RTS_IN;
  754. config->wFlags |= TI_UART_ENABLE_CTS_OUT;
  755. } else {
  756. tty->hw_stopped = 0;
  757. ti_restart_read(tport, tty);
  758. }
  759. if (I_IXOFF(tty) || I_IXON(tty)) {
  760. config->cXon = START_CHAR(tty);
  761. config->cXoff = STOP_CHAR(tty);
  762. if (I_IXOFF(tty))
  763. config->wFlags |= TI_UART_ENABLE_X_IN;
  764. else
  765. ti_restart_read(tport, tty);
  766. if (I_IXON(tty))
  767. config->wFlags |= TI_UART_ENABLE_X_OUT;
  768. }
  769. baud = tty_get_baud_rate(tty);
  770. if (!baud)
  771. baud = 9600;
  772. if (tport->tp_tdev->td_is_3410)
  773. config->wBaudRate = (__u16)((923077 + baud/2) / baud);
  774. else
  775. config->wBaudRate = (__u16)((461538 + baud/2) / baud);
  776. /* FIXME: Should calculate resulting baud here and report it back */
  777. if ((cflag & CBAUD) != B0)
  778. tty_encode_baud_rate(tty, baud, baud);
  779. dev_dbg(&port->dev,
  780. "%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d",
  781. __func__, baud, config->wBaudRate, config->wFlags,
  782. config->bDataBits, config->bParity, config->bStopBits,
  783. config->cXon, config->cXoff, config->bUartMode);
  784. cpu_to_be16s(&config->wBaudRate);
  785. cpu_to_be16s(&config->wFlags);
  786. status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG,
  787. (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config,
  788. sizeof(*config));
  789. if (status)
  790. dev_err(&port->dev, "%s - cannot set config on port %d, %d\n",
  791. __func__, port_number, status);
  792. /* SET_CONFIG asserts RTS and DTR, reset them correctly */
  793. mcr = tport->tp_shadow_mcr;
  794. /* if baud rate is B0, clear RTS and DTR */
  795. if ((cflag & CBAUD) == B0)
  796. mcr &= ~(TI_MCR_DTR | TI_MCR_RTS);
  797. status = ti_set_mcr(tport, mcr);
  798. if (status)
  799. dev_err(&port->dev,
  800. "%s - cannot set modem control on port %d, %d\n",
  801. __func__, port_number, status);
  802. kfree(config);
  803. }
  804. static int ti_tiocmget(struct tty_struct *tty)
  805. {
  806. struct usb_serial_port *port = tty->driver_data;
  807. struct ti_port *tport = usb_get_serial_port_data(port);
  808. unsigned int result;
  809. unsigned int msr;
  810. unsigned int mcr;
  811. unsigned long flags;
  812. if (tport == NULL)
  813. return -ENODEV;
  814. spin_lock_irqsave(&tport->tp_lock, flags);
  815. msr = tport->tp_msr;
  816. mcr = tport->tp_shadow_mcr;
  817. spin_unlock_irqrestore(&tport->tp_lock, flags);
  818. result = ((mcr & TI_MCR_DTR) ? TIOCM_DTR : 0)
  819. | ((mcr & TI_MCR_RTS) ? TIOCM_RTS : 0)
  820. | ((mcr & TI_MCR_LOOP) ? TIOCM_LOOP : 0)
  821. | ((msr & TI_MSR_CTS) ? TIOCM_CTS : 0)
  822. | ((msr & TI_MSR_CD) ? TIOCM_CAR : 0)
  823. | ((msr & TI_MSR_RI) ? TIOCM_RI : 0)
  824. | ((msr & TI_MSR_DSR) ? TIOCM_DSR : 0);
  825. dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result);
  826. return result;
  827. }
  828. static int ti_tiocmset(struct tty_struct *tty,
  829. unsigned int set, unsigned int clear)
  830. {
  831. struct usb_serial_port *port = tty->driver_data;
  832. struct ti_port *tport = usb_get_serial_port_data(port);
  833. unsigned int mcr;
  834. unsigned long flags;
  835. if (tport == NULL)
  836. return -ENODEV;
  837. spin_lock_irqsave(&tport->tp_lock, flags);
  838. mcr = tport->tp_shadow_mcr;
  839. if (set & TIOCM_RTS)
  840. mcr |= TI_MCR_RTS;
  841. if (set & TIOCM_DTR)
  842. mcr |= TI_MCR_DTR;
  843. if (set & TIOCM_LOOP)
  844. mcr |= TI_MCR_LOOP;
  845. if (clear & TIOCM_RTS)
  846. mcr &= ~TI_MCR_RTS;
  847. if (clear & TIOCM_DTR)
  848. mcr &= ~TI_MCR_DTR;
  849. if (clear & TIOCM_LOOP)
  850. mcr &= ~TI_MCR_LOOP;
  851. spin_unlock_irqrestore(&tport->tp_lock, flags);
  852. return ti_set_mcr(tport, mcr);
  853. }
  854. static void ti_break(struct tty_struct *tty, int break_state)
  855. {
  856. struct usb_serial_port *port = tty->driver_data;
  857. struct ti_port *tport = usb_get_serial_port_data(port);
  858. int status;
  859. dev_dbg(&port->dev, "%s - state = %d\n", __func__, break_state);
  860. if (tport == NULL)
  861. return;
  862. ti_drain(tport, (tport->tp_closing_wait*HZ)/100, 0);
  863. status = ti_write_byte(port, tport->tp_tdev,
  864. tport->tp_uart_base_addr + TI_UART_OFFSET_LCR,
  865. TI_LCR_BREAK, break_state == -1 ? TI_LCR_BREAK : 0);
  866. if (status)
  867. dev_dbg(&port->dev, "%s - error setting break, %d\n", __func__, status);
  868. }
  869. static void ti_interrupt_callback(struct urb *urb)
  870. {
  871. struct ti_device *tdev = urb->context;
  872. struct usb_serial_port *port;
  873. struct usb_serial *serial = tdev->td_serial;
  874. struct ti_port *tport;
  875. struct device *dev = &urb->dev->dev;
  876. unsigned char *data = urb->transfer_buffer;
  877. int length = urb->actual_length;
  878. int port_number;
  879. int function;
  880. int status = urb->status;
  881. int retval;
  882. __u8 msr;
  883. switch (status) {
  884. case 0:
  885. break;
  886. case -ECONNRESET:
  887. case -ENOENT:
  888. case -ESHUTDOWN:
  889. dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status);
  890. tdev->td_urb_error = 1;
  891. return;
  892. default:
  893. dev_err(dev, "%s - nonzero urb status, %d\n", __func__, status);
  894. tdev->td_urb_error = 1;
  895. goto exit;
  896. }
  897. if (length != 2) {
  898. dev_dbg(dev, "%s - bad packet size, %d\n", __func__, length);
  899. goto exit;
  900. }
  901. if (data[0] == TI_CODE_HARDWARE_ERROR) {
  902. dev_err(dev, "%s - hardware error, %d\n", __func__, data[1]);
  903. goto exit;
  904. }
  905. port_number = TI_GET_PORT_FROM_CODE(data[0]);
  906. function = TI_GET_FUNC_FROM_CODE(data[0]);
  907. dev_dbg(dev, "%s - port_number %d, function %d, data 0x%02X\n",
  908. __func__, port_number, function, data[1]);
  909. if (port_number >= serial->num_ports) {
  910. dev_err(dev, "%s - bad port number, %d\n",
  911. __func__, port_number);
  912. goto exit;
  913. }
  914. port = serial->port[port_number];
  915. tport = usb_get_serial_port_data(port);
  916. if (!tport)
  917. goto exit;
  918. switch (function) {
  919. case TI_CODE_DATA_ERROR:
  920. dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n",
  921. __func__, port_number, data[1]);
  922. break;
  923. case TI_CODE_MODEM_STATUS:
  924. msr = data[1];
  925. dev_dbg(dev, "%s - port %d, msr 0x%02X\n", __func__, port_number, msr);
  926. ti_handle_new_msr(tport, msr);
  927. break;
  928. default:
  929. dev_err(dev, "%s - unknown interrupt code, 0x%02X\n",
  930. __func__, data[1]);
  931. break;
  932. }
  933. exit:
  934. retval = usb_submit_urb(urb, GFP_ATOMIC);
  935. if (retval)
  936. dev_err(dev, "%s - resubmit interrupt urb failed, %d\n",
  937. __func__, retval);
  938. }
  939. static void ti_bulk_in_callback(struct urb *urb)
  940. {
  941. struct ti_port *tport = urb->context;
  942. struct usb_serial_port *port = tport->tp_port;
  943. struct device *dev = &urb->dev->dev;
  944. int status = urb->status;
  945. int retval = 0;
  946. struct tty_struct *tty;
  947. switch (status) {
  948. case 0:
  949. break;
  950. case -ECONNRESET:
  951. case -ENOENT:
  952. case -ESHUTDOWN:
  953. dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status);
  954. tport->tp_tdev->td_urb_error = 1;
  955. wake_up_interruptible(&tport->tp_write_wait);
  956. return;
  957. default:
  958. dev_err(dev, "%s - nonzero urb status, %d\n",
  959. __func__, status);
  960. tport->tp_tdev->td_urb_error = 1;
  961. wake_up_interruptible(&tport->tp_write_wait);
  962. }
  963. if (status == -EPIPE)
  964. goto exit;
  965. if (status) {
  966. dev_err(dev, "%s - stopping read!\n", __func__);
  967. return;
  968. }
  969. tty = tty_port_tty_get(&port->port);
  970. if (tty) {
  971. if (urb->actual_length) {
  972. usb_serial_debug_data(dev, __func__, urb->actual_length,
  973. urb->transfer_buffer);
  974. if (!tport->tp_is_open)
  975. dev_dbg(dev, "%s - port closed, dropping data\n",
  976. __func__);
  977. else
  978. ti_recv(&urb->dev->dev, tty,
  979. urb->transfer_buffer,
  980. urb->actual_length);
  981. spin_lock(&tport->tp_lock);
  982. tport->tp_icount.rx += urb->actual_length;
  983. spin_unlock(&tport->tp_lock);
  984. }
  985. tty_kref_put(tty);
  986. }
  987. exit:
  988. /* continue to read unless stopping */
  989. spin_lock(&tport->tp_lock);
  990. if (tport->tp_read_urb_state == TI_READ_URB_RUNNING)
  991. retval = usb_submit_urb(urb, GFP_ATOMIC);
  992. else if (tport->tp_read_urb_state == TI_READ_URB_STOPPING)
  993. tport->tp_read_urb_state = TI_READ_URB_STOPPED;
  994. spin_unlock(&tport->tp_lock);
  995. if (retval)
  996. dev_err(dev, "%s - resubmit read urb failed, %d\n",
  997. __func__, retval);
  998. }
  999. static void ti_bulk_out_callback(struct urb *urb)
  1000. {
  1001. struct ti_port *tport = urb->context;
  1002. struct usb_serial_port *port = tport->tp_port;
  1003. int status = urb->status;
  1004. tport->tp_write_urb_in_use = 0;
  1005. switch (status) {
  1006. case 0:
  1007. break;
  1008. case -ECONNRESET:
  1009. case -ENOENT:
  1010. case -ESHUTDOWN:
  1011. dev_dbg(&port->dev, "%s - urb shutting down, %d\n", __func__, status);
  1012. tport->tp_tdev->td_urb_error = 1;
  1013. wake_up_interruptible(&tport->tp_write_wait);
  1014. return;
  1015. default:
  1016. dev_err_console(port, "%s - nonzero urb status, %d\n",
  1017. __func__, status);
  1018. tport->tp_tdev->td_urb_error = 1;
  1019. wake_up_interruptible(&tport->tp_write_wait);
  1020. }
  1021. /* send any buffered data */
  1022. ti_send(tport);
  1023. }
  1024. static void ti_recv(struct device *dev, struct tty_struct *tty,
  1025. unsigned char *data, int length)
  1026. {
  1027. int cnt;
  1028. do {
  1029. cnt = tty_insert_flip_string(tty, data, length);
  1030. if (cnt < length) {
  1031. dev_err(dev, "%s - dropping data, %d bytes lost\n",
  1032. __func__, length - cnt);
  1033. if (cnt == 0)
  1034. break;
  1035. }
  1036. tty_flip_buffer_push(tty);
  1037. data += cnt;
  1038. length -= cnt;
  1039. } while (length > 0);
  1040. }
  1041. static void ti_send(struct ti_port *tport)
  1042. {
  1043. int count, result;
  1044. struct usb_serial_port *port = tport->tp_port;
  1045. struct tty_struct *tty = tty_port_tty_get(&port->port); /* FIXME */
  1046. unsigned long flags;
  1047. spin_lock_irqsave(&tport->tp_lock, flags);
  1048. if (tport->tp_write_urb_in_use)
  1049. goto unlock;
  1050. count = kfifo_out(&tport->write_fifo,
  1051. port->write_urb->transfer_buffer,
  1052. port->bulk_out_size);
  1053. if (count == 0)
  1054. goto unlock;
  1055. tport->tp_write_urb_in_use = 1;
  1056. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1057. usb_serial_debug_data(&port->dev, __func__, count,
  1058. port->write_urb->transfer_buffer);
  1059. usb_fill_bulk_urb(port->write_urb, port->serial->dev,
  1060. usb_sndbulkpipe(port->serial->dev,
  1061. port->bulk_out_endpointAddress),
  1062. port->write_urb->transfer_buffer, count,
  1063. ti_bulk_out_callback, tport);
  1064. result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
  1065. if (result) {
  1066. dev_err_console(port, "%s - submit write urb failed, %d\n",
  1067. __func__, result);
  1068. tport->tp_write_urb_in_use = 0;
  1069. /* TODO: reschedule ti_send */
  1070. } else {
  1071. spin_lock_irqsave(&tport->tp_lock, flags);
  1072. tport->tp_icount.tx += count;
  1073. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1074. }
  1075. /* more room in the buffer for new writes, wakeup */
  1076. if (tty)
  1077. tty_wakeup(tty);
  1078. tty_kref_put(tty);
  1079. wake_up_interruptible(&tport->tp_write_wait);
  1080. return;
  1081. unlock:
  1082. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1083. tty_kref_put(tty);
  1084. return;
  1085. }
  1086. static int ti_set_mcr(struct ti_port *tport, unsigned int mcr)
  1087. {
  1088. unsigned long flags;
  1089. int status;
  1090. status = ti_write_byte(tport->tp_port, tport->tp_tdev,
  1091. tport->tp_uart_base_addr + TI_UART_OFFSET_MCR,
  1092. TI_MCR_RTS | TI_MCR_DTR | TI_MCR_LOOP, mcr);
  1093. spin_lock_irqsave(&tport->tp_lock, flags);
  1094. if (!status)
  1095. tport->tp_shadow_mcr = mcr;
  1096. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1097. return status;
  1098. }
  1099. static int ti_get_lsr(struct ti_port *tport)
  1100. {
  1101. int size, status;
  1102. struct ti_device *tdev = tport->tp_tdev;
  1103. struct usb_serial_port *port = tport->tp_port;
  1104. int port_number = port->number - port->serial->minor;
  1105. struct ti_port_status *data;
  1106. size = sizeof(struct ti_port_status);
  1107. data = kmalloc(size, GFP_KERNEL);
  1108. if (!data) {
  1109. dev_err(&port->dev, "%s - out of memory\n", __func__);
  1110. return -ENOMEM;
  1111. }
  1112. status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS,
  1113. (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size);
  1114. if (status) {
  1115. dev_err(&port->dev,
  1116. "%s - get port status command failed, %d\n",
  1117. __func__, status);
  1118. goto free_data;
  1119. }
  1120. dev_dbg(&port->dev, "%s - lsr 0x%02X\n", __func__, data->bLSR);
  1121. tport->tp_lsr = data->bLSR;
  1122. free_data:
  1123. kfree(data);
  1124. return status;
  1125. }
  1126. static int ti_get_serial_info(struct ti_port *tport,
  1127. struct serial_struct __user *ret_arg)
  1128. {
  1129. struct usb_serial_port *port = tport->tp_port;
  1130. struct serial_struct ret_serial;
  1131. if (!ret_arg)
  1132. return -EFAULT;
  1133. memset(&ret_serial, 0, sizeof(ret_serial));
  1134. ret_serial.type = PORT_16550A;
  1135. ret_serial.line = port->serial->minor;
  1136. ret_serial.port = port->number - port->serial->minor;
  1137. ret_serial.flags = tport->tp_flags;
  1138. ret_serial.xmit_fifo_size = TI_WRITE_BUF_SIZE;
  1139. ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800;
  1140. ret_serial.closing_wait = tport->tp_closing_wait;
  1141. if (copy_to_user(ret_arg, &ret_serial, sizeof(*ret_arg)))
  1142. return -EFAULT;
  1143. return 0;
  1144. }
  1145. static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
  1146. struct serial_struct __user *new_arg)
  1147. {
  1148. struct serial_struct new_serial;
  1149. if (copy_from_user(&new_serial, new_arg, sizeof(new_serial)))
  1150. return -EFAULT;
  1151. tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS;
  1152. tport->tp_closing_wait = new_serial.closing_wait;
  1153. return 0;
  1154. }
  1155. static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
  1156. {
  1157. struct async_icount *icount;
  1158. struct tty_struct *tty;
  1159. unsigned long flags;
  1160. dev_dbg(&tport->tp_port->dev, "%s - msr 0x%02X\n", __func__, msr);
  1161. if (msr & TI_MSR_DELTA_MASK) {
  1162. spin_lock_irqsave(&tport->tp_lock, flags);
  1163. icount = &tport->tp_icount;
  1164. if (msr & TI_MSR_DELTA_CTS)
  1165. icount->cts++;
  1166. if (msr & TI_MSR_DELTA_DSR)
  1167. icount->dsr++;
  1168. if (msr & TI_MSR_DELTA_CD)
  1169. icount->dcd++;
  1170. if (msr & TI_MSR_DELTA_RI)
  1171. icount->rng++;
  1172. wake_up_interruptible(&tport->tp_msr_wait);
  1173. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1174. }
  1175. tport->tp_msr = msr & TI_MSR_MASK;
  1176. /* handle CTS flow control */
  1177. tty = tty_port_tty_get(&tport->tp_port->port);
  1178. if (tty && C_CRTSCTS(tty)) {
  1179. if (msr & TI_MSR_CTS) {
  1180. tty->hw_stopped = 0;
  1181. tty_wakeup(tty);
  1182. } else {
  1183. tty->hw_stopped = 1;
  1184. }
  1185. }
  1186. tty_kref_put(tty);
  1187. }
  1188. static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
  1189. {
  1190. struct ti_device *tdev = tport->tp_tdev;
  1191. struct usb_serial_port *port = tport->tp_port;
  1192. wait_queue_t wait;
  1193. spin_lock_irq(&tport->tp_lock);
  1194. /* wait for data to drain from the buffer */
  1195. tdev->td_urb_error = 0;
  1196. init_waitqueue_entry(&wait, current);
  1197. add_wait_queue(&tport->tp_write_wait, &wait);
  1198. for (;;) {
  1199. set_current_state(TASK_INTERRUPTIBLE);
  1200. if (kfifo_len(&tport->write_fifo) == 0
  1201. || timeout == 0 || signal_pending(current)
  1202. || tdev->td_urb_error
  1203. || port->serial->disconnected) /* disconnect */
  1204. break;
  1205. spin_unlock_irq(&tport->tp_lock);
  1206. timeout = schedule_timeout(timeout);
  1207. spin_lock_irq(&tport->tp_lock);
  1208. }
  1209. set_current_state(TASK_RUNNING);
  1210. remove_wait_queue(&tport->tp_write_wait, &wait);
  1211. /* flush any remaining data in the buffer */
  1212. if (flush)
  1213. kfifo_reset_out(&tport->write_fifo);
  1214. spin_unlock_irq(&tport->tp_lock);
  1215. mutex_lock(&port->serial->disc_mutex);
  1216. /* wait for data to drain from the device */
  1217. /* wait for empty tx register, plus 20 ms */
  1218. timeout += jiffies;
  1219. tport->tp_lsr &= ~TI_LSR_TX_EMPTY;
  1220. while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
  1221. && !(tport->tp_lsr&TI_LSR_TX_EMPTY) && !tdev->td_urb_error
  1222. && !port->serial->disconnected) {
  1223. if (ti_get_lsr(tport))
  1224. break;
  1225. mutex_unlock(&port->serial->disc_mutex);
  1226. msleep_interruptible(20);
  1227. mutex_lock(&port->serial->disc_mutex);
  1228. }
  1229. mutex_unlock(&port->serial->disc_mutex);
  1230. }
  1231. static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty)
  1232. {
  1233. unsigned long flags;
  1234. spin_lock_irqsave(&tport->tp_lock, flags);
  1235. if (tport->tp_read_urb_state == TI_READ_URB_RUNNING)
  1236. tport->tp_read_urb_state = TI_READ_URB_STOPPING;
  1237. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1238. }
  1239. static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty)
  1240. {
  1241. struct urb *urb;
  1242. int status = 0;
  1243. unsigned long flags;
  1244. spin_lock_irqsave(&tport->tp_lock, flags);
  1245. if (tport->tp_read_urb_state == TI_READ_URB_STOPPED) {
  1246. tport->tp_read_urb_state = TI_READ_URB_RUNNING;
  1247. urb = tport->tp_port->read_urb;
  1248. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1249. urb->context = tport;
  1250. status = usb_submit_urb(urb, GFP_KERNEL);
  1251. } else {
  1252. tport->tp_read_urb_state = TI_READ_URB_RUNNING;
  1253. spin_unlock_irqrestore(&tport->tp_lock, flags);
  1254. }
  1255. return status;
  1256. }
  1257. static int ti_command_out_sync(struct ti_device *tdev, __u8 command,
  1258. __u16 moduleid, __u16 value, __u8 *data, int size)
  1259. {
  1260. int status;
  1261. status = usb_control_msg(tdev->td_serial->dev,
  1262. usb_sndctrlpipe(tdev->td_serial->dev, 0), command,
  1263. (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
  1264. value, moduleid, data, size, 1000);
  1265. if (status == size)
  1266. status = 0;
  1267. if (status > 0)
  1268. status = -ECOMM;
  1269. return status;
  1270. }
  1271. static int ti_command_in_sync(struct ti_device *tdev, __u8 command,
  1272. __u16 moduleid, __u16 value, __u8 *data, int size)
  1273. {
  1274. int status;
  1275. status = usb_control_msg(tdev->td_serial->dev,
  1276. usb_rcvctrlpipe(tdev->td_serial->dev, 0), command,
  1277. (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
  1278. value, moduleid, data, size, 1000);
  1279. if (status == size)
  1280. status = 0;
  1281. if (status > 0)
  1282. status = -ECOMM;
  1283. return status;
  1284. }
  1285. static int ti_write_byte(struct usb_serial_port *port,
  1286. struct ti_device *tdev, unsigned long addr,
  1287. __u8 mask, __u8 byte)
  1288. {
  1289. int status;
  1290. unsigned int size;
  1291. struct ti_write_data_bytes *data;
  1292. dev_dbg(&port->dev, "%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X\n", __func__,
  1293. addr, mask, byte);
  1294. size = sizeof(struct ti_write_data_bytes) + 2;
  1295. data = kmalloc(size, GFP_KERNEL);
  1296. if (!data) {
  1297. dev_err(&port->dev, "%s - out of memory\n", __func__);
  1298. return -ENOMEM;
  1299. }
  1300. data->bAddrType = TI_RW_DATA_ADDR_XDATA;
  1301. data->bDataType = TI_RW_DATA_BYTE;
  1302. data->bDataCounter = 1;
  1303. data->wBaseAddrHi = cpu_to_be16(addr>>16);
  1304. data->wBaseAddrLo = cpu_to_be16(addr);
  1305. data->bData[0] = mask;
  1306. data->bData[1] = byte;
  1307. status = ti_command_out_sync(tdev, TI_WRITE_DATA, TI_RAM_PORT, 0,
  1308. (__u8 *)data, size);
  1309. if (status < 0)
  1310. dev_err(&port->dev, "%s - failed, %d\n", __func__, status);
  1311. kfree(data);
  1312. return status;
  1313. }
  1314. static int ti_do_download(struct usb_device *dev, int pipe,
  1315. u8 *buffer, int size)
  1316. {
  1317. int pos;
  1318. u8 cs = 0;
  1319. int done;
  1320. struct ti_firmware_header *header;
  1321. int status = 0;
  1322. int len;
  1323. for (pos = sizeof(struct ti_firmware_header); pos < size; pos++)
  1324. cs = (__u8)(cs + buffer[pos]);
  1325. header = (struct ti_firmware_header *)buffer;
  1326. header->wLength = cpu_to_le16((__u16)(size
  1327. - sizeof(struct ti_firmware_header)));
  1328. header->bCheckSum = cs;
  1329. dev_dbg(&dev->dev, "%s - downloading firmware\n", __func__);
  1330. for (pos = 0; pos < size; pos += done) {
  1331. len = min(size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE);
  1332. status = usb_bulk_msg(dev, pipe, buffer + pos, len,
  1333. &done, 1000);
  1334. if (status)
  1335. break;
  1336. }
  1337. return status;
  1338. }
  1339. static int ti_download_firmware(struct ti_device *tdev)
  1340. {
  1341. int status;
  1342. int buffer_size;
  1343. __u8 *buffer;
  1344. struct usb_device *dev = tdev->td_serial->dev;
  1345. unsigned int pipe = usb_sndbulkpipe(dev,
  1346. tdev->td_serial->port[0]->bulk_out_endpointAddress);
  1347. const struct firmware *fw_p;
  1348. char buf[32];
  1349. /* try ID specific firmware first, then try generic firmware */
  1350. sprintf(buf, "ti_usb-v%04x-p%04x.fw", dev->descriptor.idVendor,
  1351. dev->descriptor.idProduct);
  1352. status = request_firmware(&fw_p, buf, &dev->dev);
  1353. if (status != 0) {
  1354. buf[0] = '\0';
  1355. if (dev->descriptor.idVendor == MTS_VENDOR_ID) {
  1356. switch (dev->descriptor.idProduct) {
  1357. case MTS_CDMA_PRODUCT_ID:
  1358. strcpy(buf, "mts_cdma.fw");
  1359. break;
  1360. case MTS_GSM_PRODUCT_ID:
  1361. strcpy(buf, "mts_gsm.fw");
  1362. break;
  1363. case MTS_EDGE_PRODUCT_ID:
  1364. strcpy(buf, "mts_edge.fw");
  1365. break;
  1366. case MTS_MT9234MU_PRODUCT_ID:
  1367. strcpy(buf, "mts_mt9234mu.fw");
  1368. break;
  1369. case MTS_MT9234ZBA_PRODUCT_ID:
  1370. strcpy(buf, "mts_mt9234zba.fw");
  1371. break;
  1372. case MTS_MT9234ZBAOLD_PRODUCT_ID:
  1373. strcpy(buf, "mts_mt9234zba.fw");
  1374. break; }
  1375. }
  1376. if (buf[0] == '\0') {
  1377. if (tdev->td_is_3410)
  1378. strcpy(buf, "ti_3410.fw");
  1379. else
  1380. strcpy(buf, "ti_5052.fw");
  1381. }
  1382. status = request_firmware(&fw_p, buf, &dev->dev);
  1383. }
  1384. if (status) {
  1385. dev_err(&dev->dev, "%s - firmware not found\n", __func__);
  1386. return -ENOENT;
  1387. }
  1388. if (fw_p->size > TI_FIRMWARE_BUF_SIZE) {
  1389. dev_err(&dev->dev, "%s - firmware too large %zu\n", __func__, fw_p->size);
  1390. release_firmware(fw_p);
  1391. return -ENOENT;
  1392. }
  1393. buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header);
  1394. buffer = kmalloc(buffer_size, GFP_KERNEL);
  1395. if (buffer) {
  1396. memcpy(buffer, fw_p->data, fw_p->size);
  1397. memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size);
  1398. status = ti_do_download(dev, pipe, buffer, fw_p->size);
  1399. kfree(buffer);
  1400. } else {
  1401. dev_dbg(&dev->dev, "%s ENOMEM\n", __func__);
  1402. status = -ENOMEM;
  1403. }
  1404. release_firmware(fw_p);
  1405. if (status) {
  1406. dev_err(&dev->dev, "%s - error downloading firmware, %d\n",
  1407. __func__, status);
  1408. return status;
  1409. }
  1410. dev_dbg(&dev->dev, "%s - download successful\n", __func__);
  1411. return 0;
  1412. }