visor.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * USB HandSpring Visor, Palm m50x, and Sony Clie driver
  3. * (supports all of the Palm OS USB devices)
  4. *
  5. * Copyright (C) 1999 - 2004
  6. * Greg Kroah-Hartman (greg@kroah.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * See Documentation/usb/usb-serial.txt for more information on using this
  13. * driver
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/init.h>
  19. #include <linux/slab.h>
  20. #include <linux/tty.h>
  21. #include <linux/tty_driver.h>
  22. #include <linux/tty_flip.h>
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/usb.h>
  28. #include <linux/usb/serial.h>
  29. #include <linux/usb/cdc.h>
  30. #include "visor.h"
  31. /*
  32. * Version Information
  33. */
  34. #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
  35. #define DRIVER_DESC "USB HandSpring Visor / Palm OS driver"
  36. /* function prototypes for a handspring visor */
  37. static int visor_open(struct tty_struct *tty, struct usb_serial_port *port);
  38. static void visor_close(struct usb_serial_port *port);
  39. static int visor_probe(struct usb_serial *serial,
  40. const struct usb_device_id *id);
  41. static int visor_calc_num_ports(struct usb_serial *serial);
  42. static void visor_read_int_callback(struct urb *urb);
  43. static int clie_3_5_startup(struct usb_serial *serial);
  44. static int treo_attach(struct usb_serial *serial);
  45. static int clie_5_attach(struct usb_serial *serial);
  46. static int palm_os_3_probe(struct usb_serial *serial,
  47. const struct usb_device_id *id);
  48. static int palm_os_4_probe(struct usb_serial *serial,
  49. const struct usb_device_id *id);
  50. /* Parameters that may be passed into the module. */
  51. static bool debug;
  52. static struct usb_device_id id_table [] = {
  53. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID),
  54. .driver_info = (kernel_ulong_t)&palm_os_3_probe },
  55. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID),
  56. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  57. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID),
  58. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  59. { USB_DEVICE(GSPDA_VENDOR_ID, GSPDA_XPLORE_M68_ID),
  60. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  61. { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID),
  62. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  63. { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID),
  64. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  65. { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID),
  66. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  67. { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID),
  68. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  69. { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID),
  70. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  71. { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID),
  72. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  73. { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID),
  74. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  75. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID),
  76. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  77. { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650),
  78. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  79. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID),
  80. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  81. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID),
  82. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  83. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID),
  84. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  85. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID),
  86. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  87. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID),
  88. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  89. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID),
  90. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  91. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID),
  92. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  93. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID),
  94. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  95. { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID),
  96. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  97. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID),
  98. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  99. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID),
  100. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  101. { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID),
  102. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  103. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID),
  104. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  105. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID),
  106. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  107. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID),
  108. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  109. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID),
  110. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  111. { } /* Terminating entry */
  112. };
  113. static struct usb_device_id clie_id_5_table [] = {
  114. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID),
  115. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  116. { } /* Terminating entry */
  117. };
  118. static struct usb_device_id clie_id_3_5_table [] = {
  119. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  120. { } /* Terminating entry */
  121. };
  122. static struct usb_device_id id_table_combined [] = {
  123. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
  124. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) },
  125. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) },
  126. { USB_DEVICE(GSPDA_VENDOR_ID, GSPDA_XPLORE_M68_ID) },
  127. { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
  128. { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
  129. { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
  130. { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
  131. { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID) },
  132. { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
  133. { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
  134. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID) },
  135. { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650) },
  136. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID) },
  137. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID) },
  138. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  139. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
  140. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
  141. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID) },
  142. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID) },
  143. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID) },
  144. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID) },
  145. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID) },
  146. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID) },
  147. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID) },
  148. { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID) },
  149. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID) },
  150. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID) },
  151. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID) },
  152. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID) },
  153. { } /* Terminating entry */
  154. };
  155. MODULE_DEVICE_TABLE(usb, id_table_combined);
  156. static struct usb_driver visor_driver = {
  157. .name = "visor",
  158. .disconnect = usb_serial_disconnect,
  159. .id_table = id_table_combined,
  160. };
  161. /* All of the device info needed for the Handspring Visor,
  162. and Palm 4.0 devices */
  163. static struct usb_serial_driver handspring_device = {
  164. .driver = {
  165. .owner = THIS_MODULE,
  166. .name = "visor",
  167. },
  168. .description = "Handspring Visor / Palm OS",
  169. .id_table = id_table,
  170. .num_ports = 2,
  171. .bulk_out_size = 256,
  172. .open = visor_open,
  173. .close = visor_close,
  174. .throttle = usb_serial_generic_throttle,
  175. .unthrottle = usb_serial_generic_unthrottle,
  176. .attach = treo_attach,
  177. .probe = visor_probe,
  178. .calc_num_ports = visor_calc_num_ports,
  179. .read_int_callback = visor_read_int_callback,
  180. };
  181. /* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */
  182. static struct usb_serial_driver clie_5_device = {
  183. .driver = {
  184. .owner = THIS_MODULE,
  185. .name = "clie_5",
  186. },
  187. .description = "Sony Clie 5.0",
  188. .id_table = clie_id_5_table,
  189. .num_ports = 2,
  190. .bulk_out_size = 256,
  191. .open = visor_open,
  192. .close = visor_close,
  193. .throttle = usb_serial_generic_throttle,
  194. .unthrottle = usb_serial_generic_unthrottle,
  195. .attach = clie_5_attach,
  196. .probe = visor_probe,
  197. .calc_num_ports = visor_calc_num_ports,
  198. .read_int_callback = visor_read_int_callback,
  199. };
  200. /* device info for the Sony Clie OS version 3.5 */
  201. static struct usb_serial_driver clie_3_5_device = {
  202. .driver = {
  203. .owner = THIS_MODULE,
  204. .name = "clie_3.5",
  205. },
  206. .description = "Sony Clie 3.5",
  207. .id_table = clie_id_3_5_table,
  208. .num_ports = 1,
  209. .bulk_out_size = 256,
  210. .open = visor_open,
  211. .close = visor_close,
  212. .throttle = usb_serial_generic_throttle,
  213. .unthrottle = usb_serial_generic_unthrottle,
  214. .attach = clie_3_5_startup,
  215. };
  216. static struct usb_serial_driver * const serial_drivers[] = {
  217. &handspring_device, &clie_5_device, &clie_3_5_device, NULL
  218. };
  219. /******************************************************************************
  220. * Handspring Visor specific driver functions
  221. ******************************************************************************/
  222. static int visor_open(struct tty_struct *tty, struct usb_serial_port *port)
  223. {
  224. int result = 0;
  225. if (!port->read_urb) {
  226. /* this is needed for some brain dead Sony devices */
  227. dev_err(&port->dev, "Device lied about number of ports, please use a lower one.\n");
  228. return -ENODEV;
  229. }
  230. /* Start reading from the device */
  231. result = usb_serial_generic_open(tty, port);
  232. if (result)
  233. goto exit;
  234. if (port->interrupt_in_urb) {
  235. dev_dbg(&port->dev, "adding interrupt input for treo\n");
  236. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  237. if (result)
  238. dev_err(&port->dev,
  239. "%s - failed submitting interrupt urb, error %d\n",
  240. __func__, result);
  241. }
  242. exit:
  243. return result;
  244. }
  245. static void visor_close(struct usb_serial_port *port)
  246. {
  247. unsigned char *transfer_buffer;
  248. /* shutdown our urbs */
  249. usb_serial_generic_close(port);
  250. usb_kill_urb(port->interrupt_in_urb);
  251. mutex_lock(&port->serial->disc_mutex);
  252. if (!port->serial->disconnected) {
  253. /* Try to send shutdown message, unless the device is gone */
  254. transfer_buffer = kmalloc(0x12, GFP_KERNEL);
  255. if (transfer_buffer) {
  256. usb_control_msg(port->serial->dev,
  257. usb_rcvctrlpipe(port->serial->dev, 0),
  258. VISOR_CLOSE_NOTIFICATION, 0xc2,
  259. 0x0000, 0x0000,
  260. transfer_buffer, 0x12, 300);
  261. kfree(transfer_buffer);
  262. }
  263. }
  264. mutex_unlock(&port->serial->disc_mutex);
  265. }
  266. static void visor_read_int_callback(struct urb *urb)
  267. {
  268. struct usb_serial_port *port = urb->context;
  269. int status = urb->status;
  270. int result;
  271. switch (status) {
  272. case 0:
  273. /* success */
  274. break;
  275. case -ECONNRESET:
  276. case -ENOENT:
  277. case -ESHUTDOWN:
  278. /* this urb is terminated, clean up */
  279. dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n",
  280. __func__, status);
  281. return;
  282. default:
  283. dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n",
  284. __func__, status);
  285. goto exit;
  286. }
  287. /*
  288. * This information is still unknown what it can be used for.
  289. * If anyone has an idea, please let the author know...
  290. *
  291. * Rumor has it this endpoint is used to notify when data
  292. * is ready to be read from the bulk ones.
  293. */
  294. usb_serial_debug_data(debug, &port->dev, __func__,
  295. urb->actual_length, urb->transfer_buffer);
  296. exit:
  297. result = usb_submit_urb(urb, GFP_ATOMIC);
  298. if (result)
  299. dev_err(&urb->dev->dev,
  300. "%s - Error %d submitting interrupt urb\n",
  301. __func__, result);
  302. }
  303. static int palm_os_3_probe(struct usb_serial *serial,
  304. const struct usb_device_id *id)
  305. {
  306. struct device *dev = &serial->dev->dev;
  307. struct visor_connection_info *connection_info;
  308. unsigned char *transfer_buffer;
  309. char *string;
  310. int retval = 0;
  311. int i;
  312. int num_ports = 0;
  313. transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
  314. if (!transfer_buffer) {
  315. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
  316. sizeof(*connection_info));
  317. return -ENOMEM;
  318. }
  319. /* send a get connection info request */
  320. retval = usb_control_msg(serial->dev,
  321. usb_rcvctrlpipe(serial->dev, 0),
  322. VISOR_GET_CONNECTION_INFORMATION,
  323. 0xc2, 0x0000, 0x0000, transfer_buffer,
  324. sizeof(*connection_info), 300);
  325. if (retval < 0) {
  326. dev_err(dev, "%s - error %d getting connection information\n",
  327. __func__, retval);
  328. goto exit;
  329. }
  330. if (retval == sizeof(*connection_info)) {
  331. connection_info = (struct visor_connection_info *)
  332. transfer_buffer;
  333. num_ports = le16_to_cpu(connection_info->num_ports);
  334. for (i = 0; i < num_ports; ++i) {
  335. switch (
  336. connection_info->connections[i].port_function_id) {
  337. case VISOR_FUNCTION_GENERIC:
  338. string = "Generic";
  339. break;
  340. case VISOR_FUNCTION_DEBUGGER:
  341. string = "Debugger";
  342. break;
  343. case VISOR_FUNCTION_HOTSYNC:
  344. string = "HotSync";
  345. break;
  346. case VISOR_FUNCTION_CONSOLE:
  347. string = "Console";
  348. break;
  349. case VISOR_FUNCTION_REMOTE_FILE_SYS:
  350. string = "Remote File System";
  351. break;
  352. default:
  353. string = "unknown";
  354. break;
  355. }
  356. dev_info(dev, "%s: port %d, is for %s use\n",
  357. serial->type->description,
  358. connection_info->connections[i].port, string);
  359. }
  360. }
  361. /*
  362. * Handle devices that report invalid stuff here.
  363. */
  364. if (num_ports == 0 || num_ports > 2) {
  365. dev_warn(dev, "%s: No valid connect info available\n",
  366. serial->type->description);
  367. num_ports = 2;
  368. }
  369. dev_info(dev, "%s: Number of ports: %d\n", serial->type->description,
  370. num_ports);
  371. /*
  372. * save off our num_ports info so that we can use it in the
  373. * calc_num_ports callback
  374. */
  375. usb_set_serial_data(serial, (void *)(long)num_ports);
  376. /* ask for the number of bytes available, but ignore the
  377. response as it is broken */
  378. retval = usb_control_msg(serial->dev,
  379. usb_rcvctrlpipe(serial->dev, 0),
  380. VISOR_REQUEST_BYTES_AVAILABLE,
  381. 0xc2, 0x0000, 0x0005, transfer_buffer,
  382. 0x02, 300);
  383. if (retval < 0)
  384. dev_err(dev, "%s - error %d getting bytes available request\n",
  385. __func__, retval);
  386. retval = 0;
  387. exit:
  388. kfree(transfer_buffer);
  389. return retval;
  390. }
  391. static int palm_os_4_probe(struct usb_serial *serial,
  392. const struct usb_device_id *id)
  393. {
  394. struct device *dev = &serial->dev->dev;
  395. struct palm_ext_connection_info *connection_info;
  396. unsigned char *transfer_buffer;
  397. int retval;
  398. transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
  399. if (!transfer_buffer) {
  400. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
  401. sizeof(*connection_info));
  402. return -ENOMEM;
  403. }
  404. retval = usb_control_msg(serial->dev,
  405. usb_rcvctrlpipe(serial->dev, 0),
  406. PALM_GET_EXT_CONNECTION_INFORMATION,
  407. 0xc2, 0x0000, 0x0000, transfer_buffer,
  408. sizeof(*connection_info), 300);
  409. if (retval < 0)
  410. dev_err(dev, "%s - error %d getting connection info\n",
  411. __func__, retval);
  412. else
  413. usb_serial_debug_data(debug, &serial->dev->dev, __func__,
  414. retval, transfer_buffer);
  415. kfree(transfer_buffer);
  416. return 0;
  417. }
  418. static int visor_probe(struct usb_serial *serial,
  419. const struct usb_device_id *id)
  420. {
  421. int retval = 0;
  422. int (*startup)(struct usb_serial *serial,
  423. const struct usb_device_id *id);
  424. /*
  425. * some Samsung Android phones in modem mode have the same ID
  426. * as SPH-I500, but they are ACM devices, so dont bind to them
  427. */
  428. if (id->idVendor == SAMSUNG_VENDOR_ID &&
  429. id->idProduct == SAMSUNG_SPH_I500_ID &&
  430. serial->dev->descriptor.bDeviceClass == USB_CLASS_COMM &&
  431. serial->dev->descriptor.bDeviceSubClass ==
  432. USB_CDC_SUBCLASS_ACM)
  433. return -ENODEV;
  434. if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
  435. dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
  436. serial->dev->actconfig->desc.bConfigurationValue);
  437. return -ENODEV;
  438. }
  439. if (id->driver_info) {
  440. startup = (void *)id->driver_info;
  441. retval = startup(serial, id);
  442. }
  443. return retval;
  444. }
  445. static int visor_calc_num_ports(struct usb_serial *serial)
  446. {
  447. int num_ports = (int)(long)(usb_get_serial_data(serial));
  448. if (num_ports)
  449. usb_set_serial_data(serial, NULL);
  450. return num_ports;
  451. }
  452. static int clie_3_5_startup(struct usb_serial *serial)
  453. {
  454. struct device *dev = &serial->dev->dev;
  455. int result;
  456. u8 *data;
  457. data = kmalloc(1, GFP_KERNEL);
  458. if (!data)
  459. return -ENOMEM;
  460. /*
  461. * Note that PEG-300 series devices expect the following two calls.
  462. */
  463. /* get the config number */
  464. result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  465. USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
  466. 0, 0, data, 1, 3000);
  467. if (result < 0) {
  468. dev_err(dev, "%s: get config number failed: %d\n",
  469. __func__, result);
  470. goto out;
  471. }
  472. if (result != 1) {
  473. dev_err(dev, "%s: get config number bad return length: %d\n",
  474. __func__, result);
  475. result = -EIO;
  476. goto out;
  477. }
  478. /* get the interface number */
  479. result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  480. USB_REQ_GET_INTERFACE,
  481. USB_DIR_IN | USB_RECIP_INTERFACE,
  482. 0, 0, data, 1, 3000);
  483. if (result < 0) {
  484. dev_err(dev, "%s: get interface number failed: %d\n",
  485. __func__, result);
  486. goto out;
  487. }
  488. if (result != 1) {
  489. dev_err(dev,
  490. "%s: get interface number bad return length: %d\n",
  491. __func__, result);
  492. result = -EIO;
  493. goto out;
  494. }
  495. result = 0;
  496. out:
  497. kfree(data);
  498. return result;
  499. }
  500. static int treo_attach(struct usb_serial *serial)
  501. {
  502. struct usb_serial_port *swap_port;
  503. /* Only do this endpoint hack for the Handspring devices with
  504. * interrupt in endpoints, which for now are the Treo devices. */
  505. if (!((le16_to_cpu(serial->dev->descriptor.idVendor)
  506. == HANDSPRING_VENDOR_ID) ||
  507. (le16_to_cpu(serial->dev->descriptor.idVendor)
  508. == KYOCERA_VENDOR_ID)) ||
  509. (serial->num_interrupt_in == 0))
  510. return 0;
  511. /*
  512. * It appears that Treos and Kyoceras want to use the
  513. * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint,
  514. * so let's swap the 1st and 2nd bulk in and interrupt endpoints.
  515. * Note that swapping the bulk out endpoints would break lots of
  516. * apps that want to communicate on the second port.
  517. */
  518. #define COPY_PORT(dest, src) \
  519. do { \
  520. dest->read_urb = src->read_urb; \
  521. dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress;\
  522. dest->bulk_in_buffer = src->bulk_in_buffer; \
  523. dest->interrupt_in_urb = src->interrupt_in_urb; \
  524. dest->interrupt_in_endpointAddress = \
  525. src->interrupt_in_endpointAddress;\
  526. dest->interrupt_in_buffer = src->interrupt_in_buffer; \
  527. } while (0);
  528. swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL);
  529. if (!swap_port)
  530. return -ENOMEM;
  531. COPY_PORT(swap_port, serial->port[0]);
  532. COPY_PORT(serial->port[0], serial->port[1]);
  533. COPY_PORT(serial->port[1], swap_port);
  534. kfree(swap_port);
  535. return 0;
  536. }
  537. static int clie_5_attach(struct usb_serial *serial)
  538. {
  539. struct usb_serial_port *port;
  540. unsigned int pipe;
  541. int j;
  542. /* TH55 registers 2 ports.
  543. Communication in from the UX50/TH55 uses bulk_in_endpointAddress
  544. from port 0. Communication out to the UX50/TH55 uses
  545. bulk_out_endpointAddress from port 1
  546. Lets do a quick and dirty mapping
  547. */
  548. /* some sanity check */
  549. if (serial->num_ports < 2)
  550. return -1;
  551. /* port 0 now uses the modified endpoint Address */
  552. port = serial->port[0];
  553. port->bulk_out_endpointAddress =
  554. serial->port[1]->bulk_out_endpointAddress;
  555. pipe = usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress);
  556. for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j)
  557. port->write_urbs[j]->pipe = pipe;
  558. return 0;
  559. }
  560. module_usb_serial_driver(visor_driver, serial_drivers);
  561. MODULE_AUTHOR(DRIVER_AUTHOR);
  562. MODULE_DESCRIPTION(DRIVER_DESC);
  563. MODULE_LICENSE("GPL");
  564. module_param(debug, bool, S_IRUGO | S_IWUSR);
  565. MODULE_PARM_DESC(debug, "Debug enabled or not");