From fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Tue, 22 Jan 2013 10:38:37 -0500 Subject: Added missing tegra files. --- drivers/usb/serial/ChangeLog.history | 730 +++++++++++++++++++++ drivers/usb/serial/baseband_usb_chr.c | 1124 +++++++++++++++++++++++++++++++++ drivers/usb/serial/baseband_usb_chr.h | 106 ++++ drivers/usb/serial/ezusb.c | 61 ++ 4 files changed, 2021 insertions(+) create mode 100644 drivers/usb/serial/ChangeLog.history create mode 100644 drivers/usb/serial/baseband_usb_chr.c create mode 100644 drivers/usb/serial/baseband_usb_chr.h create mode 100644 drivers/usb/serial/ezusb.c (limited to 'drivers/usb/serial') diff --git a/drivers/usb/serial/ChangeLog.history b/drivers/usb/serial/ChangeLog.history new file mode 100644 index 00000000000..f13fd488ebe --- /dev/null +++ b/drivers/usb/serial/ChangeLog.history @@ -0,0 +1,730 @@ +This is the contents of some of the drivers/usb/serial/ files that had old +changelog comments. They were quite old, and out of date, and we don't keep +them anymore, so I've put them here, away from the source files, in case +people still care to see them. + +- Greg Kroah-Hartman October 20, 2005 + +----------------------------------------------------------------------- +usb-serial.h Change Log comments: + + (03/26/2002) gkh + removed the port->tty check from port_paranoia_check() due to serial + consoles not having a tty device assigned to them. + + (12/03/2001) gkh + removed active from the port structure. + added documentation to the usb_serial_device_type structure + + (10/10/2001) gkh + added vendor and product to serial structure. Needed to determine device + owner when the device is disconnected. + + (05/30/2001) gkh + added sem to port structure and removed port_lock + + (10/05/2000) gkh + Added interrupt_in_endpointAddress and bulk_in_endpointAddress to help + fix bug with urb->dev not being set properly, now that the usb core + needs it. + + (09/11/2000) gkh + Added usb_serial_debug_data function to help get rid of #DEBUG in the + drivers. + + (08/28/2000) gkh + Added port_lock to port structure. + + (08/08/2000) gkh + Added open_count to port structure. + + (07/23/2000) gkh + Added bulk_out_endpointAddress to port structure. + + (07/19/2000) gkh, pberger, and borchers + Modifications to allow usb-serial drivers to be modules. + +----------------------------------------------------------------------- +usb-serial.c Change Log comments: + + (12/10/2002) gkh + Split the ports off into their own struct device, and added a + usb-serial bus driver. + + (11/19/2002) gkh + removed a few #ifdefs for the generic code and cleaned up the failure + logic in initialization. + + (10/02/2002) gkh + moved the console code to console.c and out of this file. + + (06/05/2002) gkh + moved location of startup() call in serial_probe() until after all + of the port information and endpoints are initialized. This makes + things easier for some drivers. + + (04/10/2002) gkh + added serial_read_proc function which creates a + /proc/tty/driver/usb-serial file. + + (03/27/2002) gkh + Got USB serial console code working properly and merged into the main + version of the tree. Thanks to Randy Dunlap for the initial version + of this code, and for pushing me to finish it up. + The USB serial console works with any usb serial driver device. + + (03/21/2002) gkh + Moved all manipulation of port->open_count into the core. Now the + individual driver's open and close functions are called only when the + first open() and last close() is called. Making the drivers a bit + smaller and simpler. + Fixed a bug if a driver didn't have the owner field set. + + (02/26/2002) gkh + Moved all locking into the main serial_* functions, instead of having + the individual drivers have to grab the port semaphore. This should + reduce races. + Reworked the MOD_INC logic a bit to always increment and decrement, even + if the generic driver is being used. + + (10/10/2001) gkh + usb_serial_disconnect() now sets the serial->dev pointer is to NULL to + help prevent child drivers from accessing the device since it is now + gone. + + (09/13/2001) gkh + Moved generic driver initialize after we have registered with the USB + core. Thanks to Randy Dunlap for pointing this problem out. + + (07/03/2001) gkh + Fixed module paramater size. Thanks to John Brockmeyer for the pointer. + Fixed vendor and product getting defined through the MODULE_PARM macro + if the Generic driver wasn't compiled in. + Fixed problem with generic_shutdown() not being called for drivers that + don't have a shutdown() function. + + (06/06/2001) gkh + added evil hack that is needed for the prolific pl2303 device due to the + crazy way its endpoints are set up. + + (05/30/2001) gkh + switched from using spinlock to a semaphore, which fixes lots of problems. + + (04/08/2001) gb + Identify version on module load. + + 2001_02_05 gkh + Fixed buffer overflows bug with the generic serial driver. Thanks to + Todd Squires for fixing this. + + (01/10/2001) gkh + Fixed bug where the generic serial adaptor grabbed _any_ device that was + offered to it. + + (12/12/2000) gkh + Removed MOD_INC and MOD_DEC from poll and disconnect functions, and + moved them to the serial_open and serial_close functions. + Also fixed bug with there not being a MOD_DEC for the generic driver + (thanks to Gary Brubaker for finding this.) + + (11/29/2000) gkh + Small NULL pointer initialization cleanup which saves a bit of disk image + + (11/01/2000) Adam J. Richter + instead of using idVendor/idProduct pairs, usb serial drivers + now identify their hardware interest with usb_device_id tables, + which they usually have anyhow for use with MODULE_DEVICE_TABLE. + + (10/05/2000) gkh + Fixed bug with urb->dev not being set properly, now that the usb + core needs it. + + (09/11/2000) gkh + Removed DEBUG #ifdefs with call to usb_serial_debug_data + + (08/28/2000) gkh + Added port_lock to port structure. + Added locks for SMP safeness to generic driver + Fixed the ability to open a generic device's port more than once. + + (07/23/2000) gkh + Added bulk_out_endpointAddress to port structure. + + (07/19/2000) gkh, pberger, and borchers + Modifications to allow usb-serial drivers to be modules. + + (07/03/2000) gkh + Added more debugging to serial_ioctl call + + (06/25/2000) gkh + Changed generic_write_bulk_callback to not call wake_up_interruptible + directly, but to have port_softint do it at a safer time. + + (06/23/2000) gkh + Cleaned up debugging statements in a quest to find UHCI timeout bug. + + (05/22/2000) gkh + Changed the makefile, enabling the big CONFIG_USB_SERIAL_SOMTHING to be + removed from the individual device source files. + + (05/03/2000) gkh + Added the Digi Acceleport driver from Al Borchers and Peter Berger. + + (05/02/2000) gkh + Changed devfs and tty register code to work properly now. This was based on + the ACM driver changes by Vojtech Pavlik. + + (04/27/2000) Ryan VanderBijl + Put calls to *_paranoia_checks into one function. + + (04/23/2000) gkh + Fixed bug that Randy Dunlap found for Generic devices with no bulk out ports. + Moved when the startup code printed out the devices that are supported. + + (04/19/2000) gkh + Added driver for ZyXEL omni.net lcd plus ISDN TA + Made startup info message specify which drivers were compiled in. + + (04/03/2000) gkh + Changed the probe process to remove the module unload races. + Changed where the tty layer gets initialized to have devfs work nicer. + Added initial devfs support. + + (03/26/2000) gkh + Split driver up into device specific pieces. + + (03/19/2000) gkh + Fixed oops that could happen when device was removed while a program + was talking to the device. + Removed the static urbs and now all urbs are created and destroyed + dynamically. + Reworked the internal interface. Now everything is based on the + usb_serial_port structure instead of the larger usb_serial structure. + This fixes the bug that a multiport device could not have more than + one port open at one time. + + (03/17/2000) gkh + Added config option for debugging messages. + Added patch for keyspan pda from Brian Warner. + + (03/06/2000) gkh + Added the keyspan pda code from Brian Warner + Moved a bunch of the port specific stuff into its own structure. This + is in anticipation of the true multiport devices (there's a bug if you + try to access more than one port of any multiport device right now) + + (02/21/2000) gkh + Made it so that any serial devices only have to specify which functions + they want to overload from the generic function calls (great, + inheritance in C, in a driver, just what I wanted...) + Added support for set_termios and ioctl function calls. No drivers take + advantage of this yet. + Removed the #ifdef MODULE, now there is no module specific code. + Cleaned up a few comments in usb-serial.h that were wrong (thanks again + to Miles Lott). + Small fix to get_free_serial. + + (02/14/2000) gkh + Removed the Belkin and Peracom functionality from the driver due to + the lack of support from the vendor, and me not wanting people to + accidenatly buy the device, expecting it to work with Linux. + Added read_bulk_callback and write_bulk_callback to the type structure + for the needs of the FTDI and WhiteHEAT driver. + Changed all reverences to FTDI to FTDI_SIO at the request of Bill + Ryder. + Changed the output urb size back to the max endpoint size to make + the ftdi_sio driver have it easier, and due to the fact that it didn't + really increase the speed any. + + (02/11/2000) gkh + Added VISOR_FUNCTION_CONSOLE to the visor startup function. This was a + patch from Miles Lott (milos@insync.net). + Fixed bug with not restoring the minor range that a device grabs, if + the startup function fails (thanks Miles for finding this). + + (02/05/2000) gkh + Added initial framework for the Keyspan PDA serial converter so that + Brian Warner has a place to put his code. + Made the ezusb specific functions generic enough that different + devices can use them (whiteheat and keyspan_pda both need them). + Split out a whole bunch of structure and other stuff to a separate + usb-serial.h file. + Made the Visor connection messages a little more understandable, now + that Miles Lott (milos@insync.net) has gotten the Generic channel to + work. Also made them always show up in the log file. + + (01/25/2000) gkh + Added initial framework for FTDI serial converter so that Bill Ryder + has a place to put his code. + Added the vendor specific info from Handspring. Now we can print out + informational debug messages as well as understand what is happening. + + (01/23/2000) gkh + Fixed problem of crash when trying to open a port that didn't have a + device assigned to it. Made the minor node finding a little smarter, + now it looks to find a continuous space for the new device. + + (01/21/2000) gkh + Fixed bug in visor_startup with patch from Miles Lott (milos@insync.net) + Fixed get_serial_by_minor which was all messed up for multi port + devices. Fixed multi port problem for generic devices. Now the number + of ports is determined by the number of bulk out endpoints for the + generic device. + + (01/19/2000) gkh + Removed lots of cruft that was around from the old (pre urb) driver + interface. + Made the serial_table dynamic. This should save lots of memory when + the number of minor nodes goes up to 256. + Added initial support for devices that have more than one port. + Added more debugging comments for the Visor, and added a needed + set_configuration call. + + (01/17/2000) gkh + Fixed the WhiteHEAT firmware (my processing tool had a bug) + and added new debug loader firmware for it. + Removed the put_char function as it isn't really needed. + Added visor startup commands as found by the Win98 dump. + + (01/13/2000) gkh + Fixed the vendor id for the generic driver to the one I meant it to be. + + (01/12/2000) gkh + Forget the version numbering...that's pretty useless... + Made the driver able to be compiled so that the user can select which + converter they want to use. This allows people who only want the Visor + support to not pay the memory size price of the WhiteHEAT. + Fixed bug where the generic driver (idVendor=0000 and idProduct=0000) + grabbed the root hub. Not good. + + version 0.4.0 (01/10/2000) gkh + Added whiteheat.h containing the firmware for the ConnectTech WhiteHEAT + device. Added startup function to allow firmware to be downloaded to + a device if it needs to be. + Added firmware download logic to the WhiteHEAT device. + Started to add #defines to split up the different drivers for potential + configuration option. + + version 0.3.1 (12/30/99) gkh + Fixed problems with urb for bulk out. + Added initial support for multiple sets of endpoints. This enables + the Handspring Visor to be attached successfully. Only the first + bulk in / bulk out endpoint pair is being used right now. + + version 0.3.0 (12/27/99) gkh + Added initial support for the Handspring Visor based on a patch from + Miles Lott (milos@sneety.insync.net) + Cleaned up the code a bunch and converted over to using urbs only. + + version 0.2.3 (12/21/99) gkh + Added initial support for the Connect Tech WhiteHEAT converter. + Incremented the number of ports in expectation of getting the + WhiteHEAT to work properly (4 ports per connection). + Added notification on insertion and removal of what port the + device is/was connected to (and what kind of device it was). + + version 0.2.2 (12/16/99) gkh + Changed major number to the new allocated number. We're legal now! + + version 0.2.1 (12/14/99) gkh + Fixed bug that happens when device node is opened when there isn't a + device attached to it. Thanks to marek@webdesign.no for noticing this. + + version 0.2.0 (11/10/99) gkh + Split up internals to make it easier to add different types of serial + converters to the code. + Added a "generic" driver that gets it's vendor and product id + from when the module is loaded. Thanks to David E. Nelson (dnelson@jump.net) + for the idea and sample code (from the usb scanner driver.) + Cleared up any licensing questions by releasing it under the GNU GPL. + + version 0.1.2 (10/25/99) gkh + Fixed bug in detecting device. + + version 0.1.1 (10/05/99) gkh + Changed the major number to not conflict with anything else. + + version 0.1 (09/28/99) gkh + Can recognize the two different devices and start up a read from + device when asked to. Writes also work. No control signals yet, this + all is vendor specific data (i.e. no spec), also no control for + different baud rates or other bit settings. + Currently we are using the same devid as the acm driver. This needs + to change. + +----------------------------------------------------------------------- +visor.c Change Log comments: + + (06/03/2003) Judd Montgomery + Added support for module parameter options for untested/unknown + devices. + + (03/09/2003) gkh + Added support for the Sony Clie NZ90V device. Thanks to Martin Brachtl + for the information. + + (03/05/2003) gkh + Think Treo support is now working. + + (04/03/2002) gkh + Added support for the Sony OS 4.1 devices. Thanks to Hiroyuki ARAKI + for the information. + + (03/27/2002) gkh + Removed assumptions that port->tty was always valid (is not true + for usb serial console devices.) + + (03/23/2002) gkh + Added support for the Palm i705 device, thanks to Thomas Riemer + for the information. + + (03/21/2002) gkh + Added support for the Palm m130 device, thanks to Udo Eisenbarth + for the information. + + (02/27/2002) gkh + Reworked the urb handling logic. We have no more pool, but dynamically + allocate the urb and the transfer buffer on the fly. In testing this + does not incure any measurable overhead. This also relies on the fact + that we have proper reference counting logic for urbs. + + (02/21/2002) SilaS + Added initial support for the Palm m515 devices. + + (02/14/2002) gkh + Added support for the Clie S-360 device. + + (12/18/2001) gkh + Added better Clie support for 3.5 devices. Thanks to Geoffrey Levand + for the patch. + + (11/11/2001) gkh + Added support for the m125 devices, and added check to prevent oopses + for CliƩ devices that lie about the number of ports they have. + + (08/30/2001) gkh + Added support for the Clie devices, both the 3.5 and 4.0 os versions. + Many thanks to Daniel Burke, and Bryan Payne for helping with this. + + (08/23/2001) gkh + fixed a few potential bugs pointed out by Oliver Neukum. + + (05/30/2001) gkh + switched from using spinlock to a semaphore, which fixes lots of problems. + + (05/28/2000) gkh + Added initial support for the Palm m500 and Palm m505 devices. + + (04/08/2001) gb + Identify version on module load. + + (01/21/2000) gkh + Added write_room and chars_in_buffer, as they were previously using the + generic driver versions which is all wrong now that we are using an urb + pool. Thanks to Wolfgang Grandegger for pointing this out to me. + Removed count assignment in the write function, which was not needed anymore + either. Thanks to Al Borchers for pointing this out. + + (12/12/2000) gkh + Moved MOD_DEC to end of visor_close to be nicer, as the final write + message can sleep. + + (11/12/2000) gkh + Fixed bug with data being dropped on the floor by forcing tty->low_latency + to be on. Hopefully this fixes the OHCI issue! + + (11/01/2000) Adam J. Richter + usb_device_id table support + + (10/05/2000) gkh + Fixed bug with urb->dev not being set properly, now that the usb + core needs it. + + (09/11/2000) gkh + Got rid of always calling kmalloc for every urb we wrote out to the + device. + Added visor_read_callback so we can keep track of bytes in and out for + those people who like to know the speed of their device. + Removed DEBUG #ifdefs with call to usb_serial_debug_data + + (09/06/2000) gkh + Fixed oops in visor_exit. Need to uncomment usb_unlink_urb call _after_ + the host controller drivers set urb->dev = NULL when the urb is finished. + + (08/28/2000) gkh + Added locks for SMP safeness. + + (08/08/2000) gkh + Fixed endian problem in visor_startup. + Fixed MOD_INC and MOD_DEC logic and the ability to open a port more + than once. + + (07/23/2000) gkh + Added pool of write urbs to speed up transfers to the visor. + + (07/19/2000) gkh + Added module_init and module_exit functions to handle the fact that this + driver is a loadable module now. + + (07/03/2000) gkh + Added visor_set_ioctl and visor_set_termios functions (they don't do much + of anything, but are good for debugging.) + + (06/25/2000) gkh + Fixed bug in visor_unthrottle that should help with the disconnect in PPP + bug that people have been reporting. + + (06/23/2000) gkh + Cleaned up debugging statements in a quest to find UHCI timeout bug. + + (04/27/2000) Ryan VanderBijl + Fixed memory leak in visor_close + + (03/26/2000) gkh + Split driver up into device specific pieces. + +----------------------------------------------------------------------- +pl2303.c Change Log comments: + + 2002_Mar_26 gkh + allowed driver to work properly if there is no tty assigned to a port + (this happens for serial console devices.) + + 2001_Oct_06 gkh + Added RTS and DTR line control. Thanks to joe@bndlg.de for parts of it. + + 2001_Sep_19 gkh + Added break support. + + 2001_Aug_30 gkh + fixed oops in write_bulk_callback. + + 2001_Aug_28 gkh + reworked buffer logic to be like other usb-serial drivers. Hopefully + removing some reported problems. + + 2001_Jun_06 gkh + finished porting to 2.4 format. + + +----------------------------------------------------------------------- +io_edgeport.c Change Log comments: + + 2003_04_03 al borchers + - fixed a bug (that shows up with dosemu) where the tty struct is + used in a callback after it has been freed + + 2.3 2002_03_08 greg kroah-hartman + - fixed bug when multiple devices were attached at the same time. + + 2.2 2001_11_14 greg kroah-hartman + - fixed bug in edge_close that kept the port from being used more + than once. + - fixed memory leak on device removal. + - fixed potential double free of memory when command urb submitting + failed. + - other small cleanups when the device is removed + + 2.1 2001_07_09 greg kroah-hartman + - added support for TIOCMBIS and TIOCMBIC. + + (04/08/2001) gb + - Identify version on module load. + + 2.0 2001_03_05 greg kroah-hartman + - reworked entire driver to fit properly in with the other usb-serial + drivers. Occasional oopses still happen, but it's a good start. + + 1.2.3 (02/23/2001) greg kroah-hartman + - changed device table to work properly for 2.4.x final format. + - fixed problem with dropping data at high data rates. + + 1.2.2 (11/27/2000) greg kroah-hartman + - cleaned up more NTisms. + - Added device table for 2.4.0-test11 + + 1.2.1 (11/08/2000) greg kroah-hartman + - Started to clean up NTisms. + - Fixed problem with dev field of urb for kernels >= 2.4.0-test9 + + 1.2 (10/17/2000) David Iacovelli + Remove all EPIC code and GPL source + Fix RELEVANT_IFLAG macro to include flow control + changes port configuration changes. + Fix redefinition of SERIAL_MAGIC + Change all timeout values to 5 seconds + Tried to fix the UHCI multiple urb submission, but failed miserably. + it seems to work fine with OHCI. + ( Greg take a look at the #if 0 at end of WriteCmdUsb() we must + find a way to work arount this UHCI bug ) + + 1.1 (10/11/2000) David Iacovelli + Fix XON/XOFF flow control to support both IXON and IXOFF + + 0.9.27 (06/30/2000) David Iacovelli + Added transmit queue and now allocate urb for command writes. + + 0.9.26 (06/29/2000) David Iacovelli + Add support for 80251 based edgeport + + 0.9.25 (06/27/2000) David Iacovelli + Do not close the port if it has multiple opens. + + 0.9.24 (05/26/2000) David Iacovelli + Add IOCTLs to support RXTX and JAVA POS + and first cut at running BlackBox Demo + + 0.9.23 (05/24/2000) David Iacovelli + Add IOCTLs to support RXTX and JAVA POS + + 0.9.22 (05/23/2000) David Iacovelli + fixed bug in enumeration. If epconfig turns on mapping by + path after a device is already plugged in, we now update + the mapping correctly + + 0.9.21 (05/16/2000) David Iacovelli + Added BlockUntilChaseResp() to also wait for txcredits + Updated the way we allocate and handle write URBs + Add debug code to dump buffers + + 0.9.20 (05/01/2000) David Iacovelli + change driver to use usb/tts/ + + 0.9.19 (05/01/2000) David Iacovelli + Update code to compile if DEBUG is off + + 0.9.18 (04/28/2000) David Iacovelli + cleanup and test tty_register with devfs + + 0.9.17 (04/27/2000) greg kroah-hartman + changed tty_register around to be like the way it + was before, but now it works properly with devfs. + + 0.9.16 (04/26/2000) david iacovelli + Fixed bug in GetProductInfo() + + 0.9.15 (04/25/2000) david iacovelli + Updated enumeration + + 0.9.14 (04/24/2000) david iacovelli + Removed all config/status IOCTLS and + converted to using /proc/edgeport + still playing with devfs + + 0.9.13 (04/24/2000) david iacovelli + Removed configuration based on ttyUSB0 + Added support for configuration using /prod/edgeport + first attempt at using devfs (not working yet!) + Added IOCTL to GetProductInfo() + Added support for custom baud rates + Add support for random port numbers + + 0.9.12 (04/18/2000) david iacovelli + added additional configuration IOCTLs + use ttyUSB0 for configuration + + 0.9.11 (04/17/2000) greg kroah-hartman + fixed module initialization race conditions. + made all urbs dynamically allocated. + made driver devfs compatible. now it only registers the tty device + when the device is actually plugged in. + + 0.9.10 (04/13/2000) greg kroah-hartman + added proc interface framework. + + 0.9.9 (04/13/2000) david iacovelli + added enumeration code and ioctls to configure the device + + 0.9.8 (04/12/2000) david iacovelli + Change interrupt read start when device is plugged in + and stop when device is removed + process interrupt reads when all ports are closed + (keep value of rxBytesAvail consistent with the edgeport) + set the USB_BULK_QUEUE flag so that we can shove a bunch + of urbs at once down the pipe + + 0.9.7 (04/10/2000) david iacovelli + start to add enumeration code. + generate serial number for epic devices + add support for kdb + + 0.9.6 (03/30/2000) david iacovelli + add IOCTL to get string, manufacture, and boot descriptors + + 0.9.5 (03/14/2000) greg kroah-hartman + more error checking added to SerialOpen to try to fix UHCI open problem + + 0.9.4 (03/09/2000) greg kroah-hartman + added more error checking to handle oops when data is hanging + around and tty is abruptly closed. + + 0.9.3 (03/09/2000) david iacovelli + Add epic support for xon/xoff chars + play with performance + + 0.9.2 (03/08/2000) greg kroah-hartman + changed most "info" calls to "dbg" + implemented flow control properly in the termios call + + 0.9.1 (03/08/2000) david iacovelli + added EPIC support + enabled bootloader update + + 0.9 (03/08/2000) greg kroah-hartman + Release to IO networks. + Integrated changes that David made + made getting urbs for writing SMP safe + + 0.8 (03/07/2000) greg kroah-hartman + Release to IO networks. + Fixed problems that were seen in code by David. + Now both Edgeport/4 and Edgeport/2 works properly. + Changed most of the functions to use port instead of serial. + + 0.7 (02/27/2000) greg kroah-hartman + Milestone 3 release. + Release to IO Networks + ioctl for waiting on line change implemented. + ioctl for getting statistics implemented. + multiport support working. + lsr and msr registers are now handled properly. + change break now hooked up and working. + support for all known Edgeport devices. + + 0.6 (02/22/2000) greg kroah-hartman + Release to IO networks. + CHASE is implemented correctly when port is closed. + SerialOpen now blocks correctly until port is fully opened. + + 0.5 (02/20/2000) greg kroah-hartman + Release to IO networks. + Known problems: + modem status register changes are not sent on to the user + CHASE is not implemented when the port is closed. + + 0.4 (02/16/2000) greg kroah-hartman + Second cut at the CeBit demo. + Doesn't leak memory on every write to the port + Still small leaks on startup. + Added support for Edgeport/2 and Edgeport/8 + + 0.3 (02/15/2000) greg kroah-hartman + CeBit demo release. + Force the line settings to 4800, 8, 1, e for the demo. + Warning! This version leaks memory like crazy! + + 0.2 (01/30/2000) greg kroah-hartman + Milestone 1 release. + Device is found by USB subsystem, enumerated, firmware is downloaded + and the descriptors are printed to the debug log, config is set, and + green light starts to blink. Open port works, and data can be sent + and received at the default settings of the UART. Loopback connector + and debug log confirms this. + + 0.1 (01/23/2000) greg kroah-hartman + Initial release to help IO Networks try to set up their test system. + Edgeport4 is recognized, firmware is downloaded, config is set so + device blinks green light every 3 sec. Port is bound, but opening, + closing, and sending data do not work properly. + + diff --git a/drivers/usb/serial/baseband_usb_chr.c b/drivers/usb/serial/baseband_usb_chr.c new file mode 100644 index 00000000000..6d691a40312 --- /dev/null +++ b/drivers/usb/serial/baseband_usb_chr.c @@ -0,0 +1,1124 @@ +/* + * baseband_usb_chr.c + * + * USB character driver to communicate with baseband modems. + * + * Copyright (c) 2011, NVIDIA Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "baseband_usb_chr.h" + +MODULE_LICENSE("GPL"); + +unsigned long baseband_usb_chr_vid = 0x058b; +unsigned long baseband_usb_chr_pid = 0x0041; +unsigned long baseband_usb_chr_intf = 0x01; + +module_param(baseband_usb_chr_vid, ulong, 0644); +MODULE_PARM_DESC(baseband_usb_chr_vid, "baseband (usb chr) - USB VID"); +module_param(baseband_usb_chr_pid, ulong, 0644); +MODULE_PARM_DESC(baseband_usb_chr_pid, "baseband (usb chr) - USB PID"); +module_param(baseband_usb_chr_intf, ulong, 0644); +MODULE_PARM_DESC(baseband_usb_chr_intf, "baseband (usb chr) - USB interface"); + +static struct baseband_usb *baseband_usb_chr; +static bool usb_device_connection; + +static atomic_t g_rx_count = ATOMIC_INIT(0); + +/* baseband ipc functions */ + +static void baseband_ipc_dump(const char *prefix, unsigned long int offset, + const void *buf, size_t bufsiz) +{ + size_t i; + + for (i = 0; i < bufsiz; i += 16) { + pr_debug("%s" + "[%lx+%x] %p " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x " + "%02x %02x %02x %02x\n", + prefix, + offset, + i, + ((const unsigned char *) buf) + i, + (i + 0 < bufsiz) ? ((const unsigned char *) buf)[i+0] + : 0xff, + (i + 1 < bufsiz) ? ((const unsigned char *) buf)[i+1] + : 0xff, + (i + 2 < bufsiz) ? ((const unsigned char *) buf)[i+2] + : 0xff, + (i + 3 < bufsiz) ? ((const unsigned char *) buf)[i+3] + : 0xff, + (i + 4 < bufsiz) ? ((const unsigned char *) buf)[i+4] + : 0xff, + (i + 5 < bufsiz) ? ((const unsigned char *) buf)[i+5] + : 0xff, + (i + 6 < bufsiz) ? ((const unsigned char *) buf)[i+6] + : 0xff, + (i + 7 < bufsiz) ? ((const unsigned char *) buf)[i+7] + : 0xff, + (i + 8 < bufsiz) ? ((const unsigned char *) buf)[i+8] + : 0xff, + (i + 9 < bufsiz) ? ((const unsigned char *) buf)[i+9] + : 0xff, + (i + 10 < bufsiz) ? ((const unsigned char *) buf)[i+10] + : 0xff, + (i + 11 < bufsiz) ? ((const unsigned char *) buf)[i+11] + : 0xff, + (i + 12 < bufsiz) ? ((const unsigned char *) buf)[i+12] + : 0xff, + (i + 13 < bufsiz) ? ((const unsigned char *) buf)[i+13] + : 0xff, + (i + 14 < bufsiz) ? ((const unsigned char *) buf)[i+14] + : 0xff, + (i + 15 < bufsiz) ? ((const unsigned char *) buf)[i+15] + : 0xff); + } + +} + +static size_t peek_ipc_tx_bufsiz(struct baseband_ipc *ipc, + size_t bufsiz) +{ + struct baseband_ipc_buf *ipc_buf, *ipc_buf_next; + size_t tx_bufsiz; + + pr_debug("peek_ipc_tx_bufsiz\n"); + + /* check input */ + if (!ipc) { + pr_err("!ipc\n"); + return 0; + } + + /* acquire tx buffer semaphores */ + if (down_interruptible(&ipc->buf_sem)) { + pr_err("peek_ipc_tx_bufsiz - " + "cannot acquire buffer semaphore\n"); + return -ERESTARTSYS; + } + + /* calculate maximum number of tx buffers which can be sent */ + tx_bufsiz = 0; + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->tx.buf, list) + { + pr_debug("peek_ipc_tx_bufsiz - " + "ipc_buf %p ipc_buf->offset %x ipc_buf->count %x\n", + ipc_buf, ipc_buf->offset, ipc_buf->count); + if (ipc_buf->count > bufsiz - tx_bufsiz) + break; + else + tx_bufsiz += ipc_buf->count; + } + + /* release tx buffer semaphores */ + up(&ipc->buf_sem); + + return tx_bufsiz; +} + +static size_t get_ipc_tx_buf(struct baseband_ipc *ipc, + void *buf, size_t bufsiz) +{ + struct baseband_ipc_buf *ipc_buf, *ipc_buf_next; + size_t tx_bufsiz; + + pr_debug("get_ipc_tx_buf\n"); + + /* check input */ + if (!ipc || !buf) { + pr_err("!ipc || !buf\n"); + return 0; + } + if (!bufsiz) + return 0; + + /* acquire tx buffer semaphores */ + if (down_interruptible(&ipc->buf_sem)) { + pr_err("get_ipc_tx_buf - " + "cannot acquire buffer semaphore\n"); + return -ERESTARTSYS; + } + + /* get tx data from tx linked list */ + tx_bufsiz = 0; + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->tx.buf, list) + { + pr_debug("get_ipc_tx_buf - " + "ipc_buf %p ipc_buf->offset %x ipc_buf->count %x\n", + ipc_buf, ipc_buf->offset, ipc_buf->count); + pr_debug("get_ipc_tx_buf - " + "ipc_buf->data [0] %x [1] %x [2] %x [3] %x\n", + ipc_buf->data[0], + ipc_buf->data[1], + ipc_buf->data[2], + ipc_buf->data[3]); + if (ipc_buf->count > bufsiz - tx_bufsiz) { + /* copy part of tx buffer */ + memcpy(buf + tx_bufsiz, + ipc_buf->data + ipc_buf->offset, + bufsiz - tx_bufsiz); + ipc_buf->offset += bufsiz - tx_bufsiz; + ipc_buf->count -= bufsiz - tx_bufsiz; + tx_bufsiz = bufsiz; + } else { + /* copy all data from tx buffer */ + memcpy(buf + tx_bufsiz, + ipc_buf->data + ipc_buf->offset, + ipc_buf->count); + tx_bufsiz += ipc_buf->count; + ipc_buf->offset = 0; + ipc_buf->count = 0; + /* add tx buffer to tx free list */ + list_move_tail(&ipc_buf->list, &ipc->tx_free.buf); + wake_up(&ipc->tx_free.wait); + } + /* check if done */ + if (tx_bufsiz == bufsiz) + break; + } + + /* release tx buffer semaphores */ + up(&ipc->buf_sem); + + return tx_bufsiz; +} + +static size_t put_ipc_rx_buf(struct baseband_ipc *ipc, + const void *buf, size_t bufsiz) +{ + struct baseband_ipc_buf *ipc_buf, *ipc_buf_next; + size_t rx_bufsiz; + + pr_debug("put_ipc_rx_buf\n"); + + /* check input */ + if (!ipc || !buf) { + pr_err("!ipc || !buf\n"); + return 0; + } + if (!bufsiz) + return 0; + + /* acquire rx buffer semaphores */ +retry: + if (down_interruptible(&ipc->buf_sem)) { + pr_err("put_ipc_rx_buf - " + "cannot acquire buffer semaphore\n"); + return -ERESTARTSYS; + } + + /* put rx data in rx linked list */ + rx_bufsiz = 0; + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->rx_free.buf, list) + { + pr_debug("put_ipc_rx_buf - " + "ipc_buf %p ipc_buf->offset %x ipc_buf->count %x\n", + ipc_buf, ipc_buf->offset, ipc_buf->count); + if (sizeof(ipc_buf->data) > bufsiz - rx_bufsiz) { + /* partially fill rx free buffer */ + memcpy(ipc_buf->data, + buf + rx_bufsiz, + bufsiz - rx_bufsiz); + ipc_buf->offset = 0; + ipc_buf->count = bufsiz - rx_bufsiz; + rx_bufsiz = bufsiz; + } else { + /* fill entire rx free buffer */ + memcpy(ipc_buf->data, + buf + rx_bufsiz, + sizeof(ipc_buf->data)); + ipc_buf->offset = 0; + ipc_buf->count = sizeof(ipc_buf->data); + rx_bufsiz += sizeof(ipc_buf->data); + } + /* add filled rx free buffer to rx linked list */ + list_move_tail(&ipc_buf->list, &ipc->rx.buf); + wake_up(&ipc->rx.wait); + /* check if done */ + if (rx_bufsiz == bufsiz) + break; + } + + /* release rx buffer semaphores */ + up(&ipc->buf_sem); + + /* wait for rx free buffer available */ + if (!rx_bufsiz) { + if (wait_event_interruptible(ipc->rx_free.wait, + !list_empty(&ipc->rx_free.buf))) { + pr_err("put_ipc_rx_buf - " + "interrupted wait\n"); + return -ERESTARTSYS; + } + goto retry; + } + + return rx_bufsiz; + +} + +static ssize_t baseband_ipc_file_read(struct baseband_ipc *ipc, + struct file *file, char *buf, size_t count, loff_t *pos) +{ + struct baseband_ipc_buf *ipc_buf, *ipc_buf_next; + size_t read_count; + + pr_debug("baseband_ipc_file_read\n"); + + /* check input */ + if (!ipc) { + pr_err("!ipc\n"); + return -EIO; + } + + /* acquire rx buffer semaphores */ +retry: + if (down_interruptible(&ipc->buf_sem)) { + pr_err("baseband_ipc_file_read - " + "cannot acquire buffer semaphore\n"); + return -ERESTARTSYS; + } + + /* get read data from rx linked list */ + read_count = 0; + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->rx.buf, list) + { + pr_debug("baseband_ipc_file_read - " + "ipc_buf %p ipc_buf->offset %x ipc_buf->count %x\n", + ipc_buf, ipc_buf->offset, ipc_buf->count); + pr_debug("baseband_ipc_file_read - " + "ipc_buf->data [0] %x [1] %x [2] %x [3] %x\n", + ipc_buf->data[0], + ipc_buf->data[1], + ipc_buf->data[2], + ipc_buf->data[3]); + if (ipc_buf->count > count - read_count) { + /* copy part of rx buffer */ + if (copy_to_user(buf + read_count, + ipc_buf->data + ipc_buf->offset, + count - read_count)) { + pr_err("copy_to_user failed\n"); + up(&ipc->buf_sem); + return -EFAULT; + } + ipc_buf->offset += count - read_count; + ipc_buf->count -= count - read_count; + read_count = count; + } else { + /* copy all data from rx buffer */ + if (copy_to_user(buf + read_count, + ipc_buf->data + ipc_buf->offset, + ipc_buf->count)) { + pr_err("copy_to_user failed\n"); + up(&ipc->buf_sem); + return -EFAULT; + } + read_count += ipc_buf->count; + ipc_buf->offset = 0; + ipc_buf->count = 0; + /* add rx buffer to rx free list */ + list_move_tail(&ipc_buf->list, &ipc->rx_free.buf); + wake_up(&ipc->rx_free.wait); + } + /* check if done */ + if (read_count == count) + break; + } + + /* release rx buffer semaphores */ + up(&ipc->buf_sem); + + /* wait for rx buffer available */ + if (!read_count) { + if (wait_event_interruptible(ipc->rx.wait, + !list_empty(&ipc->rx.buf))) { + pr_err("baseband_ipc_file_read - " + "interrupted wait\n"); + return -ERESTARTSYS; + } + goto retry; + } + + return read_count; +} + +static ssize_t baseband_ipc_file_write(struct baseband_ipc *ipc, + struct file *file, const char *buf, size_t count, loff_t *pos) +{ + struct baseband_ipc_buf *ipc_buf, *ipc_buf_next; + size_t write_count; + + pr_debug("baseband_ipc_file_write\n"); + + /* check input */ + if (!ipc) { + pr_err("!ipc\n"); + return -EIO; + } + + /* acquire tx buffer semaphores */ +retry: + if (down_interruptible(&ipc->buf_sem)) { + pr_err("baseband_ipc_file_write - " + "cannot acquire buffer semaphore\n"); + return -ERESTARTSYS; + } + + /* put write data in tx linked list */ + write_count = 0; + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->tx_free.buf, list) + { + pr_debug("baseband_ipc_file_write - " + "ipc_buf %p ipc_buf->offset %x ipc_buf->count %x\n", + ipc_buf, ipc_buf->offset, ipc_buf->count); + if (sizeof(ipc_buf->data) > count - write_count) { + /* partially fill tx free buffer */ + if (copy_from_user(ipc_buf->data, + buf + write_count, + count - write_count)) { + pr_err("copy_from_user failed\n"); + up(&ipc->buf_sem); + return -EFAULT; + } + ipc_buf->offset = 0; + ipc_buf->count = count - write_count; + write_count = count; + } else { + /* fill entire tx free buffer */ + if (copy_from_user(ipc_buf->data, + buf + write_count, + sizeof(ipc_buf->data))) { + pr_err("copy_from_user failed\n"); + up(&ipc->buf_sem); + return -EFAULT; + } + ipc_buf->offset = 0; + ipc_buf->count = sizeof(ipc_buf->data); + write_count += sizeof(ipc_buf->data); + } + /* add filled tx free buffer to tx linked list */ + pr_debug("baseband_ipc_file_write - " + "ipc_buf->data [0] %x [1] %x [2] %x [3] %x\n", + ipc_buf->data[0], + ipc_buf->data[1], + ipc_buf->data[2], + ipc_buf->data[3]); + list_move_tail(&ipc_buf->list, &ipc->tx.buf); + wake_up(&ipc->tx.wait); + /* check if done */ + if (write_count == count) + break; + } + + /* release tx buffer semaphores */ + up(&ipc->buf_sem); + + /* wait for tx buffer available */ + if (!write_count) { + if (wait_event_interruptible(ipc->tx_free.wait, + !list_empty(&ipc->tx_free.buf))) { + pr_err("baseband_ipc_file_write - " + "interrupted wait\n"); + return -ERESTARTSYS; + } + goto retry; + } + + /* queue ipc transaction work */ + queue_work(ipc->workqueue, &ipc->work); + + return write_count; +} + +static void baseband_ipc_close(struct baseband_ipc *ipc) +{ + struct baseband_ipc_buf *ipc_buf, *ipc_buf_next; + + pr_debug("baseband_ipc_close {\n"); + + /* check input */ + if (!ipc) + return; + + /* destroy work queue */ + if (ipc->workqueue) { + pr_debug("destroy workqueue {\n"); + cancel_work_sync(&ipc->work); + destroy_workqueue(ipc->workqueue); + ipc->workqueue = (struct workqueue_struct *) 0; + pr_debug("destroy workqueue }\n"); + } + memset(&ipc->work, 0, sizeof(ipc->work)); + + /* destroy wait queues */ + memset(&ipc->tx_free.wait, 0, sizeof(ipc->tx_free.wait)); + memset(&ipc->rx_free.wait, 0, sizeof(ipc->rx_free.wait)); + memset(&ipc->tx.wait, 0, sizeof(ipc->tx.wait)); + memset(&ipc->rx.wait, 0, sizeof(ipc->rx.wait)); + + /* destroy data buffers */ + kfree(ipc->ipc_tx); + ipc->ipc_tx = (unsigned char *) 0; + kfree(ipc->ipc_rx); + ipc->ipc_rx = (unsigned char *) 0; + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->tx_free.buf, list) + { + kfree(ipc_buf); + } + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->rx_free.buf, list) + { + kfree(ipc_buf); + } + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->tx.buf, list) + { + kfree(ipc_buf); + } + list_for_each_entry_safe(ipc_buf, ipc_buf_next, &ipc->rx.buf, list) + { + kfree(ipc_buf); + } + + /* destroy semaphores */ + memset(&ipc->buf_sem, 0, sizeof(ipc->buf_sem)); + + /* free baseband ipc structure */ + kfree(ipc); + + pr_debug("baseband_ipc_close }\n"); +} + +static struct baseband_ipc *baseband_ipc_open(work_func_t work_func, + work_func_t rx_work_func, + work_func_t tx_work_func) +{ + struct baseband_ipc *ipc; + struct baseband_ipc_buf *ipc_buf; + int i; + + pr_debug("baseband_ipc_open {\n"); + + /* allocate baseband ipc structure */ + ipc = kzalloc(sizeof(struct baseband_ipc), GFP_KERNEL); + if (!ipc) + return (struct baseband_ipc *) 0; + + /* create semaphores */ + sema_init(&ipc->buf_sem, 1); + + /* create data buffers */ + INIT_LIST_HEAD(&ipc->rx.buf); + INIT_LIST_HEAD(&ipc->tx.buf); + INIT_LIST_HEAD(&ipc->rx_free.buf); + INIT_LIST_HEAD(&ipc->tx_free.buf); + for (i = 0; i < BASEBAND_IPC_NUM_RX_BUF; i++) { + ipc_buf = (struct baseband_ipc_buf *) + kzalloc(sizeof(struct baseband_ipc_buf), GFP_KERNEL); + if (!ipc_buf) { + pr_err("cannot allocate baseband ipc rx buffer #%d\n", + i); + goto error_exit; + } + pr_debug("baseband_ipc_open - " + "rx_free: ipc_buf %p\n", + ipc_buf); + list_add_tail(&ipc_buf->list, &ipc->rx_free.buf); + } + for (i = 0; i < BASEBAND_IPC_NUM_TX_BUF; i++) { + ipc_buf = (struct baseband_ipc_buf *) + kzalloc(sizeof(struct baseband_ipc_buf), GFP_KERNEL); + if (!ipc_buf) { + pr_err("cannot allocate baseband ipc tx buffer #%d\n", + i); + goto error_exit; + } + pr_debug("baseband_ipc_open - " + "tx_free: ipc_buf %p\n", + ipc_buf); + list_add_tail(&ipc_buf->list, &ipc->tx_free.buf); + } + ipc->ipc_rx = (unsigned char *) 0; + ipc->ipc_tx = (unsigned char *) 0; + + /* create wait queues */ + init_waitqueue_head(&ipc->rx.wait); + init_waitqueue_head(&ipc->tx.wait); + init_waitqueue_head(&ipc->rx_free.wait); + init_waitqueue_head(&ipc->tx_free.wait); + + /* create work queue */ + ipc->workqueue = create_singlethread_workqueue + ("baseband_usb_chr_ipc_workqueue"); + if (!ipc->workqueue) { + pr_err("cannot create workqueue\n"); + goto error_exit; + } + if (work_func) + INIT_WORK(&ipc->work, work_func); + if (rx_work_func) + INIT_WORK(&ipc->rx_work, rx_work_func); + if (tx_work_func) + INIT_WORK(&ipc->tx_work, tx_work_func); + + pr_debug("baseband_ipc_open }\n"); + return ipc; + +error_exit: + baseband_ipc_close(ipc); + return (struct baseband_ipc *) 0; +} + +/* usb rx */ + +static void baseband_usb_chr_rx_urb_comp(struct urb *urb) +{ + struct baseband_usb *usb = (struct baseband_usb *) urb->context; + + pr_debug("baseband_usb_chr_rx_urb_comp { urb %p\n", urb); + + /* queue rx urb completion work */ + queue_work(usb->ipc->workqueue, &usb->ipc->rx_work); + + pr_debug("baseband_usb_chr_rx_urb_comp }\n"); +} + +static int baseband_usb_chr_rx_urb_submit(struct baseband_usb *usb) +{ + struct urb *urb; + void *buf; + int err; + + pr_debug("baseband_usb_chr_rx_urb_submit { usb %p\n", usb); + + if (!usb_device_connection) { + pr_err("!!no usb device conenction!!!!!\n"); + return -1; + } + + /* check input */ + if (usb->usb.rx_urb) { + pr_err("previous urb still active\n"); + return -1; + } + + /* allocate rx urb */ + urb = usb_alloc_urb(0, GFP_ATOMIC); + if (!urb) { + pr_err("usb_alloc_urb() failed\n"); + return -ENOMEM; + } + buf = kzalloc(USB_CHR_RX_BUFSIZ, GFP_ATOMIC); + if (!buf) { + pr_err("usb buffer kzalloc() failed\n"); + usb_free_urb(urb); + return -ENOMEM; + } + usb_fill_bulk_urb(urb, usb->usb.device, usb->usb.pipe.bulk.in, + buf, USB_CHR_RX_BUFSIZ, + baseband_usb_chr_rx_urb_comp, + usb); + urb->transfer_flags = 0; + + /* submit rx urb */ + usb->usb.rx_urb = urb; + err = usb_submit_urb(urb, GFP_ATOMIC); + if (err < 0) { + pr_err("usb_submit_urb() failed - err %d\n", err); + usb->usb.rx_urb = (struct urb *) 0; + kfree(urb->transfer_buffer); + usb_free_urb(urb); + return err; + } + + pr_debug("baseband_usb_chr_rx_urb_submit }\n"); + return err; +} + +static void baseband_usb_chr_rx_urb_comp_work(struct work_struct *work) +{ + struct baseband_usb *usb = baseband_usb_chr; + struct urb *urb = usb->usb.rx_urb; + size_t len; + + pr_debug("baseband_usb_chr_rx_urb_comp_work { work %p\n", work); + + /* put rx urb data in rx buffer */ + if (urb->actual_length) { + pr_debug("baseband_usb_chr_rx_urb_comp_work - " + "urb->actual_length %d\n", urb->actual_length); + len = put_ipc_rx_buf(usb->ipc, + urb->transfer_buffer, urb->actual_length); + baseband_ipc_dump("baseband_usb_chr_rx_urb_comp_work" + " - rx buf ", 0, + urb->transfer_buffer, len > 16 ? 16 : len); + if (len != urb->actual_length) { + pr_err("baseband_usb_chr_rx_urb_comp_work - " + "put_ipx_rx_buf() only put %d/%d bytes\n", + len, urb->actual_length); + } + /* increment count of available rx bytes */ + atomic_add(len, &g_rx_count); + } + + /* free rx urb */ + kfree(urb->transfer_buffer); + urb->transfer_buffer = (void *) 0; + usb_free_urb(urb); + usb->usb.rx_urb = (struct urb *) 0; + + /* submit next rx urb */ + baseband_usb_chr_rx_urb_submit(usb); + + pr_debug("baseband_usb_chr_rx_urb_comp_work }\n"); +} + +/* usb functions */ + +static void find_usb_pipe(struct baseband_usb *usb) +{ + struct usb_device *usbdev = usb->usb.device; + struct usb_interface *intf = usb->usb.interface; + unsigned char numendpoint = intf->cur_altsetting->desc.bNumEndpoints; + struct usb_host_endpoint *endpoint = intf->cur_altsetting->endpoint; + unsigned char n; + + for (n = 0; n < numendpoint; n++) { + if (usb_endpoint_is_isoc_in(&endpoint[n].desc)) { + pr_debug("endpoint[%d] isochronous in\n", n); + usb->usb.pipe.isoch.in = usb_rcvisocpipe(usbdev, + endpoint[n].desc.bEndpointAddress); + } else if (usb_endpoint_is_isoc_out(&endpoint[n].desc)) { + pr_debug("endpoint[%d] isochronous out\n", n); + usb->usb.pipe.isoch.out = usb_sndisocpipe(usbdev, + endpoint[n].desc.bEndpointAddress); + } else if (usb_endpoint_is_bulk_in(&endpoint[n].desc)) { + pr_debug("endpoint[%d] bulk in\n", n); + usb->usb.pipe.bulk.in = usb_rcvbulkpipe(usbdev, + endpoint[n].desc.bEndpointAddress); + } else if (usb_endpoint_is_bulk_out(&endpoint[n].desc)) { + pr_debug("endpoint[%d] bulk out\n", n); + usb->usb.pipe.bulk.out = usb_sndbulkpipe(usbdev, + endpoint[n].desc.bEndpointAddress); + } else if (usb_endpoint_is_int_in(&endpoint[n].desc)) { + pr_debug("endpoint[%d] interrupt in\n", n); + usb->usb.pipe.interrupt.in = usb_rcvintpipe(usbdev, + endpoint[n].desc.bEndpointAddress); + } else if (usb_endpoint_is_int_out(&endpoint[n].desc)) { + pr_debug("endpoint[%d] interrupt out\n", n); + usb->usb.pipe.interrupt.out = usb_sndintpipe(usbdev, + endpoint[n].desc.bEndpointAddress); + } else { + pr_debug("endpoint[%d] skipped\n", n); + } + } +} + +static int baseband_usb_driver_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + int err; + + pr_debug("%s(%d) { intf %p id %p\n", __func__, __LINE__, intf, id); + + pr_debug("intf->cur_altsetting->desc.bInterfaceNumber %02x\n", + intf->cur_altsetting->desc.bInterfaceNumber); + pr_debug("intf->cur_altsetting->desc.bAlternateSetting %02x\n", + intf->cur_altsetting->desc.bAlternateSetting); + pr_debug("intf->cur_altsetting->desc.bNumEndpoints %02x\n", + intf->cur_altsetting->desc.bNumEndpoints); + pr_debug("intf->cur_altsetting->desc.bInterfaceClass %02x\n", + intf->cur_altsetting->desc.bInterfaceClass); + pr_debug("intf->cur_altsetting->desc.bInterfaceSubClass %02x\n", + intf->cur_altsetting->desc.bInterfaceSubClass); + pr_debug("intf->cur_altsetting->desc.bInterfaceProtocol %02x\n", + intf->cur_altsetting->desc.bInterfaceProtocol); + pr_debug("intf->cur_altsetting->desc.iInterface %02x\n", + intf->cur_altsetting->desc.iInterface); + + /* usb interface mismatch */ + if (baseband_usb_chr_intf != + intf->cur_altsetting->desc.bInterfaceNumber) { + pr_debug("%s(%d) } -ENODEV\n", __func__, __LINE__); + return -ENODEV; + } + + /* usb interface match */ + baseband_usb_chr->usb.device = interface_to_usbdev(intf); + baseband_usb_chr->usb.interface = intf; + find_usb_pipe(baseband_usb_chr); + baseband_usb_chr->usb.rx_urb = (struct urb *) 0; + baseband_usb_chr->usb.tx_urb = (struct urb *) 0; + pr_debug("baseband_usb_chr->usb.driver->name %s\n", + baseband_usb_chr->usb.driver->name); + pr_debug("baseband_usb_chr->usb.device %p\n", + baseband_usb_chr->usb.device); + pr_debug("baseband_usb_chr->usb.interface %p\n", + baseband_usb_chr->usb.interface); + pr_debug("baseband_usb_chr->usb.pipe.isoch.in %x\n", + baseband_usb_chr->usb.pipe.isoch.in); + pr_debug("baseband_usb_chr->usb.pipe.isoch.out %x\n", + baseband_usb_chr->usb.pipe.isoch.out); + pr_debug("baseband_usb_chr->usb.pipe.bulk.in %x\n", + baseband_usb_chr->usb.pipe.bulk.in); + pr_debug("baseband_usb_chr->usb.pipe.bulk.out %x\n", + baseband_usb_chr->usb.pipe.bulk.out); + pr_debug("baseband_usb_chr->usb.pipe.interrupt.in %x\n", + baseband_usb_chr->usb.pipe.interrupt.in); + pr_debug("baseband_usb_chr->usb.pipe.interrupt.out %x\n", + baseband_usb_chr->usb.pipe.interrupt.out); + usb_device_connection = true; + + /* start usb rx */ + err = baseband_usb_chr_rx_urb_submit(baseband_usb_chr); + if (err < 0) { + pr_err("submit rx failed - err %d\n", err); + return -ENODEV; + } + + pr_debug("%s(%d) }\n", __func__, __LINE__); + return 0; +} + +static void baseband_usb_driver_disconnect(struct usb_interface *intf) +{ + struct usb_device *usb_dev = interface_to_usbdev(intf); + pr_debug("%s(%d) { intf %p\n", __func__, __LINE__, intf); + pr_debug("%s(%d) }\n", __func__, __LINE__); + if (baseband_usb_chr->usb.interface != intf) { + pr_info("%s(%d) -ENODEV\n", __func__, __LINE__); + return; + } + if (baseband_usb_chr->usb.device == usb_dev) { + pr_info("%s: Matching usb device: Flush workqueue\n", __func__); + flush_workqueue(baseband_usb_chr->ipc->workqueue); + usb_device_connection = false; + } + +} + +static char baseband_usb_driver_name[32]; + +static struct usb_device_id baseband_usb_driver_id_table[2]; + +static struct usb_driver baseband_usb_driver = { + .name = baseband_usb_driver_name, + .probe = baseband_usb_driver_probe, + .disconnect = baseband_usb_driver_disconnect, + .id_table = baseband_usb_driver_id_table, +}; + +static void baseband_usb_chr_work(struct work_struct *work) +{ + struct baseband_usb *usb = baseband_usb_chr; + struct { + unsigned char *buf; + unsigned int bufsiz_byte; + } rx, tx; + int ipc_tx_byte; + int err; + + pr_debug("baseband_usb_chr_work {\n"); + + /* check input */ + if (!usb || !usb->ipc) { + pr_err("baseband_usb_chr_work - " + "usb not open\n"); + return; + } + if (!usb->usb.device) { + pr_err("baseband_usb_chr_work - " + "usb device not probed yet\n"); + mdelay(10); + queue_work(usb->ipc->workqueue, &usb->ipc->work); + return; + } + + /* allocate buffers on first transaction (will be freed on close) */ + if (!usb->ipc->ipc_rx) { + usb->ipc->ipc_rx = kzalloc(USB_CHR_RX_BUFSIZ, GFP_KERNEL); + if (!usb->ipc->ipc_rx) { + pr_err("baseband_usb_chr_work - " + "cannot allocate usb->ipc->ipc_rx\n"); + return; + } + } + if (!usb->ipc->ipc_tx) { + usb->ipc->ipc_tx = kzalloc(USB_CHR_TX_BUFSIZ, GFP_KERNEL); + if (!usb->ipc->ipc_tx) { + pr_err("baseband_usb_chr_work - " + "cannot allocate usb->ipc->ipc_tx\n"); + return; + } + } + + /* usb transaction loop */ + rx.buf = usb->ipc->ipc_rx; + tx.buf = usb->ipc->ipc_tx; + while ((tx.bufsiz_byte = peek_ipc_tx_bufsiz(usb->ipc, + USB_CHR_TX_BUFSIZ)) != 0) { + get_ipc_tx_buf(usb->ipc, tx.buf, tx.bufsiz_byte); + err = usb_bulk_msg(usb->usb.device, usb->usb.pipe.bulk.out, + tx.buf, tx.bufsiz_byte, &ipc_tx_byte, USB_CHR_TIMEOUT); + if (err < 0) { + pr_err("baseband_usb_chr_work - " + "usb_bulk_msg err %d\n", err); + continue; + } + if (tx.bufsiz_byte != ipc_tx_byte) { + pr_err("tx.bufsiz_byte %d != ipc_tx_byte %d\n", + tx.bufsiz_byte, ipc_tx_byte); + continue; + } + } + + pr_debug("baseband_usb_chr_work }\n"); +} + +/* usb character file operations */ + +static int baseband_usb_chr_open(struct inode *inode, struct file *file) +{ + pr_debug("baseband_usb_chr_open\n"); + return 0; +} + +static int baseband_usb_chr_release(struct inode *inode, struct file *file) +{ + pr_debug("baseband_usb_chr_release\n"); + return 0; +} + +static ssize_t baseband_usb_chr_read(struct file *file, char *buf, + size_t count, loff_t *pos) +{ + ssize_t ret; + + pr_debug("baseband_usb_chr_read\n"); + + ret = baseband_ipc_file_read(baseband_usb_chr->ipc, + file, buf, count, pos); + if (ret > 0) { + /* decrement count of available rx bytes */ + int val = atomic_read(&g_rx_count); + pr_debug("baseband_usb_chr_read - read %d unread %d\n", + ret, val - ret); + atomic_sub(ret, &g_rx_count); + } + return ret; +} + +static ssize_t baseband_usb_chr_write(struct file *file, const char *buf, + size_t count, loff_t *pos) +{ + pr_debug("baseband_usb_chr_write\n"); + return baseband_ipc_file_write(baseband_usb_chr->ipc, + file, buf, count, pos); +} + +static long baseband_usb_chr_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + pr_debug("baseband_usb_chr_ioctl\n"); + switch (cmd) { + case TCFLSH: + pr_debug("TCFLSH\n"); + /* flush queued ipc transaction work */ + flush_workqueue(baseband_usb_chr->ipc->workqueue); + return 0; + case FIONREAD: + pr_debug("FIONREAD\n"); + /* return count of available rx bytes */ + { + int __user *p = (int __user *) arg; + int val = atomic_read(&g_rx_count); + if (put_user(val, p)) + break; + } + return 0; + default: + pr_err("unsupported ioctl cmd %x\n", cmd); + } + return -ENODEV; +} + +static const struct file_operations baseband_usb_chr_fops = { + .open = baseband_usb_chr_open, + .release = baseband_usb_chr_release, + .read = baseband_usb_chr_read, + .write = baseband_usb_chr_write, + .unlocked_ioctl = baseband_usb_chr_ioctl, +}; + +/* usb device driver functions */ + +static void baseband_usb_close(struct baseband_usb *usb) +{ + pr_debug("baseband_usb_close {\n"); + + /* check input */ + if (!usb) + return; + + /* close usb driver */ + if (usb->usb.driver) { + pr_debug("close usb driver {\n"); + usb_deregister(usb->usb.driver); + usb->usb.driver = (struct usb_driver *) 0; + pr_debug("close usb driver }\n"); + } + + /* close baseband ipc */ + if (usb->ipc) { + baseband_ipc_close(usb->ipc); + usb->ipc = (struct baseband_ipc *) 0; + } + + /* free baseband usb structure */ + kfree(usb); + + pr_debug("baseband_usb_close }\n"); +} + +static struct baseband_usb *baseband_usb_open(unsigned int vid, + unsigned int pid, + unsigned int intf, + work_func_t work_func, + work_func_t rx_work_func, + work_func_t tx_work_func) +{ + struct baseband_usb *usb; + int err; + + pr_debug("baseband_usb_open {\n"); + + /* allocate baseband usb structure */ + usb = kzalloc(sizeof(struct baseband_usb), GFP_KERNEL); + if (!usb) + return (struct baseband_usb *) 0; + baseband_usb_chr = usb; + + /* open baseband ipc */ + usb->ipc = baseband_ipc_open(work_func, + rx_work_func, + tx_work_func); + if (!usb->ipc) { + pr_err("open baseband ipc failed\n"); + goto error_exit; + } + + /* open usb driver */ + sprintf(baseband_usb_driver_name, + "baseband_usb_%x_%x_%x", + vid, pid, intf); + baseband_usb_driver_id_table[0].match_flags + = USB_DEVICE_ID_MATCH_DEVICE; + baseband_usb_driver_id_table[0].idVendor = vid; + baseband_usb_driver_id_table[0].idProduct = pid; + usb->usb.driver = &baseband_usb_driver; + err = usb_register(&baseband_usb_driver); + if (err < 0) { + pr_err("cannot open usb driver - err %d\n", err); + goto error_exit; + } + + pr_debug("baseband_usb_open }\n"); + return usb; + +error_exit: + baseband_usb_close(usb); + baseband_usb_chr = (struct baseband_usb *) 0; + return (struct baseband_usb *) 0; +} + +/* module init / exit functions */ + +static int baseband_usb_chr_init(void) +{ + int err; + + pr_debug("baseband_usb_chr_init {\n"); + + /* open baseband usb */ + baseband_usb_chr = baseband_usb_open + (baseband_usb_chr_vid, + baseband_usb_chr_pid, + baseband_usb_chr_intf, + baseband_usb_chr_work, + baseband_usb_chr_rx_urb_comp_work, + (work_func_t) 0); + if (!baseband_usb_chr) { + pr_err("cannot open baseband usb chr\n"); + err = -1; + goto err1; + } + + /* register character device */ + err = register_chrdev(BASEBAND_USB_CHR_DEV_MAJOR, + BASEBAND_USB_CHR_DEV_NAME, + &baseband_usb_chr_fops); + if (err < 0) { + pr_err("cannot register character device - %d\n", err); + goto err2; + } + pr_debug("registered baseband usb character device - major %d\n", + BASEBAND_USB_CHR_DEV_MAJOR); + + pr_debug("baseband_usb_chr_init }\n"); + return 0; +err2: baseband_usb_close(baseband_usb_chr); + baseband_usb_chr = (struct baseband_usb *) 0; +err1: return err; +} + +static void baseband_usb_chr_exit(void) +{ + pr_debug("baseband_usb_chr_exit {\n"); + + /* unregister character device */ + unregister_chrdev(BASEBAND_USB_CHR_DEV_MAJOR, + BASEBAND_USB_CHR_DEV_NAME); + + /* close baseband usb */ + if (baseband_usb_chr) { + baseband_usb_close(baseband_usb_chr); + baseband_usb_chr = (struct baseband_usb *) 0; + } + + pr_debug("baseband_usb_chr_exit }\n"); +} + +module_init(baseband_usb_chr_init) +module_exit(baseband_usb_chr_exit) + diff --git a/drivers/usb/serial/baseband_usb_chr.h b/drivers/usb/serial/baseband_usb_chr.h new file mode 100644 index 00000000000..7935e795a54 --- /dev/null +++ b/drivers/usb/serial/baseband_usb_chr.h @@ -0,0 +1,106 @@ +/* + * baseband_usb_chr.h + * + * USB character driver to communicate with baseband modems. + * + * Copyright (c) 2011, NVIDIA Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __BASEBAND_USB_CHR_H__ +#define __BASEBAND_USB_CHR_H__ + +#define BASEBAND_USB_CHR_DEV_NAME "baseband_usb_chr" +#define BASEBAND_USB_CHR_DEV_MAJOR 66 + +#ifndef USB_CHR_RX_BUFSIZ +#define USB_CHR_RX_BUFSIZ (128*1024) +#endif /* USB_CHR_RX_BUFSIZ */ + +#ifndef USB_CHR_TX_BUFSIZ +#define USB_CHR_TX_BUFSIZ (128*1024) +#endif /* USB_CHR_TX_BUFSIZ */ + +#ifndef USB_CHR_TIMEOUT +#define USB_CHR_TIMEOUT 5000 /* ms */ +#endif /* USB_CHR_TIMEOUT */ + +#ifndef BASEBAND_IPC_NUM_RX_BUF +#define BASEBAND_IPC_NUM_RX_BUF 32 +#endif /* BASEBAND_IPC_NUM_RX_BUF */ + +#ifndef BASEBAND_IPC_NUM_TX_BUF +#define BASEBAND_IPC_NUM_TX_BUF 16 +#endif /* BASEBAND_IPC_NUM_TX_BUF */ + +#ifndef BASEBAND_IPC_BUFSIZ +#define BASEBAND_IPC_BUFSIZ 65536 +#endif /* BASEBAND_IPC_BUFSIZ */ + +struct baseband_ipc { + /* rx / tx data */ + struct semaphore buf_sem; + struct { + /* linked list of data buffers */ + struct list_head buf; + /* wait queue of processes trying to access data buffers */ + wait_queue_head_t wait; + } rx, tx, rx_free, tx_free; + unsigned char *ipc_rx; + unsigned char *ipc_tx; + /* work queue + * - queued per ipc transaction + * - initiated by either: + * = interrupt on gpio line (rx data available) + * = tx data packet being added to tx linked list + */ + struct workqueue_struct *workqueue; + struct work_struct work; + struct work_struct rx_work; + struct work_struct tx_work; +}; + +struct baseband_ipc_buf { + struct list_head list; + /* data buffer */ + unsigned char data[BASEBAND_IPC_BUFSIZ]; + /* offset of first data byte */ + size_t offset; + /* number of valid data bytes */ + size_t count; +}; + +struct baseband_usb { + struct baseband_ipc *ipc; + struct { + struct usb_driver *driver; + struct usb_device *device; + struct usb_interface *interface; + struct { + struct { + unsigned int in; + unsigned int out; + } isoch, bulk, interrupt; + } pipe; + /* currently active rx urb */ + struct urb *rx_urb; + /* currently active tx urb */ + struct urb *tx_urb; + } usb; +}; + +#endif /* __BASEBAND_USB_CHR_H__ */ + diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c new file mode 100644 index 00000000000..3cfc762f505 --- /dev/null +++ b/drivers/usb/serial/ezusb.c @@ -0,0 +1,61 @@ +/* + * EZ-USB specific functions used by some of the USB to Serial drivers. + * + * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */ +#define CPUCS_REG 0x7F92 + +int ezusb_writememory(struct usb_serial *serial, int address, + unsigned char *data, int length, __u8 request) +{ + int result; + unsigned char *transfer_buffer; + + /* dbg("ezusb_writememory %x, %d", address, length); */ + if (!serial->dev) { + printk(KERN_ERR "ezusb: %s - no physical device present, " + "failing.\n", __func__); + return -ENODEV; + } + + transfer_buffer = kmemdup(data, length, GFP_KERNEL); + if (!transfer_buffer) { + dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", + __func__, length); + return -ENOMEM; + } + result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), + request, 0x40, address, 0, transfer_buffer, length, 3000); + kfree(transfer_buffer); + return result; +} +EXPORT_SYMBOL_GPL(ezusb_writememory); + +int ezusb_set_reset(struct usb_serial *serial, unsigned char reset_bit) +{ + int response; + + /* dbg("%s - %d", __func__, reset_bit); */ + response = ezusb_writememory(serial, CPUCS_REG, &reset_bit, 1, 0xa0); + if (response < 0) + dev_err(&serial->dev->dev, "%s- %d failed\n", + __func__, reset_bit); + return response; +} +EXPORT_SYMBOL_GPL(ezusb_set_reset); + -- cgit v1.2.2