visor.c 17 KB

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