| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484 |
- --- /dev/null
- +++ b/drivers/usb/serial/sierra.c
- @@ -0,0 +1,1446 @@
- +/*
- + * Sierra Wireless CDMA Wireless Serial USB drive
- + *
- + * Current Copy modified by: Kevin Lloyd <[email protected]>
- + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License version
- + * 2 as published by the Free Software Foundation.
- + *
- + * Version history:
- + Version 1.03 (Lloyd):
- + Included support for DTR control and enhanced buffering (should help
- + speed).
- + */
- +
- +#include <linux/config.h>
- +#include <linux/kernel.h>
- +#include <linux/init.h>
- +#include <linux/slab.h>
- +#include <linux/tty.h>
- +#include <linux/tty_driver.h>
- +#include <linux/tty_flip.h>
- +#include <linux/module.h>
- +#include <linux/usb.h>
- +#include <linux/mm.h>
- +#include <asm/uaccess.h>
- +#include <linux/errno.h>
- +#include <linux/list.h>
- +#include <linux/spinlock.h>
- +#include <linux/smp_lock.h>
- +
- +#ifdef CONFIG_USB_SERIAL_DEBUG
- + static int debug = 1;
- +#else
- + static int debug;
- +#endif
- +
- +#include "usb-serial.h"
- +#include "sierra.h"
- +#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
- +#include "pl2303.h" // see /* BEGIN HORRIBLE HACK FOR PL2303 */ below
- +#endif
- +
- +#define DRIVER_VERSION "v1.03"
- +
- +#if 0
- +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
- +
- +#define USB_DEVICE_POWER_STATE_D0 0x0000
- +#define USB_DEVICE_POWER_STATE_D1 0x0001
- +#define USB_DEVICE_POWER_STATE_D2 0x0002
- +#define USB_DEVICE_POWER_STATE_D3 0x0003
- +
- +#define SET_CONTROL_LINE_STATE 0x22
- +/*
- + * Output control lines.
- + */
- +
- +#define ACM_CTRL_DTR 0x01
- +#define ACM_CTRL_RTS 0x02
- +#endif
- +
- +//static int sw_attach(struct usb_serial *serial);
- +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial);
- +
- +static int sw_usb_serial_generic_open(struct usb_serial_port *port, struct file *filp);
- +static void sw_usb_serial_generic_close(struct usb_serial_port *port, struct file *filp);
- +
- +#if 1
- +/*-----------------------------------------------------------*/
- +static int serial_refcount;
- +static struct tty_driver serial_tty_driver;
- +static struct tty_struct * serial_tty[SERIAL_TTY_MINORS];
- +static struct termios * serial_termios[SERIAL_TTY_MINORS];
- +static struct termios * serial_termios_locked[SERIAL_TTY_MINORS];
- +static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */
- +
- +static LIST_HEAD(usb_serial_driver_list);
- +static struct usb_serial *get_free_serial (int num_ports, int *minor);
- +static void generic_write_bulk_callback (struct urb *urb);
- +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,const struct usb_device_id *id);
- +static void usb_serial_disconnect(struct usb_device *dev, void *ptr);
- +static void sw_usb_serial_generic_read_bulk_callback (struct urb *urb);
- +static void port_softint(void *private);
- +static void return_serial (struct usb_serial *serial);
- +static struct usb_serial *get_free_serial (int num_ports, int *minor);
- +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data);
- +/*-----------------------------------------------------------*/
- +
- +#endif
- +
- +
- +static struct usb_device_id id_table [] = {
- + { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
- + { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
- + { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
- + { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
- + { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
- + { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
- + { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
- + { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
- + { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
- + { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless C597 */
- +
- + { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
- + { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
- + { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
- + { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
- + { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
- + { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */
- + { USB_DEVICE(0x03f0, 0x1e1d) }, /* HP hs2300 a.k.a MC8775 */
- + { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
- + { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */
- + { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
- + { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
- + { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite*/
- + { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
- + { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
- + { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
- + { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
- + { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
- + { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
- + { USB_DEVICE(0x1199, 0x6859) }, /* Sierra Wireless AirCard 885 E */
- + { USB_DEVICE(0x1199, 0x685A) }, /* Sierra Wireless AirCard 885 E */
- +
- + { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
- + { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
- +
- + { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
- + { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra Wireless PC 5220 */
- + { USB_DEVICE(0x05C6, 0x6613) }, /* Onda H600/ZTE MF330 */
- + { }
- +};
- +
- +MODULE_DEVICE_TABLE(usb, id_table);
- +
- +static struct usb_driver sierra_driver = {
- +// .owner = THIS_MODULE,
- + .name = "Sierra wireless",
- + .probe = usb_serial_probe,
- + .disconnect = usb_serial_disconnect,
- + .id_table = id_table,
- +};
- +
- +static struct usb_serial_device_type sierra_device = {
- +// .driver = {
- + .owner = THIS_MODULE,
- + .name = "Sierra Wireless",
- +// },
- + .id_table = id_table,
- + .num_interrupt_in = NUM_DONT_CARE,
- + .num_bulk_in = NUM_DONT_CARE,
- + .num_bulk_out = NUM_DONT_CARE,
- + .num_ports = 3,
- + //.startup = sw_attach,
- + .shutdown = sw_usb_serial_generic_shutdown,
- + .open = sw_usb_serial_generic_open,
- + .close = sw_usb_serial_generic_close,
- +};
- +
- +#define MAX_NUM_PORTS 8
- +
- +/* local function prototypes */
- +static int serial_open (struct tty_struct *tty, struct file * filp);
- +static void serial_close (struct tty_struct *tty, struct file * filp);
- +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count);
- +static int serial_write_room (struct tty_struct *tty);
- +static int serial_chars_in_buffer (struct tty_struct *tty);
- +static void serial_throttle (struct tty_struct * tty);
- +static void serial_unthrottle (struct tty_struct * tty);
- +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg);
- +static void serial_set_termios (struct tty_struct *tty, struct termios * old);
- +//static void serial_shutdown (struct usb_serial *serial);
- +static void serial_break (struct tty_struct *tty, int break_state);
- +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
- +static int generic_write_room (struct usb_serial_port *port);
- +static void generic_cleanup (struct usb_serial_port *port);
- +static int generic_chars_in_buffer (struct usb_serial_port *port);
- +//static void generic_shutdown (struct usb_serial *serial);
- +
- +#if 1
- +static struct tty_driver serial_tty_driver = {
- + .magic = TTY_DRIVER_MAGIC,
- + .driver_name = "usb-serial",
- +#ifndef CONFIG_DEVFS_FS
- + .name = "ttyUSB",
- +#else
- + .name = "usb/tts/%d",
- +#endif
- + .major = SERIAL_TTY_MAJOR,
- + .minor_start = 0,
- + .num = SERIAL_TTY_MINORS,
- + .type = TTY_DRIVER_TYPE_SERIAL,
- + .subtype = SERIAL_TYPE_NORMAL,
- + .flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
- +
- + .refcount = &serial_refcount,
- + .table = serial_tty,
- + .termios = serial_termios,
- + .termios_locked = serial_termios_locked,
- +
- + .open = serial_open,
- + .close = serial_close,
- + .write = serial_write,
- + .write_room = serial_write_room,
- + .ioctl = serial_ioctl,
- + .set_termios = serial_set_termios,
- + .throttle = serial_throttle,
- + .unthrottle = serial_unthrottle,
- + .break_ctl = serial_break,
- + .chars_in_buffer = serial_chars_in_buffer,
- + .read_proc = serial_read_proc,
- +};
- +#endif
- +
- +
- +/*****************************************************************************
- + * Driver tty interface functions
- + *****************************************************************************/
- +static struct usb_serial *get_serial_by_minor (unsigned int minor)
- +{
- + return serial_table[minor];
- +}
- +
- +static int serial_open (struct tty_struct *tty, struct file * filp)
- +{
- + struct usb_serial *serial;
- + struct usb_serial_port *port;
- + unsigned int portNumber;
- + int retval = 0;
- +
- + dbg("%s", __FUNCTION__);
- +
- + /* initialize the pointer incase something fails */
- + tty->driver_data = NULL;
- +
- + /* get the serial object associated with this tty pointer */
- + serial = get_serial_by_minor (MINOR(tty->device));
- +
- + if (serial_paranoia_check (serial, __FUNCTION__))
- + return -ENODEV;
- +
- + /* set up our port structure making the tty driver remember our port object, and us it */
- + portNumber = MINOR(tty->device) - serial->minor;
- + port = &serial->port[portNumber];
- + tty->driver_data = port;
- +
- + down (&port->sem);
- + port->tty = tty;
- +
- + /* lock this module before we call it */
- + if (serial->type->owner)
- + __MOD_INC_USE_COUNT(serial->type->owner);
- +
- + ++port->open_count;
- + if (port->open_count == 1) {
- + /* only call the device specific open if this
- + * is the first time the port is opened */
- + if (serial->type->open)
- + retval = serial->type->open(port, filp);
- + else
- + retval = sw_usb_serial_generic_open(port, filp);//@.@
- + }
- +
- + if (retval) {
- + port->open_count = 0;
- + if (serial->type->owner)
- + __MOD_DEC_USE_COUNT(serial->type->owner);
- + }
- +
- + up (&port->sem);
- + return retval;
- +}
- +
- +static void __serial_close(struct usb_serial_port *port, struct file *filp)
- +{
- + if (!port->open_count) {
- + dbg ("%s - port not opened", __FUNCTION__);
- + return;
- + }
- +
- + --port->open_count;
- + if (port->open_count <= 0) {
- + /* only call the device specific close if this
- + * port is being closed by the last owner */
- + if (port->serial->type->close)
- + port->serial->type->close(port, filp);
- + else
- + //generic_close(port, filp);
- + sw_usb_serial_generic_close(port, filp);
- + port->open_count = 0;
- + }
- +
- + if (port->serial->type->owner)
- + __MOD_DEC_USE_COUNT(port->serial->type->owner);
- +}
- +
- +static void serial_close(struct tty_struct *tty, struct file * filp)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- +
- + if (!serial)
- + return;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + /* if disconnect beat us to the punch here, there's nothing to do */
- + if (tty->driver_data) {
- + __serial_close(port, filp);
- + }
- +
- + up (&port->sem);
- +}
- +
- +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- + int retval = -EINVAL;
- +
- + if (!serial)
- + return -ENODEV;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
- +
- + if (!port->open_count) {
- + dbg("%s - port not opened", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function if it is available */
- + if (serial->type->write)
- + retval = serial->type->write(port, from_user, buf, count);
- + else
- + retval = generic_write(port, from_user, buf, count);
- +
- +exit:
- + up (&port->sem);
- + return retval;
- +}
- +
- +static int serial_write_room (struct tty_struct *tty)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- + int retval = -EINVAL;
- +
- + if (!serial)
- + return -ENODEV;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (!port->open_count) {
- + dbg("%s - port not open", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function if it is available */
- + if (serial->type->write_room)
- + retval = serial->type->write_room(port);
- + else
- + retval = generic_write_room(port);
- +
- +exit:
- + up (&port->sem);
- + return retval;
- +}
- +
- +static int serial_chars_in_buffer (struct tty_struct *tty)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- + int retval = -EINVAL;
- +
- + if (!serial)
- + return -ENODEV;
- +
- + down (&port->sem);
- +
- + dbg("%s = port %d", __FUNCTION__, port->number);
- +
- + if (!port->open_count) {
- + dbg("%s - port not open", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function if it is available */
- + if (serial->type->chars_in_buffer)
- + retval = serial->type->chars_in_buffer(port);
- + else
- + retval = generic_chars_in_buffer(port);
- +
- +exit:
- + up (&port->sem);
- + return retval;
- +}
- +
- +static void serial_throttle (struct tty_struct * tty)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- +
- + if (!serial)
- + return;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (!port->open_count) {
- + dbg ("%s - port not open", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function */
- + if (serial->type->throttle)
- + serial->type->throttle(port);
- +
- +exit:
- + up (&port->sem);
- +}
- +
- +static void serial_unthrottle (struct tty_struct * tty)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- +
- + if (!serial)
- + return;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (!port->open_count) {
- + dbg("%s - port not open", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function */
- + if (serial->type->unthrottle)
- + serial->type->unthrottle(port);
- +
- +exit:
- + up (&port->sem);
- +}
- +
- +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- + int retval = -ENODEV;
- +
- + if (!serial)
- + return -ENODEV;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
- +
- + if (!port->open_count) {
- + dbg ("%s - port not open", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function if it is available */
- + if (serial->type->ioctl)
- + retval = serial->type->ioctl(port, file, cmd, arg);
- + else
- + retval = -ENOIOCTLCMD;
- +
- +exit:
- + up (&port->sem);
- + return retval;
- +}
- +
- +static void serial_set_termios (struct tty_struct *tty, struct termios * old)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- +
- + if (!serial)
- + return;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (!port->open_count) {
- + dbg("%s - port not open", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function if it is available */
- + if (serial->type->set_termios)
- + serial->type->set_termios(port, old);
- +
- +exit:
- + up (&port->sem);
- +}
- +
- +static void serial_break (struct tty_struct *tty, int break_state)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- +
- + if (!serial)
- + return;
- +
- + down (&port->sem);
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (!port->open_count) {
- + dbg("%s - port not open", __FUNCTION__);
- + goto exit;
- + }
- +
- + /* pass on to the driver specific version of this function if it is available */
- + if (serial->type->break_ctl)
- + serial->type->break_ctl(port, break_state);
- +
- +exit:
- + up (&port->sem);
- +}
- +#if 0
- +static void serial_shutdown (struct usb_serial *serial)
- +{
- + dbg ("%s", __FUNCTION__);
- +
- + if (serial->type->shutdown)
- + serial->type->shutdown(serial);
- + else
- + generic_shutdown(serial);
- +}
- +#endif
- +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
- +{
- + struct usb_serial *serial;
- + int length = 0;
- + int i;
- + off_t begin = 0;
- + char tmp[40];
- +
- + dbg("%s", __FUNCTION__);
- + length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION);
- + for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
- + serial = get_serial_by_minor(i);
- + if (serial == NULL)
- + continue;
- +
- + length += sprintf (page+length, "%d:", i);
- + if (serial->type->owner)
- + length += sprintf (page+length, " module:%s", serial->type->owner->name);
- + length += sprintf (page+length, " name:\"%s\"", serial->type->name);
- + length += sprintf (page+length, " vendor:%04x product:%04x", serial->vendor, serial->product);
- + length += sprintf (page+length, " num_ports:%d", serial->num_ports);
- + length += sprintf (page+length, " port:%d", i - serial->minor + 1);
- +
- + usb_make_path(serial->dev, tmp, sizeof(tmp));
- + length += sprintf (page+length, " path:%s", tmp);
- +
- + length += sprintf (page+length, "\n");
- + if ((length + begin) > (off + count))
- + goto done;
- + if ((length + begin) < off) {
- + begin += length;
- + length = 0;
- + }
- + }
- + *eof = 1;
- +done:
- + if (off >= (length + begin))
- + return 0;
- + *start = page + (off-begin);
- + return ((count < begin+length-off) ? count : begin+length-off);
- +}
- +
- +
- +/*-----------------------------------------------------------*/
- +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
- +{
- + struct usb_serial *serial = port->serial;
- + int result;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (count == 0) {
- + dbg("%s - write request of 0 bytes", __FUNCTION__);
- + return (0);
- + }
- +
- + /* only do something if we have a bulk out endpoint */
- + if (serial->num_bulk_out) {
- + if (port->write_urb->status == -EINPROGRESS) {
- + dbg("%s - already writing", __FUNCTION__);
- + return (0);
- + }
- +
- + count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
- +
- + if (from_user) {
- + if (copy_from_user(port->write_urb->transfer_buffer, buf, count))
- + return -EFAULT;
- + }
- + else {
- + memcpy (port->write_urb->transfer_buffer, buf, count);
- + }
- +
- + usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
- +
- + /* set up our urb */
- + usb_fill_bulk_urb (port->write_urb, serial->dev,
- + usb_sndbulkpipe (serial->dev,
- + port->bulk_out_endpointAddress),
- + port->write_urb->transfer_buffer, count,
- + ((serial->type->write_bulk_callback) ?
- + serial->type->write_bulk_callback :
- + generic_write_bulk_callback), port);
- +
- + /* send the data out the bulk port */
- + result = usb_submit_urb(port->write_urb);
- + if (result)
- + err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
- + else
- + result = count;
- +
- + return result;
- + }
- +
- + /* no bulk out, so return 0 bytes written */
- + return (0);
- +}
- +
- +static int generic_write_room (struct usb_serial_port *port)
- +{
- + struct usb_serial *serial = port->serial;
- + int room = 0;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (serial->num_bulk_out) {
- + if (port->write_urb->status != -EINPROGRESS)
- + room = port->bulk_out_size;
- + }
- +
- + dbg("%s - returns %d", __FUNCTION__, room);
- + return (room);
- +}
- +
- +static int generic_chars_in_buffer (struct usb_serial_port *port)
- +{
- + struct usb_serial *serial = port->serial;
- + int chars = 0;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (serial->num_bulk_out) {
- + if (port->write_urb->status == -EINPROGRESS)
- + chars = port->write_urb->transfer_buffer_length;
- + }
- +
- + dbg("%s - returns %d", __FUNCTION__, chars);
- + return (chars);
- +}
- +#if 0
- +static void generic_shutdown (struct usb_serial *serial)
- +{
- + int i;
- +
- + dbg("%s", __FUNCTION__);
- +
- + /* stop reads and writes on all ports */
- + for (i=0; i < serial->num_ports; ++i) {
- + generic_cleanup (&serial->port[i]);
- + }
- +}
- +static void generic_cleanup (struct usb_serial_port *port)
- +{
- + struct usb_serial *serial = port->serial;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (serial->dev) {
- + /* shutdown any bulk reads that might be going on */
- + if (serial->num_bulk_out)
- + usb_unlink_urb (port->write_urb);
- + if (serial->num_bulk_in)
- + usb_unlink_urb (port->read_urb);
- + }
- +}
- +#endif
- +/*----------------------------------------------------------*/
- +static void generic_write_bulk_callback (struct urb *urb)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (!serial) {
- + dbg("%s - bad serial pointer, exiting", __FUNCTION__);
- + return;
- + }
- +
- + if (urb->status) {
- + dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
- + return;
- + }
- +
- + queue_task(&port->tqueue, &tq_immediate);
- + mark_bh(IMMEDIATE_BH);
- +
- + return;
- +}
- +
- +static struct usb_serial *get_free_serial (int num_ports, int *minor)
- +{
- + struct usb_serial *serial = NULL;
- + int i, j;
- + int good_spot;
- +
- + dbg("%s %d", __FUNCTION__, num_ports);
- +
- + *minor = 0;
- + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
- + if (serial_table[i])
- + continue;
- +
- + good_spot = 1;
- + for (j = 1; j <= num_ports-1; ++j)
- + if (serial_table[i+j])
- + good_spot = 0;
- + if (good_spot == 0)
- + continue;
- +
- + if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) {
- + err("%s - Out of memory", __FUNCTION__);
- + return NULL;
- + }
- + memset(serial, 0, sizeof(struct usb_serial));
- + serial->magic = USB_SERIAL_MAGIC;
- + serial_table[i] = serial;
- + *minor = i;
- + dbg("%s - minor base = %d", __FUNCTION__, *minor);
- + for (i = *minor+1; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i)
- + serial_table[i] = serial;
- + return serial;
- + }
- + return NULL;
- +}
- +
- +static void return_serial (struct usb_serial *serial)
- +{
- + int i;
- +
- + dbg("%s", __FUNCTION__);
- +
- + if (serial == NULL)
- + return;
- +
- + for (i = 0; i < serial->num_ports; ++i) {
- + serial_table[serial->minor + i] = NULL;
- + }
- +
- + return;
- +}
- +
- +static void port_softint(void *private)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *)private;
- + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- + struct tty_struct *tty;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (!serial)
- + return;
- +
- + tty = port->tty;
- + if (!tty)
- + return;
- +
- + if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) {
- + dbg("%s - write wakeup call.", __FUNCTION__);
- + (tty->ldisc.write_wakeup)(tty);
- + }
- +
- + wake_up_interruptible(&tty->write_wait);
- +}
- +
- +
- +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,
- + const struct usb_device_id *id)
- +{
- + struct usb_serial *serial = NULL;
- + struct usb_serial_port *port;
- + struct usb_interface *interface;
- + struct usb_interface_descriptor *iface_desc;
- + struct usb_endpoint_descriptor *endpoint;
- + struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS];
- + struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS];
- + struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS];
- + struct usb_serial_device_type *type = NULL;
- + struct list_head *tmp;
- + int found;
- + int minor;
- + int buffer_size;
- + int i;
- + int num_interrupt_in = 0;
- + int num_bulk_in = 0;
- + int num_bulk_out = 0;
- + int num_ports;
- + int max_endpoints;
- + const struct usb_device_id *id_pattern = NULL;
- +
- + /* loop through our list of known serial converters, and see if this
- + device matches. */
- + found = 0;
- + interface = &dev->actconfig->interface[ifnum];
- + list_for_each (tmp, &usb_serial_driver_list) {
- + type = list_entry(tmp, struct usb_serial_device_type, driver_list);
- + id_pattern = usb_match_id(dev, interface, type->id_table);
- + if (id_pattern != NULL) {
- + dbg("descriptor matches");
- + found = 1;
- + break;
- + }
- + }
- + if (!found) {
- + /* no match */
- + dbg("none matched");
- + return(NULL);
- + }
- + /* descriptor matches, let's find the endpoints needed */
- + /* check out the endpoints */
- + iface_desc = &interface->altsetting[0];
- + for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
- + endpoint = &iface_desc->endpoint[i];
- +
- + if ((endpoint->bEndpointAddress & 0x80) &&
- + ((endpoint->bmAttributes & 3) == 0x02)) {
- + /* we found a bulk in endpoint */
- + dbg("found bulk in");
- + bulk_in_endpoint[num_bulk_in] = endpoint;
- + ++num_bulk_in;
- + }
- +
- + if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
- + ((endpoint->bmAttributes & 3) == 0x02)) {
- + /* we found a bulk out endpoint */
- + dbg("found bulk out");
- + bulk_out_endpoint[num_bulk_out] = endpoint;
- + ++num_bulk_out;
- + }
- +
- + if ((endpoint->bEndpointAddress & 0x80) &&
- + ((endpoint->bmAttributes & 3) == 0x03)) {
- + /* we found a interrupt in endpoint */
- + dbg("found interrupt in");
- + interrupt_in_endpoint[num_interrupt_in] = endpoint;
- + ++num_interrupt_in;
- + }
- + }
- +
- +#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
- + /* BEGIN HORRIBLE HACK FOR PL2303 */
- + /* this is needed due to the looney way its endpoints are set up */
- + if (((dev->descriptor.idVendor == PL2303_VENDOR_ID) &&
- + (dev->descriptor.idProduct == PL2303_PRODUCT_ID)) ||
- + ((dev->descriptor.idVendor == ATEN_VENDOR_ID) &&
- + (dev->descriptor.idProduct == ATEN_PRODUCT_ID))) {
- + if (ifnum == 1) {
- + /* check out the endpoints of the other interface*/
- + interface = &dev->actconfig->interface[ifnum ^ 1];
- + iface_desc = &interface->altsetting[0];
- + for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
- + endpoint = &iface_desc->endpoint[i];
- + if ((endpoint->bEndpointAddress & 0x80) &&
- + ((endpoint->bmAttributes & 3) == 0x03)) {
- + /* we found a interrupt in endpoint */
- + dbg("found interrupt in for Prolific device on separate interface");
- + interrupt_in_endpoint[num_interrupt_in] = endpoint;
- + ++num_interrupt_in;
- + }
- + }
- + }
- +
- + /* Now make sure the PL-2303 is configured correctly.
- + * If not, give up now and hope this hack will work
- + * properly during a later invocation of usb_serial_probe
- + */
- + if (num_bulk_in == 0 || num_bulk_out == 0) {
- + info("PL-2303 hack: descriptors matched but endpoints did not");
- + return NULL;
- + }
- + }
- + /* END HORRIBLE HACK FOR PL2303 */
- +#endif
- +
- + /* found all that we need */
- + info("%s converter detected", type->name);
- +
- +#ifdef CONFIG_USB_SERIAL_SIERRAWIRELESS
- + if (type == &sierra_driver) {
- + num_ports = num_bulk_out;
- + if (num_ports == 0) {
- + err("Sierra 3G device with no bulk out, not allowed.");
- + return NULL;
- + }
- + } else
- +#endif
- + num_ports = type->num_ports;
- +
- + serial = get_free_serial (num_ports, &minor);
- + if (serial == NULL) {
- + err("No more free serial devices");
- + return NULL;
- + }
- +
- + serial->dev = dev;
- + serial->type = type;
- + serial->interface = interface;
- + serial->minor = minor;
- + serial->num_ports = num_ports;
- + serial->num_bulk_in = num_bulk_in;
- + serial->num_bulk_out = num_bulk_out;
- + serial->num_interrupt_in = num_interrupt_in;
- + serial->vendor = dev->descriptor.idVendor;
- + serial->product = dev->descriptor.idProduct;
- +
- + /* set up the endpoint information */
- + for (i = 0; i < num_bulk_in; ++i) {
- + endpoint = bulk_in_endpoint[i];
- + port = &serial->port[i];
- + port->read_urb = usb_alloc_urb (0);
- + if (!port->read_urb) {
- + err("No free urbs available");
- + goto probe_error;
- + }
- +//Amin marked buffer_size = endpoint->wMaxPacketSize;
- +// ===> 20060310 Amin modify for improve EVDO and HSDPA Card
- + buffer_size = 2048;
- + printk("KERNEL DEBUG => USBSERIAL.O buffer_size = 2048\n");
- +// <=== 20060310 Amin modify for improve EVDO and HSDPA Card
- + port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
- + port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
- + if (!port->bulk_in_buffer) {
- + err("Couldn't allocate bulk_in_buffer");
- + goto probe_error;
- + }
- + usb_fill_bulk_urb (port->read_urb, dev,
- + usb_rcvbulkpipe (dev,
- + endpoint->bEndpointAddress),
- + port->bulk_in_buffer, buffer_size,
- + ((serial->type->read_bulk_callback) ?
- + serial->type->read_bulk_callback :
- + sw_usb_serial_generic_read_bulk_callback),
- + port);
- + }
- +
- + for (i = 0; i < num_bulk_out; ++i) {
- + endpoint = bulk_out_endpoint[i];
- + port = &serial->port[i];
- + port->write_urb = usb_alloc_urb(0);
- + if (!port->write_urb) {
- + err("No free urbs available");
- + goto probe_error;
- + }
- + buffer_size = endpoint->wMaxPacketSize;
- + port->bulk_out_size = buffer_size;
- + port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
- + port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL);
- + if (!port->bulk_out_buffer) {
- + err("Couldn't allocate bulk_out_buffer");
- + goto probe_error;
- + }
- + usb_fill_bulk_urb (port->write_urb, dev,
- + usb_sndbulkpipe (dev,
- + endpoint->bEndpointAddress),
- + port->bulk_out_buffer, buffer_size,
- + ((serial->type->write_bulk_callback) ?
- + serial->type->write_bulk_callback :
- + generic_write_bulk_callback),
- + port);
- + }
- +
- + for (i = 0; i < num_interrupt_in; ++i) {
- + endpoint = interrupt_in_endpoint[i];
- + port = &serial->port[i];
- + port->interrupt_in_urb = usb_alloc_urb(0);
- + if (!port->interrupt_in_urb) {
- + err("No free urbs available");
- + goto probe_error;
- + }
- + buffer_size = endpoint->wMaxPacketSize;
- + port->interrupt_in_endpointAddress = endpoint->bEndpointAddress;
- + port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
- + if (!port->interrupt_in_buffer) {
- + err("Couldn't allocate interrupt_in_buffer");
- + goto probe_error;
- + }
- + usb_fill_int_urb (port->interrupt_in_urb, dev,
- + usb_rcvintpipe (dev,
- + endpoint->bEndpointAddress),
- + port->interrupt_in_buffer, buffer_size,
- + serial->type->read_int_callback, port,
- + endpoint->bInterval);
- + }
- +
- + /* initialize some parts of the port structures */
- + /* we don't use num_ports here cauz some devices have more endpoint pairs than ports */
- + max_endpoints = max(num_bulk_in, num_bulk_out);
- + max_endpoints = max(max_endpoints, num_interrupt_in);
- + max_endpoints = max(max_endpoints, (int)serial->num_ports);
- + dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints);
- + for (i = 0; i < max_endpoints; ++i) {
- + port = &serial->port[i];
- + port->number = i + serial->minor;
- + port->serial = serial;
- + port->magic = USB_SERIAL_PORT_MAGIC;
- + port->tqueue.routine = port_softint;
- + port->tqueue.data = port;
- + init_MUTEX (&port->sem);
- + }
- +
- + /* if this device type has a startup function, call it */
- + if (type->startup) {
- + i = type->startup (serial);
- + if (i < 0)
- + goto probe_error;
- + if (i > 0)
- + return serial;
- + }
- +
- + /* initialize the devfs nodes for this device and let the user know what ports we are bound to */
- + for (i = 0; i < serial->num_ports; ++i) {
- + tty_register_devfs (&serial_tty_driver, 0, serial->port[i].number);
- + info("%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)",
- + type->name, serial->port[i].number, serial->port[i].number);
- + }
- +
- + return serial; /* success */
- +
- +
- +probe_error:
- + for (i = 0; i < num_bulk_in; ++i) {
- + port = &serial->port[i];
- + if (port->read_urb)
- + usb_free_urb (port->read_urb);
- + if (port->bulk_in_buffer)
- + kfree (port->bulk_in_buffer);
- + }
- + for (i = 0; i < num_bulk_out; ++i) {
- + port = &serial->port[i];
- + if (port->write_urb)
- + usb_free_urb (port->write_urb);
- + if (port->bulk_out_buffer)
- + kfree (port->bulk_out_buffer);
- + }
- + for (i = 0; i < num_interrupt_in; ++i) {
- + port = &serial->port[i];
- + if (port->interrupt_in_urb)
- + usb_free_urb (port->interrupt_in_urb);
- + if (port->interrupt_in_buffer)
- + kfree (port->interrupt_in_buffer);
- + }
- +
- + /* return the minor range that this device had */
- + return_serial (serial);
- +
- + /* free up any memory that we allocated */
- + kfree (serial);
- + return NULL;
- +}
- +
- +static void usb_serial_disconnect(struct usb_device *dev, void *ptr)
- +{
- + struct usb_serial *serial = (struct usb_serial *) ptr;
- + struct usb_serial_port *port;
- + int i;
- +
- + dbg ("%s", __FUNCTION__);
- + if (serial) {
- + /* fail all future close/read/write/ioctl/etc calls */
- + for (i = 0; i < serial->num_ports; ++i) {
- + port = &serial->port[i];
- + down (&port->sem);
- + if (port->tty != NULL) {
- + while (port->open_count > 0) {
- + //__serial_close(port, NULL);
- + sw_usb_serial_generic_close(port,NULL);
- + }
- + port->tty->driver_data = NULL;
- + }
- + up (&port->sem);
- + }
- +
- + serial->dev = NULL;
- + //serial_shutdown (serial);
- + sw_usb_serial_generic_shutdown(serial);
- +
- + for (i = 0; i < serial->num_ports; ++i)
- + serial->port[i].open_count = 0;
- +
- + for (i = 0; i < serial->num_bulk_in; ++i) {
- + port = &serial->port[i];
- + if (port->read_urb) {
- + usb_unlink_urb (port->read_urb);
- + usb_free_urb (port->read_urb);
- + }
- + if (port->bulk_in_buffer)
- + kfree (port->bulk_in_buffer);
- + }
- + for (i = 0; i < serial->num_bulk_out; ++i) {
- + port = &serial->port[i];
- + if (port->write_urb) {
- + usb_unlink_urb (port->write_urb);
- + usb_free_urb (port->write_urb);
- + }
- + if (port->bulk_out_buffer)
- + kfree (port->bulk_out_buffer);
- + }
- + for (i = 0; i < serial->num_interrupt_in; ++i) {
- + port = &serial->port[i];
- + if (port->interrupt_in_urb) {
- + usb_unlink_urb (port->interrupt_in_urb);
- + usb_free_urb (port->interrupt_in_urb);
- + }
- + if (port->interrupt_in_buffer)
- + kfree (port->interrupt_in_buffer);
- + }
- +
- + for (i = 0; i < serial->num_ports; ++i) {
- + tty_unregister_devfs (&serial_tty_driver, serial->port[i].number);
- + info("%s converter now disconnected from ttyUSB%d", serial->type->name, serial->port[i].number);
- + }
- +
- + /* return the minor range that this device had */
- + return_serial (serial);
- +
- + /* free up any memory that we allocated */
- + kfree (serial);
- +
- + } else {
- + info("device disconnected");
- + }
- +
- +}
- +
- +#if 0
- +static int sw_attach(struct usb_serial *serial)
- +{
- + struct usb_device *hdev = serial->dev;
- + int rc;
- +
- + dbg("%s - serial(0x%p)", __FUNCTION__, serial);
- +
- + rc = usb_control_msg(
- + hdev,
- + usb_sndctrlpipe(hdev, 0),
- + USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE, /* bRequest */
- + USB_TYPE_VENDOR|USB_RECIP_DEVICE, /* bmRequestType */
- + USB_DEVICE_POWER_STATE_D0, /* wValue */
- + 0, /* wIndex */
- + NULL, /* Data */
- + 0, /* wLength */
- + 1000); /* Timeout */
- +
- + err("%s - rc(%d)", __FUNCTION__, rc);
- + return rc;
- +}
- +#endif
- +//void sw_usb_serial_generic_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
- +static void sw_usb_serial_generic_read_bulk_callback (struct urb *urb)
- +{
- + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
- + struct usb_serial *serial = port->serial;
- + struct tty_struct *tty;
- + unsigned char *data = urb->transfer_buffer;
- + int result;
- + int i;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (urb->status) {
- + dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
- + return;
- + }
- +
- + //usb_serial_dbg_data(__FILE__, __FUNCTION__, urb->actual_length, data);
- +
- + tty = port->tty;
- + if (tty && urb->actual_length) {
- + #if 0
- + tty_buffer_request_room(tty, urb->actual_length);
- + tty_insert_flip_string(tty, data, urb->actual_length);
- + tty_flip_buffer_push(tty);
- + #endif
- + #if 1
- + for (i = 0; i < urb->actual_length ; ++i) {
- + /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
- + if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
- + tty_flip_buffer_push(tty);
- + }
- + /* this doesn't actually push the data through unless tty->low_latency is set */
- + tty_insert_flip_char(tty, data[i], 0);
- + }
- + tty_flip_buffer_push(tty);
- + #endif
- +
- + }
- + else
- + dbg("%s: empty read urb received", __FUNCTION__);
- +
- + /* Continue trying to always read */
- + usb_fill_bulk_urb (port->read_urb, serial->dev,
- + usb_rcvbulkpipe (serial->dev,
- + port->bulk_in_endpointAddress),
- + port->read_urb->transfer_buffer,
- + port->read_urb->transfer_buffer_length,
- + ((serial->type->read_bulk_callback) ?
- + serial->type->read_bulk_callback :
- + sw_usb_serial_generic_read_bulk_callback), port);
- + result = usb_submit_urb(port->read_urb);
- + //result = usb_submit_urb(port->read_urb, GFP_ATOMIC); //for kernel 2.6
- + if (result)
- + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
- +}
- +#if 1
- +static int generic_open (struct usb_serial_port *port, struct file *filp)
- +{
- + struct usb_serial *serial = port->serial;
- + int result = 0;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + /* force low_latency on so that our tty_push actually forces the data through,
- + otherwise it is scheduled, and with high data rates (like with OHCI) data
- + can get lost. */
- + if (port->tty)
- + port->tty->low_latency = 1;
- +
- + /* if we have a bulk interrupt, start reading from it */
- + if (serial->num_bulk_in) {
- + /* Start reading from the device */
- + usb_fill_bulk_urb (port->read_urb, serial->dev,
- + usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
- + port->read_urb->transfer_buffer,
- + port->read_urb->transfer_buffer_length,
- + ((serial->type->read_bulk_callback) ?
- + serial->type->read_bulk_callback :
- + sw_usb_serial_generic_read_bulk_callback),
- + port);
- + result = usb_submit_urb(port->read_urb); //, GFP_KERNEL);
- + if (result)
- + //dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
- + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
- +
- + }
- +
- + return result;
- +}
- +#endif
- +int sw_usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
- +{
- + int rc;
- + struct usb_serial *serial = port->serial;
- + struct usb_device *hdev = serial->dev;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + rc = generic_open(port, filp);
- + err("%s - rc(%d)", __FUNCTION__, rc);
- +
- + if(0 == rc)
- + {
- + rc = usb_control_msg(
- + hdev,
- + usb_sndctrlpipe(hdev, 0),
- + SET_CONTROL_LINE_STATE, /* bRequest */
- + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
- + ACM_CTRL_DTR|ACM_CTRL_RTS, /* wValue */
- + 0, /* wIndex */
- + NULL, /* Data */
- + 0, /* wLength */
- + 1000); /* Timeout */
- + err("%s - usb_control_msg: rc(%d)", __FUNCTION__, rc);
- + }
- +
- + return rc;
- +}
- +
- +static void generic_cleanup (struct usb_serial_port *port)
- +{
- + struct usb_serial *serial = port->serial;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + if (serial->dev) {
- + /* shutdown any bulk reads that might be going on */
- + if (serial->num_bulk_out)
- + usb_unlink_urb(port->write_urb);
- + //usb_kill_urb(port->write_urb);
- + if (serial->num_bulk_in)
- + usb_unlink_urb(port->read_urb);
- + //usb_kill_urb(port->read_urb);
- + }
- +}
- +
- +static void sw_usb_serial_generic_close (struct usb_serial_port *port, struct file * filp)
- +{
- + int rc;
- + struct usb_serial *serial = port->serial;
- + struct usb_device *hdev = serial->dev;
- +
- + dbg("%s - port %d", __FUNCTION__, port->number);
- +
- + rc = usb_control_msg(
- + hdev,
- + usb_sndctrlpipe(hdev, 0),
- + SET_CONTROL_LINE_STATE, /* bRequest */
- + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
- + 0, /* wValue */
- + 0, /* wIndex */
- + NULL, /* Data */
- + 0, /* wLength */
- + 1000); /* Timeout */
- + err("%s - rc(%d)", __FUNCTION__, rc);
- +
- + generic_cleanup (port);
- +}
- +
- +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial)
- +{
- + int i, rc;
- + struct usb_device *hdev = serial->dev;
- +
- + dbg("%s serial(0x%p)", __FUNCTION__, serial);
- +
- + if(hdev)
- + {
- + rc = usb_control_msg(
- + hdev,
- + usb_sndctrlpipe(hdev, 0),
- + USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE, /* bRequest */
- + USB_TYPE_VENDOR|USB_RECIP_DEVICE, /* bmRequestType */
- + USB_DEVICE_POWER_STATE_D3, /* wValue */
- + 0, /* wIndex */
- + NULL, /* Data */
- + 0, /* wLength */
- + 1000); /* Timeout */
- + err("%s - rc(%d)", __FUNCTION__, rc);
- + }
- +
- + /* stop reads and writes on all ports */
- + for (i=0; i < serial->num_ports; ++i) {
- + generic_cleanup(&serial->port[i]);
- + }
- +}
- +int usb_serial_register(struct usb_serial_device_type *new_device)
- +{
- + /* Add this device to our list of devices */
- + list_add(&new_device->driver_list, &usb_serial_driver_list);
- +
- + info ("USB Serial support registered for %s", new_device->name);
- +
- + usb_scan_devices();
- +
- + return 0;
- +}
- +
- +
- +void usb_serial_deregister(struct usb_serial_device_type *device)
- +{
- + struct usb_serial *serial;
- + int i;
- +
- + info("USB Serial deregistering driver %s", device->name);
- +
- + /* clear out the serial_table if the device is attached to a port */
- + for(i = 0; i < SERIAL_TTY_MINORS; ++i) {
- + serial = serial_table[i];
- + if ((serial != NULL) && (serial->type == device)) {
- + usb_driver_release_interface (&sierra_driver, serial->interface);
- + usb_serial_disconnect (NULL, serial);
- + }
- + }
- +
- + list_del(&device->driver_list);
- +}
- +
- +static int __init sierra_init(void)
- +{
- + int retval;
- + int i;
- +
- + /* Initalize our global data */
- + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
- + serial_table[i] = NULL;
- + }
- +
- + /* register the tty driver */
- + serial_tty_driver.init_termios = tty_std_termios;
- + serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
- + if (tty_register_driver (&serial_tty_driver)) {
- + err("%s - failed to register tty driver", __FUNCTION__);
- + return -1;
- + }
- +
- + retval = usb_serial_register(&sierra_device);
- + if (retval)
- + {
- + tty_unregister_driver(&serial_tty_driver);
- + printk("%s return usb_serial_register. retval=[%d].\n",__FUNCTION__, retval);
- + return retval;
- + }
- + retval = usb_register(&sierra_driver);
- + if (retval){
- + usb_serial_deregister(&sierra_device);
- + tty_unregister_driver(&serial_tty_driver);
- + err("usb_register failed for the Sierra 3G USB-Serial driver. Error number %d\n", retval);
- + return -1;
- + }
- +
- + return retval;
- +}
- +
- +static void __exit sierra_exit(void)
- +{
- + usb_deregister(&sierra_driver);
- + usb_serial_deregister(&sierra_device);
- +}
- +
- +module_init(sierra_init);
- +module_exit(sierra_exit);
- +MODULE_LICENSE("GPL");
- --- /dev/null
- +++ b/drivers/usb/serial/sierra.h
- @@ -0,0 +1,32 @@
- +/*
- + * Sierra Wireless CDMA Wireless Serial USB drive
- + *
- + * Current Copy modified by: Kevin Lloyd <[email protected]>
- + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License version
- + * 2 as published by the Free Software Foundation.
- + *
- + * Version history:
- + Version 1.03 (Lloyd):
- + Included support for DTR control and enhanced buffering (should help
- + speed).
- + */
- +
- +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
- +
- +#define USB_DEVICE_POWER_STATE_D0 0x0000
- +#define USB_DEVICE_POWER_STATE_D1 0x0001
- +#define USB_DEVICE_POWER_STATE_D2 0x0002
- +#define USB_DEVICE_POWER_STATE_D3 0x0003
- +
- +#define SET_CONTROL_LINE_STATE 0x22
- +/*
- + * Output control lines.
- + */
- +
- +#define ACM_CTRL_DTR 0x01
- +#define ACM_CTRL_RTS 0x02
- +
|