18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * USB HandSpring Visor, Palm m50x, and Sony Clie driver 48c2ecf20Sopenharmony_ci * (supports all of the Palm OS USB devices) 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 1999 - 2004 78c2ecf20Sopenharmony_ci * Greg Kroah-Hartman (greg@kroah.com) 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * See Documentation/usb/usb-serial.rst for more information on using this 108c2ecf20Sopenharmony_ci * driver 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/kernel.h> 158c2ecf20Sopenharmony_ci#include <linux/errno.h> 168c2ecf20Sopenharmony_ci#include <linux/slab.h> 178c2ecf20Sopenharmony_ci#include <linux/tty.h> 188c2ecf20Sopenharmony_ci#include <linux/tty_driver.h> 198c2ecf20Sopenharmony_ci#include <linux/tty_flip.h> 208c2ecf20Sopenharmony_ci#include <linux/module.h> 218c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 228c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 238c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 248c2ecf20Sopenharmony_ci#include <linux/usb.h> 258c2ecf20Sopenharmony_ci#include <linux/usb/serial.h> 268c2ecf20Sopenharmony_ci#include <linux/usb/cdc.h> 278c2ecf20Sopenharmony_ci#include "visor.h" 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* 308c2ecf20Sopenharmony_ci * Version Information 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" 338c2ecf20Sopenharmony_ci#define DRIVER_DESC "USB HandSpring Visor / Palm OS driver" 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* function prototypes for a handspring visor */ 368c2ecf20Sopenharmony_cistatic int visor_open(struct tty_struct *tty, struct usb_serial_port *port); 378c2ecf20Sopenharmony_cistatic void visor_close(struct usb_serial_port *port); 388c2ecf20Sopenharmony_cistatic int visor_probe(struct usb_serial *serial, 398c2ecf20Sopenharmony_ci const struct usb_device_id *id); 408c2ecf20Sopenharmony_cistatic int visor_calc_num_ports(struct usb_serial *serial, 418c2ecf20Sopenharmony_ci struct usb_serial_endpoints *epds); 428c2ecf20Sopenharmony_cistatic int clie_5_calc_num_ports(struct usb_serial *serial, 438c2ecf20Sopenharmony_ci struct usb_serial_endpoints *epds); 448c2ecf20Sopenharmony_cistatic void visor_read_int_callback(struct urb *urb); 458c2ecf20Sopenharmony_cistatic int clie_3_5_startup(struct usb_serial *serial); 468c2ecf20Sopenharmony_cistatic int palm_os_3_probe(struct usb_serial *serial, 478c2ecf20Sopenharmony_ci const struct usb_device_id *id); 488c2ecf20Sopenharmony_cistatic int palm_os_4_probe(struct usb_serial *serial, 498c2ecf20Sopenharmony_ci const struct usb_device_id *id); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic const struct usb_device_id id_table[] = { 528c2ecf20Sopenharmony_ci { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID), 538c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_3_probe }, 548c2ecf20Sopenharmony_ci { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID), 558c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 568c2ecf20Sopenharmony_ci { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID), 578c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 588c2ecf20Sopenharmony_ci { USB_DEVICE(GSPDA_VENDOR_ID, GSPDA_XPLORE_M68_ID), 598c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 608c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID), 618c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 628c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID), 638c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 648c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID), 658c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 668c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID), 678c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 688c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID), 698c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 708c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID), 718c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 728c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID), 738c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 748c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID), 758c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 768c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650), 778c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 788c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID), 798c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 808c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID), 818c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 828c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID), 838c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 848c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID), 858c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 868c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID), 878c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 888c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID), 898c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 908c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID), 918c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 928c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID), 938c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 948c2ecf20Sopenharmony_ci { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID), 958c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 968c2ecf20Sopenharmony_ci { USB_DEVICE_INTERFACE_CLASS(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID, 0xff), 978c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 988c2ecf20Sopenharmony_ci { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID), 998c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 1008c2ecf20Sopenharmony_ci { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID), 1018c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 1028c2ecf20Sopenharmony_ci { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID), 1038c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 1048c2ecf20Sopenharmony_ci { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID), 1058c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 1068c2ecf20Sopenharmony_ci { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID), 1078c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 1088c2ecf20Sopenharmony_ci { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID), 1098c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 1108c2ecf20Sopenharmony_ci { } /* Terminating entry */ 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic const struct usb_device_id clie_id_5_table[] = { 1148c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID), 1158c2ecf20Sopenharmony_ci .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 1168c2ecf20Sopenharmony_ci { } /* Terminating entry */ 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic const struct usb_device_id clie_id_3_5_table[] = { 1208c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) }, 1218c2ecf20Sopenharmony_ci { } /* Terminating entry */ 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic const struct usb_device_id id_table_combined[] = { 1258c2ecf20Sopenharmony_ci { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) }, 1268c2ecf20Sopenharmony_ci { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) }, 1278c2ecf20Sopenharmony_ci { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) }, 1288c2ecf20Sopenharmony_ci { USB_DEVICE(GSPDA_VENDOR_ID, GSPDA_XPLORE_M68_ID) }, 1298c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) }, 1308c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) }, 1318c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) }, 1328c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) }, 1338c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID) }, 1348c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) }, 1358c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) }, 1368c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID) }, 1378c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650) }, 1388c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID) }, 1398c2ecf20Sopenharmony_ci { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID) }, 1408c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) }, 1418c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) }, 1428c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) }, 1438c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID) }, 1448c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID) }, 1458c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID) }, 1468c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID) }, 1478c2ecf20Sopenharmony_ci { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID) }, 1488c2ecf20Sopenharmony_ci { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID) }, 1498c2ecf20Sopenharmony_ci { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID) }, 1508c2ecf20Sopenharmony_ci { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID) }, 1518c2ecf20Sopenharmony_ci { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID) }, 1528c2ecf20Sopenharmony_ci { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID) }, 1538c2ecf20Sopenharmony_ci { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID) }, 1548c2ecf20Sopenharmony_ci { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID) }, 1558c2ecf20Sopenharmony_ci { } /* Terminating entry */ 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(usb, id_table_combined); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/* All of the device info needed for the Handspring Visor, 1618c2ecf20Sopenharmony_ci and Palm 4.0 devices */ 1628c2ecf20Sopenharmony_cistatic struct usb_serial_driver handspring_device = { 1638c2ecf20Sopenharmony_ci .driver = { 1648c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 1658c2ecf20Sopenharmony_ci .name = "visor", 1668c2ecf20Sopenharmony_ci }, 1678c2ecf20Sopenharmony_ci .description = "Handspring Visor / Palm OS", 1688c2ecf20Sopenharmony_ci .id_table = id_table, 1698c2ecf20Sopenharmony_ci .num_ports = 2, 1708c2ecf20Sopenharmony_ci .bulk_out_size = 256, 1718c2ecf20Sopenharmony_ci .open = visor_open, 1728c2ecf20Sopenharmony_ci .close = visor_close, 1738c2ecf20Sopenharmony_ci .throttle = usb_serial_generic_throttle, 1748c2ecf20Sopenharmony_ci .unthrottle = usb_serial_generic_unthrottle, 1758c2ecf20Sopenharmony_ci .probe = visor_probe, 1768c2ecf20Sopenharmony_ci .calc_num_ports = visor_calc_num_ports, 1778c2ecf20Sopenharmony_ci .read_int_callback = visor_read_int_callback, 1788c2ecf20Sopenharmony_ci}; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci/* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */ 1818c2ecf20Sopenharmony_cistatic struct usb_serial_driver clie_5_device = { 1828c2ecf20Sopenharmony_ci .driver = { 1838c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 1848c2ecf20Sopenharmony_ci .name = "clie_5", 1858c2ecf20Sopenharmony_ci }, 1868c2ecf20Sopenharmony_ci .description = "Sony Clie 5.0", 1878c2ecf20Sopenharmony_ci .id_table = clie_id_5_table, 1888c2ecf20Sopenharmony_ci .num_ports = 2, 1898c2ecf20Sopenharmony_ci .num_bulk_out = 2, 1908c2ecf20Sopenharmony_ci .bulk_out_size = 256, 1918c2ecf20Sopenharmony_ci .open = visor_open, 1928c2ecf20Sopenharmony_ci .close = visor_close, 1938c2ecf20Sopenharmony_ci .throttle = usb_serial_generic_throttle, 1948c2ecf20Sopenharmony_ci .unthrottle = usb_serial_generic_unthrottle, 1958c2ecf20Sopenharmony_ci .probe = visor_probe, 1968c2ecf20Sopenharmony_ci .calc_num_ports = clie_5_calc_num_ports, 1978c2ecf20Sopenharmony_ci .read_int_callback = visor_read_int_callback, 1988c2ecf20Sopenharmony_ci}; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* device info for the Sony Clie OS version 3.5 */ 2018c2ecf20Sopenharmony_cistatic struct usb_serial_driver clie_3_5_device = { 2028c2ecf20Sopenharmony_ci .driver = { 2038c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 2048c2ecf20Sopenharmony_ci .name = "clie_3.5", 2058c2ecf20Sopenharmony_ci }, 2068c2ecf20Sopenharmony_ci .description = "Sony Clie 3.5", 2078c2ecf20Sopenharmony_ci .id_table = clie_id_3_5_table, 2088c2ecf20Sopenharmony_ci .num_ports = 1, 2098c2ecf20Sopenharmony_ci .bulk_out_size = 256, 2108c2ecf20Sopenharmony_ci .open = visor_open, 2118c2ecf20Sopenharmony_ci .close = visor_close, 2128c2ecf20Sopenharmony_ci .throttle = usb_serial_generic_throttle, 2138c2ecf20Sopenharmony_ci .unthrottle = usb_serial_generic_unthrottle, 2148c2ecf20Sopenharmony_ci .attach = clie_3_5_startup, 2158c2ecf20Sopenharmony_ci}; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistatic struct usb_serial_driver * const serial_drivers[] = { 2188c2ecf20Sopenharmony_ci &handspring_device, &clie_5_device, &clie_3_5_device, NULL 2198c2ecf20Sopenharmony_ci}; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci/****************************************************************************** 2228c2ecf20Sopenharmony_ci * Handspring Visor specific driver functions 2238c2ecf20Sopenharmony_ci ******************************************************************************/ 2248c2ecf20Sopenharmony_cistatic int visor_open(struct tty_struct *tty, struct usb_serial_port *port) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci int result = 0; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci if (!port->read_urb) { 2298c2ecf20Sopenharmony_ci /* this is needed for some brain dead Sony devices */ 2308c2ecf20Sopenharmony_ci dev_err(&port->dev, "Device lied about number of ports, please use a lower one.\n"); 2318c2ecf20Sopenharmony_ci return -ENODEV; 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci /* Start reading from the device */ 2358c2ecf20Sopenharmony_ci result = usb_serial_generic_open(tty, port); 2368c2ecf20Sopenharmony_ci if (result) 2378c2ecf20Sopenharmony_ci goto exit; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci if (port->interrupt_in_urb) { 2408c2ecf20Sopenharmony_ci dev_dbg(&port->dev, "adding interrupt input for treo\n"); 2418c2ecf20Sopenharmony_ci result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 2428c2ecf20Sopenharmony_ci if (result) 2438c2ecf20Sopenharmony_ci dev_err(&port->dev, 2448c2ecf20Sopenharmony_ci "%s - failed submitting interrupt urb, error %d\n", 2458c2ecf20Sopenharmony_ci __func__, result); 2468c2ecf20Sopenharmony_ci } 2478c2ecf20Sopenharmony_ciexit: 2488c2ecf20Sopenharmony_ci return result; 2498c2ecf20Sopenharmony_ci} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cistatic void visor_close(struct usb_serial_port *port) 2538c2ecf20Sopenharmony_ci{ 2548c2ecf20Sopenharmony_ci unsigned char *transfer_buffer; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci usb_serial_generic_close(port); 2578c2ecf20Sopenharmony_ci usb_kill_urb(port->interrupt_in_urb); 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci transfer_buffer = kmalloc(0x12, GFP_KERNEL); 2608c2ecf20Sopenharmony_ci if (!transfer_buffer) 2618c2ecf20Sopenharmony_ci return; 2628c2ecf20Sopenharmony_ci usb_control_msg(port->serial->dev, 2638c2ecf20Sopenharmony_ci usb_rcvctrlpipe(port->serial->dev, 0), 2648c2ecf20Sopenharmony_ci VISOR_CLOSE_NOTIFICATION, 0xc2, 2658c2ecf20Sopenharmony_ci 0x0000, 0x0000, 2668c2ecf20Sopenharmony_ci transfer_buffer, 0x12, 300); 2678c2ecf20Sopenharmony_ci kfree(transfer_buffer); 2688c2ecf20Sopenharmony_ci} 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_cistatic void visor_read_int_callback(struct urb *urb) 2718c2ecf20Sopenharmony_ci{ 2728c2ecf20Sopenharmony_ci struct usb_serial_port *port = urb->context; 2738c2ecf20Sopenharmony_ci int status = urb->status; 2748c2ecf20Sopenharmony_ci int result; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci switch (status) { 2778c2ecf20Sopenharmony_ci case 0: 2788c2ecf20Sopenharmony_ci /* success */ 2798c2ecf20Sopenharmony_ci break; 2808c2ecf20Sopenharmony_ci case -ECONNRESET: 2818c2ecf20Sopenharmony_ci case -ENOENT: 2828c2ecf20Sopenharmony_ci case -ESHUTDOWN: 2838c2ecf20Sopenharmony_ci /* this urb is terminated, clean up */ 2848c2ecf20Sopenharmony_ci dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n", 2858c2ecf20Sopenharmony_ci __func__, status); 2868c2ecf20Sopenharmony_ci return; 2878c2ecf20Sopenharmony_ci default: 2888c2ecf20Sopenharmony_ci dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n", 2898c2ecf20Sopenharmony_ci __func__, status); 2908c2ecf20Sopenharmony_ci goto exit; 2918c2ecf20Sopenharmony_ci } 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci /* 2948c2ecf20Sopenharmony_ci * This information is still unknown what it can be used for. 2958c2ecf20Sopenharmony_ci * If anyone has an idea, please let the author know... 2968c2ecf20Sopenharmony_ci * 2978c2ecf20Sopenharmony_ci * Rumor has it this endpoint is used to notify when data 2988c2ecf20Sopenharmony_ci * is ready to be read from the bulk ones. 2998c2ecf20Sopenharmony_ci */ 3008c2ecf20Sopenharmony_ci usb_serial_debug_data(&port->dev, __func__, urb->actual_length, 3018c2ecf20Sopenharmony_ci urb->transfer_buffer); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ciexit: 3048c2ecf20Sopenharmony_ci result = usb_submit_urb(urb, GFP_ATOMIC); 3058c2ecf20Sopenharmony_ci if (result) 3068c2ecf20Sopenharmony_ci dev_err(&urb->dev->dev, 3078c2ecf20Sopenharmony_ci "%s - Error %d submitting interrupt urb\n", 3088c2ecf20Sopenharmony_ci __func__, result); 3098c2ecf20Sopenharmony_ci} 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_cistatic int palm_os_3_probe(struct usb_serial *serial, 3128c2ecf20Sopenharmony_ci const struct usb_device_id *id) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci struct device *dev = &serial->dev->dev; 3158c2ecf20Sopenharmony_ci struct visor_connection_info *connection_info; 3168c2ecf20Sopenharmony_ci unsigned char *transfer_buffer; 3178c2ecf20Sopenharmony_ci char *string; 3188c2ecf20Sopenharmony_ci int retval = 0; 3198c2ecf20Sopenharmony_ci int i; 3208c2ecf20Sopenharmony_ci int num_ports = 0; 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL); 3238c2ecf20Sopenharmony_ci if (!transfer_buffer) 3248c2ecf20Sopenharmony_ci return -ENOMEM; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* send a get connection info request */ 3278c2ecf20Sopenharmony_ci retval = usb_control_msg(serial->dev, 3288c2ecf20Sopenharmony_ci usb_rcvctrlpipe(serial->dev, 0), 3298c2ecf20Sopenharmony_ci VISOR_GET_CONNECTION_INFORMATION, 3308c2ecf20Sopenharmony_ci 0xc2, 0x0000, 0x0000, transfer_buffer, 3318c2ecf20Sopenharmony_ci sizeof(*connection_info), 300); 3328c2ecf20Sopenharmony_ci if (retval < 0) { 3338c2ecf20Sopenharmony_ci dev_err(dev, "%s - error %d getting connection information\n", 3348c2ecf20Sopenharmony_ci __func__, retval); 3358c2ecf20Sopenharmony_ci goto exit; 3368c2ecf20Sopenharmony_ci } 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci if (retval != sizeof(*connection_info)) { 3398c2ecf20Sopenharmony_ci dev_err(dev, "Invalid connection information received from device\n"); 3408c2ecf20Sopenharmony_ci retval = -ENODEV; 3418c2ecf20Sopenharmony_ci goto exit; 3428c2ecf20Sopenharmony_ci } 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci connection_info = (struct visor_connection_info *)transfer_buffer; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci num_ports = le16_to_cpu(connection_info->num_ports); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci /* Handle devices that report invalid stuff here. */ 3498c2ecf20Sopenharmony_ci if (num_ports == 0 || num_ports > 2) { 3508c2ecf20Sopenharmony_ci dev_warn(dev, "%s: No valid connect info available\n", 3518c2ecf20Sopenharmony_ci serial->type->description); 3528c2ecf20Sopenharmony_ci num_ports = 2; 3538c2ecf20Sopenharmony_ci } 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci for (i = 0; i < num_ports; ++i) { 3568c2ecf20Sopenharmony_ci switch (connection_info->connections[i].port_function_id) { 3578c2ecf20Sopenharmony_ci case VISOR_FUNCTION_GENERIC: 3588c2ecf20Sopenharmony_ci string = "Generic"; 3598c2ecf20Sopenharmony_ci break; 3608c2ecf20Sopenharmony_ci case VISOR_FUNCTION_DEBUGGER: 3618c2ecf20Sopenharmony_ci string = "Debugger"; 3628c2ecf20Sopenharmony_ci break; 3638c2ecf20Sopenharmony_ci case VISOR_FUNCTION_HOTSYNC: 3648c2ecf20Sopenharmony_ci string = "HotSync"; 3658c2ecf20Sopenharmony_ci break; 3668c2ecf20Sopenharmony_ci case VISOR_FUNCTION_CONSOLE: 3678c2ecf20Sopenharmony_ci string = "Console"; 3688c2ecf20Sopenharmony_ci break; 3698c2ecf20Sopenharmony_ci case VISOR_FUNCTION_REMOTE_FILE_SYS: 3708c2ecf20Sopenharmony_ci string = "Remote File System"; 3718c2ecf20Sopenharmony_ci break; 3728c2ecf20Sopenharmony_ci default: 3738c2ecf20Sopenharmony_ci string = "unknown"; 3748c2ecf20Sopenharmony_ci break; 3758c2ecf20Sopenharmony_ci } 3768c2ecf20Sopenharmony_ci dev_info(dev, "%s: port %d, is for %s use\n", 3778c2ecf20Sopenharmony_ci serial->type->description, 3788c2ecf20Sopenharmony_ci connection_info->connections[i].port, string); 3798c2ecf20Sopenharmony_ci } 3808c2ecf20Sopenharmony_ci dev_info(dev, "%s: Number of ports: %d\n", serial->type->description, 3818c2ecf20Sopenharmony_ci num_ports); 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci /* 3848c2ecf20Sopenharmony_ci * save off our num_ports info so that we can use it in the 3858c2ecf20Sopenharmony_ci * calc_num_ports callback 3868c2ecf20Sopenharmony_ci */ 3878c2ecf20Sopenharmony_ci usb_set_serial_data(serial, (void *)(long)num_ports); 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci /* ask for the number of bytes available, but ignore the 3908c2ecf20Sopenharmony_ci response as it is broken */ 3918c2ecf20Sopenharmony_ci retval = usb_control_msg(serial->dev, 3928c2ecf20Sopenharmony_ci usb_rcvctrlpipe(serial->dev, 0), 3938c2ecf20Sopenharmony_ci VISOR_REQUEST_BYTES_AVAILABLE, 3948c2ecf20Sopenharmony_ci 0xc2, 0x0000, 0x0005, transfer_buffer, 3958c2ecf20Sopenharmony_ci 0x02, 300); 3968c2ecf20Sopenharmony_ci if (retval < 0) 3978c2ecf20Sopenharmony_ci dev_err(dev, "%s - error %d getting bytes available request\n", 3988c2ecf20Sopenharmony_ci __func__, retval); 3998c2ecf20Sopenharmony_ci retval = 0; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ciexit: 4028c2ecf20Sopenharmony_ci kfree(transfer_buffer); 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci return retval; 4058c2ecf20Sopenharmony_ci} 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_cistatic int palm_os_4_probe(struct usb_serial *serial, 4088c2ecf20Sopenharmony_ci const struct usb_device_id *id) 4098c2ecf20Sopenharmony_ci{ 4108c2ecf20Sopenharmony_ci struct device *dev = &serial->dev->dev; 4118c2ecf20Sopenharmony_ci struct palm_ext_connection_info *connection_info; 4128c2ecf20Sopenharmony_ci unsigned char *transfer_buffer; 4138c2ecf20Sopenharmony_ci int retval; 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL); 4168c2ecf20Sopenharmony_ci if (!transfer_buffer) 4178c2ecf20Sopenharmony_ci return -ENOMEM; 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci retval = usb_control_msg(serial->dev, 4208c2ecf20Sopenharmony_ci usb_rcvctrlpipe(serial->dev, 0), 4218c2ecf20Sopenharmony_ci PALM_GET_EXT_CONNECTION_INFORMATION, 4228c2ecf20Sopenharmony_ci 0xc2, 0x0000, 0x0000, transfer_buffer, 4238c2ecf20Sopenharmony_ci sizeof(*connection_info), 300); 4248c2ecf20Sopenharmony_ci if (retval < 0) 4258c2ecf20Sopenharmony_ci dev_err(dev, "%s - error %d getting connection info\n", 4268c2ecf20Sopenharmony_ci __func__, retval); 4278c2ecf20Sopenharmony_ci else 4288c2ecf20Sopenharmony_ci usb_serial_debug_data(dev, __func__, retval, transfer_buffer); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci kfree(transfer_buffer); 4318c2ecf20Sopenharmony_ci return 0; 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_cistatic int visor_probe(struct usb_serial *serial, 4368c2ecf20Sopenharmony_ci const struct usb_device_id *id) 4378c2ecf20Sopenharmony_ci{ 4388c2ecf20Sopenharmony_ci int retval = 0; 4398c2ecf20Sopenharmony_ci int (*startup)(struct usb_serial *serial, 4408c2ecf20Sopenharmony_ci const struct usb_device_id *id); 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci /* 4438c2ecf20Sopenharmony_ci * some Samsung Android phones in modem mode have the same ID 4448c2ecf20Sopenharmony_ci * as SPH-I500, but they are ACM devices, so dont bind to them 4458c2ecf20Sopenharmony_ci */ 4468c2ecf20Sopenharmony_ci if (id->idVendor == SAMSUNG_VENDOR_ID && 4478c2ecf20Sopenharmony_ci id->idProduct == SAMSUNG_SPH_I500_ID && 4488c2ecf20Sopenharmony_ci serial->dev->descriptor.bDeviceClass == USB_CLASS_COMM && 4498c2ecf20Sopenharmony_ci serial->dev->descriptor.bDeviceSubClass == 4508c2ecf20Sopenharmony_ci USB_CDC_SUBCLASS_ACM) 4518c2ecf20Sopenharmony_ci return -ENODEV; 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 4548c2ecf20Sopenharmony_ci dev_err(&serial->dev->dev, "active config #%d != 1 ??\n", 4558c2ecf20Sopenharmony_ci serial->dev->actconfig->desc.bConfigurationValue); 4568c2ecf20Sopenharmony_ci return -ENODEV; 4578c2ecf20Sopenharmony_ci } 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci if (id->driver_info) { 4608c2ecf20Sopenharmony_ci startup = (void *)id->driver_info; 4618c2ecf20Sopenharmony_ci retval = startup(serial, id); 4628c2ecf20Sopenharmony_ci } 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci return retval; 4658c2ecf20Sopenharmony_ci} 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_cistatic int visor_calc_num_ports(struct usb_serial *serial, 4688c2ecf20Sopenharmony_ci struct usb_serial_endpoints *epds) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci unsigned int vid = le16_to_cpu(serial->dev->descriptor.idVendor); 4718c2ecf20Sopenharmony_ci int num_ports = (int)(long)(usb_get_serial_data(serial)); 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci if (num_ports) 4748c2ecf20Sopenharmony_ci usb_set_serial_data(serial, NULL); 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci /* 4778c2ecf20Sopenharmony_ci * Only swap the bulk endpoints for the Handspring devices with 4788c2ecf20Sopenharmony_ci * interrupt in endpoints, which for now are the Treo devices. 4798c2ecf20Sopenharmony_ci */ 4808c2ecf20Sopenharmony_ci if (!(vid == HANDSPRING_VENDOR_ID || vid == KYOCERA_VENDOR_ID) || 4818c2ecf20Sopenharmony_ci epds->num_interrupt_in == 0) 4828c2ecf20Sopenharmony_ci goto out; 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci if (epds->num_bulk_in < 2 || epds->num_interrupt_in < 2) { 4858c2ecf20Sopenharmony_ci dev_err(&serial->interface->dev, "missing endpoints\n"); 4868c2ecf20Sopenharmony_ci return -ENODEV; 4878c2ecf20Sopenharmony_ci } 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci /* 4908c2ecf20Sopenharmony_ci * It appears that Treos and Kyoceras want to use the 4918c2ecf20Sopenharmony_ci * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint, 4928c2ecf20Sopenharmony_ci * so let's swap the 1st and 2nd bulk in and interrupt endpoints. 4938c2ecf20Sopenharmony_ci * Note that swapping the bulk out endpoints would break lots of 4948c2ecf20Sopenharmony_ci * apps that want to communicate on the second port. 4958c2ecf20Sopenharmony_ci */ 4968c2ecf20Sopenharmony_ci swap(epds->bulk_in[0], epds->bulk_in[1]); 4978c2ecf20Sopenharmony_ci swap(epds->interrupt_in[0], epds->interrupt_in[1]); 4988c2ecf20Sopenharmony_ciout: 4998c2ecf20Sopenharmony_ci return num_ports; 5008c2ecf20Sopenharmony_ci} 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_cistatic int clie_5_calc_num_ports(struct usb_serial *serial, 5038c2ecf20Sopenharmony_ci struct usb_serial_endpoints *epds) 5048c2ecf20Sopenharmony_ci{ 5058c2ecf20Sopenharmony_ci /* 5068c2ecf20Sopenharmony_ci * TH55 registers 2 ports. 5078c2ecf20Sopenharmony_ci * Communication in from the UX50/TH55 uses the first bulk-in 5088c2ecf20Sopenharmony_ci * endpoint, while communication out to the UX50/TH55 uses the second 5098c2ecf20Sopenharmony_ci * bulk-out endpoint. 5108c2ecf20Sopenharmony_ci */ 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci /* 5138c2ecf20Sopenharmony_ci * FIXME: Should we swap the descriptors instead of using the same 5148c2ecf20Sopenharmony_ci * bulk-out endpoint for both ports? 5158c2ecf20Sopenharmony_ci */ 5168c2ecf20Sopenharmony_ci epds->bulk_out[0] = epds->bulk_out[1]; 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci return serial->type->num_ports; 5198c2ecf20Sopenharmony_ci} 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_cistatic int clie_3_5_startup(struct usb_serial *serial) 5228c2ecf20Sopenharmony_ci{ 5238c2ecf20Sopenharmony_ci struct device *dev = &serial->dev->dev; 5248c2ecf20Sopenharmony_ci int result; 5258c2ecf20Sopenharmony_ci u8 *data; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci data = kmalloc(1, GFP_KERNEL); 5288c2ecf20Sopenharmony_ci if (!data) 5298c2ecf20Sopenharmony_ci return -ENOMEM; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci /* 5328c2ecf20Sopenharmony_ci * Note that PEG-300 series devices expect the following two calls. 5338c2ecf20Sopenharmony_ci */ 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci /* get the config number */ 5368c2ecf20Sopenharmony_ci result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 5378c2ecf20Sopenharmony_ci USB_REQ_GET_CONFIGURATION, USB_DIR_IN, 5388c2ecf20Sopenharmony_ci 0, 0, data, 1, 3000); 5398c2ecf20Sopenharmony_ci if (result < 0) { 5408c2ecf20Sopenharmony_ci dev_err(dev, "%s: get config number failed: %d\n", 5418c2ecf20Sopenharmony_ci __func__, result); 5428c2ecf20Sopenharmony_ci goto out; 5438c2ecf20Sopenharmony_ci } 5448c2ecf20Sopenharmony_ci if (result != 1) { 5458c2ecf20Sopenharmony_ci dev_err(dev, "%s: get config number bad return length: %d\n", 5468c2ecf20Sopenharmony_ci __func__, result); 5478c2ecf20Sopenharmony_ci result = -EIO; 5488c2ecf20Sopenharmony_ci goto out; 5498c2ecf20Sopenharmony_ci } 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci /* get the interface number */ 5528c2ecf20Sopenharmony_ci result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 5538c2ecf20Sopenharmony_ci USB_REQ_GET_INTERFACE, 5548c2ecf20Sopenharmony_ci USB_DIR_IN | USB_RECIP_INTERFACE, 5558c2ecf20Sopenharmony_ci 0, 0, data, 1, 3000); 5568c2ecf20Sopenharmony_ci if (result < 0) { 5578c2ecf20Sopenharmony_ci dev_err(dev, "%s: get interface number failed: %d\n", 5588c2ecf20Sopenharmony_ci __func__, result); 5598c2ecf20Sopenharmony_ci goto out; 5608c2ecf20Sopenharmony_ci } 5618c2ecf20Sopenharmony_ci if (result != 1) { 5628c2ecf20Sopenharmony_ci dev_err(dev, 5638c2ecf20Sopenharmony_ci "%s: get interface number bad return length: %d\n", 5648c2ecf20Sopenharmony_ci __func__, result); 5658c2ecf20Sopenharmony_ci result = -EIO; 5668c2ecf20Sopenharmony_ci goto out; 5678c2ecf20Sopenharmony_ci } 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci result = 0; 5708c2ecf20Sopenharmony_ciout: 5718c2ecf20Sopenharmony_ci kfree(data); 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci return result; 5748c2ecf20Sopenharmony_ci} 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_cimodule_usb_serial_driver(serial_drivers, id_table_combined); 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ciMODULE_AUTHOR(DRIVER_AUTHOR); 5798c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(DRIVER_DESC); 5808c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 581