visor.c 21 KB

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