aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSteve French <sfrench@us.ibm.com>2008-04-25 16:20:10 -0400
committerSteve French <sfrench@us.ibm.com>2008-04-25 16:20:10 -0400
commit404e86e1550cc2c84bb57a372af784585c732f9a (patch)
treec0e8e2d61c1b1c79705c0dc9f0f16e35267286e4 /drivers
parent0206e61b467fde4d7b50f1a64355182a4fd9576b (diff)
parentb9fa38f75ea7e1f64bc29653ca9758303ce698e4 (diff)
Merge branch 'master' of /pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/ata/ahci.c15
-rw-r--r--drivers/ata/ata_piix.c1
-rw-r--r--drivers/ata/libata-acpi.c4
-rw-r--r--drivers/ata/libata-core.c7
-rw-r--r--drivers/ata/libata-eh.c1
-rw-r--r--drivers/ata/libata-sff.c4
-rw-r--r--drivers/ata/libata.h1
-rw-r--r--drivers/ata/pata_at32.c3
-rw-r--r--drivers/ata/pata_bf54x.c3
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c1
-rw-r--r--drivers/ata/pata_platform.c1
-rw-r--r--drivers/ata/pata_rb500_cf.c3
-rw-r--r--drivers/ata/sata_mv.c583
-rw-r--r--drivers/ata/sata_nv.c11
-rw-r--r--drivers/ata/sata_sis.c12
-rw-r--r--drivers/block/xen-blkfront.c23
-rw-r--r--drivers/char/keyboard.c6
-rw-r--r--drivers/char/mem.c133
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c2
-rw-r--r--drivers/hid/usbhid/hid-quirks.c4
-rw-r--r--drivers/ide/arm/palm_bk3710.c4
-rw-r--r--drivers/ide/legacy/ide_platform.c2
-rw-r--r--drivers/ieee1394/dv1394.c2
-rw-r--r--drivers/ieee1394/iso.h2
-rw-r--r--drivers/ieee1394/ohci1394.c34
-rw-r--r--drivers/ieee1394/raw1394.c9
-rw-r--r--drivers/ieee1394/video1394.c2
-rw-r--r--drivers/input/Kconfig9
-rw-r--r--drivers/input/Makefile2
-rw-r--r--drivers/input/input-polldev.c6
-rw-r--r--drivers/input/joystick/Kconfig12
-rw-r--r--drivers/input/joystick/Makefile3
-rw-r--r--drivers/input/joystick/xpad.c233
-rw-r--r--drivers/input/joystick/zhenhua.c243
-rw-r--r--drivers/input/keyboard/aaed2000_kbd.c4
-rw-r--r--drivers/input/keyboard/bf54x-keys.c37
-rw-r--r--drivers/input/keyboard/corgikbd.c2
-rw-r--r--drivers/input/keyboard/gpio_keys.c5
-rw-r--r--drivers/input/keyboard/jornada680_kbd.c2
-rw-r--r--drivers/input/keyboard/jornada720_kbd.c4
-rw-r--r--drivers/input/keyboard/locomokbd.c73
-rw-r--r--drivers/input/keyboard/omap-keypad.c9
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c4
-rw-r--r--drivers/input/keyboard/spitzkbd.c1
-rw-r--r--drivers/input/keyboard/tosakbd.c23
-rw-r--r--drivers/input/misc/cobalt_btns.c3
-rw-r--r--drivers/input/mouse/gpio_mouse.c4
-rw-r--r--drivers/input/serio/Kconfig10
-rw-r--r--drivers/input/serio/Makefile1
-rw-r--r--drivers/input/serio/at32psif.c375
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h12
-rw-r--r--drivers/input/serio/rpckbd.c2
-rw-r--r--drivers/input/tablet/Kconfig10
-rw-r--r--drivers/input/tablet/aiptek.c2
-rw-r--r--drivers/input/tablet/wacom.h3
-rw-r--r--drivers/input/tablet/wacom_sys.c76
-rw-r--r--drivers/input/tablet/wacom_wac.c2
-rw-r--r--drivers/input/touchscreen/Kconfig53
-rw-r--r--drivers/input/touchscreen/Makefile7
-rw-r--r--drivers/input/touchscreen/ads7846.c22
-rw-r--r--drivers/input/touchscreen/corgi_ts.c2
-rw-r--r--drivers/input/touchscreen/jornada720_ts.c4
-rw-r--r--drivers/input/touchscreen/mainstone-wm97xx.c302
-rw-r--r--drivers/input/touchscreen/ucb1400_ts.c4
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c31
-rw-r--r--drivers/input/touchscreen/wm9705.c353
-rw-r--r--drivers/input/touchscreen/wm9712.c462
-rw-r--r--drivers/input/touchscreen/wm9713.c460
-rw-r--r--drivers/input/touchscreen/wm97xx-core.c829
-rw-r--r--drivers/input/xen-kbdfront.c340
-rw-r--r--drivers/leds/Kconfig17
-rw-r--r--drivers/leds/Makefile2
-rw-r--r--drivers/leds/led-class.c12
-rw-r--r--drivers/leds/led-core.c4
-rw-r--r--drivers/leds/led-triggers.c120
-rw-r--r--drivers/leds/leds-clevo-mail.c16
-rw-r--r--drivers/leds/leds-cobalt-qube.c2
-rw-r--r--drivers/leds/leds-cobalt-raq.c6
-rw-r--r--drivers/leds/leds-corgi.c11
-rw-r--r--drivers/leds/leds-fsg.c261
-rw-r--r--drivers/leds/leds-gpio.c15
-rw-r--r--drivers/leds/leds-h1940.c64
-rw-r--r--drivers/leds/leds-hp6xx.c6
-rw-r--r--drivers/leds/leds-s3c24xx.c4
-rw-r--r--drivers/leds/leds-spitz.c11
-rw-r--r--drivers/leds/leds.h11
-rw-r--r--drivers/leds/ledtrig-default-on.c45
-rw-r--r--drivers/leds/ledtrig-ide-disk.c2
-rw-r--r--drivers/leds/ledtrig-timer.c35
-rw-r--r--drivers/macintosh/mac_hid.c6
-rw-r--r--drivers/macintosh/windfarm_pm112.c3
-rw-r--r--drivers/macintosh/windfarm_pm81.c4
-rw-r--r--drivers/macintosh/windfarm_pm91.c3
-rw-r--r--drivers/md/Makefile6
-rw-r--r--drivers/md/dm-exception-store.c10
-rw-r--r--drivers/md/dm-io.c38
-rw-r--r--drivers/md/dm-io.h79
-rw-r--r--drivers/md/dm-kcopyd.c (renamed from drivers/md/kcopyd.c)298
-rw-r--r--drivers/md/dm-log.c254
-rw-r--r--drivers/md/dm-log.h131
-rw-r--r--drivers/md/dm-raid1.c132
-rw-r--r--drivers/md/dm-snap.c22
-rw-r--r--drivers/md/dm-snap.h4
-rw-r--r--drivers/md/dm-table.c42
-rw-r--r--drivers/md/dm.c16
-rw-r--r--drivers/md/dm.h98
-rw-r--r--drivers/md/kcopyd.h42
-rw-r--r--drivers/mtd/Kconfig6
-rw-r--r--drivers/mtd/Makefile1
-rw-r--r--drivers/mtd/ar7part.c151
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c19
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c30
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c15
-rw-r--r--drivers/mtd/chips/cfi_probe.c7
-rw-r--r--drivers/mtd/chips/cfi_util.c2
-rw-r--r--drivers/mtd/chips/jedec_probe.c73
-rw-r--r--drivers/mtd/cmdlinepart.c15
-rw-r--r--drivers/mtd/devices/Kconfig7
-rw-r--r--drivers/mtd/devices/block2mtd.c10
-rw-r--r--drivers/mtd/devices/lart.c16
-rw-r--r--drivers/mtd/devices/m25p80.c40
-rw-r--r--drivers/mtd/devices/mtdram.c1
-rw-r--r--drivers/mtd/devices/phram.c2
-rw-r--r--drivers/mtd/ftl.c6
-rw-r--r--drivers/mtd/inftlmount.c5
-rw-r--r--drivers/mtd/maps/Kconfig3
-rw-r--r--drivers/mtd/maps/bast-flash.c5
-rw-r--r--drivers/mtd/maps/ck804xrom.c89
-rw-r--r--drivers/mtd/maps/integrator-flash.c2
-rw-r--r--drivers/mtd/maps/ixp2000.c3
-rw-r--r--drivers/mtd/maps/ixp4xx.c2
-rw-r--r--drivers/mtd/maps/omap_nor.c12
-rw-r--r--drivers/mtd/maps/pcmciamtd.c2
-rw-r--r--drivers/mtd/maps/physmap.c8
-rw-r--r--drivers/mtd/maps/plat-ram.c50
-rw-r--r--drivers/mtd/maps/pmcmsp-flash.c2
-rw-r--r--drivers/mtd/maps/sa1100-flash.c2
-rw-r--r--drivers/mtd/maps/sharpsl-flash.c2
-rw-r--r--drivers/mtd/maps/tqm8xxl.c6
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/nand/Kconfig56
-rw-r--r--drivers/mtd/nand/Makefile2
-rw-r--r--drivers/mtd/nand/at91_nand.c370
-rw-r--r--drivers/mtd/nand/bf5xx_nand.c17
-rw-r--r--drivers/mtd/nand/cs553x_nand.c2
-rw-r--r--drivers/mtd/nand/fsl_elbc_nand.c39
-rw-r--r--drivers/mtd/nand/fsl_upm.c291
-rw-r--r--drivers/mtd/nand/nand_base.c21
-rw-r--r--drivers/mtd/nand/ndfc.c2
-rw-r--r--drivers/mtd/nand/orion_nand.c1
-rw-r--r--drivers/mtd/nand/plat_nand.c2
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c1249
-rw-r--r--drivers/mtd/nand/rtc_from4.c50
-rw-r--r--drivers/mtd/nand/s3c2410.c73
-rw-r--r--drivers/mtd/nftlmount.c5
-rw-r--r--drivers/mtd/ofpart.c2
-rw-r--r--drivers/mtd/onenand/onenand_base.c51
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c3
-rw-r--r--drivers/mtd/rfd_ftl.c2
-rw-r--r--drivers/mtd/ubi/Kconfig9
-rw-r--r--drivers/mtd/ubi/build.c40
-rw-r--r--drivers/mtd/ubi/debug.h4
-rw-r--r--drivers/mtd/ubi/gluebi.c5
-rw-r--r--drivers/mtd/ubi/io.c4
-rw-r--r--drivers/mtd/ubi/scan.c41
-rw-r--r--drivers/mtd/ubi/scan.h2
-rw-r--r--drivers/mtd/ubi/ubi-media.h372
-rw-r--r--drivers/mtd/ubi/ubi.h7
-rw-r--r--drivers/net/Kconfig1
-rw-r--r--drivers/net/arm/at91_ether.c1
-rw-r--r--drivers/net/arm/ep93xx_eth.c2
-rw-r--r--drivers/net/atlx/atl1.c138
-rw-r--r--drivers/net/atlx/atlx.c177
-rw-r--r--drivers/net/ax88796.c1
-rw-r--r--drivers/net/bfin_mac.c7
-rw-r--r--drivers/net/cpmac.c2
-rw-r--r--drivers/net/dm9000.c1
-rw-r--r--drivers/net/e1000e/82571.c6
-rw-r--r--drivers/net/e1000e/defines.h3
-rw-r--r--drivers/net/e1000e/e1000.h34
-rw-r--r--drivers/net/e1000e/es2lan.c129
-rw-r--r--drivers/net/e1000e/ethtool.c49
-rw-r--r--drivers/net/e1000e/hw.h12
-rw-r--r--drivers/net/e1000e/netdev.c159
-rw-r--r--drivers/net/e1000e/phy.c73
-rw-r--r--drivers/net/ehea/ehea_main.c4
-rw-r--r--drivers/net/forcedeth.c432
-rw-r--r--drivers/net/gianfar.c104
-rw-r--r--drivers/net/ibm_newemac/core.c83
-rw-r--r--drivers/net/ibm_newemac/core.h14
-rw-r--r--drivers/net/ibm_newemac/mal.c20
-rw-r--r--drivers/net/ibm_newemac/rgmii.c2
-rw-r--r--drivers/net/ibm_newemac/tah.c2
-rw-r--r--drivers/net/ibm_newemac/zmii.c2
-rw-r--r--drivers/net/igb/igb_main.c2
-rw-r--r--drivers/net/irda/ali-ircc.c2
-rw-r--r--drivers/net/irda/pxaficp_ir.c2
-rw-r--r--drivers/net/irda/sa1100_ir.c2
-rw-r--r--drivers/net/ixgbe/ixgbe_main.c2
-rw-r--r--drivers/net/jazzsonic.c2
-rw-r--r--drivers/net/korina.c39
-rw-r--r--drivers/net/macb.c2
-rw-r--r--drivers/net/meth.c2
-rw-r--r--drivers/net/mv643xx_eth.c5
-rw-r--r--drivers/net/netx-eth.c2
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c15
-rw-r--r--drivers/net/niu.c371
-rw-r--r--drivers/net/niu.h12
-rw-r--r--drivers/net/phy/mdio_bus.c3
-rw-r--r--drivers/net/phy/phy.c4
-rw-r--r--drivers/net/phy/phy_device.c129
-rw-r--r--drivers/net/s2io.c128
-rw-r--r--drivers/net/s2io.h9
-rw-r--r--drivers/net/sgiseeq.c4
-rw-r--r--drivers/net/smc911x.c8
-rw-r--r--drivers/net/smc91x.c2
-rw-r--r--drivers/net/sni_82596.c2
-rw-r--r--drivers/net/tehuti.c15
-rw-r--r--drivers/net/tg3.c2
-rw-r--r--drivers/net/tsi108_eth.c2
-rw-r--r--drivers/net/typhoon.c1
-rw-r--r--drivers/net/ucc_geth.c2
-rw-r--r--drivers/net/via-velocity.c46
-rw-r--r--drivers/net/wan/c101.c6
-rw-r--r--drivers/net/wan/hdlc_fr.c4
-rw-r--r--drivers/net/xen-netfront.c2
-rw-r--r--drivers/of/of_i2c.c3
-rw-r--r--drivers/serial/of_serial.c14
-rw-r--r--drivers/usb/atm/cxacru.c2
-rw-r--r--drivers/usb/atm/ueagle-atm.c6
-rw-r--r--drivers/usb/atm/usbatm.c27
-rw-r--r--drivers/usb/atm/usbatm.h2
-rw-r--r--drivers/usb/class/cdc-acm.c98
-rw-r--r--drivers/usb/class/cdc-acm.h7
-rw-r--r--drivers/usb/core/Kconfig42
-rw-r--r--drivers/usb/core/config.c17
-rw-r--r--drivers/usb/core/devio.c73
-rw-r--r--drivers/usb/core/driver.c52
-rw-r--r--drivers/usb/core/hcd-pci.c15
-rw-r--r--drivers/usb/core/hcd.c25
-rw-r--r--drivers/usb/core/hcd.h9
-rw-r--r--drivers/usb/core/hub.c396
-rw-r--r--drivers/usb/core/hub.h9
-rw-r--r--drivers/usb/core/inode.c4
-rw-r--r--drivers/usb/core/message.c17
-rw-r--r--drivers/usb/core/quirks.c14
-rw-r--r--drivers/usb/core/sysfs.c22
-rw-r--r--drivers/usb/core/urb.c26
-rw-r--r--drivers/usb/core/usb.h2
-rw-r--r--drivers/usb/gadget/Kconfig18
-rw-r--r--drivers/usb/gadget/amd5536udc.c10
-rw-r--r--drivers/usb/gadget/at91_udc.c9
-rw-r--r--drivers/usb/gadget/dummy_hcd.c98
-rw-r--r--drivers/usb/gadget/epautoconf.c12
-rw-r--r--drivers/usb/gadget/ether.c18
-rw-r--r--drivers/usb/gadget/file_storage.c36
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c4
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h2
-rw-r--r--drivers/usb/gadget/gmidi.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c20
-rw-r--r--drivers/usb/gadget/inode.c18
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c132
-rw-r--r--drivers/usb/gadget/m66592-udc.h2
-rw-r--r--drivers/usb/gadget/net2280.h2
-rw-r--r--drivers/usb/gadget/omap_udc.c20
-rw-r--r--drivers/usb/gadget/printer.c92
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c26
-rw-r--r--drivers/usb/gadget/rndis.c148
-rw-r--r--drivers/usb/gadget/serial.c3
-rw-r--r--drivers/usb/host/Kconfig10
-rw-r--r--drivers/usb/host/ehci-au1xxx.c5
-rw-r--r--drivers/usb/host/ehci-dbg.c4
-rw-r--r--drivers/usb/host/ehci-fsl.c9
-rw-r--r--drivers/usb/host/ehci-hcd.c113
-rw-r--r--drivers/usb/host/ehci-hub.c34
-rw-r--r--drivers/usb/host/ehci-ixp4xx.c3
-rw-r--r--drivers/usb/host/ehci-pci.c9
-rw-r--r--drivers/usb/host/ehci-ppc-soc.c5
-rw-r--r--drivers/usb/host/ehci-ps3.c1
-rw-r--r--drivers/usb/host/ehci-q.c104
-rw-r--r--drivers/usb/host/ehci-sched.c46
-rw-r--r--drivers/usb/host/isp116x-hcd.c14
-rw-r--r--drivers/usb/host/ohci-at91.c2
-rw-r--r--drivers/usb/host/ohci-au1xxx.c1
-rw-r--r--drivers/usb/host/ohci-dbg.c2
-rw-r--r--drivers/usb/host/ohci-ep93xx.c5
-rw-r--r--drivers/usb/host/ohci-hub.c128
-rw-r--r--drivers/usb/host/ohci-lh7a404.c1
-rw-r--r--drivers/usb/host/ohci-omap.c8
-rw-r--r--drivers/usb/host/ohci-pci.c47
-rw-r--r--drivers/usb/host/ohci-pnx4008.c1
-rw-r--r--drivers/usb/host/ohci-pnx8550.c1
-rw-r--r--drivers/usb/host/ohci-ppc-of.c1
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c1
-rw-r--r--drivers/usb/host/ohci-ps3.c2
-rw-r--r--drivers/usb/host/ohci-pxa27x.c6
-rw-r--r--drivers/usb/host/ohci-s3c2410.c1
-rw-r--r--drivers/usb/host/ohci-sa1111.c1
-rw-r--r--drivers/usb/host/ohci-sh.c1
-rw-r--r--drivers/usb/host/ohci-sm501.c16
-rw-r--r--drivers/usb/host/ohci-ssb.c37
-rw-r--r--drivers/usb/host/pci-quirks.c6
-rw-r--r--drivers/usb/host/r8a66597-hcd.c256
-rw-r--r--drivers/usb/host/r8a66597.h51
-rw-r--r--drivers/usb/host/sl811-hcd.c12
-rw-r--r--drivers/usb/host/u132-hcd.c5124
-rw-r--r--drivers/usb/host/uhci-hcd.c35
-rw-r--r--drivers/usb/host/uhci-q.c2
-rw-r--r--drivers/usb/image/Kconfig4
-rw-r--r--drivers/usb/image/microtek.c3
-rw-r--r--drivers/usb/image/microtek.h1
-rw-r--r--drivers/usb/misc/Kconfig20
-rw-r--r--drivers/usb/misc/adutux.c120
-rw-r--r--drivers/usb/misc/appledisplay.c6
-rw-r--r--drivers/usb/misc/auerswald.c135
-rw-r--r--drivers/usb/misc/emi26.c30
-rw-r--r--drivers/usb/misc/emi62.c32
-rw-r--r--drivers/usb/misc/ftdi-elan.c2
-rw-r--r--drivers/usb/misc/iowarrior.c10
-rw-r--r--drivers/usb/misc/ldusb.c10
-rw-r--r--drivers/usb/misc/legousbtower.c92
-rw-r--r--drivers/usb/misc/phidgetkit.c6
-rw-r--r--drivers/usb/misc/phidgetmotorcontrol.c2
-rw-r--r--drivers/usb/misc/phidgetservo.c6
-rw-r--r--drivers/usb/misc/usblcd.c8
-rw-r--r--drivers/usb/misc/usbtest.c13
-rw-r--r--drivers/usb/mon/Makefile2
-rw-r--r--drivers/usb/mon/mon_bin.c9
-rw-r--r--drivers/usb/mon/mon_main.c3
-rw-r--r--drivers/usb/mon/mon_stat.c3
-rw-r--r--drivers/usb/serial/Kconfig76
-rw-r--r--drivers/usb/serial/Makefile3
-rw-r--r--drivers/usb/serial/aircable.c52
-rw-r--r--drivers/usb/serial/airprime.c37
-rw-r--r--drivers/usb/serial/ark3116.c10
-rw-r--r--drivers/usb/serial/belkin_sa.c23
-rw-r--r--drivers/usb/serial/ch341.c3
-rw-r--r--drivers/usb/serial/console.c10
-rw-r--r--drivers/usb/serial/cp2101.c114
-rw-r--r--drivers/usb/serial/cyberjack.c112
-rw-r--r--drivers/usb/serial/cypress_m8.c579
-rw-r--r--drivers/usb/serial/digi_acceleport.c50
-rw-r--r--drivers/usb/serial/empeg.c59
-rw-r--r--drivers/usb/serial/ezusb.c8
-rw-r--r--drivers/usb/serial/ftdi_sio.c171
-rw-r--r--drivers/usb/serial/funsoft.c3
-rw-r--r--drivers/usb/serial/garmin_gps.c115
-rw-r--r--drivers/usb/serial/generic.c56
-rw-r--r--drivers/usb/serial/hp4x.c3
-rw-r--r--drivers/usb/serial/io_edgeport.c326
-rw-r--r--drivers/usb/serial/io_tables.h12
-rw-r--r--drivers/usb/serial/io_ti.c398
-rw-r--r--drivers/usb/serial/ipaq.c53
-rw-r--r--drivers/usb/serial/ipw.c51
-rw-r--r--drivers/usb/serial/ir-usb.c53
-rw-r--r--drivers/usb/serial/iuu_phoenix.c165
-rw-r--r--drivers/usb/serial/keyspan.c281
-rw-r--r--drivers/usb/serial/keyspan.h16
-rw-r--r--drivers/usb/serial/keyspan_pda.c42
-rw-r--r--drivers/usb/serial/kl5kusb105.c124
-rw-r--r--drivers/usb/serial/kobil_sct.c75
-rw-r--r--drivers/usb/serial/mct_u232.c41
-rw-r--r--drivers/usb/serial/mos7720.c122
-rw-r--r--drivers/usb/serial/mos7840.c164
-rw-r--r--drivers/usb/serial/navman.c31
-rw-r--r--drivers/usb/serial/omninet.c42
-rw-r--r--drivers/usb/serial/option.c92
-rw-r--r--drivers/usb/serial/oti6858.c121
-rw-r--r--drivers/usb/serial/pl2303.c117
-rw-r--r--drivers/usb/serial/safe_serial.c60
-rw-r--r--drivers/usb/serial/sierra.c129
-rw-r--r--drivers/usb/serial/spcp8x5.c1072
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c211
-rw-r--r--drivers/usb/serial/usb-serial.c107
-rw-r--r--drivers/usb/serial/usb_debug.c3
-rw-r--r--drivers/usb/serial/visor.c103
-rw-r--r--drivers/usb/serial/whiteheat.c118
-rw-r--r--drivers/usb/storage/Kconfig39
-rw-r--r--drivers/usb/storage/Makefile1
-rw-r--r--drivers/usb/storage/cypress_atacb.c200
-rw-r--r--drivers/usb/storage/cypress_atacb.h25
-rw-r--r--drivers/usb/storage/libusual.c14
-rw-r--r--drivers/usb/storage/scsiglue.c26
-rw-r--r--drivers/usb/storage/transport.c23
-rw-r--r--drivers/usb/storage/unusual_devs.h8
-rw-r--r--drivers/usb/storage/usb.c26
-rw-r--r--drivers/usb/usb-skeleton.c8
-rw-r--r--drivers/video/Kconfig14
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/xen-fbfront.c550
-rw-r--r--drivers/xen/Kconfig19
-rw-r--r--drivers/xen/Makefile4
-rw-r--r--drivers/xen/balloon.c712
-rw-r--r--drivers/xen/events.c674
-rw-r--r--drivers/xen/features.c29
-rw-r--r--drivers/xen/grant-table.c37
-rw-r--r--drivers/xen/xenbus/xenbus_client.c6
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c32
-rw-r--r--drivers/xen/xencomm.c232
400 files changed, 20050 insertions, 8772 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 3a0e3549739f..80f0ec91e2cf 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -97,4 +97,6 @@ source "drivers/dca/Kconfig"
97source "drivers/auxdisplay/Kconfig" 97source "drivers/auxdisplay/Kconfig"
98 98
99source "drivers/uio/Kconfig" 99source "drivers/uio/Kconfig"
100
101source "drivers/xen/Kconfig"
100endmenu 102endmenu
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 986e3324e302..7c4f886f1f16 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -556,16 +556,27 @@ static inline void __iomem *ahci_port_base(struct ata_port *ap)
556 556
557static void ahci_enable_ahci(void __iomem *mmio) 557static void ahci_enable_ahci(void __iomem *mmio)
558{ 558{
559 int i;
559 u32 tmp; 560 u32 tmp;
560 561
561 /* turn on AHCI_EN */ 562 /* turn on AHCI_EN */
562 tmp = readl(mmio + HOST_CTL); 563 tmp = readl(mmio + HOST_CTL);
563 if (!(tmp & HOST_AHCI_EN)) { 564 if (tmp & HOST_AHCI_EN)
565 return;
566
567 /* Some controllers need AHCI_EN to be written multiple times.
568 * Try a few times before giving up.
569 */
570 for (i = 0; i < 5; i++) {
564 tmp |= HOST_AHCI_EN; 571 tmp |= HOST_AHCI_EN;
565 writel(tmp, mmio + HOST_CTL); 572 writel(tmp, mmio + HOST_CTL);
566 tmp = readl(mmio + HOST_CTL); /* flush && sanity check */ 573 tmp = readl(mmio + HOST_CTL); /* flush && sanity check */
567 WARN_ON(!(tmp & HOST_AHCI_EN)); 574 if (tmp & HOST_AHCI_EN)
575 return;
576 msleep(10);
568 } 577 }
578
579 WARN_ON(1);
569} 580}
570 581
571/** 582/**
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index b7c38eeb498f..ea2c7649d399 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -573,6 +573,7 @@ static const struct ich_laptop ich_laptop[] = {
573 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 573 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
574 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */ 574 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
575 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */ 575 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */
576 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
576 /* end marker */ 577 /* end marker */
577 { 0, } 578 { 0, }
578}; 579};
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 8c1cfc645c85..70b77e0899a8 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -227,11 +227,9 @@ void ata_acpi_associate(struct ata_host *host)
227 acpi_install_notify_handler(ap->acpi_handle, 227 acpi_install_notify_handler(ap->acpi_handle,
228 ACPI_SYSTEM_NOTIFY, 228 ACPI_SYSTEM_NOTIFY,
229 ata_acpi_ap_notify, ap); 229 ata_acpi_ap_notify, ap);
230#if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
231 /* we might be on a docking station */ 230 /* we might be on a docking station */
232 register_hotplug_dock_device(ap->acpi_handle, 231 register_hotplug_dock_device(ap->acpi_handle,
233 ata_acpi_ap_notify, ap); 232 ata_acpi_ap_notify, ap);
234#endif
235 } 233 }
236 234
237 for (j = 0; j < ata_link_max_devices(&ap->link); j++) { 235 for (j = 0; j < ata_link_max_devices(&ap->link); j++) {
@@ -241,11 +239,9 @@ void ata_acpi_associate(struct ata_host *host)
241 acpi_install_notify_handler(dev->acpi_handle, 239 acpi_install_notify_handler(dev->acpi_handle,
242 ACPI_SYSTEM_NOTIFY, 240 ACPI_SYSTEM_NOTIFY,
243 ata_acpi_dev_notify, dev); 241 ata_acpi_dev_notify, dev);
244#if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
245 /* we might be on a docking station */ 242 /* we might be on a docking station */
246 register_hotplug_dock_device(dev->acpi_handle, 243 register_hotplug_dock_device(dev->acpi_handle,
247 ata_acpi_dev_notify, dev); 244 ata_acpi_dev_notify, dev);
248#endif
249 } 245 }
250 } 246 }
251 } 247 }
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index b0b00af90d0e..51b7d2fad36a 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2616,7 +2616,7 @@ void ata_port_probe(struct ata_port *ap)
2616 * LOCKING: 2616 * LOCKING:
2617 * None. 2617 * None.
2618 */ 2618 */
2619void sata_print_link_status(struct ata_link *link) 2619static void sata_print_link_status(struct ata_link *link)
2620{ 2620{
2621 u32 sstatus, scontrol, tmp; 2621 u32 sstatus, scontrol, tmp;
2622 2622
@@ -2772,7 +2772,7 @@ static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol)
2772 * RETURNS: 2772 * RETURNS:
2773 * 1 if SATA spd configuration is needed, 0 otherwise. 2773 * 1 if SATA spd configuration is needed, 0 otherwise.
2774 */ 2774 */
2775int sata_set_spd_needed(struct ata_link *link) 2775static int sata_set_spd_needed(struct ata_link *link)
2776{ 2776{
2777 u32 scontrol; 2777 u32 scontrol;
2778 2778
@@ -3377,7 +3377,7 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
3377 * RETURNS: 3377 * RETURNS:
3378 * 0 if @linke is ready before @deadline; otherwise, -errno. 3378 * 0 if @linke is ready before @deadline; otherwise, -errno.
3379 */ 3379 */
3380extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline, 3380int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
3381 int (*check_ready)(struct ata_link *link)) 3381 int (*check_ready)(struct ata_link *link))
3382{ 3382{
3383 msleep(ATA_WAIT_AFTER_RESET_MSECS); 3383 msleep(ATA_WAIT_AFTER_RESET_MSECS);
@@ -6208,7 +6208,6 @@ EXPORT_SYMBOL_GPL(ata_host_detach);
6208EXPORT_SYMBOL_GPL(ata_sg_init); 6208EXPORT_SYMBOL_GPL(ata_sg_init);
6209EXPORT_SYMBOL_GPL(ata_qc_complete); 6209EXPORT_SYMBOL_GPL(ata_qc_complete);
6210EXPORT_SYMBOL_GPL(ata_qc_complete_multiple); 6210EXPORT_SYMBOL_GPL(ata_qc_complete_multiple);
6211EXPORT_SYMBOL_GPL(sata_print_link_status);
6212EXPORT_SYMBOL_GPL(atapi_cmd_type); 6211EXPORT_SYMBOL_GPL(atapi_cmd_type);
6213EXPORT_SYMBOL_GPL(ata_tf_to_fis); 6212EXPORT_SYMBOL_GPL(ata_tf_to_fis);
6214EXPORT_SYMBOL_GPL(ata_tf_from_fis); 6213EXPORT_SYMBOL_GPL(ata_tf_from_fis);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index d94359a24d41..61dcd0026c64 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1402,6 +1402,7 @@ static void ata_eh_analyze_ncq_error(struct ata_link *link)
1402 /* we've got the perpetrator, condemn it */ 1402 /* we've got the perpetrator, condemn it */
1403 qc = __ata_qc_from_tag(ap, tag); 1403 qc = __ata_qc_from_tag(ap, tag);
1404 memcpy(&qc->result_tf, &tf, sizeof(tf)); 1404 memcpy(&qc->result_tf, &tf, sizeof(tf));
1405 qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
1405 qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; 1406 qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
1406 ehc->i.err_mask &= ~AC_ERR_DEV; 1407 ehc->i.err_mask &= ~AC_ERR_DEV;
1407} 1408}
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 15499522e642..2ec65a8fda79 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -1208,7 +1208,7 @@ fsm_start:
1208 DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n", 1208 DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n",
1209 ap->print_id, qc->dev->devno, status); 1209 ap->print_id, qc->dev->devno, status);
1210 1210
1211 WARN_ON(qc->err_mask); 1211 WARN_ON(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM));
1212 1212
1213 ap->hsm_task_state = HSM_ST_IDLE; 1213 ap->hsm_task_state = HSM_ST_IDLE;
1214 1214
@@ -1222,7 +1222,7 @@ fsm_start:
1222 /* make sure qc->err_mask is available to 1222 /* make sure qc->err_mask is available to
1223 * know what's wrong and recover 1223 * know what's wrong and recover
1224 */ 1224 */
1225 WARN_ON(qc->err_mask == 0); 1225 WARN_ON(!(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)));
1226 1226
1227 ap->hsm_task_state = HSM_ST_IDLE; 1227 ap->hsm_task_state = HSM_ST_IDLE;
1228 1228
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 4aeeabb10a47..ae2cfd95d43e 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -101,7 +101,6 @@ extern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
101 unsigned int readid_flags); 101 unsigned int readid_flags);
102extern int ata_dev_configure(struct ata_device *dev); 102extern int ata_dev_configure(struct ata_device *dev);
103extern int sata_down_spd_limit(struct ata_link *link); 103extern int sata_down_spd_limit(struct ata_link *link);
104extern int sata_set_spd_needed(struct ata_link *link);
105extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); 104extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
106extern void ata_sg_clean(struct ata_queued_cmd *qc); 105extern void ata_sg_clean(struct ata_queued_cmd *qc);
107extern void ata_qc_free(struct ata_queued_cmd *qc); 106extern void ata_qc_free(struct ata_queued_cmd *qc);
diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
index 3e8651d78952..5e104385d6a3 100644
--- a/drivers/ata/pata_at32.c
+++ b/drivers/ata/pata_at32.c
@@ -381,6 +381,9 @@ static int __exit pata_at32_remove(struct platform_device *pdev)
381 return 0; 381 return 0;
382} 382}
383 383
384/* work with hotplug and coldplug */
385MODULE_ALIAS("platform:at32_ide");
386
384static struct platform_driver pata_at32_driver = { 387static struct platform_driver pata_at32_driver = {
385 .remove = __exit_p(pata_at32_remove), 388 .remove = __exit_p(pata_at32_remove),
386 .driver = { 389 .driver = {
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
index 0a5ad98635b1..a75de0684c15 100644
--- a/drivers/ata/pata_bf54x.c
+++ b/drivers/ata/pata_bf54x.c
@@ -1417,7 +1417,7 @@ static int bfin_reset_controller(struct ata_host *host)
1417 count = 10000000; 1417 count = 10000000;
1418 do { 1418 do {
1419 status = read_atapi_register(base, ATA_REG_STATUS); 1419 status = read_atapi_register(base, ATA_REG_STATUS);
1420 } while (count-- && (status & ATA_BUSY)); 1420 } while (--count && (status & ATA_BUSY));
1421 1421
1422 /* Enable only ATAPI Device interrupt */ 1422 /* Enable only ATAPI Device interrupt */
1423 ATAPI_SET_INT_MASK(base, 1); 1423 ATAPI_SET_INT_MASK(base, 1);
@@ -1601,3 +1601,4 @@ MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
1601MODULE_DESCRIPTION("PATA driver for blackfin 54x ATAPI controller"); 1601MODULE_DESCRIPTION("PATA driver for blackfin 54x ATAPI controller");
1602MODULE_LICENSE("GPL"); 1602MODULE_LICENSE("GPL");
1603MODULE_VERSION(DRV_VERSION); 1603MODULE_VERSION(DRV_VERSION);
1604MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 8a175f23b907..de8d186f5abf 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -221,6 +221,7 @@ MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
221MODULE_DESCRIPTION("low-level driver for ixp4xx Compact Flash PATA"); 221MODULE_DESCRIPTION("low-level driver for ixp4xx Compact Flash PATA");
222MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
223MODULE_VERSION(DRV_VERSION); 223MODULE_VERSION(DRV_VERSION);
224MODULE_ALIAS("platform:" DRV_NAME);
224 225
225module_init(ixp4xx_pata_init); 226module_init(ixp4xx_pata_init);
226module_exit(ixp4xx_pata_exit); 227module_exit(ixp4xx_pata_exit);
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 6527c56c34a3..8f65ad61b8af 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -277,3 +277,4 @@ MODULE_AUTHOR("Paul Mundt");
277MODULE_DESCRIPTION("low-level driver for platform device ATA"); 277MODULE_DESCRIPTION("low-level driver for platform device ATA");
278MODULE_LICENSE("GPL"); 278MODULE_LICENSE("GPL");
279MODULE_VERSION(DRV_VERSION); 279MODULE_VERSION(DRV_VERSION);
280MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/ata/pata_rb500_cf.c b/drivers/ata/pata_rb500_cf.c
index 800ae4601f44..4345174aaeec 100644
--- a/drivers/ata/pata_rb500_cf.c
+++ b/drivers/ata/pata_rb500_cf.c
@@ -239,6 +239,9 @@ static __devexit int rb500_pata_driver_remove(struct platform_device *pdev)
239 return 0; 239 return 0;
240} 240}
241 241
242/* work with hotplug and coldplug */
243MODULE_ALIAS("platform:" DRV_NAME);
244
242static struct platform_driver rb500_pata_platform_driver = { 245static struct platform_driver rb500_pata_platform_driver = {
243 .probe = rb500_pata_driver_probe, 246 .probe = rb500_pata_driver_probe,
244 .remove = __devexit_p(rb500_pata_driver_remove), 247 .remove = __devexit_p(rb500_pata_driver_remove),
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index d52ce1188327..26a6337195b3 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -23,46 +23,34 @@
23 */ 23 */
24 24
25/* 25/*
26 sata_mv TODO list: 26 * sata_mv TODO list:
27 27 *
28 1) Needs a full errata audit for all chipsets. I implemented most 28 * --> Errata workaround for NCQ device errors.
29 of the errata workarounds found in the Marvell vendor driver, but 29 *
30 I distinctly remember a couple workarounds (one related to PCI-X) 30 * --> More errata workarounds for PCI-X.
31 are still needed. 31 *
32 32 * --> Complete a full errata audit for all chipsets to identify others.
33 2) Improve/fix IRQ and error handling sequences. 33 *
34 34 * --> ATAPI support (Marvell claims the 60xx/70xx chips can do it).
35 3) ATAPI support (Marvell claims the 60xx/70xx chips can do it). 35 *
36 36 * --> Investigate problems with PCI Message Signalled Interrupts (MSI).
37 4) Think about TCQ support here, and for libata in general 37 *
38 with controllers that suppport it via host-queuing hardware 38 * --> Cache frequently-accessed registers in mv_port_priv to reduce overhead.
39 (a software-only implementation could be a nightmare). 39 *
40 40 * --> Develop a low-power-consumption strategy, and implement it.
41 5) Investigate problems with PCI Message Signalled Interrupts (MSI). 41 *
42 42 * --> [Experiment, low priority] Investigate interrupt coalescing.
43 6) Cache frequently-accessed registers in mv_port_priv to reduce overhead. 43 * Quite often, especially with PCI Message Signalled Interrupts (MSI),
44 44 * the overhead reduced by interrupt mitigation is quite often not
45 7) Fix/reenable hot plug/unplug (should happen as a side-effect of (2) above). 45 * worth the latency cost.
46 46 *
47 8) Develop a low-power-consumption strategy, and implement it. 47 * --> [Experiment, Marvell value added] Is it possible to use target
48 48 * mode to cross-connect two Linux boxes with Marvell cards? If so,
49 9) [Experiment, low priority] See if ATAPI can be supported using 49 * creating LibATA target mode support would be very interesting.
50 "unknown FIS" or "vendor-specific FIS" support, or something creative 50 *
51 like that. 51 * Target mode, for those without docs, is the ability to directly
52 52 * connect two SATA ports.
53 10) [Experiment, low priority] Investigate interrupt coalescing. 53 */
54 Quite often, especially with PCI Message Signalled Interrupts (MSI),
55 the overhead reduced by interrupt mitigation is quite often not
56 worth the latency cost.
57
58 11) [Experiment, Marvell value added] Is it possible to use target
59 mode to cross-connect two Linux boxes with Marvell cards? If so,
60 creating LibATA target mode support would be very interesting.
61
62 Target mode, for those without docs, is the ability to directly
63 connect two SATA controllers.
64
65*/
66 54
67#include <linux/kernel.h> 55#include <linux/kernel.h>
68#include <linux/module.h> 56#include <linux/module.h>
@@ -124,11 +112,11 @@ enum {
124 MV_MAX_SG_CT = 256, 112 MV_MAX_SG_CT = 256,
125 MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT), 113 MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT),
126 114
127 MV_PORTS_PER_HC = 4, 115 /* Determine hc from 0-7 port: hc = port >> MV_PORT_HC_SHIFT */
128 /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */
129 MV_PORT_HC_SHIFT = 2, 116 MV_PORT_HC_SHIFT = 2,
130 /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */ 117 MV_PORTS_PER_HC = (1 << MV_PORT_HC_SHIFT), /* 4 */
131 MV_PORT_MASK = 3, 118 /* Determine hc port from 0-7 port: hardport = port & MV_PORT_MASK */
119 MV_PORT_MASK = (MV_PORTS_PER_HC - 1), /* 3 */
132 120
133 /* Host Flags */ 121 /* Host Flags */
134 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 122 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
@@ -188,8 +176,8 @@ enum {
188 HC_MAIN_IRQ_MASK_OFS = 0x1d64, 176 HC_MAIN_IRQ_MASK_OFS = 0x1d64,
189 HC_SOC_MAIN_IRQ_CAUSE_OFS = 0x20020, 177 HC_SOC_MAIN_IRQ_CAUSE_OFS = 0x20020,
190 HC_SOC_MAIN_IRQ_MASK_OFS = 0x20024, 178 HC_SOC_MAIN_IRQ_MASK_OFS = 0x20024,
191 PORT0_ERR = (1 << 0), /* shift by port # */ 179 ERR_IRQ = (1 << 0), /* shift by port # */
192 PORT0_DONE = (1 << 1), /* shift by port # */ 180 DONE_IRQ = (1 << 1), /* shift by port # */
193 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */ 181 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
194 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */ 182 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
195 PCI_ERR = (1 << 18), 183 PCI_ERR = (1 << 18),
@@ -205,6 +193,7 @@ enum {
205 HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */ 193 HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */
206 HC_MAIN_RSVD_SOC = (0x3fffffb << 6), /* bits 31-9, 7-6 */ 194 HC_MAIN_RSVD_SOC = (0x3fffffb << 6), /* bits 31-9, 7-6 */
207 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE | 195 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
196 PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
208 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT | 197 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
209 HC_MAIN_RSVD), 198 HC_MAIN_RSVD),
210 HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE | 199 HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
@@ -215,8 +204,8 @@ enum {
215 HC_CFG_OFS = 0, 204 HC_CFG_OFS = 0,
216 205
217 HC_IRQ_CAUSE_OFS = 0x14, 206 HC_IRQ_CAUSE_OFS = 0x14,
218 CRPB_DMA_DONE = (1 << 0), /* shift by port # */ 207 DMA_IRQ = (1 << 0), /* shift by port # */
219 HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */ 208 HC_COAL_IRQ = (1 << 4), /* IRQ coalescing */
220 DEV_IRQ = (1 << 8), /* shift by port # */ 209 DEV_IRQ = (1 << 8), /* shift by port # */
221 210
222 /* Shadow block registers */ 211 /* Shadow block registers */
@@ -299,9 +288,7 @@ enum {
299 EDMA_ERR_IRQ_TRANSIENT = EDMA_ERR_LNK_CTRL_RX_0 | 288 EDMA_ERR_IRQ_TRANSIENT = EDMA_ERR_LNK_CTRL_RX_0 |
300 EDMA_ERR_LNK_CTRL_RX_1 | 289 EDMA_ERR_LNK_CTRL_RX_1 |
301 EDMA_ERR_LNK_CTRL_RX_3 | 290 EDMA_ERR_LNK_CTRL_RX_3 |
302 EDMA_ERR_LNK_CTRL_TX | 291 EDMA_ERR_LNK_CTRL_TX,
303 /* temporary, until we fix hotplug: */
304 (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON),
305 292
306 EDMA_EH_FREEZE = EDMA_ERR_D_PAR | 293 EDMA_EH_FREEZE = EDMA_ERR_D_PAR |
307 EDMA_ERR_PRD_PAR | 294 EDMA_ERR_PRD_PAR |
@@ -349,6 +336,8 @@ enum {
349 EDMA_IORDY_TMOUT = 0x34, 336 EDMA_IORDY_TMOUT = 0x34,
350 EDMA_ARB_CFG = 0x38, 337 EDMA_ARB_CFG = 0x38,
351 338
339 GEN_II_NCQ_MAX_SECTORS = 256, /* max sects/io on Gen2 w/NCQ */
340
352 /* Host private flags (hp_flags) */ 341 /* Host private flags (hp_flags) */
353 MV_HP_FLAG_MSI = (1 << 0), 342 MV_HP_FLAG_MSI = (1 << 0),
354 MV_HP_ERRATA_50XXB0 = (1 << 1), 343 MV_HP_ERRATA_50XXB0 = (1 << 1),
@@ -722,11 +711,6 @@ static inline void writelfl(unsigned long data, void __iomem *addr)
722 (void) readl(addr); /* flush to avoid PCI posted write */ 711 (void) readl(addr); /* flush to avoid PCI posted write */
723} 712}
724 713
725static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
726{
727 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
728}
729
730static inline unsigned int mv_hc_from_port(unsigned int port) 714static inline unsigned int mv_hc_from_port(unsigned int port)
731{ 715{
732 return port >> MV_PORT_HC_SHIFT; 716 return port >> MV_PORT_HC_SHIFT;
@@ -737,6 +721,29 @@ static inline unsigned int mv_hardport_from_port(unsigned int port)
737 return port & MV_PORT_MASK; 721 return port & MV_PORT_MASK;
738} 722}
739 723
724/*
725 * Consolidate some rather tricky bit shift calculations.
726 * This is hot-path stuff, so not a function.
727 * Simple code, with two return values, so macro rather than inline.
728 *
729 * port is the sole input, in range 0..7.
730 * shift is one output, for use with the main_cause and main_mask registers.
731 * hardport is the other output, in range 0..3
732 *
733 * Note that port and hardport may be the same variable in some cases.
734 */
735#define MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport) \
736{ \
737 shift = mv_hc_from_port(port) * HC_SHIFT; \
738 hardport = mv_hardport_from_port(port); \
739 shift += hardport * 2; \
740}
741
742static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
743{
744 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
745}
746
740static inline void __iomem *mv_hc_base_from_port(void __iomem *base, 747static inline void __iomem *mv_hc_base_from_port(void __iomem *base,
741 unsigned int port) 748 unsigned int port)
742{ 749{
@@ -783,7 +790,8 @@ static void mv_set_edma_ptrs(void __iomem *port_mmio,
783 /* 790 /*
784 * initialize request queue 791 * initialize request queue
785 */ 792 */
786 index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; 793 pp->req_idx &= MV_MAX_Q_DEPTH_MASK; /* paranoia */
794 index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT;
787 795
788 WARN_ON(pp->crqb_dma & 0x3ff); 796 WARN_ON(pp->crqb_dma & 0x3ff);
789 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); 797 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
@@ -799,7 +807,8 @@ static void mv_set_edma_ptrs(void __iomem *port_mmio,
799 /* 807 /*
800 * initialize response queue 808 * initialize response queue
801 */ 809 */
802 index = (pp->resp_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_RSP_Q_PTR_SHIFT; 810 pp->resp_idx &= MV_MAX_Q_DEPTH_MASK; /* paranoia */
811 index = pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT;
803 812
804 WARN_ON(pp->crpb_dma & 0xff); 813 WARN_ON(pp->crpb_dma & 0xff);
805 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); 814 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
@@ -837,9 +846,9 @@ static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio,
837 } 846 }
838 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) { 847 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) {
839 struct mv_host_priv *hpriv = ap->host->private_data; 848 struct mv_host_priv *hpriv = ap->host->private_data;
840 int hard_port = mv_hardport_from_port(ap->port_no); 849 int hardport = mv_hardport_from_port(ap->port_no);
841 void __iomem *hc_mmio = mv_hc_base_from_port( 850 void __iomem *hc_mmio = mv_hc_base_from_port(
842 mv_host_base(ap->host), hard_port); 851 mv_host_base(ap->host), hardport);
843 u32 hc_irq_cause, ipending; 852 u32 hc_irq_cause, ipending;
844 853
845 /* clear EDMA event indicators, if any */ 854 /* clear EDMA event indicators, if any */
@@ -847,8 +856,7 @@ static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio,
847 856
848 /* clear EDMA interrupt indicator, if any */ 857 /* clear EDMA interrupt indicator, if any */
849 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 858 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
850 ipending = (DEV_IRQ << hard_port) | 859 ipending = (DEV_IRQ | DMA_IRQ) << hardport;
851 (CRPB_DMA_DONE << hard_port);
852 if (hc_irq_cause & ipending) { 860 if (hc_irq_cause & ipending) {
853 writelfl(hc_irq_cause & ~ipending, 861 writelfl(hc_irq_cause & ~ipending,
854 hc_mmio + HC_IRQ_CAUSE_OFS); 862 hc_mmio + HC_IRQ_CAUSE_OFS);
@@ -864,7 +872,6 @@ static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio,
864 writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS); 872 writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS);
865 pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 873 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
866 } 874 }
867 WARN_ON(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)));
868} 875}
869 876
870/** 877/**
@@ -1036,10 +1043,16 @@ static void mv6_dev_config(struct ata_device *adev)
1036 * See mv_qc_prep() for more info. 1043 * See mv_qc_prep() for more info.
1037 */ 1044 */
1038 if (adev->flags & ATA_DFLAG_NCQ) { 1045 if (adev->flags & ATA_DFLAG_NCQ) {
1039 if (sata_pmp_attached(adev->link->ap)) 1046 if (sata_pmp_attached(adev->link->ap)) {
1040 adev->flags &= ~ATA_DFLAG_NCQ; 1047 adev->flags &= ~ATA_DFLAG_NCQ;
1041 else if (adev->max_sectors > ATA_MAX_SECTORS) 1048 ata_dev_printk(adev, KERN_INFO,
1042 adev->max_sectors = ATA_MAX_SECTORS; 1049 "NCQ disabled for command-based switching\n");
1050 } else if (adev->max_sectors > GEN_II_NCQ_MAX_SECTORS) {
1051 adev->max_sectors = GEN_II_NCQ_MAX_SECTORS;
1052 ata_dev_printk(adev, KERN_INFO,
1053 "max_sectors limited to %u for NCQ\n",
1054 adev->max_sectors);
1055 }
1043 } 1056 }
1044} 1057}
1045 1058
@@ -1287,7 +1300,7 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
1287 flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT; 1300 flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT;
1288 1301
1289 /* get current queue index from software */ 1302 /* get current queue index from software */
1290 in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1303 in_index = pp->req_idx;
1291 1304
1292 pp->crqb[in_index].sg_addr = 1305 pp->crqb[in_index].sg_addr =
1293 cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1306 cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff);
@@ -1379,7 +1392,7 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1379 flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT; 1392 flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT;
1380 1393
1381 /* get current queue index from software */ 1394 /* get current queue index from software */
1382 in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1395 in_index = pp->req_idx;
1383 1396
1384 crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; 1397 crqb = (struct mv_crqb_iie *) &pp->crqb[in_index];
1385 crqb->addr = cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1398 crqb->addr = cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff);
@@ -1446,9 +1459,8 @@ static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
1446 1459
1447 mv_start_dma(ap, port_mmio, pp, qc->tf.protocol); 1460 mv_start_dma(ap, port_mmio, pp, qc->tf.protocol);
1448 1461
1449 pp->req_idx++; 1462 pp->req_idx = (pp->req_idx + 1) & MV_MAX_Q_DEPTH_MASK;
1450 1463 in_index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT;
1451 in_index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT;
1452 1464
1453 /* and write the request in pointer to kick the EDMA to life */ 1465 /* and write the request in pointer to kick the EDMA to life */
1454 writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index, 1466 writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index,
@@ -1457,16 +1469,51 @@ static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
1457 return 0; 1469 return 0;
1458} 1470}
1459 1471
1472static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap)
1473{
1474 struct mv_port_priv *pp = ap->private_data;
1475 struct ata_queued_cmd *qc;
1476
1477 if (pp->pp_flags & MV_PP_FLAG_NCQ_EN)
1478 return NULL;
1479 qc = ata_qc_from_tag(ap, ap->link.active_tag);
1480 if (qc && (qc->tf.flags & ATA_TFLAG_POLLING))
1481 qc = NULL;
1482 return qc;
1483}
1484
1485static void mv_unexpected_intr(struct ata_port *ap)
1486{
1487 struct mv_port_priv *pp = ap->private_data;
1488 struct ata_eh_info *ehi = &ap->link.eh_info;
1489 char *when = "";
1490
1491 /*
1492 * We got a device interrupt from something that
1493 * was supposed to be using EDMA or polling.
1494 */
1495 ata_ehi_clear_desc(ehi);
1496 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
1497 when = " while EDMA enabled";
1498 } else {
1499 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag);
1500 if (qc && (qc->tf.flags & ATA_TFLAG_POLLING))
1501 when = " while polling";
1502 }
1503 ata_ehi_push_desc(ehi, "unexpected device interrupt%s", when);
1504 ehi->err_mask |= AC_ERR_OTHER;
1505 ehi->action |= ATA_EH_RESET;
1506 ata_port_freeze(ap);
1507}
1508
1460/** 1509/**
1461 * mv_err_intr - Handle error interrupts on the port 1510 * mv_err_intr - Handle error interrupts on the port
1462 * @ap: ATA channel to manipulate 1511 * @ap: ATA channel to manipulate
1463 * @reset_allowed: bool: 0 == don't trigger from reset here 1512 * @qc: affected command (non-NCQ), or NULL
1464 * 1513 *
1465 * In most cases, just clear the interrupt and move on. However, 1514 * Most cases require a full reset of the chip's state machine,
1466 * some cases require an eDMA reset, which also performs a COMRESET. 1515 * which also performs a COMRESET.
1467 * The SERR case requires a clear of pending errors in the SATA 1516 * Also, if the port disabled DMA, update our cached copy to match.
1468 * SERROR register. Finally, if the port disabled DMA,
1469 * update our cached copy to match.
1470 * 1517 *
1471 * LOCKING: 1518 * LOCKING:
1472 * Inherited from caller. 1519 * Inherited from caller.
@@ -1477,28 +1524,24 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1477 u32 edma_err_cause, eh_freeze_mask, serr = 0; 1524 u32 edma_err_cause, eh_freeze_mask, serr = 0;
1478 struct mv_port_priv *pp = ap->private_data; 1525 struct mv_port_priv *pp = ap->private_data;
1479 struct mv_host_priv *hpriv = ap->host->private_data; 1526 struct mv_host_priv *hpriv = ap->host->private_data;
1480 unsigned int edma_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN);
1481 unsigned int action = 0, err_mask = 0; 1527 unsigned int action = 0, err_mask = 0;
1482 struct ata_eh_info *ehi = &ap->link.eh_info; 1528 struct ata_eh_info *ehi = &ap->link.eh_info;
1483 1529
1484 ata_ehi_clear_desc(ehi); 1530 ata_ehi_clear_desc(ehi);
1485 1531
1486 if (!edma_enabled) { 1532 /*
1487 /* just a guess: do we need to do this? should we 1533 * Read and clear the err_cause bits. This won't actually
1488 * expand this, and do it in all cases? 1534 * clear for some errors (eg. SError), but we will be doing
1489 */ 1535 * a hard reset in those cases regardless, which *will* clear it.
1490 sata_scr_read(&ap->link, SCR_ERROR, &serr); 1536 */
1491 sata_scr_write_flush(&ap->link, SCR_ERROR, serr);
1492 }
1493
1494 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1537 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1538 writelfl(~edma_err_cause, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1495 1539
1496 ata_ehi_push_desc(ehi, "edma_err 0x%08x", edma_err_cause); 1540 ata_ehi_push_desc(ehi, "edma_err_cause=%08x", edma_err_cause);
1497 1541
1498 /* 1542 /*
1499 * all generations share these EDMA error cause bits 1543 * All generations share these EDMA error cause bits:
1500 */ 1544 */
1501
1502 if (edma_err_cause & EDMA_ERR_DEV) 1545 if (edma_err_cause & EDMA_ERR_DEV)
1503 err_mask |= AC_ERR_DEV; 1546 err_mask |= AC_ERR_DEV;
1504 if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 1547 if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
@@ -1515,34 +1558,36 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1515 action |= ATA_EH_RESET; 1558 action |= ATA_EH_RESET;
1516 } 1559 }
1517 1560
1561 /*
1562 * Gen-I has a different SELF_DIS bit,
1563 * different FREEZE bits, and no SERR bit:
1564 */
1518 if (IS_GEN_I(hpriv)) { 1565 if (IS_GEN_I(hpriv)) {
1519 eh_freeze_mask = EDMA_EH_FREEZE_5; 1566 eh_freeze_mask = EDMA_EH_FREEZE_5;
1520
1521 if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { 1567 if (edma_err_cause & EDMA_ERR_SELF_DIS_5) {
1522 pp = ap->private_data;
1523 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1568 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1524 ata_ehi_push_desc(ehi, "EDMA self-disable"); 1569 ata_ehi_push_desc(ehi, "EDMA self-disable");
1525 } 1570 }
1526 } else { 1571 } else {
1527 eh_freeze_mask = EDMA_EH_FREEZE; 1572 eh_freeze_mask = EDMA_EH_FREEZE;
1528
1529 if (edma_err_cause & EDMA_ERR_SELF_DIS) { 1573 if (edma_err_cause & EDMA_ERR_SELF_DIS) {
1530 pp = ap->private_data;
1531 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1574 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1532 ata_ehi_push_desc(ehi, "EDMA self-disable"); 1575 ata_ehi_push_desc(ehi, "EDMA self-disable");
1533 } 1576 }
1534
1535 if (edma_err_cause & EDMA_ERR_SERR) { 1577 if (edma_err_cause & EDMA_ERR_SERR) {
1536 sata_scr_read(&ap->link, SCR_ERROR, &serr); 1578 /*
1537 sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 1579 * Ensure that we read our own SCR, not a pmp link SCR:
1538 err_mask = AC_ERR_ATA_BUS; 1580 */
1581 ap->ops->scr_read(ap, SCR_ERROR, &serr);
1582 /*
1583 * Don't clear SError here; leave it for libata-eh:
1584 */
1585 ata_ehi_push_desc(ehi, "SError=%08x", serr);
1586 err_mask |= AC_ERR_ATA_BUS;
1539 action |= ATA_EH_RESET; 1587 action |= ATA_EH_RESET;
1540 } 1588 }
1541 } 1589 }
1542 1590
1543 /* Clear EDMA now that SERR cleanup done */
1544 writelfl(~edma_err_cause, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1545
1546 if (!err_mask) { 1591 if (!err_mask) {
1547 err_mask = AC_ERR_OTHER; 1592 err_mask = AC_ERR_OTHER;
1548 action |= ATA_EH_RESET; 1593 action |= ATA_EH_RESET;
@@ -1562,178 +1607,151 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1562 ata_port_abort(ap); 1607 ata_port_abort(ap);
1563} 1608}
1564 1609
1565static void mv_intr_pio(struct ata_port *ap) 1610static void mv_process_crpb_response(struct ata_port *ap,
1611 struct mv_crpb *response, unsigned int tag, int ncq_enabled)
1566{ 1612{
1567 struct ata_queued_cmd *qc; 1613 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
1568 u8 ata_status;
1569
1570 /* ignore spurious intr if drive still BUSY */
1571 ata_status = readb(ap->ioaddr.status_addr);
1572 if (unlikely(ata_status & ATA_BUSY))
1573 return;
1574 1614
1575 /* get active ATA command */ 1615 if (qc) {
1576 qc = ata_qc_from_tag(ap, ap->link.active_tag); 1616 u8 ata_status;
1577 if (unlikely(!qc)) /* no active tag */ 1617 u16 edma_status = le16_to_cpu(response->flags);
1578 return; 1618 /*
1579 if (qc->tf.flags & ATA_TFLAG_POLLING) /* polling; we don't own qc */ 1619 * edma_status from a response queue entry:
1580 return; 1620 * LSB is from EDMA_ERR_IRQ_CAUSE_OFS (non-NCQ only).
1581 1621 * MSB is saved ATA status from command completion.
1582 /* and finally, complete the ATA command */ 1622 */
1583 qc->err_mask |= ac_err_mask(ata_status); 1623 if (!ncq_enabled) {
1584 ata_qc_complete(qc); 1624 u8 err_cause = edma_status & 0xff & ~EDMA_ERR_DEV;
1625 if (err_cause) {
1626 /*
1627 * Error will be seen/handled by mv_err_intr().
1628 * So do nothing at all here.
1629 */
1630 return;
1631 }
1632 }
1633 ata_status = edma_status >> CRPB_FLAG_STATUS_SHIFT;
1634 qc->err_mask |= ac_err_mask(ata_status);
1635 ata_qc_complete(qc);
1636 } else {
1637 ata_port_printk(ap, KERN_ERR, "%s: no qc for tag=%d\n",
1638 __func__, tag);
1639 }
1585} 1640}
1586 1641
1587static void mv_intr_edma(struct ata_port *ap) 1642static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp)
1588{ 1643{
1589 void __iomem *port_mmio = mv_ap_base(ap); 1644 void __iomem *port_mmio = mv_ap_base(ap);
1590 struct mv_host_priv *hpriv = ap->host->private_data; 1645 struct mv_host_priv *hpriv = ap->host->private_data;
1591 struct mv_port_priv *pp = ap->private_data; 1646 u32 in_index;
1592 struct ata_queued_cmd *qc;
1593 u32 out_index, in_index;
1594 bool work_done = false; 1647 bool work_done = false;
1648 int ncq_enabled = (pp->pp_flags & MV_PP_FLAG_NCQ_EN);
1595 1649
1596 /* get h/w response queue pointer */ 1650 /* Get the hardware queue position index */
1597 in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) 1651 in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS)
1598 >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1652 >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
1599 1653
1600 while (1) { 1654 /* Process new responses from since the last time we looked */
1601 u16 status; 1655 while (in_index != pp->resp_idx) {
1602 unsigned int tag; 1656 unsigned int tag;
1657 struct mv_crpb *response = &pp->crpb[pp->resp_idx];
1603 1658
1604 /* get s/w response queue last-read pointer, and compare */ 1659 pp->resp_idx = (pp->resp_idx + 1) & MV_MAX_Q_DEPTH_MASK;
1605 out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK;
1606 if (in_index == out_index)
1607 break;
1608 1660
1609 /* 50xx: get active ATA command */ 1661 if (IS_GEN_I(hpriv)) {
1610 if (IS_GEN_I(hpriv)) 1662 /* 50xx: no NCQ, only one command active at a time */
1611 tag = ap->link.active_tag; 1663 tag = ap->link.active_tag;
1612 1664 } else {
1613 /* Gen II/IIE: get active ATA command via tag, to enable 1665 /* Gen II/IIE: get command tag from CRPB entry */
1614 * support for queueing. this works transparently for 1666 tag = le16_to_cpu(response->id) & 0x1f;
1615 * queued and non-queued modes.
1616 */
1617 else
1618 tag = le16_to_cpu(pp->crpb[out_index].id) & 0x1f;
1619
1620 qc = ata_qc_from_tag(ap, tag);
1621
1622 /* For non-NCQ mode, the lower 8 bits of status
1623 * are from EDMA_ERR_IRQ_CAUSE_OFS,
1624 * which should be zero if all went well.
1625 */
1626 status = le16_to_cpu(pp->crpb[out_index].flags);
1627 if ((status & 0xff) && !(pp->pp_flags & MV_PP_FLAG_NCQ_EN)) {
1628 mv_err_intr(ap, qc);
1629 return;
1630 }
1631
1632 /* and finally, complete the ATA command */
1633 if (qc) {
1634 qc->err_mask |=
1635 ac_err_mask(status >> CRPB_FLAG_STATUS_SHIFT);
1636 ata_qc_complete(qc);
1637 } 1667 }
1638 1668 mv_process_crpb_response(ap, response, tag, ncq_enabled);
1639 /* advance software response queue pointer, to
1640 * indicate (after the loop completes) to hardware
1641 * that we have consumed a response queue entry.
1642 */
1643 work_done = true; 1669 work_done = true;
1644 pp->resp_idx++;
1645 } 1670 }
1646 1671
1672 /* Update the software queue position index in hardware */
1647 if (work_done) 1673 if (work_done)
1648 writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | 1674 writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) |
1649 (out_index << EDMA_RSP_Q_PTR_SHIFT), 1675 (pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT),
1650 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 1676 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1651} 1677}
1652 1678
1653/** 1679/**
1654 * mv_host_intr - Handle all interrupts on the given host controller 1680 * mv_host_intr - Handle all interrupts on the given host controller
1655 * @host: host specific structure 1681 * @host: host specific structure
1656 * @relevant: port error bits relevant to this host controller 1682 * @main_cause: Main interrupt cause register for the chip.
1657 * @hc: which host controller we're to look at
1658 *
1659 * Read then write clear the HC interrupt status then walk each
1660 * port connected to the HC and see if it needs servicing. Port
1661 * success ints are reported in the HC interrupt status reg, the
1662 * port error ints are reported in the higher level main
1663 * interrupt status register and thus are passed in via the
1664 * 'relevant' argument.
1665 * 1683 *
1666 * LOCKING: 1684 * LOCKING:
1667 * Inherited from caller. 1685 * Inherited from caller.
1668 */ 1686 */
1669static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) 1687static int mv_host_intr(struct ata_host *host, u32 main_cause)
1670{ 1688{
1671 struct mv_host_priv *hpriv = host->private_data; 1689 struct mv_host_priv *hpriv = host->private_data;
1672 void __iomem *mmio = hpriv->base; 1690 void __iomem *mmio = hpriv->base, *hc_mmio = NULL;
1673 void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1691 u32 hc_irq_cause = 0;
1674 u32 hc_irq_cause; 1692 unsigned int handled = 0, port;
1675 int port, port0, last_port;
1676 1693
1677 if (hc == 0) 1694 for (port = 0; port < hpriv->n_ports; port++) {
1678 port0 = 0;
1679 else
1680 port0 = MV_PORTS_PER_HC;
1681
1682 if (HAS_PCI(host))
1683 last_port = port0 + MV_PORTS_PER_HC;
1684 else
1685 last_port = port0 + hpriv->n_ports;
1686 /* we'll need the HC success int register in most cases */
1687 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
1688 if (!hc_irq_cause)
1689 return;
1690
1691 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
1692
1693 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
1694 hc, relevant, hc_irq_cause);
1695
1696 for (port = port0; port < last_port; port++) {
1697 struct ata_port *ap = host->ports[port]; 1695 struct ata_port *ap = host->ports[port];
1698 struct mv_port_priv *pp; 1696 struct mv_port_priv *pp;
1699 int have_err_bits, hard_port, shift; 1697 unsigned int shift, hardport, port_cause;
1700 1698 /*
1701 if ((!ap) || (ap->flags & ATA_FLAG_DISABLED)) 1699 * When we move to the second hc, flag our cached
1700 * copies of hc_mmio (and hc_irq_cause) as invalid again.
1701 */
1702 if (port == MV_PORTS_PER_HC)
1703 hc_mmio = NULL;
1704 /*
1705 * Do nothing if port is not interrupting or is disabled:
1706 */
1707 MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport);
1708 port_cause = (main_cause >> shift) & (DONE_IRQ | ERR_IRQ);
1709 if (!port_cause || !ap || (ap->flags & ATA_FLAG_DISABLED))
1702 continue; 1710 continue;
1703 1711 /*
1712 * Each hc within the host has its own hc_irq_cause register.
1713 * We defer reading it until we know we need it, right now:
1714 *
1715 * FIXME later: we don't really need to read this register
1716 * (some logic changes required below if we go that way),
1717 * because it doesn't tell us anything new. But we do need
1718 * to write to it, outside the top of this loop,
1719 * to reset the interrupt triggers for next time.
1720 */
1721 if (!hc_mmio) {
1722 hc_mmio = mv_hc_base_from_port(mmio, port);
1723 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
1724 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
1725 handled = 1;
1726 }
1727 /*
1728 * Process completed CRPB response(s) before other events.
1729 */
1704 pp = ap->private_data; 1730 pp = ap->private_data;
1705 1731 if (hc_irq_cause & (DMA_IRQ << hardport)) {
1706 shift = port << 1; /* (port * 2) */ 1732 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN)
1707 if (port >= MV_PORTS_PER_HC) 1733 mv_process_crpb_entries(ap, pp);
1708 shift++; /* skip bit 8 in the HC Main IRQ reg */
1709
1710 have_err_bits = ((PORT0_ERR << shift) & relevant);
1711
1712 if (unlikely(have_err_bits)) {
1713 struct ata_queued_cmd *qc;
1714
1715 qc = ata_qc_from_tag(ap, ap->link.active_tag);
1716 if (qc && (qc->tf.flags & ATA_TFLAG_POLLING))
1717 continue;
1718
1719 mv_err_intr(ap, qc);
1720 continue;
1721 } 1734 }
1722 1735 /*
1723 hard_port = mv_hardport_from_port(port); /* range 0..3 */ 1736 * Handle chip-reported errors, or continue on to handle PIO.
1724 1737 */
1725 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 1738 if (unlikely(port_cause & ERR_IRQ)) {
1726 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) 1739 mv_err_intr(ap, mv_get_active_qc(ap));
1727 mv_intr_edma(ap); 1740 } else if (hc_irq_cause & (DEV_IRQ << hardport)) {
1728 } else { 1741 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) {
1729 if ((DEV_IRQ << hard_port) & hc_irq_cause) 1742 struct ata_queued_cmd *qc = mv_get_active_qc(ap);
1730 mv_intr_pio(ap); 1743 if (qc) {
1744 ata_sff_host_intr(ap, qc);
1745 continue;
1746 }
1747 }
1748 mv_unexpected_intr(ap);
1731 } 1749 }
1732 } 1750 }
1733 VPRINTK("EXIT\n"); 1751 return handled;
1734} 1752}
1735 1753
1736static void mv_pci_error(struct ata_host *host, void __iomem *mmio) 1754static int mv_pci_error(struct ata_host *host, void __iomem *mmio)
1737{ 1755{
1738 struct mv_host_priv *hpriv = host->private_data; 1756 struct mv_host_priv *hpriv = host->private_data;
1739 struct ata_port *ap; 1757 struct ata_port *ap;
@@ -1771,6 +1789,7 @@ static void mv_pci_error(struct ata_host *host, void __iomem *mmio)
1771 ata_port_freeze(ap); 1789 ata_port_freeze(ap);
1772 } 1790 }
1773 } 1791 }
1792 return 1; /* handled */
1774} 1793}
1775 1794
1776/** 1795/**
@@ -1791,41 +1810,23 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance)
1791{ 1810{
1792 struct ata_host *host = dev_instance; 1811 struct ata_host *host = dev_instance;
1793 struct mv_host_priv *hpriv = host->private_data; 1812 struct mv_host_priv *hpriv = host->private_data;
1794 unsigned int hc, handled = 0, n_hcs; 1813 unsigned int handled = 0;
1795 void __iomem *mmio = hpriv->base; 1814 u32 main_cause, main_mask;
1796 u32 irq_stat, irq_mask;
1797 1815
1798 /* Note to self: &host->lock == &ap->host->lock == ap->lock */
1799 spin_lock(&host->lock); 1816 spin_lock(&host->lock);
1800 1817 main_cause = readl(hpriv->main_cause_reg_addr);
1801 irq_stat = readl(hpriv->main_cause_reg_addr); 1818 main_mask = readl(hpriv->main_mask_reg_addr);
1802 irq_mask = readl(hpriv->main_mask_reg_addr); 1819 /*
1803 1820 * Deal with cases where we either have nothing pending, or have read
1804 /* check the cases where we either have nothing pending or have read 1821 * a bogus register value which can indicate HW removal or PCI fault.
1805 * a bogus register value which can indicate HW removal or PCI fault
1806 */ 1822 */
1807 if (!(irq_stat & irq_mask) || (0xffffffffU == irq_stat)) 1823 if ((main_cause & main_mask) && (main_cause != 0xffffffffU)) {
1808 goto out_unlock; 1824 if (unlikely((main_cause & PCI_ERR) && HAS_PCI(host)))
1809 1825 handled = mv_pci_error(host, hpriv->base);
1810 n_hcs = mv_get_hc_count(host->ports[0]->flags); 1826 else
1811 1827 handled = mv_host_intr(host, main_cause);
1812 if (unlikely((irq_stat & PCI_ERR) && HAS_PCI(host))) {
1813 mv_pci_error(host, mmio);
1814 handled = 1;
1815 goto out_unlock; /* skip all other HC irq handling */
1816 }
1817
1818 for (hc = 0; hc < n_hcs; hc++) {
1819 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
1820 if (relevant) {
1821 mv_host_intr(host, relevant, hc);
1822 handled = 1;
1823 }
1824 } 1828 }
1825
1826out_unlock:
1827 spin_unlock(&host->lock); 1829 spin_unlock(&host->lock);
1828
1829 return IRQ_RETVAL(handled); 1830 return IRQ_RETVAL(handled);
1830} 1831}
1831 1832
@@ -2109,13 +2110,6 @@ static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
2109 printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); 2110 printk(KERN_ERR DRV_NAME ": can't clear global reset\n");
2110 rc = 1; 2111 rc = 1;
2111 } 2112 }
2112 /*
2113 * Temporary: wait 3 seconds before port-probing can happen,
2114 * so that we don't miss finding sleepy SilXXXX port-multipliers.
2115 * This can go away once hotplug is fully/correctly implemented.
2116 */
2117 if (rc == 0)
2118 msleep(3000);
2119done: 2113done:
2120 return rc; 2114 return rc;
2121} 2115}
@@ -2409,55 +2403,44 @@ static int mv_hardreset(struct ata_link *link, unsigned int *class,
2409static void mv_eh_freeze(struct ata_port *ap) 2403static void mv_eh_freeze(struct ata_port *ap)
2410{ 2404{
2411 struct mv_host_priv *hpriv = ap->host->private_data; 2405 struct mv_host_priv *hpriv = ap->host->private_data;
2412 unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2406 unsigned int shift, hardport, port = ap->port_no;
2413 u32 tmp, mask; 2407 u32 main_mask;
2414 unsigned int shift;
2415 2408
2416 /* FIXME: handle coalescing completion events properly */ 2409 /* FIXME: handle coalescing completion events properly */
2417 2410
2418 shift = ap->port_no * 2; 2411 mv_stop_edma(ap);
2419 if (hc > 0) 2412 MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport);
2420 shift++;
2421
2422 mask = 0x3 << shift;
2423 2413
2424 /* disable assertion of portN err, done events */ 2414 /* disable assertion of portN err, done events */
2425 tmp = readl(hpriv->main_mask_reg_addr); 2415 main_mask = readl(hpriv->main_mask_reg_addr);
2426 writelfl(tmp & ~mask, hpriv->main_mask_reg_addr); 2416 main_mask &= ~((DONE_IRQ | ERR_IRQ) << shift);
2417 writelfl(main_mask, hpriv->main_mask_reg_addr);
2427} 2418}
2428 2419
2429static void mv_eh_thaw(struct ata_port *ap) 2420static void mv_eh_thaw(struct ata_port *ap)
2430{ 2421{
2431 struct mv_host_priv *hpriv = ap->host->private_data; 2422 struct mv_host_priv *hpriv = ap->host->private_data;
2432 void __iomem *mmio = hpriv->base; 2423 unsigned int shift, hardport, port = ap->port_no;
2433 unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2424 void __iomem *hc_mmio = mv_hc_base_from_port(hpriv->base, port);
2434 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
2435 void __iomem *port_mmio = mv_ap_base(ap); 2425 void __iomem *port_mmio = mv_ap_base(ap);
2436 u32 tmp, mask, hc_irq_cause; 2426 u32 main_mask, hc_irq_cause;
2437 unsigned int shift, hc_port_no = ap->port_no;
2438 2427
2439 /* FIXME: handle coalescing completion events properly */ 2428 /* FIXME: handle coalescing completion events properly */
2440 2429
2441 shift = ap->port_no * 2; 2430 MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport);
2442 if (hc > 0) {
2443 shift++;
2444 hc_port_no -= 4;
2445 }
2446
2447 mask = 0x3 << shift;
2448 2431
2449 /* clear EDMA errors on this port */ 2432 /* clear EDMA errors on this port */
2450 writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2433 writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
2451 2434
2452 /* clear pending irq events */ 2435 /* clear pending irq events */
2453 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 2436 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
2454 hc_irq_cause &= ~(1 << hc_port_no); /* clear CRPB-done */ 2437 hc_irq_cause &= ~((DEV_IRQ | DMA_IRQ) << hardport);
2455 hc_irq_cause &= ~(1 << (hc_port_no + 8)); /* clear Device int */ 2438 writelfl(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
2456 writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
2457 2439
2458 /* enable assertion of portN err, done events */ 2440 /* enable assertion of portN err, done events */
2459 tmp = readl(hpriv->main_mask_reg_addr); 2441 main_mask = readl(hpriv->main_mask_reg_addr);
2460 writelfl(tmp | mask, hpriv->main_mask_reg_addr); 2442 main_mask |= ((DONE_IRQ | ERR_IRQ) << shift);
2443 writelfl(main_mask, hpriv->main_mask_reg_addr);
2461} 2444}
2462 2445
2463/** 2446/**
@@ -2668,19 +2651,17 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
2668 2651
2669 rc = mv_chip_id(host, board_idx); 2652 rc = mv_chip_id(host, board_idx);
2670 if (rc) 2653 if (rc)
2671 goto done; 2654 goto done;
2672 2655
2673 if (HAS_PCI(host)) { 2656 if (HAS_PCI(host)) {
2674 hpriv->main_cause_reg_addr = hpriv->base + 2657 hpriv->main_cause_reg_addr = mmio + HC_MAIN_IRQ_CAUSE_OFS;
2675 HC_MAIN_IRQ_CAUSE_OFS; 2658 hpriv->main_mask_reg_addr = mmio + HC_MAIN_IRQ_MASK_OFS;
2676 hpriv->main_mask_reg_addr = hpriv->base + HC_MAIN_IRQ_MASK_OFS;
2677 } else { 2659 } else {
2678 hpriv->main_cause_reg_addr = hpriv->base + 2660 hpriv->main_cause_reg_addr = mmio + HC_SOC_MAIN_IRQ_CAUSE_OFS;
2679 HC_SOC_MAIN_IRQ_CAUSE_OFS; 2661 hpriv->main_mask_reg_addr = mmio + HC_SOC_MAIN_IRQ_MASK_OFS;
2680 hpriv->main_mask_reg_addr = hpriv->base +
2681 HC_SOC_MAIN_IRQ_MASK_OFS;
2682 } 2662 }
2683 /* global interrupt mask */ 2663
2664 /* global interrupt mask: 0 == mask everything */
2684 writel(0, hpriv->main_mask_reg_addr); 2665 writel(0, hpriv->main_mask_reg_addr);
2685 2666
2686 n_hc = mv_get_hc_count(host->ports[0]->flags); 2667 n_hc = mv_get_hc_count(host->ports[0]->flags);
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 109b07495721..858f70610eda 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -1591,13 +1591,16 @@ static void nv_mcp55_thaw(struct ata_port *ap)
1591static int nv_hardreset(struct ata_link *link, unsigned int *class, 1591static int nv_hardreset(struct ata_link *link, unsigned int *class,
1592 unsigned long deadline) 1592 unsigned long deadline)
1593{ 1593{
1594 unsigned int dummy; 1594 int rc;
1595 1595
1596 /* SATA hardreset fails to retrieve proper device signature on 1596 /* SATA hardreset fails to retrieve proper device signature on
1597 * some controllers. Don't classify on hardreset. For more 1597 * some controllers. Request follow up SRST. For more info,
1598 * info, see http://bugzilla.kernel.org/show_bug.cgi?id=3352 1598 * see http://bugzilla.kernel.org/show_bug.cgi?id=3352
1599 */ 1599 */
1600 return sata_sff_hardreset(link, &dummy, deadline); 1600 rc = sata_sff_hardreset(link, class, deadline);
1601 if (rc)
1602 return rc;
1603 return -EAGAIN;
1601} 1604}
1602 1605
1603static void nv_adma_error_handler(struct ata_port *ap) 1606static void nv_adma_error_handler(struct ata_port *ap)
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 6b8e45ba32e8..1010b3069bd5 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -142,7 +142,7 @@ static u32 sis_scr_cfg_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
142 u8 pmr; 142 u8 pmr;
143 143
144 if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */ 144 if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */
145 return 0xffffffff; 145 return -EINVAL;
146 146
147 pci_read_config_byte(pdev, SIS_PMR, &pmr); 147 pci_read_config_byte(pdev, SIS_PMR, &pmr);
148 148
@@ -158,14 +158,14 @@ static u32 sis_scr_cfg_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
158 return 0; 158 return 0;
159} 159}
160 160
161static void sis_scr_cfg_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 161static int sis_scr_cfg_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
162{ 162{
163 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 163 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
164 unsigned int cfg_addr = get_scr_cfg_addr(ap, sc_reg); 164 unsigned int cfg_addr = get_scr_cfg_addr(ap, sc_reg);
165 u8 pmr; 165 u8 pmr;
166 166
167 if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */ 167 if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */
168 return; 168 return -EINVAL;
169 169
170 pci_read_config_byte(pdev, SIS_PMR, &pmr); 170 pci_read_config_byte(pdev, SIS_PMR, &pmr);
171 171
@@ -174,6 +174,8 @@ static void sis_scr_cfg_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
174 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || 174 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) ||
175 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) 175 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED))
176 pci_write_config_dword(pdev, cfg_addr+0x10, val); 176 pci_write_config_dword(pdev, cfg_addr+0x10, val);
177
178 return 0;
177} 179}
178 180
179static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 181static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
@@ -211,14 +213,14 @@ static int sis_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
211 pci_read_config_byte(pdev, SIS_PMR, &pmr); 213 pci_read_config_byte(pdev, SIS_PMR, &pmr);
212 214
213 if (ap->flags & SIS_FLAG_CFGSCR) 215 if (ap->flags & SIS_FLAG_CFGSCR)
214 sis_scr_cfg_write(ap, sc_reg, val); 216 return sis_scr_cfg_write(ap, sc_reg, val);
215 else { 217 else {
216 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 218 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4));
217 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || 219 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) ||
218 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) 220 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED))
219 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10); 221 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10);
222 return 0;
220 } 223 }
221 return 0;
222} 224}
223 225
224static int sis_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 226static int sis_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 9c6f3f99208d..d771da816d95 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -47,6 +47,7 @@
47 47
48#include <xen/interface/grant_table.h> 48#include <xen/interface/grant_table.h>
49#include <xen/interface/io/blkif.h> 49#include <xen/interface/io/blkif.h>
50#include <xen/interface/io/protocols.h>
50 51
51#include <asm/xen/hypervisor.h> 52#include <asm/xen/hypervisor.h>
52 53
@@ -74,7 +75,6 @@ static struct block_device_operations xlvbd_block_fops;
74struct blkfront_info 75struct blkfront_info
75{ 76{
76 struct xenbus_device *xbdev; 77 struct xenbus_device *xbdev;
77 dev_t dev;
78 struct gendisk *gd; 78 struct gendisk *gd;
79 int vdevice; 79 int vdevice;
80 blkif_vdev_t handle; 80 blkif_vdev_t handle;
@@ -88,6 +88,7 @@ struct blkfront_info
88 struct blk_shadow shadow[BLK_RING_SIZE]; 88 struct blk_shadow shadow[BLK_RING_SIZE];
89 unsigned long shadow_free; 89 unsigned long shadow_free;
90 int feature_barrier; 90 int feature_barrier;
91 int is_ready;
91 92
92 /** 93 /**
93 * The number of people holding this device open. We won't allow a 94 * The number of people holding this device open. We won't allow a
@@ -614,6 +615,12 @@ again:
614 message = "writing event-channel"; 615 message = "writing event-channel";
615 goto abort_transaction; 616 goto abort_transaction;
616 } 617 }
618 err = xenbus_printf(xbt, dev->nodename, "protocol", "%s",
619 XEN_IO_PROTO_ABI_NATIVE);
620 if (err) {
621 message = "writing protocol";
622 goto abort_transaction;
623 }
617 624
618 err = xenbus_transaction_end(xbt, 0); 625 err = xenbus_transaction_end(xbt, 0);
619 if (err) { 626 if (err) {
@@ -833,6 +840,8 @@ static void blkfront_connect(struct blkfront_info *info)
833 spin_unlock_irq(&blkif_io_lock); 840 spin_unlock_irq(&blkif_io_lock);
834 841
835 add_disk(info->gd); 842 add_disk(info->gd);
843
844 info->is_ready = 1;
836} 845}
837 846
838/** 847/**
@@ -896,7 +905,7 @@ static void backend_changed(struct xenbus_device *dev,
896 break; 905 break;
897 906
898 case XenbusStateClosing: 907 case XenbusStateClosing:
899 bd = bdget(info->dev); 908 bd = bdget_disk(info->gd, 0);
900 if (bd == NULL) 909 if (bd == NULL)
901 xenbus_dev_fatal(dev, -ENODEV, "bdget failed"); 910 xenbus_dev_fatal(dev, -ENODEV, "bdget failed");
902 911
@@ -925,6 +934,13 @@ static int blkfront_remove(struct xenbus_device *dev)
925 return 0; 934 return 0;
926} 935}
927 936
937static int blkfront_is_ready(struct xenbus_device *dev)
938{
939 struct blkfront_info *info = dev->dev.driver_data;
940
941 return info->is_ready;
942}
943
928static int blkif_open(struct inode *inode, struct file *filep) 944static int blkif_open(struct inode *inode, struct file *filep)
929{ 945{
930 struct blkfront_info *info = inode->i_bdev->bd_disk->private_data; 946 struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
@@ -971,6 +987,7 @@ static struct xenbus_driver blkfront = {
971 .remove = blkfront_remove, 987 .remove = blkfront_remove,
972 .resume = blkfront_resume, 988 .resume = blkfront_resume,
973 .otherend_changed = backend_changed, 989 .otherend_changed = backend_changed,
990 .is_ready = blkfront_is_ready,
974}; 991};
975 992
976static int __init xlblk_init(void) 993static int __init xlblk_init(void)
@@ -998,3 +1015,5 @@ module_exit(xlblk_exit);
998MODULE_DESCRIPTION("Xen virtual block device frontend"); 1015MODULE_DESCRIPTION("Xen virtual block device frontend");
999MODULE_LICENSE("GPL"); 1016MODULE_LICENSE("GPL");
1000MODULE_ALIAS_BLOCKDEV_MAJOR(XENVBD_MAJOR); 1017MODULE_ALIAS_BLOCKDEV_MAJOR(XENVBD_MAJOR);
1018MODULE_ALIAS("xen:vbd");
1019MODULE_ALIAS("xenblk");
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 9769bf8279a6..60b934adea65 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -42,6 +42,7 @@
42#include <linux/input.h> 42#include <linux/input.h>
43#include <linux/reboot.h> 43#include <linux/reboot.h>
44#include <linux/notifier.h> 44#include <linux/notifier.h>
45#include <linux/jiffies.h>
45 46
46extern void ctrl_alt_del(void); 47extern void ctrl_alt_del(void);
47 48
@@ -928,7 +929,8 @@ static void k_brl(struct vc_data *vc, unsigned char value, char up_flag)
928 if (up_flag) { 929 if (up_flag) {
929 if (brl_timeout) { 930 if (brl_timeout) {
930 if (!committing || 931 if (!committing ||
931 jiffies - releasestart > (brl_timeout * HZ) / 1000) { 932 time_after(jiffies,
933 releasestart + msecs_to_jiffies(brl_timeout))) {
932 committing = pressed; 934 committing = pressed;
933 releasestart = jiffies; 935 releasestart = jiffies;
934 } 936 }
@@ -1238,6 +1240,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1238 } 1240 }
1239 1241
1240 param.shift = shift_final = (shift_state | kbd->slockstate) ^ kbd->lockstate; 1242 param.shift = shift_final = (shift_state | kbd->slockstate) ^ kbd->lockstate;
1243 param.ledstate = kbd->ledflagstate;
1241 key_map = key_maps[shift_final]; 1244 key_map = key_maps[shift_final];
1242 1245
1243 if (atomic_notifier_call_chain(&keyboard_notifier_list, KBD_KEYCODE, &param) == NOTIFY_STOP || !key_map) { 1246 if (atomic_notifier_call_chain(&keyboard_notifier_list, KBD_KEYCODE, &param) == NOTIFY_STOP || !key_map) {
@@ -1286,6 +1289,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1286 1289
1287 (*k_handler[type])(vc, keysym & 0xff, !down); 1290 (*k_handler[type])(vc, keysym & 0xff, !down);
1288 1291
1292 param.ledstate = kbd->ledflagstate;
1289 atomic_notifier_call_chain(&keyboard_notifier_list, KBD_POST_KEYSYM, &param); 1293 atomic_notifier_call_chain(&keyboard_notifier_list, KBD_POST_KEYSYM, &param);
1290 1294
1291 if (type != KT_SLOCK) 1295 if (type != KT_SLOCK)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 20070b7c573d..e83623ead441 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -41,36 +41,7 @@
41 */ 41 */
42static inline int uncached_access(struct file *file, unsigned long addr) 42static inline int uncached_access(struct file *file, unsigned long addr)
43{ 43{
44#if defined(__i386__) && !defined(__arch_um__) 44#if defined(CONFIG_IA64)
45 /*
46 * On the PPro and successors, the MTRRs are used to set
47 * memory types for physical addresses outside main memory,
48 * so blindly setting PCD or PWT on those pages is wrong.
49 * For Pentiums and earlier, the surround logic should disable
50 * caching for the high addresses through the KEN pin, but
51 * we maintain the tradition of paranoia in this code.
52 */
53 if (file->f_flags & O_SYNC)
54 return 1;
55 return !( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) ||
56 test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) ||
57 test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) ||
58 test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability) )
59 && addr >= __pa(high_memory);
60#elif defined(__x86_64__) && !defined(__arch_um__)
61 /*
62 * This is broken because it can generate memory type aliases,
63 * which can cause cache corruptions
64 * But it is only available for root and we have to be bug-to-bug
65 * compatible with i386.
66 */
67 if (file->f_flags & O_SYNC)
68 return 1;
69 /* same behaviour as i386. PAT always set to cached and MTRRs control the
70 caching behaviour.
71 Hopefully a full PAT implementation will fix that soon. */
72 return 0;
73#elif defined(CONFIG_IA64)
74 /* 45 /*
75 * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases. 46 * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases.
76 */ 47 */
@@ -108,6 +79,36 @@ static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
108} 79}
109#endif 80#endif
110 81
82#ifdef CONFIG_NONPROMISC_DEVMEM
83static inline int range_is_allowed(unsigned long pfn, unsigned long size)
84{
85 u64 from = ((u64)pfn) << PAGE_SHIFT;
86 u64 to = from + size;
87 u64 cursor = from;
88
89 while (cursor < to) {
90 if (!devmem_is_allowed(pfn)) {
91 printk(KERN_INFO
92 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
93 current->comm, from, to);
94 return 0;
95 }
96 cursor += PAGE_SIZE;
97 pfn++;
98 }
99 return 1;
100}
101#else
102static inline int range_is_allowed(unsigned long pfn, unsigned long size)
103{
104 return 1;
105}
106#endif
107
108void __attribute__((weak)) unxlate_dev_mem_ptr(unsigned long phys, void *addr)
109{
110}
111
111/* 112/*
112 * This funcion reads the *physical* memory. The f_pos points directly to the 113 * This funcion reads the *physical* memory. The f_pos points directly to the
113 * memory location. 114 * memory location.
@@ -150,15 +151,25 @@ static ssize_t read_mem(struct file * file, char __user * buf,
150 151
151 sz = min_t(unsigned long, sz, count); 152 sz = min_t(unsigned long, sz, count);
152 153
154 if (!range_is_allowed(p >> PAGE_SHIFT, count))
155 return -EPERM;
156
153 /* 157 /*
154 * On ia64 if a page has been mapped somewhere as 158 * On ia64 if a page has been mapped somewhere as
155 * uncached, then it must also be accessed uncached 159 * uncached, then it must also be accessed uncached
156 * by the kernel or data corruption may occur 160 * by the kernel or data corruption may occur
157 */ 161 */
158 ptr = xlate_dev_mem_ptr(p); 162 ptr = xlate_dev_mem_ptr(p);
163 if (!ptr)
164 return -EFAULT;
159 165
160 if (copy_to_user(buf, ptr, sz)) 166 if (copy_to_user(buf, ptr, sz)) {
167 unxlate_dev_mem_ptr(p, ptr);
161 return -EFAULT; 168 return -EFAULT;
169 }
170
171 unxlate_dev_mem_ptr(p, ptr);
172
162 buf += sz; 173 buf += sz;
163 p += sz; 174 p += sz;
164 count -= sz; 175 count -= sz;
@@ -207,20 +218,32 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
207 218
208 sz = min_t(unsigned long, sz, count); 219 sz = min_t(unsigned long, sz, count);
209 220
221 if (!range_is_allowed(p >> PAGE_SHIFT, sz))
222 return -EPERM;
223
210 /* 224 /*
211 * On ia64 if a page has been mapped somewhere as 225 * On ia64 if a page has been mapped somewhere as
212 * uncached, then it must also be accessed uncached 226 * uncached, then it must also be accessed uncached
213 * by the kernel or data corruption may occur 227 * by the kernel or data corruption may occur
214 */ 228 */
215 ptr = xlate_dev_mem_ptr(p); 229 ptr = xlate_dev_mem_ptr(p);
230 if (!ptr) {
231 if (written)
232 break;
233 return -EFAULT;
234 }
216 235
217 copied = copy_from_user(ptr, buf, sz); 236 copied = copy_from_user(ptr, buf, sz);
218 if (copied) { 237 if (copied) {
219 written += sz - copied; 238 written += sz - copied;
239 unxlate_dev_mem_ptr(p, ptr);
220 if (written) 240 if (written)
221 break; 241 break;
222 return -EFAULT; 242 return -EFAULT;
223 } 243 }
244
245 unxlate_dev_mem_ptr(p, ptr);
246
224 buf += sz; 247 buf += sz;
225 p += sz; 248 p += sz;
226 count -= sz; 249 count -= sz;
@@ -231,6 +254,12 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
231 return written; 254 return written;
232} 255}
233 256
257int __attribute__((weak)) phys_mem_access_prot_allowed(struct file *file,
258 unsigned long pfn, unsigned long size, pgprot_t *vma_prot)
259{
260 return 1;
261}
262
234#ifndef __HAVE_PHYS_MEM_ACCESS_PROT 263#ifndef __HAVE_PHYS_MEM_ACCESS_PROT
235static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 264static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
236 unsigned long size, pgprot_t vma_prot) 265 unsigned long size, pgprot_t vma_prot)
@@ -271,6 +300,35 @@ static inline int private_mapping_ok(struct vm_area_struct *vma)
271} 300}
272#endif 301#endif
273 302
303void __attribute__((weak))
304map_devmem(unsigned long pfn, unsigned long len, pgprot_t prot)
305{
306 /* nothing. architectures can override. */
307}
308
309void __attribute__((weak))
310unmap_devmem(unsigned long pfn, unsigned long len, pgprot_t prot)
311{
312 /* nothing. architectures can override. */
313}
314
315static void mmap_mem_open(struct vm_area_struct *vma)
316{
317 map_devmem(vma->vm_pgoff, vma->vm_end - vma->vm_start,
318 vma->vm_page_prot);
319}
320
321static void mmap_mem_close(struct vm_area_struct *vma)
322{
323 unmap_devmem(vma->vm_pgoff, vma->vm_end - vma->vm_start,
324 vma->vm_page_prot);
325}
326
327static struct vm_operations_struct mmap_mem_ops = {
328 .open = mmap_mem_open,
329 .close = mmap_mem_close
330};
331
274static int mmap_mem(struct file * file, struct vm_area_struct * vma) 332static int mmap_mem(struct file * file, struct vm_area_struct * vma)
275{ 333{
276 size_t size = vma->vm_end - vma->vm_start; 334 size_t size = vma->vm_end - vma->vm_start;
@@ -281,17 +339,28 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
281 if (!private_mapping_ok(vma)) 339 if (!private_mapping_ok(vma))
282 return -ENOSYS; 340 return -ENOSYS;
283 341
342 if (!range_is_allowed(vma->vm_pgoff, size))
343 return -EPERM;
344
345 if (!phys_mem_access_prot_allowed(file, vma->vm_pgoff, size,
346 &vma->vm_page_prot))
347 return -EINVAL;
348
284 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, 349 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
285 size, 350 size,
286 vma->vm_page_prot); 351 vma->vm_page_prot);
287 352
353 vma->vm_ops = &mmap_mem_ops;
354
288 /* Remap-pfn-range will mark the range VM_IO and VM_RESERVED */ 355 /* Remap-pfn-range will mark the range VM_IO and VM_RESERVED */
289 if (remap_pfn_range(vma, 356 if (remap_pfn_range(vma,
290 vma->vm_start, 357 vma->vm_start,
291 vma->vm_pgoff, 358 vma->vm_pgoff,
292 size, 359 size,
293 vma->vm_page_prot)) 360 vma->vm_page_prot)) {
361 unmap_devmem(vma->vm_pgoff, size, vma->vm_page_prot);
294 return -EAGAIN; 362 return -EAGAIN;
363 }
295 return 0; 364 return 0;
296} 365}
297 366
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 016f90567a52..dfe6907ae15b 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -803,7 +803,7 @@ static int __devexit hwicap_of_remove(struct of_device *op)
803} 803}
804 804
805/* Match table for of_platform binding */ 805/* Match table for of_platform binding */
806static const struct of_device_id __devinit hwicap_of_match[] = { 806static const struct of_device_id __devinitconst hwicap_of_match[] = {
807 { .compatible = "xlnx,opb-hwicap-1.00.b", .data = &buffer_icap_config}, 807 { .compatible = "xlnx,opb-hwicap-1.00.b", .data = &buffer_icap_config},
808 { .compatible = "xlnx,xps-hwicap-1.00.a", .data = &fifo_icap_config}, 808 { .compatible = "xlnx,xps-hwicap-1.00.a", .data = &fifo_icap_config},
809 {}, 809 {},
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 28ddc3fdd3d1..d3f8d9194f30 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -405,6 +405,9 @@
405#define USB_VENDOR_ID_YEALINK 0x6993 405#define USB_VENDOR_ID_YEALINK 0x6993
406#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001 406#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001
407 407
408#define USB_VENDOR_ID_KYE 0x0458
409#define USB_DEVICE_ID_KYE_GPEN_560 0x5003
410
408/* 411/*
409 * Alphabetically sorted blacklist by quirk type. 412 * Alphabetically sorted blacklist by quirk type.
410 */ 413 */
@@ -698,6 +701,7 @@ static const struct hid_blacklist {
698 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_63, HID_QUIRK_IGNORE }, 701 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_63, HID_QUIRK_IGNORE },
699 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_64, HID_QUIRK_IGNORE }, 702 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_64, HID_QUIRK_IGNORE },
700 { USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY, HID_QUIRK_IGNORE }, 703 { USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY, HID_QUIRK_IGNORE },
704 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560, HID_QUIRK_IGNORE },
701 705
702 { 0, 0 } 706 { 0, 0 }
703}; 707};
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c
index 474162cdf665..420fcb78a7cd 100644
--- a/drivers/ide/arm/palm_bk3710.c
+++ b/drivers/ide/arm/palm_bk3710.c
@@ -409,9 +409,13 @@ out:
409 return -ENODEV; 409 return -ENODEV;
410} 410}
411 411
412/* work with hotplug and coldplug */
413MODULE_ALIAS("platform:palm_bk3710");
414
412static struct platform_driver platform_bk_driver = { 415static struct platform_driver platform_bk_driver = {
413 .driver = { 416 .driver = {
414 .name = "palm_bk3710", 417 .name = "palm_bk3710",
418 .owner = THIS_MODULE,
415 }, 419 },
416 .probe = palm_bk3710_probe, 420 .probe = palm_bk3710_probe,
417 .remove = NULL, 421 .remove = NULL,
diff --git a/drivers/ide/legacy/ide_platform.c b/drivers/ide/legacy/ide_platform.c
index 249651e2da42..361b1bb544bf 100644
--- a/drivers/ide/legacy/ide_platform.c
+++ b/drivers/ide/legacy/ide_platform.c
@@ -130,6 +130,7 @@ static int __devexit plat_ide_remove(struct platform_device *pdev)
130static struct platform_driver platform_ide_driver = { 130static struct platform_driver platform_ide_driver = {
131 .driver = { 131 .driver = {
132 .name = "pata_platform", 132 .name = "pata_platform",
133 .owner = THIS_MODULE,
133 }, 134 },
134 .probe = plat_ide_probe, 135 .probe = plat_ide_probe,
135 .remove = __devexit_p(plat_ide_remove), 136 .remove = __devexit_p(plat_ide_remove),
@@ -147,6 +148,7 @@ static void __exit platform_ide_exit(void)
147 148
148MODULE_DESCRIPTION("Platform IDE driver"); 149MODULE_DESCRIPTION("Platform IDE driver");
149MODULE_LICENSE("GPL"); 150MODULE_LICENSE("GPL");
151MODULE_ALIAS("platform:pata_platform");
150 152
151module_init(platform_ide_init); 153module_init(platform_ide_init);
152module_exit(platform_ide_exit); 154module_exit(platform_ide_exit);
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index 6228fadacd38..9d19aec5820a 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -2167,6 +2167,7 @@ static const struct file_operations dv1394_fops=
2167/* 2167/*
2168 * Export information about protocols/devices supported by this driver. 2168 * Export information about protocols/devices supported by this driver.
2169 */ 2169 */
2170#ifdef MODULE
2170static struct ieee1394_device_id dv1394_id_table[] = { 2171static struct ieee1394_device_id dv1394_id_table[] = {
2171 { 2172 {
2172 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, 2173 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
@@ -2177,6 +2178,7 @@ static struct ieee1394_device_id dv1394_id_table[] = {
2177}; 2178};
2178 2179
2179MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table); 2180MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table);
2181#endif /* MODULE */
2180 2182
2181static struct hpsb_protocol_driver dv1394_driver = { 2183static struct hpsb_protocol_driver dv1394_driver = {
2182 .name = "dv1394", 2184 .name = "dv1394",
diff --git a/drivers/ieee1394/iso.h b/drivers/ieee1394/iso.h
index b94e55e6eaa5..b5de5f21ef78 100644
--- a/drivers/ieee1394/iso.h
+++ b/drivers/ieee1394/iso.h
@@ -123,6 +123,8 @@ struct hpsb_iso {
123 123
124 /* how many times the buffer has overflowed or underflowed */ 124 /* how many times the buffer has overflowed or underflowed */
125 atomic_t overflows; 125 atomic_t overflows;
126 /* how many cycles were skipped for a given context */
127 atomic_t skips;
126 128
127 /* Current number of bytes lost in discarded packets */ 129 /* Current number of bytes lost in discarded packets */
128 int bytes_discarded; 130 int bytes_discarded;
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index 0690469fcecf..e509e13cb7a7 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -1723,6 +1723,8 @@ struct ohci_iso_xmit {
1723 struct dma_prog_region prog; 1723 struct dma_prog_region prog;
1724 struct ohci1394_iso_tasklet task; 1724 struct ohci1394_iso_tasklet task;
1725 int task_active; 1725 int task_active;
1726 int last_cycle;
1727 atomic_t skips;
1726 1728
1727 u32 ContextControlSet; 1729 u32 ContextControlSet;
1728 u32 ContextControlClear; 1730 u32 ContextControlClear;
@@ -1759,6 +1761,8 @@ static int ohci_iso_xmit_init(struct hpsb_iso *iso)
1759 iso->hostdata = xmit; 1761 iso->hostdata = xmit;
1760 xmit->ohci = iso->host->hostdata; 1762 xmit->ohci = iso->host->hostdata;
1761 xmit->task_active = 0; 1763 xmit->task_active = 0;
1764 xmit->last_cycle = -1;
1765 atomic_set(&iso->skips, 0);
1762 1766
1763 dma_prog_region_init(&xmit->prog); 1767 dma_prog_region_init(&xmit->prog);
1764 1768
@@ -1856,6 +1860,26 @@ static void ohci_iso_xmit_task(unsigned long data)
1856 /* parse cycle */ 1860 /* parse cycle */
1857 cycle = le32_to_cpu(cmd->output_last.status) & 0x1FFF; 1861 cycle = le32_to_cpu(cmd->output_last.status) & 0x1FFF;
1858 1862
1863 if (xmit->last_cycle > -1) {
1864 int cycle_diff = cycle - xmit->last_cycle;
1865 int skip;
1866
1867 /* unwrap */
1868 if (cycle_diff < 0) {
1869 cycle_diff += 8000;
1870 if (cycle_diff < 0)
1871 PRINT(KERN_ERR, "bogus cycle diff %d\n",
1872 cycle_diff);
1873 }
1874
1875 skip = cycle_diff - 1;
1876 if (skip > 0) {
1877 DBGMSG("skipped %d cycles without packet loss", skip);
1878 atomic_add(skip, &iso->skips);
1879 }
1880 }
1881 xmit->last_cycle = cycle;
1882
1859 /* tell the subsystem the packet has gone out */ 1883 /* tell the subsystem the packet has gone out */
1860 hpsb_iso_packet_sent(iso, cycle, event != 0x11); 1884 hpsb_iso_packet_sent(iso, cycle, event != 0x11);
1861 1885
@@ -1943,6 +1967,16 @@ static int ohci_iso_xmit_queue(struct hpsb_iso *iso, struct hpsb_iso_packet_info
1943 prev->output_last.branchAddress = cpu_to_le32( 1967 prev->output_last.branchAddress = cpu_to_le32(
1944 dma_prog_region_offset_to_bus(&xmit->prog, sizeof(struct iso_xmit_cmd) * next_i) | 3); 1968 dma_prog_region_offset_to_bus(&xmit->prog, sizeof(struct iso_xmit_cmd) * next_i) | 3);
1945 1969
1970 /*
1971 * Link the skip address to this descriptor itself. This causes a
1972 * context to skip a cycle whenever lost cycles or FIFO overruns occur,
1973 * without dropping the data at that point the application should then
1974 * decide whether this is an error condition or not. Some protocols
1975 * can deal with this by dropping some rate-matching padding packets.
1976 */
1977 next->output_more_immediate.branchAddress =
1978 prev->output_last.branchAddress;
1979
1946 /* disable interrupt, unless required by the IRQ interval */ 1980 /* disable interrupt, unless required by the IRQ interval */
1947 if (prev_i % iso->irq_interval) { 1981 if (prev_i % iso->irq_interval) {
1948 prev->output_last.control &= cpu_to_le32(~(3 << 20)); /* no interrupt */ 1982 prev->output_last.control &= cpu_to_le32(~(3 << 20)); /* no interrupt */
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 04e96ba56e09..ec2a0adbedb2 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -2356,13 +2356,16 @@ static void rawiso_activity_cb(struct hpsb_iso *iso)
2356static void raw1394_iso_fill_status(struct hpsb_iso *iso, 2356static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2357 struct raw1394_iso_status *stat) 2357 struct raw1394_iso_status *stat)
2358{ 2358{
2359 int overflows = atomic_read(&iso->overflows);
2360 int skips = atomic_read(&iso->skips);
2361
2359 stat->config.data_buf_size = iso->buf_size; 2362 stat->config.data_buf_size = iso->buf_size;
2360 stat->config.buf_packets = iso->buf_packets; 2363 stat->config.buf_packets = iso->buf_packets;
2361 stat->config.channel = iso->channel; 2364 stat->config.channel = iso->channel;
2362 stat->config.speed = iso->speed; 2365 stat->config.speed = iso->speed;
2363 stat->config.irq_interval = iso->irq_interval; 2366 stat->config.irq_interval = iso->irq_interval;
2364 stat->n_packets = hpsb_iso_n_ready(iso); 2367 stat->n_packets = hpsb_iso_n_ready(iso);
2365 stat->overflows = atomic_read(&iso->overflows); 2368 stat->overflows = ((skips & 0xFFFF) << 16) | ((overflows & 0xFFFF));
2366 stat->xmit_cycle = iso->xmit_cycle; 2369 stat->xmit_cycle = iso->xmit_cycle;
2367} 2370}
2368 2371
@@ -2437,6 +2440,8 @@ static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2437 2440
2438 /* reset overflow counter */ 2441 /* reset overflow counter */
2439 atomic_set(&iso->overflows, 0); 2442 atomic_set(&iso->overflows, 0);
2443 /* reset skip counter */
2444 atomic_set(&iso->skips, 0);
2440 2445
2441 return 0; 2446 return 0;
2442} 2447}
@@ -2935,6 +2940,7 @@ static int raw1394_release(struct inode *inode, struct file *file)
2935/* 2940/*
2936 * Export information about protocols/devices supported by this driver. 2941 * Export information about protocols/devices supported by this driver.
2937 */ 2942 */
2943#ifdef MODULE
2938static struct ieee1394_device_id raw1394_id_table[] = { 2944static struct ieee1394_device_id raw1394_id_table[] = {
2939 { 2945 {
2940 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, 2946 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
@@ -2956,6 +2962,7 @@ static struct ieee1394_device_id raw1394_id_table[] = {
2956}; 2962};
2957 2963
2958MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table); 2964MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
2965#endif /* MODULE */
2959 2966
2960static struct hpsb_protocol_driver raw1394_driver = { 2967static struct hpsb_protocol_driver raw1394_driver = {
2961 .name = "raw1394", 2968 .name = "raw1394",
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index e03024eeeac1..e24772d336e1 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -1293,6 +1293,7 @@ static const struct file_operations video1394_fops=
1293/* 1293/*
1294 * Export information about protocols/devices supported by this driver. 1294 * Export information about protocols/devices supported by this driver.
1295 */ 1295 */
1296#ifdef MODULE
1296static struct ieee1394_device_id video1394_id_table[] = { 1297static struct ieee1394_device_id video1394_id_table[] = {
1297 { 1298 {
1298 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, 1299 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
@@ -1313,6 +1314,7 @@ static struct ieee1394_device_id video1394_id_table[] = {
1313}; 1314};
1314 1315
1315MODULE_DEVICE_TABLE(ieee1394, video1394_id_table); 1316MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
1317#endif /* MODULE */
1316 1318
1317static struct hpsb_protocol_driver video1394_driver = { 1319static struct hpsb_protocol_driver video1394_driver = {
1318 .name = VIDEO1394_DRIVER_NAME, 1320 .name = VIDEO1394_DRIVER_NAME,
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 9dea14db724c..5f9d860925a1 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -149,6 +149,15 @@ config INPUT_APMPOWER
149 To compile this driver as a module, choose M here: the 149 To compile this driver as a module, choose M here: the
150 module will be called apm-power. 150 module will be called apm-power.
151 151
152config XEN_KBDDEV_FRONTEND
153 tristate "Xen virtual keyboard and mouse support"
154 depends on XEN_FBDEV_FRONTEND
155 default y
156 help
157 This driver implements the front-end of the Xen virtual
158 keyboard and mouse device driver. It communicates with a back-end
159 in another domain.
160
152comment "Input Device Drivers" 161comment "Input Device Drivers"
153 162
154source "drivers/input/keyboard/Kconfig" 163source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 2ae87b19caa8..98c4f9a77876 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -23,3 +23,5 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
23obj-$(CONFIG_INPUT_MISC) += misc/ 23obj-$(CONFIG_INPUT_MISC) += misc/
24 24
25obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o 25obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
26
27obj-$(CONFIG_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c
index 490918a5d192..0d3ce7a50fb1 100644
--- a/drivers/input/input-polldev.c
+++ b/drivers/input/input-polldev.c
@@ -73,7 +73,7 @@ static void input_polled_device_work(struct work_struct *work)
73 73
74static int input_open_polled_device(struct input_dev *input) 74static int input_open_polled_device(struct input_dev *input)
75{ 75{
76 struct input_polled_dev *dev = input->private; 76 struct input_polled_dev *dev = input_get_drvdata(input);
77 int error; 77 int error;
78 78
79 error = input_polldev_start_workqueue(); 79 error = input_polldev_start_workqueue();
@@ -91,7 +91,7 @@ static int input_open_polled_device(struct input_dev *input)
91 91
92static void input_close_polled_device(struct input_dev *input) 92static void input_close_polled_device(struct input_dev *input)
93{ 93{
94 struct input_polled_dev *dev = input->private; 94 struct input_polled_dev *dev = input_get_drvdata(input);
95 95
96 cancel_delayed_work_sync(&dev->work); 96 cancel_delayed_work_sync(&dev->work);
97 input_polldev_stop_workqueue(); 97 input_polldev_stop_workqueue();
@@ -151,10 +151,10 @@ int input_register_polled_device(struct input_polled_dev *dev)
151{ 151{
152 struct input_dev *input = dev->input; 152 struct input_dev *input = dev->input;
153 153
154 input_set_drvdata(input, dev);
154 INIT_DELAYED_WORK(&dev->work, input_polled_device_work); 155 INIT_DELAYED_WORK(&dev->work, input_polled_device_work);
155 if (!dev->poll_interval) 156 if (!dev->poll_interval)
156 dev->poll_interval = 500; 157 dev->poll_interval = 500;
157 input->private = dev;
158 input->open = input_open_polled_device; 158 input->open = input_open_polled_device;
159 input->close = input_close_polled_device; 159 input->close = input_close_polled_device;
160 160
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 7c662ee594a3..be5c14a5a0a4 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -193,6 +193,18 @@ config JOYSTICK_TWIDJOY
193 To compile this driver as a module, choose M here: the 193 To compile this driver as a module, choose M here: the
194 module will be called twidjoy. 194 module will be called twidjoy.
195 195
196config JOYSTICK_ZHENHUA
197 tristate "5-byte Zhenhua RC transmitter"
198 select SERIO
199 help
200 Say Y here if you have a Zhen Hua PPM-4CH transmitter which is
201 supplied with a ready to fly micro electric indoor helicopters
202 such as EasyCopter, Lama, MiniCopter, DragonFly or Jabo and want
203 to use it via serial cable as a joystick.
204
205 To compile this driver as a module, choose M here: the
206 module will be called zhenhua.
207
196config JOYSTICK_DB9 208config JOYSTICK_DB9
197 tristate "Multisystem, Sega Genesis, Saturn joysticks and gamepads" 209 tristate "Multisystem, Sega Genesis, Saturn joysticks and gamepads"
198 depends on PARPORT 210 depends on PARPORT
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
index e855abb0cc51..fdbf8c4c2876 100644
--- a/drivers/input/joystick/Makefile
+++ b/drivers/input/joystick/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_JOYSTICK_GF2K) += gf2k.o
15obj-$(CONFIG_JOYSTICK_GRIP) += grip.o 15obj-$(CONFIG_JOYSTICK_GRIP) += grip.o
16obj-$(CONFIG_JOYSTICK_GRIP_MP) += grip_mp.o 16obj-$(CONFIG_JOYSTICK_GRIP_MP) += grip_mp.o
17obj-$(CONFIG_JOYSTICK_GUILLEMOT) += guillemot.o 17obj-$(CONFIG_JOYSTICK_GUILLEMOT) += guillemot.o
18obj-$(CONFIG_JOYSTICK_IFORCE) += iforce/
18obj-$(CONFIG_JOYSTICK_INTERACT) += interact.o 19obj-$(CONFIG_JOYSTICK_INTERACT) += interact.o
19obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o 20obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o
20obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o 21obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o
@@ -27,5 +28,5 @@ obj-$(CONFIG_JOYSTICK_TURBOGRAFX) += turbografx.o
27obj-$(CONFIG_JOYSTICK_TWIDJOY) += twidjoy.o 28obj-$(CONFIG_JOYSTICK_TWIDJOY) += twidjoy.o
28obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o 29obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o
29obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o 30obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
31obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
30 32
31obj-$(CONFIG_JOYSTICK_IFORCE) += iforce/
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 0380597249bb..4b07bdadb81e 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * X-Box gamepad - v0.0.6 2 * X-Box gamepad driver
3 * 3 *
4 * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de> 4 * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
5 * 2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>, 5 * 2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>,
@@ -68,6 +68,8 @@
68 * - dance pads will map D-PAD to buttons, not axes 68 * - dance pads will map D-PAD to buttons, not axes
69 * - pass the module paramater 'dpad_to_buttons' to force 69 * - pass the module paramater 'dpad_to_buttons' to force
70 * the D-PAD to map to buttons if your pad is not detected 70 * the D-PAD to map to buttons if your pad is not detected
71 *
72 * Later changes can be tracked in SCM.
71 */ 73 */
72 74
73#include <linux/kernel.h> 75#include <linux/kernel.h>
@@ -77,7 +79,6 @@
77#include <linux/module.h> 79#include <linux/module.h>
78#include <linux/usb/input.h> 80#include <linux/usb/input.h>
79 81
80#define DRIVER_VERSION "v0.0.6"
81#define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>" 82#define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>"
82#define DRIVER_DESC "X-Box pad driver" 83#define DRIVER_DESC "X-Box pad driver"
83 84
@@ -87,10 +88,12 @@
87 but we map them to axes when possible to simplify things */ 88 but we map them to axes when possible to simplify things */
88#define MAP_DPAD_TO_BUTTONS 0 89#define MAP_DPAD_TO_BUTTONS 0
89#define MAP_DPAD_TO_AXES 1 90#define MAP_DPAD_TO_AXES 1
90#define MAP_DPAD_UNKNOWN -1 91#define MAP_DPAD_UNKNOWN 2
91 92
92#define XTYPE_XBOX 0 93#define XTYPE_XBOX 0
93#define XTYPE_XBOX360 1 94#define XTYPE_XBOX360 1
95#define XTYPE_XBOX360W 2
96#define XTYPE_UNKNOWN 3
94 97
95static int dpad_to_buttons; 98static int dpad_to_buttons;
96module_param(dpad_to_buttons, bool, S_IRUGO); 99module_param(dpad_to_buttons, bool, S_IRUGO);
@@ -107,8 +110,10 @@ static const struct xpad_device {
107 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 110 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", MAP_DPAD_TO_AXES, XTYPE_XBOX },
108 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 111 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", MAP_DPAD_TO_AXES, XTYPE_XBOX },
109 { 0x045e, 0x0287, "Microsoft Xbox Controller S", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 112 { 0x045e, 0x0287, "Microsoft Xbox Controller S", MAP_DPAD_TO_AXES, XTYPE_XBOX },
113 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
110 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 114 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
111 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 115 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
116 { 0x046d, 0xc242, "Logitech Chillstream Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX360 },
112 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 117 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
113 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 118 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", MAP_DPAD_TO_AXES, XTYPE_XBOX },
114 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 119 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", MAP_DPAD_TO_AXES, XTYPE_XBOX },
@@ -135,18 +140,26 @@ static const struct xpad_device {
135 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 140 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
136 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 141 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
137 { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 142 { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
143 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", MAP_DPAD_TO_AXES, XTYPE_XBOX360 },
138 { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 144 { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
139 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 145 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", MAP_DPAD_TO_AXES, XTYPE_XBOX360 },
140 { 0xffff, 0xffff, "Chinese-made Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 146 { 0xffff, 0xffff, "Chinese-made Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
141 { 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_XBOX } 147 { 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_UNKNOWN }
142}; 148};
143 149
144static const signed short xpad_btn[] = { 150/* buttons shared with xbox and xbox360 */
145 BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, /* "analog" buttons */ 151static const signed short xpad_common_btn[] = {
152 BTN_A, BTN_B, BTN_X, BTN_Y, /* "analog" buttons */
146 BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */ 153 BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */
147 -1 /* terminating entry */ 154 -1 /* terminating entry */
148}; 155};
149 156
157/* original xbox controllers only */
158static const signed short xpad_btn[] = {
159 BTN_C, BTN_Z, /* "analog" buttons */
160 -1 /* terminating entry */
161};
162
150/* only used if MAP_DPAD_TO_BUTTONS */ 163/* only used if MAP_DPAD_TO_BUTTONS */
151static const signed short xpad_btn_pad[] = { 164static const signed short xpad_btn_pad[] = {
152 BTN_LEFT, BTN_RIGHT, /* d-pad left, right */ 165 BTN_LEFT, BTN_RIGHT, /* d-pad left, right */
@@ -173,12 +186,27 @@ static const signed short xpad_abs_pad[] = {
173 -1 /* terminating entry */ 186 -1 /* terminating entry */
174}; 187};
175 188
176/* Xbox 360 has a vendor-specific (sub)class, so we cannot match it with only 189/* Xbox 360 has a vendor-specific class, so we cannot match it with only
177 * USB_INTERFACE_INFO, more to that this device has 4 InterfaceProtocols, 190 * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we
178 * but we need only one of them. */ 191 * match against vendor id as well. Wired Xbox 360 devices have protocol 1,
192 * wireless controllers have protocol 129. */
193#define XPAD_XBOX360_VENDOR_PROTOCOL(vend,pr) \
194 .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
195 .idVendor = (vend), \
196 .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
197 .bInterfaceSubClass = 93, \
198 .bInterfaceProtocol = (pr)
199#define XPAD_XBOX360_VENDOR(vend) \
200 { XPAD_XBOX360_VENDOR_PROTOCOL(vend,1) }, \
201 { XPAD_XBOX360_VENDOR_PROTOCOL(vend,129) }
202
179static struct usb_device_id xpad_table [] = { 203static struct usb_device_id xpad_table [] = {
180 { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */ 204 { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */
181 { USB_DEVICE_INTERFACE_PROTOCOL(0x045e, 0x028e, 1) }, /* X-Box 360 controller */ 205 XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */
206 XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */
207 XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */
208 XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */
209 XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */
182 { } 210 { }
183}; 211};
184 212
@@ -188,10 +216,15 @@ struct usb_xpad {
188 struct input_dev *dev; /* input device interface */ 216 struct input_dev *dev; /* input device interface */
189 struct usb_device *udev; /* usb device */ 217 struct usb_device *udev; /* usb device */
190 218
219 int pad_present;
220
191 struct urb *irq_in; /* urb for interrupt in report */ 221 struct urb *irq_in; /* urb for interrupt in report */
192 unsigned char *idata; /* input data */ 222 unsigned char *idata; /* input data */
193 dma_addr_t idata_dma; 223 dma_addr_t idata_dma;
194 224
225 struct urb *bulk_out;
226 unsigned char *bdata;
227
195#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS) 228#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
196 struct urb *irq_out; /* urb for interrupt out report */ 229 struct urb *irq_out; /* urb for interrupt out report */
197 unsigned char *odata; /* output data */ 230 unsigned char *odata; /* output data */
@@ -227,13 +260,13 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
227 input_report_abs(dev, ABS_X, 260 input_report_abs(dev, ABS_X,
228 (__s16) le16_to_cpup((__le16 *)(data + 12))); 261 (__s16) le16_to_cpup((__le16 *)(data + 12)));
229 input_report_abs(dev, ABS_Y, 262 input_report_abs(dev, ABS_Y,
230 (__s16) le16_to_cpup((__le16 *)(data + 14))); 263 ~(__s16) le16_to_cpup((__le16 *)(data + 14)));
231 264
232 /* right stick */ 265 /* right stick */
233 input_report_abs(dev, ABS_RX, 266 input_report_abs(dev, ABS_RX,
234 (__s16) le16_to_cpup((__le16 *)(data + 16))); 267 (__s16) le16_to_cpup((__le16 *)(data + 16)));
235 input_report_abs(dev, ABS_RY, 268 input_report_abs(dev, ABS_RY,
236 (__s16) le16_to_cpup((__le16 *)(data + 18))); 269 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
237 270
238 /* triggers left/right */ 271 /* triggers left/right */
239 input_report_abs(dev, ABS_Z, data[10]); 272 input_report_abs(dev, ABS_Z, data[10]);
@@ -321,13 +354,13 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
321 input_report_abs(dev, ABS_X, 354 input_report_abs(dev, ABS_X,
322 (__s16) le16_to_cpup((__le16 *)(data + 6))); 355 (__s16) le16_to_cpup((__le16 *)(data + 6)));
323 input_report_abs(dev, ABS_Y, 356 input_report_abs(dev, ABS_Y,
324 (__s16) le16_to_cpup((__le16 *)(data + 8))); 357 ~(__s16) le16_to_cpup((__le16 *)(data + 8)));
325 358
326 /* right stick */ 359 /* right stick */
327 input_report_abs(dev, ABS_RX, 360 input_report_abs(dev, ABS_RX,
328 (__s16) le16_to_cpup((__le16 *)(data + 10))); 361 (__s16) le16_to_cpup((__le16 *)(data + 10)));
329 input_report_abs(dev, ABS_RY, 362 input_report_abs(dev, ABS_RY,
330 (__s16) le16_to_cpup((__le16 *)(data + 12))); 363 ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
331 364
332 /* triggers left/right */ 365 /* triggers left/right */
333 input_report_abs(dev, ABS_Z, data[4]); 366 input_report_abs(dev, ABS_Z, data[4]);
@@ -336,12 +369,47 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
336 input_sync(dev); 369 input_sync(dev);
337} 370}
338 371
372/*
373 * xpad360w_process_packet
374 *
375 * Completes a request by converting the data into events for the
376 * input subsystem. It is version for xbox 360 wireless controller.
377 *
378 * Byte.Bit
379 * 00.1 - Status change: The controller or headset has connected/disconnected
380 * Bits 01.7 and 01.6 are valid
381 * 01.7 - Controller present
382 * 01.6 - Headset present
383 * 01.1 - Pad state (Bytes 4+) valid
384 *
385 */
386
387static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
388{
389 /* Presence change */
390 if (data[0] & 0x08) {
391 if (data[1] & 0x80) {
392 xpad->pad_present = 1;
393 usb_submit_urb(xpad->bulk_out, GFP_ATOMIC);
394 } else
395 xpad->pad_present = 0;
396 }
397
398 /* Valid pad data */
399 if (!(data[1] & 0x1))
400 return;
401
402 xpad360_process_packet(xpad, cmd, &data[4]);
403}
404
339static void xpad_irq_in(struct urb *urb) 405static void xpad_irq_in(struct urb *urb)
340{ 406{
341 struct usb_xpad *xpad = urb->context; 407 struct usb_xpad *xpad = urb->context;
342 int retval; 408 int retval, status;
343 409
344 switch (urb->status) { 410 status = urb->status;
411
412 switch (status) {
345 case 0: 413 case 0:
346 /* success */ 414 /* success */
347 break; 415 break;
@@ -350,18 +418,24 @@ static void xpad_irq_in(struct urb *urb)
350 case -ESHUTDOWN: 418 case -ESHUTDOWN:
351 /* this urb is terminated, clean up */ 419 /* this urb is terminated, clean up */
352 dbg("%s - urb shutting down with status: %d", 420 dbg("%s - urb shutting down with status: %d",
353 __FUNCTION__, urb->status); 421 __FUNCTION__, status);
354 return; 422 return;
355 default: 423 default:
356 dbg("%s - nonzero urb status received: %d", 424 dbg("%s - nonzero urb status received: %d",
357 __FUNCTION__, urb->status); 425 __FUNCTION__, status);
358 goto exit; 426 goto exit;
359 } 427 }
360 428
361 if (xpad->xtype == XTYPE_XBOX360) 429 switch (xpad->xtype) {
430 case XTYPE_XBOX360:
362 xpad360_process_packet(xpad, 0, xpad->idata); 431 xpad360_process_packet(xpad, 0, xpad->idata);
363 else 432 break;
433 case XTYPE_XBOX360W:
434 xpad360w_process_packet(xpad, 0, xpad->idata);
435 break;
436 default:
364 xpad_process_packet(xpad, 0, xpad->idata); 437 xpad_process_packet(xpad, 0, xpad->idata);
438 }
365 439
366exit: 440exit:
367 retval = usb_submit_urb (urb, GFP_ATOMIC); 441 retval = usb_submit_urb (urb, GFP_ATOMIC);
@@ -373,9 +447,11 @@ exit:
373#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS) 447#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
374static void xpad_irq_out(struct urb *urb) 448static void xpad_irq_out(struct urb *urb)
375{ 449{
376 int retval; 450 int retval, status;
377 451
378 switch (urb->status) { 452 status = urb->status;
453
454 switch (status) {
379 case 0: 455 case 0:
380 /* success */ 456 /* success */
381 break; 457 break;
@@ -384,11 +460,11 @@ static void xpad_irq_out(struct urb *urb)
384 case -ESHUTDOWN: 460 case -ESHUTDOWN:
385 /* this urb is terminated, clean up */ 461 /* this urb is terminated, clean up */
386 dbg("%s - urb shutting down with status: %d", 462 dbg("%s - urb shutting down with status: %d",
387 __FUNCTION__, urb->status); 463 __FUNCTION__, status);
388 return; 464 return;
389 default: 465 default:
390 dbg("%s - nonzero urb status received: %d", 466 dbg("%s - nonzero urb status received: %d",
391 __FUNCTION__, urb->status); 467 __FUNCTION__, status);
392 goto exit; 468 goto exit;
393 } 469 }
394 470
@@ -399,6 +475,23 @@ exit:
399 __FUNCTION__, retval); 475 __FUNCTION__, retval);
400} 476}
401 477
478static void xpad_bulk_out(struct urb *urb)
479{
480 switch (urb->status) {
481 case 0:
482 /* success */
483 break;
484 case -ECONNRESET:
485 case -ENOENT:
486 case -ESHUTDOWN:
487 /* this urb is terminated, clean up */
488 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
489 break;
490 default:
491 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
492 }
493}
494
402static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) 495static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
403{ 496{
404 struct usb_endpoint_descriptor *ep_irq_out; 497 struct usb_endpoint_descriptor *ep_irq_out;
@@ -408,7 +501,7 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
408 return 0; 501 return 0;
409 502
410 xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, 503 xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN,
411 GFP_ATOMIC, &xpad->odata_dma ); 504 GFP_KERNEL, &xpad->odata_dma);
412 if (!xpad->odata) 505 if (!xpad->odata)
413 goto fail1; 506 goto fail1;
414 507
@@ -469,6 +562,7 @@ static int xpad_play_effect(struct input_dev *dev, void *data,
469 xpad->odata[5] = 0x00; 562 xpad->odata[5] = 0x00;
470 xpad->odata[6] = 0x00; 563 xpad->odata[6] = 0x00;
471 xpad->odata[7] = 0x00; 564 xpad->odata[7] = 0x00;
565 xpad->irq_out->transfer_buffer_length = 8;
472 usb_submit_urb(xpad->irq_out, GFP_KERNEL); 566 usb_submit_urb(xpad->irq_out, GFP_KERNEL);
473 } 567 }
474 568
@@ -477,6 +571,9 @@ static int xpad_play_effect(struct input_dev *dev, void *data,
477 571
478static int xpad_init_ff(struct usb_xpad *xpad) 572static int xpad_init_ff(struct usb_xpad *xpad)
479{ 573{
574 if (xpad->xtype != XTYPE_XBOX360)
575 return 0;
576
480 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); 577 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
481 578
482 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); 579 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
@@ -502,6 +599,7 @@ static void xpad_send_led_command(struct usb_xpad *xpad, int command)
502 xpad->odata[0] = 0x01; 599 xpad->odata[0] = 0x01;
503 xpad->odata[1] = 0x03; 600 xpad->odata[1] = 0x03;
504 xpad->odata[2] = command; 601 xpad->odata[2] = command;
602 xpad->irq_out->transfer_buffer_length = 3;
505 usb_submit_urb(xpad->irq_out, GFP_KERNEL); 603 usb_submit_urb(xpad->irq_out, GFP_KERNEL);
506 mutex_unlock(&xpad->odata_mutex); 604 mutex_unlock(&xpad->odata_mutex);
507 } 605 }
@@ -574,6 +672,10 @@ static int xpad_open(struct input_dev *dev)
574{ 672{
575 struct usb_xpad *xpad = input_get_drvdata(dev); 673 struct usb_xpad *xpad = input_get_drvdata(dev);
576 674
675 /* URB was submitted in probe */
676 if(xpad->xtype == XTYPE_XBOX360W)
677 return 0;
678
577 xpad->irq_in->dev = xpad->udev; 679 xpad->irq_in->dev = xpad->udev;
578 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) 680 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
579 return -EIO; 681 return -EIO;
@@ -585,7 +687,8 @@ static void xpad_close(struct input_dev *dev)
585{ 687{
586 struct usb_xpad *xpad = input_get_drvdata(dev); 688 struct usb_xpad *xpad = input_get_drvdata(dev);
587 689
588 usb_kill_urb(xpad->irq_in); 690 if(xpad->xtype != XTYPE_XBOX360W)
691 usb_kill_urb(xpad->irq_in);
589 xpad_stop_output(xpad); 692 xpad_stop_output(xpad);
590} 693}
591 694
@@ -632,7 +735,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
632 goto fail1; 735 goto fail1;
633 736
634 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, 737 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,
635 GFP_ATOMIC, &xpad->idata_dma); 738 GFP_KERNEL, &xpad->idata_dma);
636 if (!xpad->idata) 739 if (!xpad->idata)
637 goto fail1; 740 goto fail1;
638 741
@@ -644,7 +747,16 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
644 xpad->dpad_mapping = xpad_device[i].dpad_mapping; 747 xpad->dpad_mapping = xpad_device[i].dpad_mapping;
645 xpad->xtype = xpad_device[i].xtype; 748 xpad->xtype = xpad_device[i].xtype;
646 if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN) 749 if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN)
647 xpad->dpad_mapping = dpad_to_buttons; 750 xpad->dpad_mapping = !dpad_to_buttons;
751 if (xpad->xtype == XTYPE_UNKNOWN) {
752 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
753 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
754 xpad->xtype = XTYPE_XBOX360W;
755 else
756 xpad->xtype = XTYPE_XBOX360;
757 } else
758 xpad->xtype = XTYPE_XBOX;
759 }
648 xpad->dev = input_dev; 760 xpad->dev = input_dev;
649 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); 761 usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
650 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); 762 strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
@@ -662,11 +774,14 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
662 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 774 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
663 775
664 /* set up buttons */ 776 /* set up buttons */
665 for (i = 0; xpad_btn[i] >= 0; i++) 777 for (i = 0; xpad_common_btn[i] >= 0; i++)
666 set_bit(xpad_btn[i], input_dev->keybit); 778 set_bit(xpad_common_btn[i], input_dev->keybit);
667 if (xpad->xtype == XTYPE_XBOX360) 779 if ((xpad->xtype == XTYPE_XBOX360) || (xpad->xtype == XTYPE_XBOX360W))
668 for (i = 0; xpad360_btn[i] >= 0; i++) 780 for (i = 0; xpad360_btn[i] >= 0; i++)
669 set_bit(xpad360_btn[i], input_dev->keybit); 781 set_bit(xpad360_btn[i], input_dev->keybit);
782 else
783 for (i = 0; xpad_btn[i] >= 0; i++)
784 set_bit(xpad_btn[i], input_dev->keybit);
670 if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) 785 if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS)
671 for (i = 0; xpad_btn_pad[i] >= 0; i++) 786 for (i = 0; xpad_btn_pad[i] >= 0; i++)
672 set_bit(xpad_btn_pad[i], input_dev->keybit); 787 set_bit(xpad_btn_pad[i], input_dev->keybit);
@@ -703,8 +818,57 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
703 goto fail4; 818 goto fail4;
704 819
705 usb_set_intfdata(intf, xpad); 820 usb_set_intfdata(intf, xpad);
821
822 /*
823 * Submit the int URB immediatly rather than waiting for open
824 * because we get status messages from the device whether
825 * or not any controllers are attached. In fact, it's
826 * exactly the message that a controller has arrived that
827 * we're waiting for.
828 */
829 if (xpad->xtype == XTYPE_XBOX360W) {
830 xpad->irq_in->dev = xpad->udev;
831 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
832 if (error)
833 goto fail4;
834
835 /*
836 * Setup the message to set the LEDs on the
837 * controller when it shows up
838 */
839 xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);
840 if(!xpad->bulk_out)
841 goto fail5;
842
843 xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);
844 if(!xpad->bdata)
845 goto fail6;
846
847 xpad->bdata[2] = 0x08;
848 switch (intf->cur_altsetting->desc.bInterfaceNumber) {
849 case 0:
850 xpad->bdata[3] = 0x42;
851 break;
852 case 2:
853 xpad->bdata[3] = 0x43;
854 break;
855 case 4:
856 xpad->bdata[3] = 0x44;
857 break;
858 case 6:
859 xpad->bdata[3] = 0x45;
860 }
861
862 ep_irq_in = &intf->cur_altsetting->endpoint[1].desc;
863 usb_fill_bulk_urb(xpad->bulk_out, udev,
864 usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress),
865 xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad);
866 }
867
706 return 0; 868 return 0;
707 869
870 fail6: usb_free_urb(xpad->bulk_out);
871 fail5: usb_kill_urb(xpad->irq_in);
708 fail4: usb_free_urb(xpad->irq_in); 872 fail4: usb_free_urb(xpad->irq_in);
709 fail3: xpad_deinit_output(xpad); 873 fail3: xpad_deinit_output(xpad);
710 fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 874 fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
@@ -723,6 +887,11 @@ static void xpad_disconnect(struct usb_interface *intf)
723 xpad_led_disconnect(xpad); 887 xpad_led_disconnect(xpad);
724 input_unregister_device(xpad->dev); 888 input_unregister_device(xpad->dev);
725 xpad_deinit_output(xpad); 889 xpad_deinit_output(xpad);
890 if (xpad->xtype == XTYPE_XBOX360W) {
891 usb_kill_urb(xpad->bulk_out);
892 usb_free_urb(xpad->bulk_out);
893 usb_kill_urb(xpad->irq_in);
894 }
726 usb_free_urb(xpad->irq_in); 895 usb_free_urb(xpad->irq_in);
727 usb_buffer_free(xpad->udev, XPAD_PKT_LEN, 896 usb_buffer_free(xpad->udev, XPAD_PKT_LEN,
728 xpad->idata, xpad->idata_dma); 897 xpad->idata, xpad->idata_dma);
@@ -741,7 +910,7 @@ static int __init usb_xpad_init(void)
741{ 910{
742 int result = usb_register(&xpad_driver); 911 int result = usb_register(&xpad_driver);
743 if (result == 0) 912 if (result == 0)
744 info(DRIVER_DESC ":" DRIVER_VERSION); 913 info(DRIVER_DESC);
745 return result; 914 return result;
746} 915}
747 916
diff --git a/drivers/input/joystick/zhenhua.c b/drivers/input/joystick/zhenhua.c
new file mode 100644
index 000000000000..b5853125c898
--- /dev/null
+++ b/drivers/input/joystick/zhenhua.c
@@ -0,0 +1,243 @@
1/*
2 * derived from "twidjoy.c"
3 *
4 * Copyright (c) 2008 Martin Kebert
5 * Copyright (c) 2001 Arndt Schoenewald
6 * Copyright (c) 2000-2001 Vojtech Pavlik
7 * Copyright (c) 2000 Mark Fletcher
8 *
9 */
10
11/*
12 * Driver to use 4CH RC transmitter using Zhen Hua 5-byte protocol (Walkera Lama,
13 * EasyCopter etc.) as a joystick under Linux.
14 *
15 * RC transmitters using Zhen Hua 5-byte protocol are cheap four channels
16 * transmitters for control a RC planes or RC helicopters with possibility to
17 * connect on a serial port.
18 * Data coming from transmitter is in this order:
19 * 1. byte = synchronisation byte
20 * 2. byte = X axis
21 * 3. byte = Y axis
22 * 4. byte = RZ axis
23 * 5. byte = Z axis
24 * (and this is repeated)
25 *
26 * For questions or feedback regarding this driver module please contact:
27 * Martin Kebert <gkmarty@gmail.com> - but I am not a C-programmer nor kernel
28 * coder :-(
29 */
30
31/*
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
36 *
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
41 *
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
45 */
46
47#include <linux/kernel.h>
48#include <linux/module.h>
49#include <linux/slab.h>
50#include <linux/input.h>
51#include <linux/serio.h>
52#include <linux/init.h>
53
54#define DRIVER_DESC "RC transmitter with 5-byte Zhen Hua protocol joystick driver"
55
56MODULE_DESCRIPTION(DRIVER_DESC);
57MODULE_LICENSE("GPL");
58
59/*
60 * Constants.
61 */
62
63#define ZHENHUA_MAX_LENGTH 5
64
65/*
66 * Zhen Hua data.
67 */
68
69struct zhenhua {
70 struct input_dev *dev;
71 int idx;
72 unsigned char data[ZHENHUA_MAX_LENGTH];
73 char phys[32];
74};
75
76
77/* bits in all incoming bytes needs to be "reversed" */
78static int zhenhua_bitreverse(int x)
79{
80 x = ((x & 0xaa) >> 1) | ((x & 0x55) << 1);
81 x = ((x & 0xcc) >> 2) | ((x & 0x33) << 2);
82 x = ((x & 0xf0) >> 4) | ((x & 0x0f) << 4);
83 return x;
84}
85
86/*
87 * zhenhua_process_packet() decodes packets the driver receives from the
88 * RC transmitter. It updates the data accordingly.
89 */
90
91static void zhenhua_process_packet(struct zhenhua *zhenhua)
92{
93 struct input_dev *dev = zhenhua->dev;
94 unsigned char *data = zhenhua->data;
95
96 input_report_abs(dev, ABS_Y, data[1]);
97 input_report_abs(dev, ABS_X, data[2]);
98 input_report_abs(dev, ABS_RZ, data[3]);
99 input_report_abs(dev, ABS_Z, data[4]);
100
101 input_sync(dev);
102}
103
104/*
105 * zhenhua_interrupt() is called by the low level driver when characters
106 * are ready for us. We then buffer them for further processing, or call the
107 * packet processing routine.
108 */
109
110static irqreturn_t zhenhua_interrupt(struct serio *serio, unsigned char data, unsigned int flags)
111{
112 struct zhenhua *zhenhua = serio_get_drvdata(serio);
113
114 /* All Zhen Hua packets are 5 bytes. The fact that the first byte
115 * is allways 0xf7 and all others are in range 0x32 - 0xc8 (50-200)
116 * can be used to check and regain sync. */
117
118 if (data == 0xef)
119 zhenhua->idx = 0; /* this byte starts a new packet */
120 else if (zhenhua->idx == 0)
121 return IRQ_HANDLED; /* wrong MSB -- ignore this byte */
122
123 if (zhenhua->idx < ZHENHUA_MAX_LENGTH)
124 zhenhua->data[zhenhua->idx++] = zhenhua_bitreverse(data);
125
126 if (zhenhua->idx == ZHENHUA_MAX_LENGTH) {
127 zhenhua_process_packet(zhenhua);
128 zhenhua->idx = 0;
129 }
130
131 return IRQ_HANDLED;
132}
133
134/*
135 * zhenhua_disconnect() is the opposite of zhenhua_connect()
136 */
137
138static void zhenhua_disconnect(struct serio *serio)
139{
140 struct zhenhua *zhenhua = serio_get_drvdata(serio);
141
142 serio_close(serio);
143 serio_set_drvdata(serio, NULL);
144 input_unregister_device(zhenhua->dev);
145 kfree(zhenhua);
146}
147
148/*
149 * zhenhua_connect() is the routine that is called when someone adds a
150 * new serio device. It looks for the Twiddler, and if found, registers
151 * it as an input device.
152 */
153
154static int zhenhua_connect(struct serio *serio, struct serio_driver *drv)
155{
156 struct zhenhua *zhenhua;
157 struct input_dev *input_dev;
158 int err = -ENOMEM;
159
160 zhenhua = kzalloc(sizeof(struct zhenhua), GFP_KERNEL);
161 input_dev = input_allocate_device();
162 if (!zhenhua || !input_dev)
163 goto fail1;
164
165 zhenhua->dev = input_dev;
166 snprintf(zhenhua->phys, sizeof(zhenhua->phys), "%s/input0", serio->phys);
167
168 input_dev->name = "Zhen Hua 5-byte device";
169 input_dev->phys = zhenhua->phys;
170 input_dev->id.bustype = BUS_RS232;
171 input_dev->id.vendor = SERIO_ZHENHUA;
172 input_dev->id.product = 0x0001;
173 input_dev->id.version = 0x0100;
174 input_dev->dev.parent = &serio->dev;
175
176 input_dev->evbit[0] = BIT(EV_ABS);
177 input_set_abs_params(input_dev, ABS_X, 50, 200, 0, 0);
178 input_set_abs_params(input_dev, ABS_Y, 50, 200, 0, 0);
179 input_set_abs_params(input_dev, ABS_Z, 50, 200, 0, 0);
180 input_set_abs_params(input_dev, ABS_RZ, 50, 200, 0, 0);
181
182 serio_set_drvdata(serio, zhenhua);
183
184 err = serio_open(serio, drv);
185 if (err)
186 goto fail2;
187
188 err = input_register_device(zhenhua->dev);
189 if (err)
190 goto fail3;
191
192 return 0;
193
194 fail3: serio_close(serio);
195 fail2: serio_set_drvdata(serio, NULL);
196 fail1: input_free_device(input_dev);
197 kfree(zhenhua);
198 return err;
199}
200
201/*
202 * The serio driver structure.
203 */
204
205static struct serio_device_id zhenhua_serio_ids[] = {
206 {
207 .type = SERIO_RS232,
208 .proto = SERIO_ZHENHUA,
209 .id = SERIO_ANY,
210 .extra = SERIO_ANY,
211 },
212 { 0 }
213};
214
215MODULE_DEVICE_TABLE(serio, zhenhua_serio_ids);
216
217static struct serio_driver zhenhua_drv = {
218 .driver = {
219 .name = "zhenhua",
220 },
221 .description = DRIVER_DESC,
222 .id_table = zhenhua_serio_ids,
223 .interrupt = zhenhua_interrupt,
224 .connect = zhenhua_connect,
225 .disconnect = zhenhua_disconnect,
226};
227
228/*
229 * The functions for inserting/removing us as a module.
230 */
231
232static int __init zhenhua_init(void)
233{
234 return serio_register_driver(&zhenhua_drv);
235}
236
237static void __exit zhenhua_exit(void)
238{
239 serio_unregister_driver(&zhenhua_drv);
240}
241
242module_init(zhenhua_init);
243module_exit(zhenhua_exit);
diff --git a/drivers/input/keyboard/aaed2000_kbd.c b/drivers/input/keyboard/aaed2000_kbd.c
index 72abc196ce66..a293e8b3f508 100644
--- a/drivers/input/keyboard/aaed2000_kbd.c
+++ b/drivers/input/keyboard/aaed2000_kbd.c
@@ -156,11 +156,15 @@ static int __devexit aaedkbd_remove(struct platform_device *pdev)
156 return 0; 156 return 0;
157} 157}
158 158
159/* work with hotplug and coldplug */
160MODULE_ALIAS("platform:aaed2000-keyboard");
161
159static struct platform_driver aaedkbd_driver = { 162static struct platform_driver aaedkbd_driver = {
160 .probe = aaedkbd_probe, 163 .probe = aaedkbd_probe,
161 .remove = __devexit_p(aaedkbd_remove), 164 .remove = __devexit_p(aaedkbd_remove),
162 .driver = { 165 .driver = {
163 .name = "aaed2000-keyboard", 166 .name = "aaed2000-keyboard",
167 .owner = THIS_MODULE,
164 }, 168 },
165}; 169};
166 170
diff --git a/drivers/input/keyboard/bf54x-keys.c b/drivers/input/keyboard/bf54x-keys.c
index 05e3494cf8b8..54ed8e2e1c02 100644
--- a/drivers/input/keyboard/bf54x-keys.c
+++ b/drivers/input/keyboard/bf54x-keys.c
@@ -312,6 +312,8 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
312 312
313 bfin_write_KPAD_CTL(bfin_read_KPAD_CTL() | KPAD_EN); 313 bfin_write_KPAD_CTL(bfin_read_KPAD_CTL() | KPAD_EN);
314 314
315 device_init_wakeup(&pdev->dev, 1);
316
315 printk(KERN_ERR DRV_NAME 317 printk(KERN_ERR DRV_NAME
316 ": Blackfin BF54x Keypad registered IRQ %d\n", bf54x_kpad->irq); 318 ": Blackfin BF54x Keypad registered IRQ %d\n", bf54x_kpad->irq);
317 319
@@ -354,12 +356,40 @@ static int __devexit bfin_kpad_remove(struct platform_device *pdev)
354 return 0; 356 return 0;
355} 357}
356 358
359#ifdef CONFIG_PM
360static int bfin_kpad_suspend(struct platform_device *pdev, pm_message_t state)
361{
362 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
363
364 if (device_may_wakeup(&pdev->dev))
365 enable_irq_wake(bf54x_kpad->irq);
366
367 return 0;
368}
369
370static int bfin_kpad_resume(struct platform_device *pdev)
371{
372 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
373
374 if (device_may_wakeup(&pdev->dev))
375 disable_irq_wake(bf54x_kpad->irq);
376
377 return 0;
378}
379#else
380# define bfin_kpad_suspend NULL
381# define bfin_kpad_resume NULL
382#endif
383
357struct platform_driver bfin_kpad_device_driver = { 384struct platform_driver bfin_kpad_device_driver = {
358 .probe = bfin_kpad_probe,
359 .remove = __devexit_p(bfin_kpad_remove),
360 .driver = { 385 .driver = {
361 .name = DRV_NAME, 386 .name = DRV_NAME,
362 } 387 .owner = THIS_MODULE,
388 },
389 .probe = bfin_kpad_probe,
390 .remove = __devexit_p(bfin_kpad_remove),
391 .suspend = bfin_kpad_suspend,
392 .resume = bfin_kpad_resume,
363}; 393};
364 394
365static int __init bfin_kpad_init(void) 395static int __init bfin_kpad_init(void)
@@ -378,3 +408,4 @@ module_exit(bfin_kpad_exit);
378MODULE_LICENSE("GPL"); 408MODULE_LICENSE("GPL");
379MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 409MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
380MODULE_DESCRIPTION("Keypad driver for BF54x Processors"); 410MODULE_DESCRIPTION("Keypad driver for BF54x Processors");
411MODULE_ALIAS("platform:bf54x-keys");
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index 5d6cc7f1dc94..29fbec6218b9 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -393,6 +393,7 @@ static struct platform_driver corgikbd_driver = {
393 .resume = corgikbd_resume, 393 .resume = corgikbd_resume,
394 .driver = { 394 .driver = {
395 .name = "corgi-keyboard", 395 .name = "corgi-keyboard",
396 .owner = THIS_MODULE,
396 }, 397 },
397}; 398};
398 399
@@ -412,3 +413,4 @@ module_exit(corgikbd_exit);
412MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); 413MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
413MODULE_DESCRIPTION("Corgi Keyboard Driver"); 414MODULE_DESCRIPTION("Corgi Keyboard Driver");
414MODULE_LICENSE("GPLv2"); 415MODULE_LICENSE("GPLv2");
416MODULE_ALIAS("platform:corgi-keyboard");
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 6a9ca4bdcb74..bbd00c3fe98c 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -43,10 +43,11 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
43 43
44 input_event(input, type, button->code, !!state); 44 input_event(input, type, button->code, !!state);
45 input_sync(input); 45 input_sync(input);
46 return IRQ_HANDLED;
46 } 47 }
47 } 48 }
48 49
49 return IRQ_HANDLED; 50 return IRQ_NONE;
50} 51}
51 52
52static int __devinit gpio_keys_probe(struct platform_device *pdev) 53static int __devinit gpio_keys_probe(struct platform_device *pdev)
@@ -213,6 +214,7 @@ struct platform_driver gpio_keys_device_driver = {
213 .resume = gpio_keys_resume, 214 .resume = gpio_keys_resume,
214 .driver = { 215 .driver = {
215 .name = "gpio-keys", 216 .name = "gpio-keys",
217 .owner = THIS_MODULE,
216 } 218 }
217}; 219};
218 220
@@ -232,3 +234,4 @@ module_exit(gpio_keys_exit);
232MODULE_LICENSE("GPL"); 234MODULE_LICENSE("GPL");
233MODULE_AUTHOR("Phil Blundell <pb@handhelds.org>"); 235MODULE_AUTHOR("Phil Blundell <pb@handhelds.org>");
234MODULE_DESCRIPTION("Keyboard driver for CPU GPIOs"); 236MODULE_DESCRIPTION("Keyboard driver for CPU GPIOs");
237MODULE_ALIAS("platform:gpio-keys");
diff --git a/drivers/input/keyboard/jornada680_kbd.c b/drivers/input/keyboard/jornada680_kbd.c
index a23633a2e1b4..9387da343f97 100644
--- a/drivers/input/keyboard/jornada680_kbd.c
+++ b/drivers/input/keyboard/jornada680_kbd.c
@@ -254,6 +254,7 @@ static int __devexit jornada680kbd_remove(struct platform_device *pdev)
254static struct platform_driver jornada680kbd_driver = { 254static struct platform_driver jornada680kbd_driver = {
255 .driver = { 255 .driver = {
256 .name = "jornada680_kbd", 256 .name = "jornada680_kbd",
257 .owner = THIS_MODULE,
257 }, 258 },
258 .probe = jornada680kbd_probe, 259 .probe = jornada680kbd_probe,
259 .remove = __devexit_p(jornada680kbd_remove), 260 .remove = __devexit_p(jornada680kbd_remove),
@@ -275,3 +276,4 @@ module_exit(jornada680kbd_exit);
275MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>"); 276MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
276MODULE_DESCRIPTION("HP Jornada 620/660/680/690 Keyboard Driver"); 277MODULE_DESCRIPTION("HP Jornada 620/660/680/690 Keyboard Driver");
277MODULE_LICENSE("GPLv2"); 278MODULE_LICENSE("GPLv2");
279MODULE_ALIAS("platform:jornada680_kbd");
diff --git a/drivers/input/keyboard/jornada720_kbd.c b/drivers/input/keyboard/jornada720_kbd.c
index 986f93cfc6b8..a1164a0c7736 100644
--- a/drivers/input/keyboard/jornada720_kbd.c
+++ b/drivers/input/keyboard/jornada720_kbd.c
@@ -162,9 +162,13 @@ static int __devexit jornada720_kbd_remove(struct platform_device *pdev)
162 return 0; 162 return 0;
163} 163}
164 164
165/* work with hotplug and coldplug */
166MODULE_ALIAS("platform:jornada720_kbd");
167
165static struct platform_driver jornada720_kbd_driver = { 168static struct platform_driver jornada720_kbd_driver = {
166 .driver = { 169 .driver = {
167 .name = "jornada720_kbd", 170 .name = "jornada720_kbd",
171 .owner = THIS_MODULE,
168 }, 172 },
169 .probe = jornada720_kbd_probe, 173 .probe = jornada720_kbd_probe,
170 .remove = __devexit_p(jornada720_kbd_remove), 174 .remove = __devexit_p(jornada720_kbd_remove),
diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c
index 5a0ca18d6755..9caed30f3bbb 100644
--- a/drivers/input/keyboard/locomokbd.c
+++ b/drivers/input/keyboard/locomokbd.c
@@ -1,14 +1,12 @@
1/* 1/*
2 * Copyright (c) 2005 John Lenz 2 * LoCoMo keyboard driver for Linux-based ARM PDAs:
3 * - SHARP Zaurus Collie (SL-5500)
4 * - SHARP Zaurus Poodle (SL-5600)
3 * 5 *
6 * Copyright (c) 2005 John Lenz
4 * Based on from xtkbd.c 7 * Based on from xtkbd.c
5 */ 8 *
6 9 *
7/*
8 * LoCoMo keyboard driver for Linux/ARM
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
@@ -47,7 +45,8 @@ MODULE_LICENSE("GPL");
47#define KEY_CONTACT KEY_F18 45#define KEY_CONTACT KEY_F18
48#define KEY_CENTER KEY_F15 46#define KEY_CENTER KEY_F15
49 47
50static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = { 48static const unsigned char
49locomokbd_keycode[LOCOMOKBD_NUMKEYS] __devinitconst = {
51 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */ 50 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */
52 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */ 51 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */ 52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */
@@ -67,22 +66,21 @@ static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
67#define KB_COLS 8 66#define KB_COLS 8
68#define KB_ROWMASK(r) (1 << (r)) 67#define KB_ROWMASK(r) (1 << (r))
69#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 ) 68#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 )
70#define NR_SCANCODES 128
71 69
72#define KB_DELAY 8 70#define KB_DELAY 8
73#define SCAN_INTERVAL (HZ/10) 71#define SCAN_INTERVAL (HZ/10)
74#define LOCOMOKBD_PRESSED 1
75 72
76struct locomokbd { 73struct locomokbd {
77 unsigned char keycode[LOCOMOKBD_NUMKEYS]; 74 unsigned char keycode[LOCOMOKBD_NUMKEYS];
78 struct input_dev *input; 75 struct input_dev *input;
79 char phys[32]; 76 char phys[32];
80 77
81 struct locomo_dev *ldev;
82 unsigned long base; 78 unsigned long base;
83 spinlock_t lock; 79 spinlock_t lock;
84 80
85 struct timer_list timer; 81 struct timer_list timer;
82 unsigned long suspend_jiffies;
83 unsigned int count_cancel;
86}; 84};
87 85
88/* helper functions for reading the keyboard matrix */ 86/* helper functions for reading the keyboard matrix */
@@ -128,7 +126,7 @@ static inline void locomokbd_reset_col(unsigned long membase, int col)
128/* Scan the hardware keyboard and push any changes up through the input layer */ 126/* Scan the hardware keyboard and push any changes up through the input layer */
129static void locomokbd_scankeyboard(struct locomokbd *locomokbd) 127static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
130{ 128{
131 unsigned int row, col, rowd, scancode; 129 unsigned int row, col, rowd;
132 unsigned long flags; 130 unsigned long flags;
133 unsigned int num_pressed; 131 unsigned int num_pressed;
134 unsigned long membase = locomokbd->base; 132 unsigned long membase = locomokbd->base;
@@ -145,13 +143,33 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
145 143
146 rowd = ~locomo_readl(membase + LOCOMO_KIB); 144 rowd = ~locomo_readl(membase + LOCOMO_KIB);
147 for (row = 0; row < KB_ROWS; row++) { 145 for (row = 0; row < KB_ROWS; row++) {
146 unsigned int scancode, pressed, key;
147
148 scancode = SCANCODE(col, row); 148 scancode = SCANCODE(col, row);
149 if (rowd & KB_ROWMASK(row)) { 149 pressed = rowd & KB_ROWMASK(row);
150 num_pressed += 1; 150 key = locomokbd->keycode[scancode];
151 input_report_key(locomokbd->input, locomokbd->keycode[scancode], 1); 151
152 } else { 152 input_report_key(locomokbd->input, key, pressed);
153 input_report_key(locomokbd->input, locomokbd->keycode[scancode], 0); 153 if (likely(!pressed))
154 } 154 continue;
155
156 num_pressed++;
157
158 /* The "Cancel/ESC" key is labeled "On/Off" on
159 * Collie and Poodle and should suspend the device
160 * if it was pressed for more than a second. */
161 if (unlikely(key == KEY_ESC)) {
162 if (!time_after(jiffies,
163 locomokbd->suspend_jiffies + HZ))
164 continue;
165 if (locomokbd->count_cancel++
166 != (HZ/SCAN_INTERVAL + 1))
167 continue;
168 input_event(locomokbd->input, EV_PWR,
169 KEY_SUSPEND, 1);
170 locomokbd->suspend_jiffies = jiffies;
171 } else
172 locomokbd->count_cancel = 0;
155 } 173 }
156 locomokbd_reset_col(membase, col); 174 locomokbd_reset_col(membase, col);
157 } 175 }
@@ -162,6 +180,8 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
162 /* if any keys are pressed, enable the timer */ 180 /* if any keys are pressed, enable the timer */
163 if (num_pressed) 181 if (num_pressed)
164 mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL); 182 mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL);
183 else
184 locomokbd->count_cancel = 0;
165 185
166 spin_unlock_irqrestore(&locomokbd->lock, flags); 186 spin_unlock_irqrestore(&locomokbd->lock, flags);
167} 187}
@@ -186,10 +206,11 @@ static irqreturn_t locomokbd_interrupt(int irq, void *dev_id)
186static void locomokbd_timer_callback(unsigned long data) 206static void locomokbd_timer_callback(unsigned long data)
187{ 207{
188 struct locomokbd *locomokbd = (struct locomokbd *) data; 208 struct locomokbd *locomokbd = (struct locomokbd *) data;
209
189 locomokbd_scankeyboard(locomokbd); 210 locomokbd_scankeyboard(locomokbd);
190} 211}
191 212
192static int locomokbd_probe(struct locomo_dev *dev) 213static int __devinit locomokbd_probe(struct locomo_dev *dev)
193{ 214{
194 struct locomokbd *locomokbd; 215 struct locomokbd *locomokbd;
195 struct input_dev *input_dev; 216 struct input_dev *input_dev;
@@ -211,7 +232,6 @@ static int locomokbd_probe(struct locomo_dev *dev)
211 goto err_free_mem; 232 goto err_free_mem;
212 } 233 }
213 234
214 locomokbd->ldev = dev;
215 locomo_set_drvdata(dev, locomokbd); 235 locomo_set_drvdata(dev, locomokbd);
216 236
217 locomokbd->base = (unsigned long) dev->mapbase; 237 locomokbd->base = (unsigned long) dev->mapbase;
@@ -222,6 +242,8 @@ static int locomokbd_probe(struct locomo_dev *dev)
222 locomokbd->timer.function = locomokbd_timer_callback; 242 locomokbd->timer.function = locomokbd_timer_callback;
223 locomokbd->timer.data = (unsigned long) locomokbd; 243 locomokbd->timer.data = (unsigned long) locomokbd;
224 244
245 locomokbd->suspend_jiffies = jiffies;
246
225 locomokbd->input = input_dev; 247 locomokbd->input = input_dev;
226 strcpy(locomokbd->phys, "locomokbd/input0"); 248 strcpy(locomokbd->phys, "locomokbd/input0");
227 249
@@ -233,9 +255,10 @@ static int locomokbd_probe(struct locomo_dev *dev)
233 input_dev->id.version = 0x0100; 255 input_dev->id.version = 0x0100;
234 input_dev->dev.parent = &dev->dev; 256 input_dev->dev.parent = &dev->dev;
235 257
236 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); 258 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
259 BIT_MASK(EV_PWR);
237 input_dev->keycode = locomokbd->keycode; 260 input_dev->keycode = locomokbd->keycode;
238 input_dev->keycodesize = sizeof(unsigned char); 261 input_dev->keycodesize = sizeof(locomokbd_keycode[0]);
239 input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode); 262 input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
240 263
241 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode)); 264 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
@@ -268,7 +291,7 @@ static int locomokbd_probe(struct locomo_dev *dev)
268 return err; 291 return err;
269} 292}
270 293
271static int locomokbd_remove(struct locomo_dev *dev) 294static int __devexit locomokbd_remove(struct locomo_dev *dev)
272{ 295{
273 struct locomokbd *locomokbd = locomo_get_drvdata(dev); 296 struct locomokbd *locomokbd = locomo_get_drvdata(dev);
274 297
@@ -292,7 +315,7 @@ static struct locomo_driver keyboard_driver = {
292 }, 315 },
293 .devid = LOCOMO_DEVID_KEYBOARD, 316 .devid = LOCOMO_DEVID_KEYBOARD,
294 .probe = locomokbd_probe, 317 .probe = locomokbd_probe,
295 .remove = locomokbd_remove, 318 .remove = __devexit_p(locomokbd_remove),
296}; 319};
297 320
298static int __init locomokbd_init(void) 321static int __init locomokbd_init(void)
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c
index babc913d5492..10afd2068068 100644
--- a/drivers/input/keyboard/omap-keypad.c
+++ b/drivers/input/keyboard/omap-keypad.c
@@ -352,6 +352,9 @@ static int __init omap_kp_probe(struct platform_device *pdev)
352 } 352 }
353 omap_set_gpio_direction(row_gpios[row_idx], 1); 353 omap_set_gpio_direction(row_gpios[row_idx], 1);
354 } 354 }
355 } else {
356 col_idx = 0;
357 row_idx = 0;
355 } 358 }
356 359
357 setup_timer(&omap_kp->timer, omap_kp_timer, (unsigned long)omap_kp); 360 setup_timer(&omap_kp->timer, omap_kp_timer, (unsigned long)omap_kp);
@@ -415,10 +418,10 @@ err4:
415err3: 418err3:
416 device_remove_file(&pdev->dev, &dev_attr_enable); 419 device_remove_file(&pdev->dev, &dev_attr_enable);
417err2: 420err2:
418 for (i = row_idx-1; i >=0; i--) 421 for (i = row_idx - 1; i >=0; i--)
419 omap_free_gpio(row_gpios[i]); 422 omap_free_gpio(row_gpios[i]);
420err1: 423err1:
421 for (i = col_idx-1; i >=0; i--) 424 for (i = col_idx - 1; i >=0; i--)
422 omap_free_gpio(col_gpios[i]); 425 omap_free_gpio(col_gpios[i]);
423 426
424 kfree(omap_kp); 427 kfree(omap_kp);
@@ -464,6 +467,7 @@ static struct platform_driver omap_kp_driver = {
464 .resume = omap_kp_resume, 467 .resume = omap_kp_resume,
465 .driver = { 468 .driver = {
466 .name = "omap-keypad", 469 .name = "omap-keypad",
470 .owner = THIS_MODULE,
467 }, 471 },
468}; 472};
469 473
@@ -484,3 +488,4 @@ module_exit(omap_kp_exit);
484MODULE_AUTHOR("Timo Teräs"); 488MODULE_AUTHOR("Timo Teräs");
485MODULE_DESCRIPTION("OMAP Keypad Driver"); 489MODULE_DESCRIPTION("OMAP Keypad Driver");
486MODULE_LICENSE("GPL"); 490MODULE_LICENSE("GPL");
491MODULE_ALIAS("platform:omap-keypad");
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index 4e651c11c1da..3dea0c5077a9 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -545,6 +545,9 @@ static int __devexit pxa27x_keypad_remove(struct platform_device *pdev)
545 return 0; 545 return 0;
546} 546}
547 547
548/* work with hotplug and coldplug */
549MODULE_ALIAS("platform:pxa27x-keypad");
550
548static struct platform_driver pxa27x_keypad_driver = { 551static struct platform_driver pxa27x_keypad_driver = {
549 .probe = pxa27x_keypad_probe, 552 .probe = pxa27x_keypad_probe,
550 .remove = __devexit_p(pxa27x_keypad_remove), 553 .remove = __devexit_p(pxa27x_keypad_remove),
@@ -552,6 +555,7 @@ static struct platform_driver pxa27x_keypad_driver = {
552 .resume = pxa27x_keypad_resume, 555 .resume = pxa27x_keypad_resume,
553 .driver = { 556 .driver = {
554 .name = "pxa27x-keypad", 557 .name = "pxa27x-keypad",
558 .owner = THIS_MODULE,
555 }, 559 },
556}; 560};
557 561
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 0be74bfc58fe..61e401bc9109 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -495,3 +495,4 @@ module_exit(spitzkbd_exit);
495MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); 495MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
496MODULE_DESCRIPTION("Spitz Keyboard Driver"); 496MODULE_DESCRIPTION("Spitz Keyboard Driver");
497MODULE_LICENSE("GPLv2"); 497MODULE_LICENSE("GPLv2");
498MODULE_ALIAS("platform:spitz-keyboard");
diff --git a/drivers/input/keyboard/tosakbd.c b/drivers/input/keyboard/tosakbd.c
index 3884d1e3f070..94e444b4ee15 100644
--- a/drivers/input/keyboard/tosakbd.c
+++ b/drivers/input/keyboard/tosakbd.c
@@ -52,7 +52,7 @@ KEY_X, KEY_F, KEY_SPACE, KEY_APOSTROPHE, TOSA_KEY_MAIL, KEY_LEFT, KEY_DOWN, KEY_
52struct tosakbd { 52struct tosakbd {
53 unsigned int keycode[ARRAY_SIZE(tosakbd_keycode)]; 53 unsigned int keycode[ARRAY_SIZE(tosakbd_keycode)];
54 struct input_dev *input; 54 struct input_dev *input;
55 55 int suspended;
56 spinlock_t lock; /* protect kbd scanning */ 56 spinlock_t lock; /* protect kbd scanning */
57 struct timer_list timer; 57 struct timer_list timer;
58}; 58};
@@ -133,6 +133,9 @@ static void tosakbd_scankeyboard(struct platform_device *dev)
133 133
134 spin_lock_irqsave(&tosakbd->lock, flags); 134 spin_lock_irqsave(&tosakbd->lock, flags);
135 135
136 if (tosakbd->suspended)
137 goto out;
138
136 for (col = 0; col < TOSA_KEY_STROBE_NUM; col++) { 139 for (col = 0; col < TOSA_KEY_STROBE_NUM; col++) {
137 /* 140 /*
138 * Discharge the output driver capacitatance 141 * Discharge the output driver capacitatance
@@ -174,6 +177,7 @@ static void tosakbd_scankeyboard(struct platform_device *dev)
174 if (num_pressed) 177 if (num_pressed)
175 mod_timer(&tosakbd->timer, jiffies + SCAN_INTERVAL); 178 mod_timer(&tosakbd->timer, jiffies + SCAN_INTERVAL);
176 179
180 out:
177 spin_unlock_irqrestore(&tosakbd->lock, flags); 181 spin_unlock_irqrestore(&tosakbd->lock, flags);
178} 182}
179 183
@@ -200,6 +204,7 @@ static irqreturn_t tosakbd_interrupt(int irq, void *__dev)
200static void tosakbd_timer_callback(unsigned long __dev) 204static void tosakbd_timer_callback(unsigned long __dev)
201{ 205{
202 struct platform_device *dev = (struct platform_device *)__dev; 206 struct platform_device *dev = (struct platform_device *)__dev;
207
203 tosakbd_scankeyboard(dev); 208 tosakbd_scankeyboard(dev);
204} 209}
205 210
@@ -207,6 +212,13 @@ static void tosakbd_timer_callback(unsigned long __dev)
207static int tosakbd_suspend(struct platform_device *dev, pm_message_t state) 212static int tosakbd_suspend(struct platform_device *dev, pm_message_t state)
208{ 213{
209 struct tosakbd *tosakbd = platform_get_drvdata(dev); 214 struct tosakbd *tosakbd = platform_get_drvdata(dev);
215 unsigned long flags;
216
217 spin_lock_irqsave(&tosakbd->lock, flags);
218 PGSR1 = (PGSR1 & ~TOSA_GPIO_LOW_STROBE_BIT);
219 PGSR2 = (PGSR2 & ~TOSA_GPIO_HIGH_STROBE_BIT);
220 tosakbd->suspended = 1;
221 spin_unlock_irqrestore(&tosakbd->lock, flags);
210 222
211 del_timer_sync(&tosakbd->timer); 223 del_timer_sync(&tosakbd->timer);
212 224
@@ -215,6 +227,9 @@ static int tosakbd_suspend(struct platform_device *dev, pm_message_t state)
215 227
216static int tosakbd_resume(struct platform_device *dev) 228static int tosakbd_resume(struct platform_device *dev)
217{ 229{
230 struct tosakbd *tosakbd = platform_get_drvdata(dev);
231
232 tosakbd->suspended = 0;
218 tosakbd_scankeyboard(dev); 233 tosakbd_scankeyboard(dev);
219 234
220 return 0; 235 return 0;
@@ -365,8 +380,8 @@ fail:
365 return error; 380 return error;
366} 381}
367 382
368static int __devexit tosakbd_remove(struct platform_device *dev) { 383static int __devexit tosakbd_remove(struct platform_device *dev)
369 384{
370 int i; 385 int i;
371 struct tosakbd *tosakbd = platform_get_drvdata(dev); 386 struct tosakbd *tosakbd = platform_get_drvdata(dev);
372 387
@@ -394,6 +409,7 @@ static struct platform_driver tosakbd_driver = {
394 .resume = tosakbd_resume, 409 .resume = tosakbd_resume,
395 .driver = { 410 .driver = {
396 .name = "tosa-keyboard", 411 .name = "tosa-keyboard",
412 .owner = THIS_MODULE,
397 }, 413 },
398}; 414};
399 415
@@ -413,3 +429,4 @@ module_exit(tosakbd_exit);
413MODULE_AUTHOR("Dirk Opfer <Dirk@Opfer-Online.de>"); 429MODULE_AUTHOR("Dirk Opfer <Dirk@Opfer-Online.de>");
414MODULE_DESCRIPTION("Tosa Keyboard Driver"); 430MODULE_DESCRIPTION("Tosa Keyboard Driver");
415MODULE_LICENSE("GPL v2"); 431MODULE_LICENSE("GPL v2");
432MODULE_ALIAS("platform:tosa-keyboard");
diff --git a/drivers/input/misc/cobalt_btns.c b/drivers/input/misc/cobalt_btns.c
index 5511ef006a66..6a1f48b76e32 100644
--- a/drivers/input/misc/cobalt_btns.c
+++ b/drivers/input/misc/cobalt_btns.c
@@ -148,6 +148,9 @@ static int __devexit cobalt_buttons_remove(struct platform_device *pdev)
148 return 0; 148 return 0;
149} 149}
150 150
151/* work with hotplug and coldplug */
152MODULE_ALIAS("platform:Cobalt buttons");
153
151static struct platform_driver cobalt_buttons_driver = { 154static struct platform_driver cobalt_buttons_driver = {
152 .probe = cobalt_buttons_probe, 155 .probe = cobalt_buttons_probe,
153 .remove = __devexit_p(cobalt_buttons_remove), 156 .remove = __devexit_p(cobalt_buttons_remove),
diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
index 0936d6ba015c..339290184871 100644
--- a/drivers/input/mouse/gpio_mouse.c
+++ b/drivers/input/mouse/gpio_mouse.c
@@ -171,10 +171,14 @@ static int __devexit gpio_mouse_remove(struct platform_device *pdev)
171 return 0; 171 return 0;
172} 172}
173 173
174/* work with hotplug and coldplug */
175MODULE_ALIAS("platform:gpio_mouse");
176
174struct platform_driver gpio_mouse_device_driver = { 177struct platform_driver gpio_mouse_device_driver = {
175 .remove = __devexit_p(gpio_mouse_remove), 178 .remove = __devexit_p(gpio_mouse_remove),
176 .driver = { 179 .driver = {
177 .name = "gpio_mouse", 180 .name = "gpio_mouse",
181 .owner = THIS_MODULE,
178 } 182 }
179}; 183};
180 184
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index b88569e21d60..ec4b6610f730 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -88,6 +88,16 @@ config SERIO_RPCKBD
88 To compile this driver as a module, choose M here: the 88 To compile this driver as a module, choose M here: the
89 module will be called rpckbd. 89 module will be called rpckbd.
90 90
91config SERIO_AT32PSIF
92 tristate "AVR32 PSIF PS/2 keyboard and mouse controller"
93 depends on AVR32
94 help
95 Say Y here if you want to use the PSIF peripheral on AVR32 devices
96 and connect a PS/2 keyboard and/or mouse to it.
97
98 To compile this driver as a module, choose M here: the module will
99 be called at32psif.
100
91config SERIO_AMBAKMI 101config SERIO_AMBAKMI
92 tristate "AMBA KMI keyboard controller" 102 tristate "AMBA KMI keyboard controller"
93 depends on ARM_AMBA 103 depends on ARM_AMBA
diff --git a/drivers/input/serio/Makefile b/drivers/input/serio/Makefile
index 4155197867a3..38b886887cbc 100644
--- a/drivers/input/serio/Makefile
+++ b/drivers/input/serio/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_SERIO_CT82C710) += ct82c710.o
12obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o 12obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o
13obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o 13obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o
14obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o 14obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o
15obj-$(CONFIG_SERIO_AT32PSIF) += at32psif.o
15obj-$(CONFIG_SERIO_Q40KBD) += q40kbd.o 16obj-$(CONFIG_SERIO_Q40KBD) += q40kbd.o
16obj-$(CONFIG_SERIO_GSCPS2) += gscps2.o 17obj-$(CONFIG_SERIO_GSCPS2) += gscps2.o
17obj-$(CONFIG_HP_SDC) += hp_sdc.o 18obj-$(CONFIG_HP_SDC) += hp_sdc.o
diff --git a/drivers/input/serio/at32psif.c b/drivers/input/serio/at32psif.c
new file mode 100644
index 000000000000..41fda8c67b1e
--- /dev/null
+++ b/drivers/input/serio/at32psif.c
@@ -0,0 +1,375 @@
1/*
2 * Copyright (C) 2007 Atmel Corporation
3 *
4 * Driver for the AT32AP700X PS/2 controller (PSIF).
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/device.h>
13#include <linux/init.h>
14#include <linux/serio.h>
15#include <linux/interrupt.h>
16#include <linux/delay.h>
17#include <linux/err.h>
18#include <linux/io.h>
19#include <linux/clk.h>
20#include <linux/platform_device.h>
21
22/* PSIF register offsets */
23#define PSIF_CR 0x00
24#define PSIF_RHR 0x04
25#define PSIF_THR 0x08
26#define PSIF_SR 0x10
27#define PSIF_IER 0x14
28#define PSIF_IDR 0x18
29#define PSIF_IMR 0x1c
30#define PSIF_PSR 0x24
31
32/* Bitfields in control register. */
33#define PSIF_CR_RXDIS_OFFSET 1
34#define PSIF_CR_RXDIS_SIZE 1
35#define PSIF_CR_RXEN_OFFSET 0
36#define PSIF_CR_RXEN_SIZE 1
37#define PSIF_CR_SWRST_OFFSET 15
38#define PSIF_CR_SWRST_SIZE 1
39#define PSIF_CR_TXDIS_OFFSET 9
40#define PSIF_CR_TXDIS_SIZE 1
41#define PSIF_CR_TXEN_OFFSET 8
42#define PSIF_CR_TXEN_SIZE 1
43
44/* Bitfields in interrupt disable, enable, mask and status register. */
45#define PSIF_NACK_OFFSET 8
46#define PSIF_NACK_SIZE 1
47#define PSIF_OVRUN_OFFSET 5
48#define PSIF_OVRUN_SIZE 1
49#define PSIF_PARITY_OFFSET 9
50#define PSIF_PARITY_SIZE 1
51#define PSIF_RXRDY_OFFSET 4
52#define PSIF_RXRDY_SIZE 1
53#define PSIF_TXEMPTY_OFFSET 1
54#define PSIF_TXEMPTY_SIZE 1
55#define PSIF_TXRDY_OFFSET 0
56#define PSIF_TXRDY_SIZE 1
57
58/* Bitfields in prescale register. */
59#define PSIF_PSR_PRSCV_OFFSET 0
60#define PSIF_PSR_PRSCV_SIZE 12
61
62/* Bitfields in receive hold register. */
63#define PSIF_RHR_RXDATA_OFFSET 0
64#define PSIF_RHR_RXDATA_SIZE 8
65
66/* Bitfields in transmit hold register. */
67#define PSIF_THR_TXDATA_OFFSET 0
68#define PSIF_THR_TXDATA_SIZE 8
69
70/* Bit manipulation macros */
71#define PSIF_BIT(name) \
72 (1 << PSIF_##name##_OFFSET)
73
74#define PSIF_BF(name, value) \
75 (((value) & ((1 << PSIF_##name##_SIZE) - 1)) \
76 << PSIF_##name##_OFFSET)
77
78#define PSIF_BFEXT(name, value) \
79 (((value) >> PSIF_##name##_OFFSET) \
80 & ((1 << PSIF_##name##_SIZE) - 1))
81
82#define PSIF_BFINS(name, value, old) \
83 (((old) & ~(((1 << PSIF_##name##_SIZE) - 1) \
84 << PSIF_##name##_OFFSET)) \
85 | PSIF_BF(name, value))
86
87/* Register access macros */
88#define psif_readl(port, reg) \
89 __raw_readl((port)->regs + PSIF_##reg)
90
91#define psif_writel(port, reg, value) \
92 __raw_writel((value), (port)->regs + PSIF_##reg)
93
94struct psif {
95 struct platform_device *pdev;
96 struct clk *pclk;
97 struct serio *io;
98 void __iomem *regs;
99 unsigned int irq;
100 unsigned int open;
101 /* Prevent concurrent writes to PSIF THR. */
102 spinlock_t lock;
103};
104
105static irqreturn_t psif_interrupt(int irq, void *_ptr)
106{
107 struct psif *psif = _ptr;
108 int retval = IRQ_NONE;
109 unsigned int io_flags = 0;
110 unsigned long status;
111
112 status = psif_readl(psif, SR);
113
114 if (status & PSIF_BIT(RXRDY)) {
115 unsigned char val = (unsigned char) psif_readl(psif, RHR);
116
117 if (status & PSIF_BIT(PARITY))
118 io_flags |= SERIO_PARITY;
119 if (status & PSIF_BIT(OVRUN))
120 dev_err(&psif->pdev->dev, "overrun read error\n");
121
122 serio_interrupt(psif->io, val, io_flags);
123
124 retval = IRQ_HANDLED;
125 }
126
127 return retval;
128}
129
130static int psif_write(struct serio *io, unsigned char val)
131{
132 struct psif *psif = io->port_data;
133 unsigned long flags;
134 int timeout = 10;
135 int retval = 0;
136
137 spin_lock_irqsave(&psif->lock, flags);
138
139 while (!(psif_readl(psif, SR) & PSIF_BIT(TXEMPTY)) && timeout--)
140 msleep(10);
141
142 if (timeout >= 0) {
143 psif_writel(psif, THR, val);
144 } else {
145 dev_dbg(&psif->pdev->dev, "timeout writing to THR\n");
146 retval = -EBUSY;
147 }
148
149 spin_unlock_irqrestore(&psif->lock, flags);
150
151 return retval;
152}
153
154static int psif_open(struct serio *io)
155{
156 struct psif *psif = io->port_data;
157 int retval;
158
159 retval = clk_enable(psif->pclk);
160 if (retval)
161 goto out;
162
163 psif_writel(psif, CR, PSIF_BIT(CR_TXEN) | PSIF_BIT(CR_RXEN));
164 psif_writel(psif, IER, PSIF_BIT(RXRDY));
165
166 psif->open = 1;
167out:
168 return retval;
169}
170
171static void psif_close(struct serio *io)
172{
173 struct psif *psif = io->port_data;
174
175 psif->open = 0;
176
177 psif_writel(psif, IDR, ~0UL);
178 psif_writel(psif, CR, PSIF_BIT(CR_TXDIS) | PSIF_BIT(CR_RXDIS));
179
180 clk_disable(psif->pclk);
181}
182
183static void psif_set_prescaler(struct psif *psif)
184{
185 unsigned long prscv;
186 unsigned long rate = clk_get_rate(psif->pclk);
187
188 /* PRSCV = Pulse length (100 us) * PSIF module frequency. */
189 prscv = 100 * (rate / 1000000UL);
190
191 if (prscv > ((1<<PSIF_PSR_PRSCV_SIZE) - 1)) {
192 prscv = (1<<PSIF_PSR_PRSCV_SIZE) - 1;
193 dev_dbg(&psif->pdev->dev, "pclk too fast, "
194 "prescaler set to max\n");
195 }
196
197 clk_enable(psif->pclk);
198 psif_writel(psif, PSR, prscv);
199 clk_disable(psif->pclk);
200}
201
202static int __init psif_probe(struct platform_device *pdev)
203{
204 struct resource *regs;
205 struct psif *psif;
206 struct serio *io;
207 struct clk *pclk;
208 int irq;
209 int ret;
210
211 psif = kzalloc(sizeof(struct psif), GFP_KERNEL);
212 if (!psif) {
213 dev_dbg(&pdev->dev, "out of memory\n");
214 ret = -ENOMEM;
215 goto out;
216 }
217 psif->pdev = pdev;
218
219 io = kzalloc(sizeof(struct serio), GFP_KERNEL);
220 if (!io) {
221 dev_dbg(&pdev->dev, "out of memory\n");
222 ret = -ENOMEM;
223 goto out_free_psif;
224 }
225 psif->io = io;
226
227 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
228 if (!regs) {
229 dev_dbg(&pdev->dev, "no mmio resources defined\n");
230 ret = -ENOMEM;
231 goto out_free_io;
232 }
233
234 psif->regs = ioremap(regs->start, regs->end - regs->start + 1);
235 if (!psif->regs) {
236 ret = -ENOMEM;
237 dev_dbg(&pdev->dev, "could not map I/O memory\n");
238 goto out_free_io;
239 }
240
241 pclk = clk_get(&pdev->dev, "pclk");
242 if (IS_ERR(pclk)) {
243 dev_dbg(&pdev->dev, "could not get peripheral clock\n");
244 ret = PTR_ERR(pclk);
245 goto out_iounmap;
246 }
247 psif->pclk = pclk;
248
249 /* Reset the PSIF to enter at a known state. */
250 ret = clk_enable(pclk);
251 if (ret) {
252 dev_dbg(&pdev->dev, "could not enable pclk\n");
253 goto out_put_clk;
254 }
255 psif_writel(psif, CR, PSIF_BIT(CR_SWRST));
256 clk_disable(pclk);
257
258 irq = platform_get_irq(pdev, 0);
259 if (irq < 0) {
260 dev_dbg(&pdev->dev, "could not get irq\n");
261 ret = -ENXIO;
262 goto out_put_clk;
263 }
264 ret = request_irq(irq, psif_interrupt, IRQF_SHARED, "at32psif", psif);
265 if (ret) {
266 dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
267 goto out_put_clk;
268 }
269 psif->irq = irq;
270
271 io->id.type = SERIO_8042;
272 io->write = psif_write;
273 io->open = psif_open;
274 io->close = psif_close;
275 snprintf(io->name, sizeof(io->name), "AVR32 PS/2 port%d", pdev->id);
276 snprintf(io->phys, sizeof(io->phys), "at32psif/serio%d", pdev->id);
277 io->port_data = psif;
278 io->dev.parent = &pdev->dev;
279
280 psif_set_prescaler(psif);
281
282 spin_lock_init(&psif->lock);
283 serio_register_port(psif->io);
284 platform_set_drvdata(pdev, psif);
285
286 dev_info(&pdev->dev, "Atmel AVR32 PSIF PS/2 driver on 0x%08x irq %d\n",
287 (int)psif->regs, psif->irq);
288
289 return 0;
290
291out_put_clk:
292 clk_put(psif->pclk);
293out_iounmap:
294 iounmap(psif->regs);
295out_free_io:
296 kfree(io);
297out_free_psif:
298 kfree(psif);
299out:
300 return ret;
301}
302
303static int __exit psif_remove(struct platform_device *pdev)
304{
305 struct psif *psif = platform_get_drvdata(pdev);
306
307 psif_writel(psif, IDR, ~0UL);
308 psif_writel(psif, CR, PSIF_BIT(CR_TXDIS) | PSIF_BIT(CR_RXDIS));
309
310 serio_unregister_port(psif->io);
311 iounmap(psif->regs);
312 free_irq(psif->irq, psif);
313 clk_put(psif->pclk);
314 kfree(psif);
315
316 platform_set_drvdata(pdev, NULL);
317
318 return 0;
319}
320
321#ifdef CONFIG_PM
322static int psif_suspend(struct platform_device *pdev, pm_message_t state)
323{
324 struct psif *psif = platform_get_drvdata(pdev);
325
326 if (psif->open) {
327 psif_writel(psif, CR, PSIF_BIT(CR_RXDIS) | PSIF_BIT(CR_TXDIS));
328 clk_disable(psif->pclk);
329 }
330
331 return 0;
332}
333
334static int psif_resume(struct platform_device *pdev)
335{
336 struct psif *psif = platform_get_drvdata(pdev);
337
338 if (psif->open) {
339 clk_enable(psif->pclk);
340 psif_set_prescaler(psif);
341 psif_writel(psif, CR, PSIF_BIT(CR_RXEN) | PSIF_BIT(CR_TXEN));
342 }
343
344 return 0;
345}
346#else
347#define psif_suspend NULL
348#define psif_resume NULL
349#endif
350
351static struct platform_driver psif_driver = {
352 .remove = __exit_p(psif_remove),
353 .driver = {
354 .name = "atmel_psif",
355 },
356 .suspend = psif_suspend,
357 .resume = psif_resume,
358};
359
360static int __init psif_init(void)
361{
362 return platform_driver_probe(&psif_driver, psif_probe);
363}
364
365static void __exit psif_exit(void)
366{
367 platform_driver_unregister(&psif_driver);
368}
369
370module_init(psif_init);
371module_exit(psif_exit);
372
373MODULE_AUTHOR("Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>");
374MODULE_DESCRIPTION("Atmel AVR32 PSIF PS/2 driver");
375MODULE_LICENSE("GPL");
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 60931aceb828..5ece9f56babc 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -370,10 +370,10 @@ static int i8042_pnp_kbd_probe(struct pnp_dev *dev, const struct pnp_device_id *
370 if (pnp_irq_valid(dev,0)) 370 if (pnp_irq_valid(dev,0))
371 i8042_pnp_kbd_irq = pnp_irq(dev, 0); 371 i8042_pnp_kbd_irq = pnp_irq(dev, 0);
372 372
373 strncpy(i8042_pnp_kbd_name, did->id, sizeof(i8042_pnp_kbd_name)); 373 strlcpy(i8042_pnp_kbd_name, did->id, sizeof(i8042_pnp_kbd_name));
374 if (strlen(pnp_dev_name(dev))) { 374 if (strlen(pnp_dev_name(dev))) {
375 strncat(i8042_pnp_kbd_name, ":", sizeof(i8042_pnp_kbd_name)); 375 strlcat(i8042_pnp_kbd_name, ":", sizeof(i8042_pnp_kbd_name));
376 strncat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name)); 376 strlcat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name));
377 } 377 }
378 378
379 i8042_pnp_kbd_devices++; 379 i8042_pnp_kbd_devices++;
@@ -391,10 +391,10 @@ static int i8042_pnp_aux_probe(struct pnp_dev *dev, const struct pnp_device_id *
391 if (pnp_irq_valid(dev, 0)) 391 if (pnp_irq_valid(dev, 0))
392 i8042_pnp_aux_irq = pnp_irq(dev, 0); 392 i8042_pnp_aux_irq = pnp_irq(dev, 0);
393 393
394 strncpy(i8042_pnp_aux_name, did->id, sizeof(i8042_pnp_aux_name)); 394 strlcpy(i8042_pnp_aux_name, did->id, sizeof(i8042_pnp_aux_name));
395 if (strlen(pnp_dev_name(dev))) { 395 if (strlen(pnp_dev_name(dev))) {
396 strncat(i8042_pnp_aux_name, ":", sizeof(i8042_pnp_aux_name)); 396 strlcat(i8042_pnp_aux_name, ":", sizeof(i8042_pnp_aux_name));
397 strncat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name)); 397 strlcat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name));
398 } 398 }
399 399
400 i8042_pnp_aux_devices++; 400 i8042_pnp_aux_devices++;
diff --git a/drivers/input/serio/rpckbd.c b/drivers/input/serio/rpckbd.c
index 49f84315cb32..34c59d9c6205 100644
--- a/drivers/input/serio/rpckbd.c
+++ b/drivers/input/serio/rpckbd.c
@@ -45,6 +45,7 @@
45MODULE_AUTHOR("Vojtech Pavlik, Russell King"); 45MODULE_AUTHOR("Vojtech Pavlik, Russell King");
46MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver"); 46MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
47MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
48MODULE_ALIAS("platform:kart");
48 49
49static int rpckbd_write(struct serio *port, unsigned char val) 50static int rpckbd_write(struct serio *port, unsigned char val)
50{ 51{
@@ -140,6 +141,7 @@ static struct platform_driver rpckbd_driver = {
140 .remove = __devexit_p(rpckbd_remove), 141 .remove = __devexit_p(rpckbd_remove),
141 .driver = { 142 .driver = {
142 .name = "kart", 143 .name = "kart",
144 .owner = THIS_MODULE,
143 }, 145 },
144}; 146};
145 147
diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index d371c0bdc0bd..effb49ea24aa 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -25,14 +25,14 @@ config TABLET_USB_ACECAD
25 module will be called acecad. 25 module will be called acecad.
26 26
27config TABLET_USB_AIPTEK 27config TABLET_USB_AIPTEK
28 tristate "Aiptek 6000U/8000U tablet support (USB)" 28 tristate "Aiptek 6000U/8000U and Genius G_PEN tablet support (USB)"
29 depends on USB_ARCH_HAS_HCD 29 depends on USB_ARCH_HAS_HCD
30 select USB 30 select USB
31 help 31 help
32 Say Y here if you want to use the USB version of the Aiptek 6000U 32 Say Y here if you want to use the USB version of the Aiptek 6000U,
33 or Aiptek 8000U tablet. Make sure to say Y to "Mouse support" 33 Aiptek 8000U or Genius G-PEN 560 tablet. Make sure to say Y to
34 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support" 34 "Mouse support" (CONFIG_INPUT_MOUSEDEV) and/or "Event interface
35 (CONFIG_INPUT_EVDEV) as well. 35 support" (CONFIG_INPUT_EVDEV) as well.
36 36
37 To compile this driver as a module, choose M here: the 37 To compile this driver as a module, choose M here: the
38 module will be called aiptek. 38 module will be called aiptek.
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 94683f58c9e1..1d759f6f8076 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -184,6 +184,7 @@
184 */ 184 */
185 185
186#define USB_VENDOR_ID_AIPTEK 0x08ca 186#define USB_VENDOR_ID_AIPTEK 0x08ca
187#define USB_VENDOR_ID_KYE 0x0458
187#define USB_REQ_GET_REPORT 0x01 188#define USB_REQ_GET_REPORT 0x01
188#define USB_REQ_SET_REPORT 0x09 189#define USB_REQ_SET_REPORT 0x09
189 190
@@ -832,6 +833,7 @@ static const struct usb_device_id aiptek_ids[] = {
832 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)}, 833 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
833 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)}, 834 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
834 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)}, 835 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
836 {USB_DEVICE(USB_VENDOR_ID_KYE, 0x5003)},
835 {} 837 {}
836}; 838};
837 839
diff --git a/drivers/input/tablet/wacom.h b/drivers/input/tablet/wacom.h
index acf9830698cb..706619d06f71 100644
--- a/drivers/input/tablet/wacom.h
+++ b/drivers/input/tablet/wacom.h
@@ -101,8 +101,11 @@ struct wacom {
101 dma_addr_t data_dma; 101 dma_addr_t data_dma;
102 struct input_dev *dev; 102 struct input_dev *dev;
103 struct usb_device *usbdev; 103 struct usb_device *usbdev;
104 struct usb_interface *intf;
104 struct urb *irq; 105 struct urb *irq;
105 struct wacom_wac * wacom_wac; 106 struct wacom_wac * wacom_wac;
107 struct mutex lock;
108 int open:1;
106 char phys[32]; 109 char phys[32];
107}; 110};
108 111
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 41caaef8e2d7..71cc0c140790 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -70,6 +70,7 @@ static void wacom_sys_irq(struct urb *urb)
70 input_sync(get_input_dev(&wcombo)); 70 input_sync(get_input_dev(&wcombo));
71 71
72 exit: 72 exit:
73 usb_mark_last_busy(wacom->usbdev);
73 retval = usb_submit_urb (urb, GFP_ATOMIC); 74 retval = usb_submit_urb (urb, GFP_ATOMIC);
74 if (retval) 75 if (retval)
75 err ("%s - usb_submit_urb failed with result %d", 76 err ("%s - usb_submit_urb failed with result %d",
@@ -124,10 +125,25 @@ static int wacom_open(struct input_dev *dev)
124{ 125{
125 struct wacom *wacom = input_get_drvdata(dev); 126 struct wacom *wacom = input_get_drvdata(dev);
126 127
128 mutex_lock(&wacom->lock);
129
127 wacom->irq->dev = wacom->usbdev; 130 wacom->irq->dev = wacom->usbdev;
128 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) 131
132 if (usb_autopm_get_interface(wacom->intf) < 0) {
133 mutex_unlock(&wacom->lock);
129 return -EIO; 134 return -EIO;
135 }
136
137 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
138 usb_autopm_put_interface(wacom->intf);
139 mutex_unlock(&wacom->lock);
140 return -EIO;
141 }
142
143 wacom->open = 1;
144 wacom->intf->needs_remote_wakeup = 1;
130 145
146 mutex_unlock(&wacom->lock);
131 return 0; 147 return 0;
132} 148}
133 149
@@ -135,7 +151,11 @@ static void wacom_close(struct input_dev *dev)
135{ 151{
136 struct wacom *wacom = input_get_drvdata(dev); 152 struct wacom *wacom = input_get_drvdata(dev);
137 153
154 mutex_lock(&wacom->lock);
138 usb_kill_urb(wacom->irq); 155 usb_kill_urb(wacom->irq);
156 wacom->open = 0;
157 wacom->intf->needs_remote_wakeup = 0;
158 mutex_unlock(&wacom->lock);
139} 159}
140 160
141void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 161void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
@@ -243,6 +263,8 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
243 263
244 wacom->usbdev = dev; 264 wacom->usbdev = dev;
245 wacom->dev = input_dev; 265 wacom->dev = input_dev;
266 wacom->intf = intf;
267 mutex_init(&wacom->lock);
246 usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); 268 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
247 strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); 269 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
248 270
@@ -304,23 +326,57 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
304 326
305static void wacom_disconnect(struct usb_interface *intf) 327static void wacom_disconnect(struct usb_interface *intf)
306{ 328{
307 struct wacom *wacom = usb_get_intfdata (intf); 329 struct wacom *wacom = usb_get_intfdata(intf);
308 330
309 usb_set_intfdata(intf, NULL); 331 usb_set_intfdata(intf, NULL);
310 if (wacom) { 332
311 usb_kill_urb(wacom->irq); 333 usb_kill_urb(wacom->irq);
312 input_unregister_device(wacom->dev); 334 input_unregister_device(wacom->dev);
313 usb_free_urb(wacom->irq); 335 usb_free_urb(wacom->irq);
314 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->wacom_wac->data, wacom->data_dma); 336 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->wacom_wac->data, wacom->data_dma);
315 kfree(wacom->wacom_wac); 337 kfree(wacom->wacom_wac);
316 kfree(wacom); 338 kfree(wacom);
317 } 339}
340
341static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
342{
343 struct wacom *wacom = usb_get_intfdata(intf);
344
345 mutex_lock(&wacom->lock);
346 usb_kill_urb(wacom->irq);
347 mutex_unlock(&wacom->lock);
348
349 return 0;
350}
351
352static int wacom_resume(struct usb_interface *intf)
353{
354 struct wacom *wacom = usb_get_intfdata(intf);
355 int rv;
356
357 mutex_lock(&wacom->lock);
358 if (wacom->open)
359 rv = usb_submit_urb(wacom->irq, GFP_NOIO);
360 else
361 rv = 0;
362 mutex_unlock(&wacom->lock);
363
364 return rv;
365}
366
367static int wacom_reset_resume(struct usb_interface *intf)
368{
369 return wacom_resume(intf);
318} 370}
319 371
320static struct usb_driver wacom_driver = { 372static struct usb_driver wacom_driver = {
321 .name = "wacom", 373 .name = "wacom",
322 .probe = wacom_probe, 374 .probe = wacom_probe,
323 .disconnect = wacom_disconnect, 375 .disconnect = wacom_disconnect,
376 .suspend = wacom_suspend,
377 .resume = wacom_resume,
378 .reset_resume = wacom_reset_resume,
379 .supports_autosuspend = 1,
324}; 380};
325 381
326static int __init wacom_init(void) 382static int __init wacom_init(void)
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index ffe33842143f..192513e1f04c 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -649,6 +649,7 @@ static struct wacom_features wacom_features[] = {
649 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, 649 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 },
650 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S }, 650 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S },
651 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, 651 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ },
652 { "Wacom Cintiq 20WSX", 10, 86680, 54180, 1023, 63, WACOM_BEE },
652 { "Wacom Cintiq 12WX", 10, 53020, 33440, 1023, 63, WACOM_BEE }, 653 { "Wacom Cintiq 12WX", 10, 53020, 33440, 1023, 63, WACOM_BEE },
653 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS }, 654 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
654 { } 655 { }
@@ -702,6 +703,7 @@ static struct usb_device_id wacom_ids[] = {
702 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) }, 703 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
703 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) }, 704 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) },
704 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) }, 705 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
706 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC5) },
705 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC6) }, 707 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC6) },
706 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) }, 708 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
707 { } 709 { }
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 90e8e92dfe47..565ec711c2ee 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -185,6 +185,59 @@ config TOUCHSCREEN_UCB1400
185 To compile this driver as a module, choose M here: the 185 To compile this driver as a module, choose M here: the
186 module will be called ucb1400_ts. 186 module will be called ucb1400_ts.
187 187
188config TOUCHSCREEN_WM97XX
189 tristate "Support for WM97xx AC97 touchscreen controllers"
190 depends on AC97_BUS
191 help
192 Say Y here if you have a Wolfson Microelectronics WM97xx
193 touchscreen connected to your system. Note that this option
194 only enables core driver, you will also need to select
195 support for appropriate chip below.
196
197 If unsure, say N.
198
199 To compile this driver as a module, choose M here: the
200 module will be called wm97xx-ts.
201
202config TOUCHSCREEN_WM9705
203 bool "WM9705 Touchscreen interface support"
204 depends on TOUCHSCREEN_WM97XX
205 help
206 Say Y here if you have a Wolfson Microelectronics WM9705
207 touchscreen controller connected to your system.
208
209 If unsure, say N.
210
211config TOUCHSCREEN_WM9712
212 bool "WM9712 Touchscreen interface support"
213 depends on TOUCHSCREEN_WM97XX
214 help
215 Say Y here if you have a Wolfson Microelectronics WM9712
216 touchscreen controller connected to your system.
217
218 If unsure, say N.
219
220config TOUCHSCREEN_WM9713
221 bool "WM9713 Touchscreen interface support"
222 depends on TOUCHSCREEN_WM97XX
223 help
224 Say Y here if you have a Wolfson Microelectronics WM9713 touchscreen
225 controller connected to your system.
226
227 If unsure, say N.
228
229config TOUCHSCREEN_WM97XX_MAINSTONE
230 tristate "WM97xx Mainstone accelerated touch"
231 depends on TOUCHSCREEN_WM97XX && ARCH_PXA
232 help
233 Say Y here for support for streaming mode with WM97xx touchscreens
234 on Mainstone systems.
235
236 If unsure, say N.
237
238 To compile this driver as a module, choose M here: the
239 module will be called mainstone-wm97xx.
240
188config TOUCHSCREEN_USB_COMPOSITE 241config TOUCHSCREEN_USB_COMPOSITE
189 tristate "USB Touchscreen Driver" 242 tristate "USB Touchscreen Driver"
190 depends on USB_ARCH_HAS_HCD 243 depends on USB_ARCH_HAS_HCD
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 35d4097df35a..3c096d75651d 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -4,6 +4,8 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7wm97xx-ts-y := wm97xx-core.o
8
7obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o 9obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o
8obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o 10obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
9obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o 11obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
@@ -19,3 +21,8 @@ obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
19obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 21obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
20obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 22obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
21obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o 23obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
24obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o
25wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o
26wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o
27wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713) += wm9713.o
28obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 39573b91c8de..907a45fe9d40 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -80,6 +80,7 @@ struct ads7846 {
80#endif 80#endif
81 81
82 u16 model; 82 u16 model;
83 u16 vref_mv;
83 u16 vref_delay_usecs; 84 u16 vref_delay_usecs;
84 u16 x_plate_ohms; 85 u16 x_plate_ohms;
85 u16 pressure_max; 86 u16 pressure_max;
@@ -177,9 +178,6 @@ struct ads7846 {
177 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF; 178 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
178 * ads7846 lets that pin be unconnected, to use internal vREF. 179 * ads7846 lets that pin be unconnected, to use internal vREF.
179 */ 180 */
180static unsigned vREF_mV;
181module_param(vREF_mV, uint, 0);
182MODULE_PARM_DESC(vREF_mV, "external vREF voltage, in milliVolts");
183 181
184struct ser_req { 182struct ser_req {
185 u8 ref_on; 183 u8 ref_on;
@@ -206,7 +204,6 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
206 struct ads7846 *ts = dev_get_drvdata(dev); 204 struct ads7846 *ts = dev_get_drvdata(dev);
207 struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL); 205 struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL);
208 int status; 206 int status;
209 int uninitialized_var(sample);
210 int use_internal; 207 int use_internal;
211 208
212 if (!req) 209 if (!req)
@@ -263,13 +260,13 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
263 260
264 if (status == 0) { 261 if (status == 0) {
265 /* on-wire is a must-ignore bit, a BE12 value, then padding */ 262 /* on-wire is a must-ignore bit, a BE12 value, then padding */
266 sample = be16_to_cpu(req->sample); 263 status = be16_to_cpu(req->sample);
267 sample = sample >> 3; 264 status = status >> 3;
268 sample &= 0x0fff; 265 status &= 0x0fff;
269 } 266 }
270 267
271 kfree(req); 268 kfree(req);
272 return status ? status : sample; 269 return status;
273} 270}
274 271
275#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) 272#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
@@ -310,7 +307,7 @@ static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v)
310 unsigned retval = v; 307 unsigned retval = v;
311 308
312 /* external resistors may scale vAUX into 0..vREF */ 309 /* external resistors may scale vAUX into 0..vREF */
313 retval *= vREF_mV; 310 retval *= ts->vref_mv;
314 retval = retval >> 12; 311 retval = retval >> 12;
315 return retval; 312 return retval;
316} 313}
@@ -368,14 +365,14 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
368 /* hwmon sensors need a reference voltage */ 365 /* hwmon sensors need a reference voltage */
369 switch (ts->model) { 366 switch (ts->model) {
370 case 7846: 367 case 7846:
371 if (!vREF_mV) { 368 if (!ts->vref_mv) {
372 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); 369 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n");
373 vREF_mV = 2500; 370 ts->vref_mv = 2500;
374 } 371 }
375 break; 372 break;
376 case 7845: 373 case 7845:
377 case 7843: 374 case 7843:
378 if (!vREF_mV) { 375 if (!ts->vref_mv) {
379 dev_warn(&spi->dev, 376 dev_warn(&spi->dev,
380 "external vREF for ADS%d not specified\n", 377 "external vREF for ADS%d not specified\n",
381 ts->model); 378 ts->model);
@@ -868,6 +865,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
868 865
869 ts->spi = spi; 866 ts->spi = spi;
870 ts->input = input_dev; 867 ts->input = input_dev;
868 ts->vref_mv = pdata->vref_mv;
871 869
872 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 870 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
873 ts->timer.function = ads7846_timer; 871 ts->timer.function = ads7846_timer;
diff --git a/drivers/input/touchscreen/corgi_ts.c b/drivers/input/touchscreen/corgi_ts.c
index a22576779acd..4e9d8eece2e0 100644
--- a/drivers/input/touchscreen/corgi_ts.c
+++ b/drivers/input/touchscreen/corgi_ts.c
@@ -362,6 +362,7 @@ static struct platform_driver corgits_driver = {
362 .resume = corgits_resume, 362 .resume = corgits_resume,
363 .driver = { 363 .driver = {
364 .name = "corgi-ts", 364 .name = "corgi-ts",
365 .owner = THIS_MODULE,
365 }, 366 },
366}; 367};
367 368
@@ -381,3 +382,4 @@ module_exit(corgits_exit);
381MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); 382MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
382MODULE_DESCRIPTION("Corgi TouchScreen Driver"); 383MODULE_DESCRIPTION("Corgi TouchScreen Driver");
383MODULE_LICENSE("GPL"); 384MODULE_LICENSE("GPL");
385MODULE_ALIAS("platform:corgi-ts");
diff --git a/drivers/input/touchscreen/jornada720_ts.c b/drivers/input/touchscreen/jornada720_ts.c
index 42a1c9a1940e..742242111bf1 100644
--- a/drivers/input/touchscreen/jornada720_ts.c
+++ b/drivers/input/touchscreen/jornada720_ts.c
@@ -160,11 +160,15 @@ static int __devexit jornada720_ts_remove(struct platform_device *pdev)
160 return 0; 160 return 0;
161} 161}
162 162
163/* work with hotplug and coldplug */
164MODULE_ALIAS("platform:jornada_ts");
165
163static struct platform_driver jornada720_ts_driver = { 166static struct platform_driver jornada720_ts_driver = {
164 .probe = jornada720_ts_probe, 167 .probe = jornada720_ts_probe,
165 .remove = __devexit_p(jornada720_ts_remove), 168 .remove = __devexit_p(jornada720_ts_remove),
166 .driver = { 169 .driver = {
167 .name = "jornada_ts", 170 .name = "jornada_ts",
171 .owner = THIS_MODULE,
168 }, 172 },
169}; 173};
170 174
diff --git a/drivers/input/touchscreen/mainstone-wm97xx.c b/drivers/input/touchscreen/mainstone-wm97xx.c
new file mode 100644
index 000000000000..a79f029b91c0
--- /dev/null
+++ b/drivers/input/touchscreen/mainstone-wm97xx.c
@@ -0,0 +1,302 @@
1/*
2 * mainstone-wm97xx.c -- Mainstone Continuous Touch screen driver for
3 * Wolfson WM97xx AC97 Codecs.
4 *
5 * Copyright 2004, 2007 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * Notes:
17 * This is a wm97xx extended touch driver to capture touch
18 * data in a continuous manner on the Intel XScale archictecture
19 *
20 * Features:
21 * - codecs supported:- WM9705, WM9712, WM9713
22 * - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x
23 *
24 */
25
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/version.h>
29#include <linux/kernel.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <linux/irq.h>
33#include <linux/interrupt.h>
34#include <linux/wm97xx.h>
35#include <linux/io.h>
36#include <asm/arch/pxa-regs.h>
37
38#define VERSION "0.13"
39
40struct continuous {
41 u16 id; /* codec id */
42 u8 code; /* continuous code */
43 u8 reads; /* number of coord reads per read cycle */
44 u32 speed; /* number of coords per second */
45};
46
47#define WM_READS(sp) ((sp / HZ) + 1)
48
49static const struct continuous cinfo[] = {
50 {WM9705_ID2, 0, WM_READS(94), 94},
51 {WM9705_ID2, 1, WM_READS(188), 188},
52 {WM9705_ID2, 2, WM_READS(375), 375},
53 {WM9705_ID2, 3, WM_READS(750), 750},
54 {WM9712_ID2, 0, WM_READS(94), 94},
55 {WM9712_ID2, 1, WM_READS(188), 188},
56 {WM9712_ID2, 2, WM_READS(375), 375},
57 {WM9712_ID2, 3, WM_READS(750), 750},
58 {WM9713_ID2, 0, WM_READS(94), 94},
59 {WM9713_ID2, 1, WM_READS(120), 120},
60 {WM9713_ID2, 2, WM_READS(154), 154},
61 {WM9713_ID2, 3, WM_READS(188), 188},
62};
63
64/* continuous speed index */
65static int sp_idx;
66static u16 last, tries;
67
68/*
69 * Pen sampling frequency (Hz) in continuous mode.
70 */
71static int cont_rate = 200;
72module_param(cont_rate, int, 0);
73MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
74
75/*
76 * Pen down detection.
77 *
78 * This driver can either poll or use an interrupt to indicate a pen down
79 * event. If the irq request fails then it will fall back to polling mode.
80 */
81static int pen_int;
82module_param(pen_int, int, 0);
83MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)");
84
85/*
86 * Pressure readback.
87 *
88 * Set to 1 to read back pen down pressure
89 */
90static int pressure;
91module_param(pressure, int, 0);
92MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)");
93
94/*
95 * AC97 touch data slot.
96 *
97 * Touch screen readback data ac97 slot
98 */
99static int ac97_touch_slot = 5;
100module_param(ac97_touch_slot, int, 0);
101MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");
102
103
104/* flush AC97 slot 5 FIFO on pxa machines */
105#ifdef CONFIG_PXA27x
106static void wm97xx_acc_pen_up(struct wm97xx *wm)
107{
108 schedule_timeout_uninterruptible(1);
109
110 while (MISR & (1 << 2))
111 MODR;
112}
113#else
114static void wm97xx_acc_pen_up(struct wm97xx *wm)
115{
116 int count = 16;
117 schedule_timeout_uninterruptible(1);
118
119 while (count < 16) {
120 MODR;
121 count--;
122 }
123}
124#endif
125
126static int wm97xx_acc_pen_down(struct wm97xx *wm)
127{
128 u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
129 int reads = 0;
130
131 /* When the AC97 queue has been drained we need to allow time
132 * to buffer up samples otherwise we end up spinning polling
133 * for samples. The controller can't have a suitably low
134 * threashold set to use the notifications it gives.
135 */
136 schedule_timeout_uninterruptible(1);
137
138 if (tries > 5) {
139 tries = 0;
140 return RC_PENUP;
141 }
142
143 x = MODR;
144 if (x == last) {
145 tries++;
146 return RC_AGAIN;
147 }
148 last = x;
149 do {
150 if (reads)
151 x = MODR;
152 y = MODR;
153 if (pressure)
154 p = MODR;
155
156 /* are samples valid */
157 if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X ||
158 (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y ||
159 (p & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_PRES)
160 goto up;
161
162 /* coordinate is good */
163 tries = 0;
164 input_report_abs(wm->input_dev, ABS_X, x & 0xfff);
165 input_report_abs(wm->input_dev, ABS_Y, y & 0xfff);
166 input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff);
167 input_sync(wm->input_dev);
168 reads++;
169 } while (reads < cinfo[sp_idx].reads);
170up:
171 return RC_PENDOWN | RC_AGAIN;
172}
173
174static int wm97xx_acc_startup(struct wm97xx *wm)
175{
176 int idx = 0;
177
178 /* check we have a codec */
179 if (wm->ac97 == NULL)
180 return -ENODEV;
181
182 /* Go you big red fire engine */
183 for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) {
184 if (wm->id != cinfo[idx].id)
185 continue;
186 sp_idx = idx;
187 if (cont_rate <= cinfo[idx].speed)
188 break;
189 }
190 wm->acc_rate = cinfo[sp_idx].code;
191 wm->acc_slot = ac97_touch_slot;
192 dev_info(wm->dev,
193 "mainstone accelerated touchscreen driver, %d samples/sec\n",
194 cinfo[sp_idx].speed);
195
196 /* codec specific irq config */
197 if (pen_int) {
198 switch (wm->id) {
199 case WM9705_ID2:
200 wm->pen_irq = IRQ_GPIO(4);
201 set_irq_type(IRQ_GPIO(4), IRQT_BOTHEDGE);
202 break;
203 case WM9712_ID2:
204 case WM9713_ID2:
205 /* enable pen down interrupt */
206 /* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */
207 wm->pen_irq = MAINSTONE_AC97_IRQ;
208 wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
209 WM97XX_GPIO_POL_HIGH,
210 WM97XX_GPIO_STICKY,
211 WM97XX_GPIO_WAKE);
212 wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT,
213 WM97XX_GPIO_POL_HIGH,
214 WM97XX_GPIO_NOTSTICKY,
215 WM97XX_GPIO_NOWAKE);
216 break;
217 default:
218 dev_err(wm->dev,
219 "pen down irq not supported on this device\n");
220 pen_int = 0;
221 break;
222 }
223 }
224
225 return 0;
226}
227
228static void wm97xx_acc_shutdown(struct wm97xx *wm)
229{
230 /* codec specific deconfig */
231 if (pen_int) {
232 switch (wm->id & 0xffff) {
233 case WM9705_ID2:
234 wm->pen_irq = 0;
235 break;
236 case WM9712_ID2:
237 case WM9713_ID2:
238 /* disable interrupt */
239 wm->pen_irq = 0;
240 break;
241 }
242 }
243}
244
245static void wm97xx_irq_enable(struct wm97xx *wm, int enable)
246{
247 if (enable)
248 enable_irq(wm->pen_irq);
249 else
250 disable_irq(wm->pen_irq);
251}
252
253static struct wm97xx_mach_ops mainstone_mach_ops = {
254 .acc_enabled = 1,
255 .acc_pen_up = wm97xx_acc_pen_up,
256 .acc_pen_down = wm97xx_acc_pen_down,
257 .acc_startup = wm97xx_acc_startup,
258 .acc_shutdown = wm97xx_acc_shutdown,
259 .irq_enable = wm97xx_irq_enable,
260 .irq_gpio = WM97XX_GPIO_2,
261};
262
263static int mainstone_wm97xx_probe(struct platform_device *pdev)
264{
265 struct wm97xx *wm = platform_get_drvdata(pdev);
266
267 return wm97xx_register_mach_ops(wm, &mainstone_mach_ops);
268}
269
270static int mainstone_wm97xx_remove(struct platform_device *pdev)
271{
272 struct wm97xx *wm = platform_get_drvdata(pdev);
273
274 wm97xx_unregister_mach_ops(wm);
275 return 0;
276}
277
278static struct platform_driver mainstone_wm97xx_driver = {
279 .probe = mainstone_wm97xx_probe,
280 .remove = mainstone_wm97xx_remove,
281 .driver = {
282 .name = "wm97xx-touch",
283 },
284};
285
286static int __init mainstone_wm97xx_init(void)
287{
288 return platform_driver_register(&mainstone_wm97xx_driver);
289}
290
291static void __exit mainstone_wm97xx_exit(void)
292{
293 platform_driver_unregister(&mainstone_wm97xx_driver);
294}
295
296module_init(mainstone_wm97xx_init);
297module_exit(mainstone_wm97xx_exit);
298
299/* Module information */
300MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
301MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone");
302MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/ucb1400_ts.c b/drivers/input/touchscreen/ucb1400_ts.c
index 607f9933aa1f..bce018e45bce 100644
--- a/drivers/input/touchscreen/ucb1400_ts.c
+++ b/drivers/input/touchscreen/ucb1400_ts.c
@@ -427,10 +427,6 @@ static int ucb1400_detect_irq(struct ucb1400 *ucb)
427 unsigned long mask, timeout; 427 unsigned long mask, timeout;
428 428
429 mask = probe_irq_on(); 429 mask = probe_irq_on();
430 if (!mask) {
431 probe_irq_off(mask);
432 return -EBUSY;
433 }
434 430
435 /* Enable the ADC interrupt. */ 431 /* Enable the ADC interrupt. */
436 ucb1400_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC); 432 ucb1400_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC);
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 63f9664a066f..3a0a8ca57076 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -396,9 +396,12 @@ static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
396static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) 396static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
397{ 397{
398 struct usb_device *dev = usbtouch->udev; 398 struct usb_device *dev = usbtouch->udev;
399 int ret; 399 int ret = -ENOMEM;
400 unsigned char buf[2]; 400 unsigned char *buf;
401 401
402 buf = kmalloc(2, GFP_KERNEL);
403 if (!buf)
404 goto err_nobuf;
402 /* reset */ 405 /* reset */
403 buf[0] = buf[1] = 0xFF; 406 buf[0] = buf[1] = 0xFF;
404 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), 407 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
@@ -406,9 +409,11 @@ static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
406 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 409 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
407 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 410 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
408 if (ret < 0) 411 if (ret < 0)
409 return ret; 412 goto err_out;
410 if (buf[0] != 0x06 || buf[1] != 0x00) 413 if (buf[0] != 0x06 || buf[1] != 0x00) {
411 return -ENODEV; 414 ret = -ENODEV;
415 goto err_out;
416 }
412 417
413 /* set coordinate output rate */ 418 /* set coordinate output rate */
414 buf[0] = buf[1] = 0xFF; 419 buf[0] = buf[1] = 0xFF;
@@ -417,20 +422,22 @@ static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
417 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 422 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
418 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 423 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
419 if (ret < 0) 424 if (ret < 0)
420 return ret; 425 goto err_out;
421 if ((buf[0] != 0x06 || buf[1] != 0x00) && 426 if ((buf[0] != 0x06 || buf[1] != 0x00) &&
422 (buf[0] != 0x15 || buf[1] != 0x01)) 427 (buf[0] != 0x15 || buf[1] != 0x01)) {
423 return -ENODEV; 428 ret = -ENODEV;
429 goto err_out;
430 }
424 431
425 /* start sending data */ 432 /* start sending data */
426 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), 433 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
427 TSC10_CMD_DATA1, 434 TSC10_CMD_DATA1,
428 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 435 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
429 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 436 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
430 if (ret < 0) 437err_out:
431 return ret; 438 kfree(buf);
432 439err_nobuf:
433 return 0; 440 return ret;
434} 441}
435 442
436 443
diff --git a/drivers/input/touchscreen/wm9705.c b/drivers/input/touchscreen/wm9705.c
new file mode 100644
index 000000000000..978e1a13ffc7
--- /dev/null
+++ b/drivers/input/touchscreen/wm9705.c
@@ -0,0 +1,353 @@
1/*
2 * wm9705.c -- Codec driver for Wolfson WM9705 AC97 Codec.
3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/version.h>
21#include <linux/kernel.h>
22#include <linux/input.h>
23#include <linux/delay.h>
24#include <linux/bitops.h>
25#include <linux/wm97xx.h>
26
27#define TS_NAME "wm97xx"
28#define WM9705_VERSION "1.00"
29#define DEFAULT_PRESSURE 0xb0c0
30
31/*
32 * Module parameters
33 */
34
35/*
36 * Set current used for pressure measurement.
37 *
38 * Set pil = 2 to use 400uA
39 * pil = 1 to use 200uA and
40 * pil = 0 to disable pressure measurement.
41 *
42 * This is used to increase the range of values returned by the adc
43 * when measureing touchpanel pressure.
44 */
45static int pil;
46module_param(pil, int, 0);
47MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
48
49/*
50 * Set threshold for pressure measurement.
51 *
52 * Pen down pressure below threshold is ignored.
53 */
54static int pressure = DEFAULT_PRESSURE & 0xfff;
55module_param(pressure, int, 0);
56MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
57
58/*
59 * Set adc sample delay.
60 *
61 * For accurate touchpanel measurements, some settling time may be
62 * required between the switch matrix applying a voltage across the
63 * touchpanel plate and the ADC sampling the signal.
64 *
65 * This delay can be set by setting delay = n, where n is the array
66 * position of the delay in the array delay_table below.
67 * Long delays > 1ms are supported for completeness, but are not
68 * recommended.
69 */
70static int delay = 4;
71module_param(delay, int, 0);
72MODULE_PARM_DESC(delay, "Set adc sample delay.");
73
74/*
75 * Pen detect comparator threshold.
76 *
77 * 0 to Vmid in 15 steps, 0 = use zero power comparator with Vmid threshold
78 * i.e. 1 = Vmid/15 threshold
79 * 15 = Vmid/1 threshold
80 *
81 * Adjust this value if you are having problems with pen detect not
82 * detecting any down events.
83 */
84static int pdd = 8;
85module_param(pdd, int, 0);
86MODULE_PARM_DESC(pdd, "Set pen detect comparator threshold");
87
88/*
89 * Set adc mask function.
90 *
91 * Sources of glitch noise, such as signals driving an LCD display, may feed
92 * through to the touch screen plates and affect measurement accuracy. In
93 * order to minimise this, a signal may be applied to the MASK pin to delay or
94 * synchronise the sampling.
95 *
96 * 0 = No delay or sync
97 * 1 = High on pin stops conversions
98 * 2 = Edge triggered, edge on pin delays conversion by delay param (above)
99 * 3 = Edge triggered, edge on pin starts conversion after delay param
100 */
101static int mask;
102module_param(mask, int, 0);
103MODULE_PARM_DESC(mask, "Set adc mask function.");
104
105/*
106 * ADC sample delay times in uS
107 */
108static const int delay_table[] = {
109 21, /* 1 AC97 Link frames */
110 42, /* 2 */
111 84, /* 4 */
112 167, /* 8 */
113 333, /* 16 */
114 667, /* 32 */
115 1000, /* 48 */
116 1333, /* 64 */
117 2000, /* 96 */
118 2667, /* 128 */
119 3333, /* 160 */
120 4000, /* 192 */
121 4667, /* 224 */
122 5333, /* 256 */
123 6000, /* 288 */
124 0 /* No delay, switch matrix always on */
125};
126
127/*
128 * Delay after issuing a POLL command.
129 *
130 * The delay is 3 AC97 link frames + the touchpanel settling delay
131 */
132static inline void poll_delay(int d)
133{
134 udelay(3 * AC97_LINK_FRAME + delay_table[d]);
135}
136
137/*
138 * set up the physical settings of the WM9705
139 */
140static void wm9705_phy_init(struct wm97xx *wm)
141{
142 u16 dig1 = 0, dig2 = WM97XX_RPR;
143
144 /*
145 * mute VIDEO and AUX as they share X and Y touchscreen
146 * inputs on the WM9705
147 */
148 wm97xx_reg_write(wm, AC97_AUX, 0x8000);
149 wm97xx_reg_write(wm, AC97_VIDEO, 0x8000);
150
151 /* touchpanel pressure current*/
152 if (pil == 2) {
153 dig2 |= WM9705_PIL;
154 dev_dbg(wm->dev,
155 "setting pressure measurement current to 400uA.");
156 } else if (pil)
157 dev_dbg(wm->dev,
158 "setting pressure measurement current to 200uA.");
159 if (!pil)
160 pressure = 0;
161
162 /* polling mode sample settling delay */
163 if (delay != 4) {
164 if (delay < 0 || delay > 15) {
165 dev_dbg(wm->dev, "supplied delay out of range.");
166 delay = 4;
167 }
168 }
169 dig1 &= 0xff0f;
170 dig1 |= WM97XX_DELAY(delay);
171 dev_dbg(wm->dev, "setting adc sample delay to %d u Secs.",
172 delay_table[delay]);
173
174 /* WM9705 pdd */
175 dig2 |= (pdd & 0x000f);
176 dev_dbg(wm->dev, "setting pdd to Vmid/%d", 1 - (pdd & 0x000f));
177
178 /* mask */
179 dig2 |= ((mask & 0x3) << 4);
180
181 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
182 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
183}
184
185static void wm9705_dig_enable(struct wm97xx *wm, int enable)
186{
187 if (enable) {
188 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
189 wm->dig[2] | WM97XX_PRP_DET_DIG);
190 wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
191 } else
192 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
193 wm->dig[2] & ~WM97XX_PRP_DET_DIG);
194}
195
196static void wm9705_aux_prepare(struct wm97xx *wm)
197{
198 memcpy(wm->dig_save, wm->dig, sizeof(wm->dig));
199 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0);
200 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG);
201}
202
203static void wm9705_dig_restore(struct wm97xx *wm)
204{
205 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]);
206 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]);
207}
208
209static inline int is_pden(struct wm97xx *wm)
210{
211 return wm->dig[2] & WM9705_PDEN;
212}
213
214/*
215 * Read a sample from the WM9705 adc in polling mode.
216 */
217static int wm9705_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
218{
219 int timeout = 5 * delay;
220
221 if (!wm->pen_probably_down) {
222 u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
223 if (!(data & WM97XX_PEN_DOWN))
224 return RC_PENUP;
225 wm->pen_probably_down = 1;
226 }
227
228 /* set up digitiser */
229 if (adcsel & 0x8000)
230 adcsel = ((adcsel & 0x7fff) + 3) << 12;
231
232 if (wm->mach_ops && wm->mach_ops->pre_sample)
233 wm->mach_ops->pre_sample(adcsel);
234 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1,
235 adcsel | WM97XX_POLL | WM97XX_DELAY(delay));
236
237 /* wait 3 AC97 time slots + delay for conversion */
238 poll_delay(delay);
239
240 /* wait for POLL to go low */
241 while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL)
242 && timeout) {
243 udelay(AC97_LINK_FRAME);
244 timeout--;
245 }
246
247 if (timeout == 0) {
248 /* If PDEN is set, we can get a timeout when pen goes up */
249 if (is_pden(wm))
250 wm->pen_probably_down = 0;
251 else
252 dev_dbg(wm->dev, "adc sample timeout");
253 return RC_PENUP;
254 }
255
256 *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
257 if (wm->mach_ops && wm->mach_ops->post_sample)
258 wm->mach_ops->post_sample(adcsel);
259
260 /* check we have correct sample */
261 if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) {
262 dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel,
263 *sample & WM97XX_ADCSEL_MASK);
264 return RC_PENUP;
265 }
266
267 if (!(*sample & WM97XX_PEN_DOWN)) {
268 wm->pen_probably_down = 0;
269 return RC_PENUP;
270 }
271
272 return RC_VALID;
273}
274
275/*
276 * Sample the WM9705 touchscreen in polling mode
277 */
278static int wm9705_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
279{
280 int rc;
281
282 rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_X, &data->x);
283 if (rc != RC_VALID)
284 return rc;
285 rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y);
286 if (rc != RC_VALID)
287 return rc;
288 if (pil) {
289 rc = wm9705_poll_sample(wm, WM97XX_ADCSEL_PRES, &data->p);
290 if (rc != RC_VALID)
291 return rc;
292 } else
293 data->p = DEFAULT_PRESSURE;
294
295 return RC_VALID;
296}
297
298/*
299 * Enable WM9705 continuous mode, i.e. touch data is streamed across
300 * an AC97 slot
301 */
302static int wm9705_acc_enable(struct wm97xx *wm, int enable)
303{
304 u16 dig1, dig2;
305 int ret = 0;
306
307 dig1 = wm->dig[1];
308 dig2 = wm->dig[2];
309
310 if (enable) {
311 /* continous mode */
312 if (wm->mach_ops->acc_startup &&
313 (ret = wm->mach_ops->acc_startup(wm)) < 0)
314 return ret;
315 dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK |
316 WM97XX_DELAY_MASK | WM97XX_SLT_MASK);
317 dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN |
318 WM97XX_DELAY(delay) |
319 WM97XX_SLT(wm->acc_slot) |
320 WM97XX_RATE(wm->acc_rate);
321 if (pil)
322 dig1 |= WM97XX_ADCSEL_PRES;
323 dig2 |= WM9705_PDEN;
324 } else {
325 dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN);
326 dig2 &= ~WM9705_PDEN;
327 if (wm->mach_ops->acc_shutdown)
328 wm->mach_ops->acc_shutdown(wm);
329 }
330
331 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
332 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
333
334 return ret;
335}
336
337struct wm97xx_codec_drv wm9705_codec = {
338 .id = WM9705_ID2,
339 .name = "wm9705",
340 .poll_sample = wm9705_poll_sample,
341 .poll_touch = wm9705_poll_touch,
342 .acc_enable = wm9705_acc_enable,
343 .phy_init = wm9705_phy_init,
344 .dig_enable = wm9705_dig_enable,
345 .dig_restore = wm9705_dig_restore,
346 .aux_prepare = wm9705_aux_prepare,
347};
348EXPORT_SYMBOL_GPL(wm9705_codec);
349
350/* Module information */
351MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
352MODULE_DESCRIPTION("WM9705 Touch Screen Driver");
353MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9712.c b/drivers/input/touchscreen/wm9712.c
new file mode 100644
index 000000000000..0b6e4cfa6a21
--- /dev/null
+++ b/drivers/input/touchscreen/wm9712.c
@@ -0,0 +1,462 @@
1/*
2 * wm9712.c -- Codec driver for Wolfson WM9712 AC97 Codecs.
3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/version.h>
21#include <linux/kernel.h>
22#include <linux/input.h>
23#include <linux/delay.h>
24#include <linux/bitops.h>
25#include <linux/wm97xx.h>
26
27#define TS_NAME "wm97xx"
28#define WM9712_VERSION "1.00"
29#define DEFAULT_PRESSURE 0xb0c0
30
31/*
32 * Module parameters
33 */
34
35/*
36 * Set internal pull up for pen detect.
37 *
38 * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive)
39 * i.e. pull up resistance = 64k Ohms / rpu.
40 *
41 * Adjust this value if you are having problems with pen detect not
42 * detecting any down event.
43 */
44static int rpu = 8;
45module_param(rpu, int, 0);
46MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
47
48/*
49 * Set current used for pressure measurement.
50 *
51 * Set pil = 2 to use 400uA
52 * pil = 1 to use 200uA and
53 * pil = 0 to disable pressure measurement.
54 *
55 * This is used to increase the range of values returned by the adc
56 * when measureing touchpanel pressure.
57 */
58static int pil;
59module_param(pil, int, 0);
60MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
61
62/*
63 * Set threshold for pressure measurement.
64 *
65 * Pen down pressure below threshold is ignored.
66 */
67static int pressure = DEFAULT_PRESSURE & 0xfff;
68module_param(pressure, int, 0);
69MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
70
71/*
72 * Set adc sample delay.
73 *
74 * For accurate touchpanel measurements, some settling time may be
75 * required between the switch matrix applying a voltage across the
76 * touchpanel plate and the ADC sampling the signal.
77 *
78 * This delay can be set by setting delay = n, where n is the array
79 * position of the delay in the array delay_table below.
80 * Long delays > 1ms are supported for completeness, but are not
81 * recommended.
82 */
83static int delay = 3;
84module_param(delay, int, 0);
85MODULE_PARM_DESC(delay, "Set adc sample delay.");
86
87/*
88 * Set five_wire = 1 to use a 5 wire touchscreen.
89 *
90 * NOTE: Five wire mode does not allow for readback of pressure.
91 */
92static int five_wire;
93module_param(five_wire, int, 0);
94MODULE_PARM_DESC(five_wire, "Set to '1' to use 5-wire touchscreen.");
95
96/*
97 * Set adc mask function.
98 *
99 * Sources of glitch noise, such as signals driving an LCD display, may feed
100 * through to the touch screen plates and affect measurement accuracy. In
101 * order to minimise this, a signal may be applied to the MASK pin to delay or
102 * synchronise the sampling.
103 *
104 * 0 = No delay or sync
105 * 1 = High on pin stops conversions
106 * 2 = Edge triggered, edge on pin delays conversion by delay param (above)
107 * 3 = Edge triggered, edge on pin starts conversion after delay param
108 */
109static int mask;
110module_param(mask, int, 0);
111MODULE_PARM_DESC(mask, "Set adc mask function.");
112
113/*
114 * Coordinate Polling Enable.
115 *
116 * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together
117 * for every poll.
118 */
119static int coord;
120module_param(coord, int, 0);
121MODULE_PARM_DESC(coord, "Polling coordinate mode");
122
123/*
124 * ADC sample delay times in uS
125 */
126static const int delay_table[] = {
127 21, /* 1 AC97 Link frames */
128 42, /* 2 */
129 84, /* 4 */
130 167, /* 8 */
131 333, /* 16 */
132 667, /* 32 */
133 1000, /* 48 */
134 1333, /* 64 */
135 2000, /* 96 */
136 2667, /* 128 */
137 3333, /* 160 */
138 4000, /* 192 */
139 4667, /* 224 */
140 5333, /* 256 */
141 6000, /* 288 */
142 0 /* No delay, switch matrix always on */
143};
144
145/*
146 * Delay after issuing a POLL command.
147 *
148 * The delay is 3 AC97 link frames + the touchpanel settling delay
149 */
150static inline void poll_delay(int d)
151{
152 udelay(3 * AC97_LINK_FRAME + delay_table[d]);
153}
154
155/*
156 * set up the physical settings of the WM9712
157 */
158static void wm9712_phy_init(struct wm97xx *wm)
159{
160 u16 dig1 = 0;
161 u16 dig2 = WM97XX_RPR | WM9712_RPU(1);
162
163 /* WM9712 rpu */
164 if (rpu) {
165 dig2 &= 0xffc0;
166 dig2 |= WM9712_RPU(rpu);
167 dev_dbg(wm->dev, "setting pen detect pull-up to %d Ohms",
168 64000 / rpu);
169 }
170
171 /* touchpanel pressure current*/
172 if (pil == 2) {
173 dig2 |= WM9712_PIL;
174 dev_dbg(wm->dev,
175 "setting pressure measurement current to 400uA.");
176 } else if (pil)
177 dev_dbg(wm->dev,
178 "setting pressure measurement current to 200uA.");
179 if (!pil)
180 pressure = 0;
181
182 /* WM9712 five wire */
183 if (five_wire) {
184 dig2 |= WM9712_45W;
185 dev_dbg(wm->dev, "setting 5-wire touchscreen mode.");
186 }
187
188 /* polling mode sample settling delay */
189 if (delay < 0 || delay > 15) {
190 dev_dbg(wm->dev, "supplied delay out of range.");
191 delay = 4;
192 }
193 dig1 &= 0xff0f;
194 dig1 |= WM97XX_DELAY(delay);
195 dev_dbg(wm->dev, "setting adc sample delay to %d u Secs.",
196 delay_table[delay]);
197
198 /* mask */
199 dig2 |= ((mask & 0x3) << 6);
200 if (mask) {
201 u16 reg;
202 /* Set GPIO4 as Mask Pin*/
203 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
204 wm97xx_reg_write(wm, AC97_MISC_AFE, reg | WM97XX_GPIO_4);
205 reg = wm97xx_reg_read(wm, AC97_GPIO_CFG);
206 wm97xx_reg_write(wm, AC97_GPIO_CFG, reg | WM97XX_GPIO_4);
207 }
208
209 /* wait - coord mode */
210 if (coord)
211 dig2 |= WM9712_WAIT;
212
213 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
214 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
215}
216
217static void wm9712_dig_enable(struct wm97xx *wm, int enable)
218{
219 u16 dig2 = wm->dig[2];
220
221 if (enable) {
222 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
223 dig2 | WM97XX_PRP_DET_DIG);
224 wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
225 } else
226 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2,
227 dig2 & ~WM97XX_PRP_DET_DIG);
228}
229
230static void wm9712_aux_prepare(struct wm97xx *wm)
231{
232 memcpy(wm->dig_save, wm->dig, sizeof(wm->dig));
233 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, 0);
234 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, WM97XX_PRP_DET_DIG);
235}
236
237static void wm9712_dig_restore(struct wm97xx *wm)
238{
239 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, wm->dig_save[1]);
240 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, wm->dig_save[2]);
241}
242
243static inline int is_pden(struct wm97xx *wm)
244{
245 return wm->dig[2] & WM9712_PDEN;
246}
247
248/*
249 * Read a sample from the WM9712 adc in polling mode.
250 */
251static int wm9712_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
252{
253 int timeout = 5 * delay;
254
255 if (!wm->pen_probably_down) {
256 u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
257 if (!(data & WM97XX_PEN_DOWN))
258 return RC_PENUP;
259 wm->pen_probably_down = 1;
260 }
261
262 /* set up digitiser */
263 if (adcsel & 0x8000)
264 adcsel = ((adcsel & 0x7fff) + 3) << 12;
265
266 if (wm->mach_ops && wm->mach_ops->pre_sample)
267 wm->mach_ops->pre_sample(adcsel);
268 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1,
269 adcsel | WM97XX_POLL | WM97XX_DELAY(delay));
270
271 /* wait 3 AC97 time slots + delay for conversion */
272 poll_delay(delay);
273
274 /* wait for POLL to go low */
275 while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL)
276 && timeout) {
277 udelay(AC97_LINK_FRAME);
278 timeout--;
279 }
280
281 if (timeout <= 0) {
282 /* If PDEN is set, we can get a timeout when pen goes up */
283 if (is_pden(wm))
284 wm->pen_probably_down = 0;
285 else
286 dev_dbg(wm->dev, "adc sample timeout");
287 return RC_PENUP;
288 }
289
290 *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
291 if (wm->mach_ops && wm->mach_ops->post_sample)
292 wm->mach_ops->post_sample(adcsel);
293
294 /* check we have correct sample */
295 if ((*sample & WM97XX_ADCSEL_MASK) != adcsel) {
296 dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel,
297 *sample & WM97XX_ADCSEL_MASK);
298 return RC_PENUP;
299 }
300
301 if (!(*sample & WM97XX_PEN_DOWN)) {
302 wm->pen_probably_down = 0;
303 return RC_PENUP;
304 }
305
306 return RC_VALID;
307}
308
309/*
310 * Read a coord from the WM9712 adc in polling mode.
311 */
312static int wm9712_poll_coord(struct wm97xx *wm, struct wm97xx_data *data)
313{
314 int timeout = 5 * delay;
315
316 if (!wm->pen_probably_down) {
317 u16 data_rd = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
318 if (!(data_rd & WM97XX_PEN_DOWN))
319 return RC_PENUP;
320 wm->pen_probably_down = 1;
321 }
322
323 /* set up digitiser */
324 if (wm->mach_ops && wm->mach_ops->pre_sample)
325 wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
326
327 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1,
328 WM97XX_COO | WM97XX_POLL | WM97XX_DELAY(delay));
329
330 /* wait 3 AC97 time slots + delay for conversion and read x */
331 poll_delay(delay);
332 data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
333 /* wait for POLL to go low */
334 while ((wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER1) & WM97XX_POLL)
335 && timeout) {
336 udelay(AC97_LINK_FRAME);
337 timeout--;
338 }
339
340 if (timeout <= 0) {
341 /* If PDEN is set, we can get a timeout when pen goes up */
342 if (is_pden(wm))
343 wm->pen_probably_down = 0;
344 else
345 dev_dbg(wm->dev, "adc sample timeout");
346 return RC_PENUP;
347 }
348
349 /* read back y data */
350 data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
351 if (pil)
352 data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
353 else
354 data->p = DEFAULT_PRESSURE;
355
356 if (wm->mach_ops && wm->mach_ops->post_sample)
357 wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
358
359 /* check we have correct sample */
360 if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y))
361 goto err;
362 if (pil && !(data->p & WM97XX_ADCSEL_PRES))
363 goto err;
364
365 if (!(data->x & WM97XX_PEN_DOWN) || !(data->y & WM97XX_PEN_DOWN)) {
366 wm->pen_probably_down = 0;
367 return RC_PENUP;
368 }
369 return RC_VALID;
370err:
371 return 0;
372}
373
374/*
375 * Sample the WM9712 touchscreen in polling mode
376 */
377static int wm9712_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
378{
379 int rc;
380
381 if (coord) {
382 rc = wm9712_poll_coord(wm, data);
383 if (rc != RC_VALID)
384 return rc;
385 } else {
386 rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_X, &data->x);
387 if (rc != RC_VALID)
388 return rc;
389
390 rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_Y, &data->y);
391 if (rc != RC_VALID)
392 return rc;
393
394 if (pil && !five_wire) {
395 rc = wm9712_poll_sample(wm, WM97XX_ADCSEL_PRES,
396 &data->p);
397 if (rc != RC_VALID)
398 return rc;
399 } else
400 data->p = DEFAULT_PRESSURE;
401 }
402 return RC_VALID;
403}
404
405/*
406 * Enable WM9712 continuous mode, i.e. touch data is streamed across
407 * an AC97 slot
408 */
409static int wm9712_acc_enable(struct wm97xx *wm, int enable)
410{
411 u16 dig1, dig2;
412 int ret = 0;
413
414 dig1 = wm->dig[1];
415 dig2 = wm->dig[2];
416
417 if (enable) {
418 /* continous mode */
419 if (wm->mach_ops->acc_startup) {
420 ret = wm->mach_ops->acc_startup(wm);
421 if (ret < 0)
422 return ret;
423 }
424 dig1 &= ~(WM97XX_CM_RATE_MASK | WM97XX_ADCSEL_MASK |
425 WM97XX_DELAY_MASK | WM97XX_SLT_MASK);
426 dig1 |= WM97XX_CTC | WM97XX_COO | WM97XX_SLEN |
427 WM97XX_DELAY(delay) |
428 WM97XX_SLT(wm->acc_slot) |
429 WM97XX_RATE(wm->acc_rate);
430 if (pil)
431 dig1 |= WM97XX_ADCSEL_PRES;
432 dig2 |= WM9712_PDEN;
433 } else {
434 dig1 &= ~(WM97XX_CTC | WM97XX_COO | WM97XX_SLEN);
435 dig2 &= ~WM9712_PDEN;
436 if (wm->mach_ops->acc_shutdown)
437 wm->mach_ops->acc_shutdown(wm);
438 }
439
440 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER1, dig1);
441 wm97xx_reg_write(wm, AC97_WM97XX_DIGITISER2, dig2);
442
443 return 0;
444}
445
446struct wm97xx_codec_drv wm9712_codec = {
447 .id = WM9712_ID2,
448 .name = "wm9712",
449 .poll_sample = wm9712_poll_sample,
450 .poll_touch = wm9712_poll_touch,
451 .acc_enable = wm9712_acc_enable,
452 .phy_init = wm9712_phy_init,
453 .dig_enable = wm9712_dig_enable,
454 .dig_restore = wm9712_dig_restore,
455 .aux_prepare = wm9712_aux_prepare,
456};
457EXPORT_SYMBOL_GPL(wm9712_codec);
458
459/* Module information */
460MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
461MODULE_DESCRIPTION("WM9712 Touch Screen Driver");
462MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
new file mode 100644
index 000000000000..01278bd7e65c
--- /dev/null
+++ b/drivers/input/touchscreen/wm9713.c
@@ -0,0 +1,460 @@
1/*
2 * wm9713.c -- Codec touch driver for Wolfson WM9713 AC97 Codec.
3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/version.h>
21#include <linux/kernel.h>
22#include <linux/input.h>
23#include <linux/delay.h>
24#include <linux/bitops.h>
25#include <linux/wm97xx.h>
26
27#define TS_NAME "wm97xx"
28#define WM9713_VERSION "1.00"
29#define DEFAULT_PRESSURE 0xb0c0
30
31/*
32 * Module parameters
33 */
34
35/*
36 * Set internal pull up for pen detect.
37 *
38 * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive)
39 * i.e. pull up resistance = 64k Ohms / rpu.
40 *
41 * Adjust this value if you are having problems with pen detect not
42 * detecting any down event.
43 */
44static int rpu = 8;
45module_param(rpu, int, 0);
46MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
47
48/*
49 * Set current used for pressure measurement.
50 *
51 * Set pil = 2 to use 400uA
52 * pil = 1 to use 200uA and
53 * pil = 0 to disable pressure measurement.
54 *
55 * This is used to increase the range of values returned by the adc
56 * when measureing touchpanel pressure.
57 */
58static int pil;
59module_param(pil, int, 0);
60MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
61
62/*
63 * Set threshold for pressure measurement.
64 *
65 * Pen down pressure below threshold is ignored.
66 */
67static int pressure = DEFAULT_PRESSURE & 0xfff;
68module_param(pressure, int, 0);
69MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
70
71/*
72 * Set adc sample delay.
73 *
74 * For accurate touchpanel measurements, some settling time may be
75 * required between the switch matrix applying a voltage across the
76 * touchpanel plate and the ADC sampling the signal.
77 *
78 * This delay can be set by setting delay = n, where n is the array
79 * position of the delay in the array delay_table below.
80 * Long delays > 1ms are supported for completeness, but are not
81 * recommended.
82 */
83static int delay = 4;
84module_param(delay, int, 0);
85MODULE_PARM_DESC(delay, "Set adc sample delay.");
86
87/*
88 * Set adc mask function.
89 *
90 * Sources of glitch noise, such as signals driving an LCD display, may feed
91 * through to the touch screen plates and affect measurement accuracy. In
92 * order to minimise this, a signal may be applied to the MASK pin to delay or
93 * synchronise the sampling.
94 *
95 * 0 = No delay or sync
96 * 1 = High on pin stops conversions
97 * 2 = Edge triggered, edge on pin delays conversion by delay param (above)
98 * 3 = Edge triggered, edge on pin starts conversion after delay param
99 */
100static int mask;
101module_param(mask, int, 0);
102MODULE_PARM_DESC(mask, "Set adc mask function.");
103
104/*
105 * Coordinate Polling Enable.
106 *
107 * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together
108 * for every poll.
109 */
110static int coord;
111module_param(coord, int, 0);
112MODULE_PARM_DESC(coord, "Polling coordinate mode");
113
114/*
115 * ADC sample delay times in uS
116 */
117static const int delay_table[] = {
118 21, /* 1 AC97 Link frames */
119 42, /* 2 */
120 84, /* 4 */
121 167, /* 8 */
122 333, /* 16 */
123 667, /* 32 */
124 1000, /* 48 */
125 1333, /* 64 */
126 2000, /* 96 */
127 2667, /* 128 */
128 3333, /* 160 */
129 4000, /* 192 */
130 4667, /* 224 */
131 5333, /* 256 */
132 6000, /* 288 */
133 0 /* No delay, switch matrix always on */
134};
135
136/*
137 * Delay after issuing a POLL command.
138 *
139 * The delay is 3 AC97 link frames + the touchpanel settling delay
140 */
141static inline void poll_delay(int d)
142{
143 udelay(3 * AC97_LINK_FRAME + delay_table[d]);
144}
145
146/*
147 * set up the physical settings of the WM9713
148 */
149static void wm9713_phy_init(struct wm97xx *wm)
150{
151 u16 dig1 = 0, dig2, dig3;
152
153 /* default values */
154 dig2 = WM97XX_DELAY(4) | WM97XX_SLT(5);
155 dig3 = WM9712_RPU(1);
156
157 /* rpu */
158 if (rpu) {
159 dig3 &= 0xffc0;
160 dig3 |= WM9712_RPU(rpu);
161 dev_info(wm->dev, "setting pen detect pull-up to %d Ohms\n",
162 64000 / rpu);
163 }
164
165 /* touchpanel pressure */
166 if (pil == 2) {
167 dig3 |= WM9712_PIL;
168 dev_info(wm->dev,
169 "setting pressure measurement current to 400uA.");
170 } else if (pil)
171 dev_info(wm->dev,
172 "setting pressure measurement current to 200uA.");
173 if (!pil)
174 pressure = 0;
175
176 /* sample settling delay */
177 if (delay < 0 || delay > 15) {
178 dev_info(wm->dev, "supplied delay out of range.");
179 delay = 4;
180 dev_info(wm->dev, "setting adc sample delay to %d u Secs.",
181 delay_table[delay]);
182 }
183 dig2 &= 0xff0f;
184 dig2 |= WM97XX_DELAY(delay);
185
186 /* mask */
187 dig3 |= ((mask & 0x3) << 4);
188 if (coord)
189 dig3 |= WM9713_WAIT;
190
191 wm->misc = wm97xx_reg_read(wm, 0x5a);
192
193 wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1);
194 wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2);
195 wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3);
196 wm97xx_reg_write(wm, AC97_GPIO_STICKY, 0x0);
197}
198
199static void wm9713_dig_enable(struct wm97xx *wm, int enable)
200{
201 u16 val;
202
203 if (enable) {
204 val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
205 wm97xx_reg_write(wm, AC97_EXTENDED_MID, val & 0x7fff);
206 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] |
207 WM97XX_PRP_DET_DIG);
208 wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
209 } else {
210 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] &
211 ~WM97XX_PRP_DET_DIG);
212 val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
213 wm97xx_reg_write(wm, AC97_EXTENDED_MID, val | 0x8000);
214 }
215}
216
217static void wm9713_dig_restore(struct wm97xx *wm)
218{
219 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig_save[0]);
220 wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig_save[1]);
221 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig_save[2]);
222}
223
224static void wm9713_aux_prepare(struct wm97xx *wm)
225{
226 memcpy(wm->dig_save, wm->dig, sizeof(wm->dig));
227 wm97xx_reg_write(wm, AC97_WM9713_DIG1, 0);
228 wm97xx_reg_write(wm, AC97_WM9713_DIG2, 0);
229 wm97xx_reg_write(wm, AC97_WM9713_DIG3, WM97XX_PRP_DET_DIG);
230}
231
232static inline int is_pden(struct wm97xx *wm)
233{
234 return wm->dig[2] & WM9713_PDEN;
235}
236
237/*
238 * Read a sample from the WM9713 adc in polling mode.
239 */
240static int wm9713_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
241{
242 u16 dig1;
243 int timeout = 5 * delay;
244
245 if (!wm->pen_probably_down) {
246 u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
247 if (!(data & WM97XX_PEN_DOWN))
248 return RC_PENUP;
249 wm->pen_probably_down = 1;
250 }
251
252 /* set up digitiser */
253 if (adcsel & 0x8000)
254 adcsel = 1 << ((adcsel & 0x7fff) + 3);
255
256 dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1);
257 dig1 &= ~WM9713_ADCSEL_MASK;
258
259 if (wm->mach_ops && wm->mach_ops->pre_sample)
260 wm->mach_ops->pre_sample(adcsel);
261 wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | adcsel | WM9713_POLL);
262
263 /* wait 3 AC97 time slots + delay for conversion */
264 poll_delay(delay);
265
266 /* wait for POLL to go low */
267 while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) &&
268 timeout) {
269 udelay(AC97_LINK_FRAME);
270 timeout--;
271 }
272
273 if (timeout <= 0) {
274 /* If PDEN is set, we can get a timeout when pen goes up */
275 if (is_pden(wm))
276 wm->pen_probably_down = 0;
277 else
278 dev_dbg(wm->dev, "adc sample timeout");
279 return RC_PENUP;
280 }
281
282 *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
283 if (wm->mach_ops && wm->mach_ops->post_sample)
284 wm->mach_ops->post_sample(adcsel);
285
286 /* check we have correct sample */
287 if ((*sample & WM97XX_ADCSRC_MASK) != ffs(adcsel >> 1) << 12) {
288 dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel,
289 *sample & WM97XX_ADCSRC_MASK);
290 return RC_PENUP;
291 }
292
293 if (!(*sample & WM97XX_PEN_DOWN)) {
294 wm->pen_probably_down = 0;
295 return RC_PENUP;
296 }
297
298 return RC_VALID;
299}
300
301/*
302 * Read a coordinate from the WM9713 adc in polling mode.
303 */
304static int wm9713_poll_coord(struct wm97xx *wm, struct wm97xx_data *data)
305{
306 u16 dig1;
307 int timeout = 5 * delay;
308
309 if (!wm->pen_probably_down) {
310 u16 val = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
311 if (!(val & WM97XX_PEN_DOWN))
312 return RC_PENUP;
313 wm->pen_probably_down = 1;
314 }
315
316 /* set up digitiser */
317 dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1);
318 dig1 &= ~WM9713_ADCSEL_MASK;
319 if (pil)
320 dig1 |= WM9713_ADCSEL_PRES;
321
322 if (wm->mach_ops && wm->mach_ops->pre_sample)
323 wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
324 wm97xx_reg_write(wm, AC97_WM9713_DIG1,
325 dig1 | WM9713_POLL | WM9713_COO);
326
327 /* wait 3 AC97 time slots + delay for conversion */
328 poll_delay(delay);
329 data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
330 /* wait for POLL to go low */
331 while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL)
332 && timeout) {
333 udelay(AC97_LINK_FRAME);
334 timeout--;
335 }
336
337 if (timeout <= 0) {
338 /* If PDEN is set, we can get a timeout when pen goes up */
339 if (is_pden(wm))
340 wm->pen_probably_down = 0;
341 else
342 dev_dbg(wm->dev, "adc sample timeout");
343 return RC_PENUP;
344 }
345
346 /* read back data */
347 data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
348 if (pil)
349 data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
350 else
351 data->p = DEFAULT_PRESSURE;
352
353 if (wm->mach_ops && wm->mach_ops->post_sample)
354 wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
355
356 /* check we have correct sample */
357 if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y))
358 goto err;
359 if (pil && !(data->p & WM97XX_ADCSEL_PRES))
360 goto err;
361
362 if (!(data->x & WM97XX_PEN_DOWN) || !(data->y & WM97XX_PEN_DOWN)) {
363 wm->pen_probably_down = 0;
364 return RC_PENUP;
365 }
366 return RC_VALID;
367err:
368 return 0;
369}
370
371/*
372 * Sample the WM9713 touchscreen in polling mode
373 */
374static int wm9713_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
375{
376 int rc;
377
378 if (coord) {
379 rc = wm9713_poll_coord(wm, data);
380 if (rc != RC_VALID)
381 return rc;
382 } else {
383 rc = wm9713_poll_sample(wm, WM9713_ADCSEL_X, &data->x);
384 if (rc != RC_VALID)
385 return rc;
386 rc = wm9713_poll_sample(wm, WM9713_ADCSEL_Y, &data->y);
387 if (rc != RC_VALID)
388 return rc;
389 if (pil) {
390 rc = wm9713_poll_sample(wm, WM9713_ADCSEL_PRES,
391 &data->p);
392 if (rc != RC_VALID)
393 return rc;
394 } else
395 data->p = DEFAULT_PRESSURE;
396 }
397 return RC_VALID;
398}
399
400/*
401 * Enable WM9713 continuous mode, i.e. touch data is streamed across
402 * an AC97 slot
403 */
404static int wm9713_acc_enable(struct wm97xx *wm, int enable)
405{
406 u16 dig1, dig2, dig3;
407 int ret = 0;
408
409 dig1 = wm->dig[0];
410 dig2 = wm->dig[1];
411 dig3 = wm->dig[2];
412
413 if (enable) {
414 /* continous mode */
415 if (wm->mach_ops->acc_startup &&
416 (ret = wm->mach_ops->acc_startup(wm)) < 0)
417 return ret;
418
419 dig1 &= ~WM9713_ADCSEL_MASK;
420 dig1 |= WM9713_CTC | WM9713_COO | WM9713_ADCSEL_X |
421 WM9713_ADCSEL_Y;
422 if (pil)
423 dig1 |= WM9713_ADCSEL_PRES;
424 dig2 &= ~(WM97XX_DELAY_MASK | WM97XX_SLT_MASK |
425 WM97XX_CM_RATE_MASK);
426 dig2 |= WM97XX_SLEN | WM97XX_DELAY(delay) |
427 WM97XX_SLT(wm->acc_slot) | WM97XX_RATE(wm->acc_rate);
428 dig3 |= WM9713_PDEN;
429 } else {
430 dig1 &= ~(WM9713_CTC | WM9713_COO);
431 dig2 &= ~WM97XX_SLEN;
432 dig3 &= ~WM9713_PDEN;
433 if (wm->mach_ops->acc_shutdown)
434 wm->mach_ops->acc_shutdown(wm);
435 }
436
437 wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1);
438 wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2);
439 wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3);
440
441 return ret;
442}
443
444struct wm97xx_codec_drv wm9713_codec = {
445 .id = WM9713_ID2,
446 .name = "wm9713",
447 .poll_sample = wm9713_poll_sample,
448 .poll_touch = wm9713_poll_touch,
449 .acc_enable = wm9713_acc_enable,
450 .phy_init = wm9713_phy_init,
451 .dig_enable = wm9713_dig_enable,
452 .dig_restore = wm9713_dig_restore,
453 .aux_prepare = wm9713_aux_prepare,
454};
455EXPORT_SYMBOL_GPL(wm9713_codec);
456
457/* Module information */
458MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
459MODULE_DESCRIPTION("WM9713 Touch Screen Driver");
460MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
new file mode 100644
index 000000000000..e9c7ea46b6e3
--- /dev/null
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -0,0 +1,829 @@
1/*
2 * wm97xx-core.c -- Touch screen driver core for Wolfson WM9705, WM9712
3 * and WM9713 AC97 Codecs.
4 *
5 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru>
10 * Russell King <rmk@arm.linux.org.uk>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * Notes:
18 *
19 * Features:
20 * - supports WM9705, WM9712, WM9713
21 * - polling mode
22 * - continuous mode (arch-dependent)
23 * - adjustable rpu/dpp settings
24 * - adjustable pressure current
25 * - adjustable sample settle delay
26 * - 4 and 5 wire touchscreens (5 wire is WM9712 only)
27 * - pen down detection
28 * - battery monitor
29 * - sample AUX adcs
30 * - power management
31 * - codec GPIO
32 * - codec event notification
33 * Todo
34 * - Support for async sampling control for noisy LCDs.
35 *
36 */
37
38#include <linux/module.h>
39#include <linux/moduleparam.h>
40#include <linux/version.h>
41#include <linux/kernel.h>
42#include <linux/init.h>
43#include <linux/delay.h>
44#include <linux/string.h>
45#include <linux/proc_fs.h>
46#include <linux/pm.h>
47#include <linux/interrupt.h>
48#include <linux/bitops.h>
49#include <linux/workqueue.h>
50#include <linux/wm97xx.h>
51#include <linux/uaccess.h>
52#include <linux/io.h>
53
54#define TS_NAME "wm97xx"
55#define WM_CORE_VERSION "1.00"
56#define DEFAULT_PRESSURE 0xb0c0
57
58
59/*
60 * Touchscreen absolute values
61 *
62 * These parameters are used to help the input layer discard out of
63 * range readings and reduce jitter etc.
64 *
65 * o min, max:- indicate the min and max values your touch screen returns
66 * o fuzz:- use a higher number to reduce jitter
67 *
68 * The default values correspond to Mainstone II in QVGA mode
69 *
70 * Please read
71 * Documentation/input/input-programming.txt for more details.
72 */
73
74static int abs_x[3] = {350, 3900, 5};
75module_param_array(abs_x, int, NULL, 0);
76MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
77
78static int abs_y[3] = {320, 3750, 40};
79module_param_array(abs_y, int, NULL, 0);
80MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
81
82static int abs_p[3] = {0, 150, 4};
83module_param_array(abs_p, int, NULL, 0);
84MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
85
86/*
87 * wm97xx IO access, all IO locking done by AC97 layer
88 */
89int wm97xx_reg_read(struct wm97xx *wm, u16 reg)
90{
91 if (wm->ac97)
92 return wm->ac97->bus->ops->read(wm->ac97, reg);
93 else
94 return -1;
95}
96EXPORT_SYMBOL_GPL(wm97xx_reg_read);
97
98void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val)
99{
100 /* cache digitiser registers */
101 if (reg >= AC97_WM9713_DIG1 && reg <= AC97_WM9713_DIG3)
102 wm->dig[(reg - AC97_WM9713_DIG1) >> 1] = val;
103
104 /* cache gpio regs */
105 if (reg >= AC97_GPIO_CFG && reg <= AC97_MISC_AFE)
106 wm->gpio[(reg - AC97_GPIO_CFG) >> 1] = val;
107
108 /* wm9713 irq reg */
109 if (reg == 0x5a)
110 wm->misc = val;
111
112 if (wm->ac97)
113 wm->ac97->bus->ops->write(wm->ac97, reg, val);
114}
115EXPORT_SYMBOL_GPL(wm97xx_reg_write);
116
117/**
118 * wm97xx_read_aux_adc - Read the aux adc.
119 * @wm: wm97xx device.
120 * @adcsel: codec ADC to be read
121 *
122 * Reads the selected AUX ADC.
123 */
124
125int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel)
126{
127 int power_adc = 0, auxval;
128 u16 power = 0;
129
130 /* get codec */
131 mutex_lock(&wm->codec_mutex);
132
133 /* When the touchscreen is not in use, we may have to power up
134 * the AUX ADC before we can use sample the AUX inputs->
135 */
136 if (wm->id == WM9713_ID2 &&
137 (power = wm97xx_reg_read(wm, AC97_EXTENDED_MID)) & 0x8000) {
138 power_adc = 1;
139 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power & 0x7fff);
140 }
141
142 /* Prepare the codec for AUX reading */
143 wm->codec->aux_prepare(wm);
144
145 /* Turn polling mode on to read AUX ADC */
146 wm->pen_probably_down = 1;
147 wm->codec->poll_sample(wm, adcsel, &auxval);
148
149 if (power_adc)
150 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000);
151
152 wm->codec->dig_restore(wm);
153
154 wm->pen_probably_down = 0;
155
156 mutex_unlock(&wm->codec_mutex);
157 return auxval & 0xfff;
158}
159EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc);
160
161/**
162 * wm97xx_get_gpio - Get the status of a codec GPIO.
163 * @wm: wm97xx device.
164 * @gpio: gpio
165 *
166 * Get the status of a codec GPIO pin
167 */
168
169enum wm97xx_gpio_status wm97xx_get_gpio(struct wm97xx *wm, u32 gpio)
170{
171 u16 status;
172 enum wm97xx_gpio_status ret;
173
174 mutex_lock(&wm->codec_mutex);
175 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
176
177 if (status & gpio)
178 ret = WM97XX_GPIO_HIGH;
179 else
180 ret = WM97XX_GPIO_LOW;
181
182 mutex_unlock(&wm->codec_mutex);
183 return ret;
184}
185EXPORT_SYMBOL_GPL(wm97xx_get_gpio);
186
187/**
188 * wm97xx_set_gpio - Set the status of a codec GPIO.
189 * @wm: wm97xx device.
190 * @gpio: gpio
191 *
192 *
193 * Set the status of a codec GPIO pin
194 */
195
196void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
197 enum wm97xx_gpio_status status)
198{
199 u16 reg;
200
201 mutex_lock(&wm->codec_mutex);
202 reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
203
204 if (status & WM97XX_GPIO_HIGH)
205 reg |= gpio;
206 else
207 reg &= ~gpio;
208
209 if (wm->id == WM9712_ID2)
210 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1);
211 else
212 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg);
213 mutex_unlock(&wm->codec_mutex);
214}
215EXPORT_SYMBOL_GPL(wm97xx_set_gpio);
216
217/*
218 * Codec GPIO pin configuration, this sets pin direction, polarity,
219 * stickyness and wake up.
220 */
221void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, enum wm97xx_gpio_dir dir,
222 enum wm97xx_gpio_pol pol, enum wm97xx_gpio_sticky sticky,
223 enum wm97xx_gpio_wake wake)
224{
225 u16 reg;
226
227 mutex_lock(&wm->codec_mutex);
228 reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
229
230 if (pol == WM97XX_GPIO_POL_HIGH)
231 reg |= gpio;
232 else
233 reg &= ~gpio;
234
235 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, reg);
236 reg = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
237
238 if (sticky == WM97XX_GPIO_STICKY)
239 reg |= gpio;
240 else
241 reg &= ~gpio;
242
243 wm97xx_reg_write(wm, AC97_GPIO_STICKY, reg);
244 reg = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
245
246 if (wake == WM97XX_GPIO_WAKE)
247 reg |= gpio;
248 else
249 reg &= ~gpio;
250
251 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, reg);
252 reg = wm97xx_reg_read(wm, AC97_GPIO_CFG);
253
254 if (dir == WM97XX_GPIO_IN)
255 reg |= gpio;
256 else
257 reg &= ~gpio;
258
259 wm97xx_reg_write(wm, AC97_GPIO_CFG, reg);
260 mutex_unlock(&wm->codec_mutex);
261}
262EXPORT_SYMBOL_GPL(wm97xx_config_gpio);
263
264/*
265 * Configure the WM97XX_PRP value to use while system is suspended.
266 * If a value other than 0 is set then WM97xx pen detection will be
267 * left enabled in the configured mode while the system is in suspend,
268 * the device has users and suspend has not been disabled via the
269 * wakeup sysfs entries.
270 *
271 * @wm: WM97xx device to configure
272 * @mode: WM97XX_PRP value to configure while suspended
273 */
274void wm97xx_set_suspend_mode(struct wm97xx *wm, u16 mode)
275{
276 wm->suspend_mode = mode;
277 device_init_wakeup(&wm->input_dev->dev, mode != 0);
278}
279EXPORT_SYMBOL_GPL(wm97xx_set_suspend_mode);
280
281/*
282 * Handle a pen down interrupt.
283 */
284static void wm97xx_pen_irq_worker(struct work_struct *work)
285{
286 struct wm97xx *wm = container_of(work, struct wm97xx, pen_event_work);
287 int pen_was_down = wm->pen_is_down;
288
289 /* do we need to enable the touch panel reader */
290 if (wm->id == WM9705_ID2) {
291 if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) &
292 WM97XX_PEN_DOWN)
293 wm->pen_is_down = 1;
294 else
295 wm->pen_is_down = 0;
296 } else {
297 u16 status, pol;
298 mutex_lock(&wm->codec_mutex);
299 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
300 pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
301
302 if (WM97XX_GPIO_13 & pol & status) {
303 wm->pen_is_down = 1;
304 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol &
305 ~WM97XX_GPIO_13);
306 } else {
307 wm->pen_is_down = 0;
308 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol |
309 WM97XX_GPIO_13);
310 }
311
312 if (wm->id == WM9712_ID2)
313 wm97xx_reg_write(wm, AC97_GPIO_STATUS, (status &
314 ~WM97XX_GPIO_13) << 1);
315 else
316 wm97xx_reg_write(wm, AC97_GPIO_STATUS, status &
317 ~WM97XX_GPIO_13);
318 mutex_unlock(&wm->codec_mutex);
319 }
320
321 /* If the system is not using continuous mode or it provides a
322 * pen down operation then we need to schedule polls while the
323 * pen is down. Otherwise the machine driver is responsible
324 * for scheduling reads.
325 */
326 if (!wm->mach_ops->acc_enabled || wm->mach_ops->acc_pen_down) {
327 if (wm->pen_is_down && !pen_was_down) {
328 /* Data is not availiable immediately on pen down */
329 queue_delayed_work(wm->ts_workq, &wm->ts_reader, 1);
330 }
331
332 /* Let ts_reader report the pen up for debounce. */
333 if (!wm->pen_is_down && pen_was_down)
334 wm->pen_is_down = 1;
335 }
336
337 if (!wm->pen_is_down && wm->mach_ops->acc_enabled)
338 wm->mach_ops->acc_pen_up(wm);
339
340 wm->mach_ops->irq_enable(wm, 1);
341}
342
343/*
344 * Codec PENDOWN irq handler
345 *
346 * We have to disable the codec interrupt in the handler because it
347 * can take upto 1ms to clear the interrupt source. We schedule a task
348 * in a work queue to do the actual interaction with the chip. The
349 * interrupt is then enabled again in the slow handler when the source
350 * has been cleared.
351 */
352static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id)
353{
354 struct wm97xx *wm = dev_id;
355
356 if (!work_pending(&wm->pen_event_work)) {
357 wm->mach_ops->irq_enable(wm, 0);
358 queue_work(wm->ts_workq, &wm->pen_event_work);
359 }
360
361 return IRQ_HANDLED;
362}
363
364/*
365 * initialise pen IRQ handler and workqueue
366 */
367static int wm97xx_init_pen_irq(struct wm97xx *wm)
368{
369 u16 reg;
370
371 /* If an interrupt is supplied an IRQ enable operation must also be
372 * provided. */
373 BUG_ON(!wm->mach_ops->irq_enable);
374
375 if (request_irq(wm->pen_irq, wm97xx_pen_interrupt,
376 IRQF_SHARED | IRQF_SAMPLE_RANDOM,
377 "wm97xx-pen", wm)) {
378 dev_err(wm->dev,
379 "Failed to register pen down interrupt, polling");
380 wm->pen_irq = 0;
381 return -EINVAL;
382 }
383
384 /* Configure GPIO as interrupt source on WM971x */
385 if (wm->id != WM9705_ID2) {
386 BUG_ON(!wm->mach_ops->irq_gpio);
387 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
388 wm97xx_reg_write(wm, AC97_MISC_AFE,
389 reg & ~(wm->mach_ops->irq_gpio));
390 reg = wm97xx_reg_read(wm, 0x5a);
391 wm97xx_reg_write(wm, 0x5a, reg & ~0x0001);
392 }
393
394 return 0;
395}
396
397static int wm97xx_read_samples(struct wm97xx *wm)
398{
399 struct wm97xx_data data;
400 int rc;
401
402 mutex_lock(&wm->codec_mutex);
403
404 if (wm->mach_ops && wm->mach_ops->acc_enabled)
405 rc = wm->mach_ops->acc_pen_down(wm);
406 else
407 rc = wm->codec->poll_touch(wm, &data);
408
409 if (rc & RC_PENUP) {
410 if (wm->pen_is_down) {
411 wm->pen_is_down = 0;
412 dev_dbg(wm->dev, "pen up\n");
413 input_report_abs(wm->input_dev, ABS_PRESSURE, 0);
414 input_sync(wm->input_dev);
415 } else if (!(rc & RC_AGAIN)) {
416 /* We need high frequency updates only while
417 * pen is down, the user never will be able to
418 * touch screen faster than a few times per
419 * second... On the other hand, when the user
420 * is actively working with the touchscreen we
421 * don't want to lose the quick response. So we
422 * will slowly increase sleep time after the
423 * pen is up and quicky restore it to ~one task
424 * switch when pen is down again.
425 */
426 if (wm->ts_reader_interval < HZ / 10)
427 wm->ts_reader_interval++;
428 }
429
430 } else if (rc & RC_VALID) {
431 dev_dbg(wm->dev,
432 "pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n",
433 data.x >> 12, data.x & 0xfff, data.y >> 12,
434 data.y & 0xfff, data.p >> 12, data.p & 0xfff);
435 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);
436 input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);
437 input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);
438 input_sync(wm->input_dev);
439 wm->pen_is_down = 1;
440 wm->ts_reader_interval = wm->ts_reader_min_interval;
441 } else if (rc & RC_PENDOWN) {
442 dev_dbg(wm->dev, "pen down\n");
443 wm->pen_is_down = 1;
444 wm->ts_reader_interval = wm->ts_reader_min_interval;
445 }
446
447 mutex_unlock(&wm->codec_mutex);
448 return rc;
449}
450
451/*
452* The touchscreen sample reader.
453*/
454static void wm97xx_ts_reader(struct work_struct *work)
455{
456 int rc;
457 struct wm97xx *wm = container_of(work, struct wm97xx, ts_reader.work);
458
459 BUG_ON(!wm->codec);
460
461 do {
462 rc = wm97xx_read_samples(wm);
463 } while (rc & RC_AGAIN);
464
465 if (wm->pen_is_down || !wm->pen_irq)
466 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
467 wm->ts_reader_interval);
468}
469
470/**
471 * wm97xx_ts_input_open - Open the touch screen input device.
472 * @idev: Input device to be opened.
473 *
474 * Called by the input sub system to open a wm97xx touchscreen device.
475 * Starts the touchscreen thread and touch digitiser.
476 */
477static int wm97xx_ts_input_open(struct input_dev *idev)
478{
479 struct wm97xx *wm = input_get_drvdata(idev);
480
481 wm->ts_workq = create_singlethread_workqueue("kwm97xx");
482 if (wm->ts_workq == NULL) {
483 dev_err(wm->dev,
484 "Failed to create workqueue\n");
485 return -EINVAL;
486 }
487
488 /* start digitiser */
489 if (wm->mach_ops && wm->mach_ops->acc_enabled)
490 wm->codec->acc_enable(wm, 1);
491 wm->codec->dig_enable(wm, 1);
492
493 INIT_DELAYED_WORK(&wm->ts_reader, wm97xx_ts_reader);
494 INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker);
495
496 wm->ts_reader_min_interval = HZ >= 100 ? HZ / 100 : 1;
497 if (wm->ts_reader_min_interval < 1)
498 wm->ts_reader_min_interval = 1;
499 wm->ts_reader_interval = wm->ts_reader_min_interval;
500
501 wm->pen_is_down = 0;
502 if (wm->pen_irq)
503 wm97xx_init_pen_irq(wm);
504 else
505 dev_err(wm->dev, "No IRQ specified\n");
506
507 /* If we either don't have an interrupt for pen down events or
508 * failed to acquire it then we need to poll.
509 */
510 if (wm->pen_irq == 0)
511 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
512 wm->ts_reader_interval);
513
514 return 0;
515}
516
517/**
518 * wm97xx_ts_input_close - Close the touch screen input device.
519 * @idev: Input device to be closed.
520 *
521 * Called by the input sub system to close a wm97xx touchscreen
522 * device. Kills the touchscreen thread and stops the touch
523 * digitiser.
524 */
525
526static void wm97xx_ts_input_close(struct input_dev *idev)
527{
528 struct wm97xx *wm = input_get_drvdata(idev);
529 u16 reg;
530
531 if (wm->pen_irq) {
532 /* Return the interrupt to GPIO usage (disabling it) */
533 if (wm->id != WM9705_ID2) {
534 BUG_ON(!wm->mach_ops->irq_gpio);
535 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
536 wm97xx_reg_write(wm, AC97_MISC_AFE,
537 reg | wm->mach_ops->irq_gpio);
538 }
539
540 free_irq(wm->pen_irq, wm);
541 }
542
543 wm->pen_is_down = 0;
544
545 /* Balance out interrupt disables/enables */
546 if (cancel_work_sync(&wm->pen_event_work))
547 wm->mach_ops->irq_enable(wm, 1);
548
549 /* ts_reader rearms itself so we need to explicitly stop it
550 * before we destroy the workqueue.
551 */
552 cancel_delayed_work_sync(&wm->ts_reader);
553
554 destroy_workqueue(wm->ts_workq);
555
556 /* stop digitiser */
557 wm->codec->dig_enable(wm, 0);
558 if (wm->mach_ops && wm->mach_ops->acc_enabled)
559 wm->codec->acc_enable(wm, 0);
560}
561
562static int wm97xx_probe(struct device *dev)
563{
564 struct wm97xx *wm;
565 int ret = 0, id = 0;
566
567 wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL);
568 if (!wm)
569 return -ENOMEM;
570 mutex_init(&wm->codec_mutex);
571
572 wm->dev = dev;
573 dev->driver_data = wm;
574 wm->ac97 = to_ac97_t(dev);
575
576 /* check that we have a supported codec */
577 id = wm97xx_reg_read(wm, AC97_VENDOR_ID1);
578 if (id != WM97XX_ID1) {
579 dev_err(dev, "Device with vendor %04x is not a wm97xx\n", id);
580 ret = -ENODEV;
581 goto alloc_err;
582 }
583
584 wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2);
585
586 dev_info(wm->dev, "detected a wm97%02x codec\n", wm->id & 0xff);
587
588 switch (wm->id & 0xff) {
589#ifdef CONFIG_TOUCHSCREEN_WM9705
590 case 0x05:
591 wm->codec = &wm9705_codec;
592 break;
593#endif
594#ifdef CONFIG_TOUCHSCREEN_WM9712
595 case 0x12:
596 wm->codec = &wm9712_codec;
597 break;
598#endif
599#ifdef CONFIG_TOUCHSCREEN_WM9713
600 case 0x13:
601 wm->codec = &wm9713_codec;
602 break;
603#endif
604 default:
605 dev_err(wm->dev, "Support for wm97%02x not compiled in.\n",
606 wm->id & 0xff);
607 ret = -ENODEV;
608 goto alloc_err;
609 }
610
611 wm->input_dev = input_allocate_device();
612 if (wm->input_dev == NULL) {
613 ret = -ENOMEM;
614 goto alloc_err;
615 }
616
617 /* set up touch configuration */
618 wm->input_dev->name = "wm97xx touchscreen";
619 wm->input_dev->open = wm97xx_ts_input_open;
620 wm->input_dev->close = wm97xx_ts_input_close;
621 set_bit(EV_ABS, wm->input_dev->evbit);
622 set_bit(ABS_X, wm->input_dev->absbit);
623 set_bit(ABS_Y, wm->input_dev->absbit);
624 set_bit(ABS_PRESSURE, wm->input_dev->absbit);
625 input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
626 abs_x[2], 0);
627 input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
628 abs_y[2], 0);
629 input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
630 abs_p[2], 0);
631 input_set_drvdata(wm->input_dev, wm);
632 wm->input_dev->dev.parent = dev;
633 ret = input_register_device(wm->input_dev);
634 if (ret < 0)
635 goto dev_alloc_err;
636
637 /* set up physical characteristics */
638 wm->codec->phy_init(wm);
639
640 /* load gpio cache */
641 wm->gpio[0] = wm97xx_reg_read(wm, AC97_GPIO_CFG);
642 wm->gpio[1] = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
643 wm->gpio[2] = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
644 wm->gpio[3] = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
645 wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
646 wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE);
647
648 /* register our battery device */
649 wm->battery_dev = platform_device_alloc("wm97xx-battery", -1);
650 if (!wm->battery_dev) {
651 ret = -ENOMEM;
652 goto batt_err;
653 }
654 platform_set_drvdata(wm->battery_dev, wm);
655 wm->battery_dev->dev.parent = dev;
656 ret = platform_device_add(wm->battery_dev);
657 if (ret < 0)
658 goto batt_reg_err;
659
660 /* register our extended touch device (for machine specific
661 * extensions) */
662 wm->touch_dev = platform_device_alloc("wm97xx-touch", -1);
663 if (!wm->touch_dev) {
664 ret = -ENOMEM;
665 goto touch_err;
666 }
667 platform_set_drvdata(wm->touch_dev, wm);
668 wm->touch_dev->dev.parent = dev;
669 ret = platform_device_add(wm->touch_dev);
670 if (ret < 0)
671 goto touch_reg_err;
672
673 return ret;
674
675 touch_reg_err:
676 platform_device_put(wm->touch_dev);
677 touch_err:
678 platform_device_unregister(wm->battery_dev);
679 wm->battery_dev = NULL;
680 batt_reg_err:
681 platform_device_put(wm->battery_dev);
682 batt_err:
683 input_unregister_device(wm->input_dev);
684 wm->input_dev = NULL;
685 dev_alloc_err:
686 input_free_device(wm->input_dev);
687 alloc_err:
688 kfree(wm);
689
690 return ret;
691}
692
693static int wm97xx_remove(struct device *dev)
694{
695 struct wm97xx *wm = dev_get_drvdata(dev);
696
697 platform_device_unregister(wm->battery_dev);
698 platform_device_unregister(wm->touch_dev);
699 input_unregister_device(wm->input_dev);
700 kfree(wm);
701
702 return 0;
703}
704
705#ifdef CONFIG_PM
706static int wm97xx_suspend(struct device *dev, pm_message_t state)
707{
708 struct wm97xx *wm = dev_get_drvdata(dev);
709 u16 reg;
710 int suspend_mode;
711
712 if (device_may_wakeup(&wm->input_dev->dev))
713 suspend_mode = wm->suspend_mode;
714 else
715 suspend_mode = 0;
716
717 if (wm->input_dev->users)
718 cancel_delayed_work_sync(&wm->ts_reader);
719
720 /* Power down the digitiser (bypassing the cache for resume) */
721 reg = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER2);
722 reg &= ~WM97XX_PRP_DET_DIG;
723 if (wm->input_dev->users)
724 reg |= suspend_mode;
725 wm->ac97->bus->ops->write(wm->ac97, AC97_WM97XX_DIGITISER2, reg);
726
727 /* WM9713 has an additional power bit - turn it off if there
728 * are no users or if suspend mode is zero. */
729 if (wm->id == WM9713_ID2 &&
730 (!wm->input_dev->users || !suspend_mode)) {
731 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) | 0x8000;
732 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg);
733 }
734
735 return 0;
736}
737
738static int wm97xx_resume(struct device *dev)
739{
740 struct wm97xx *wm = dev_get_drvdata(dev);
741
742 /* restore digitiser and gpios */
743 if (wm->id == WM9713_ID2) {
744 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]);
745 wm97xx_reg_write(wm, 0x5a, wm->misc);
746 if (wm->input_dev->users) {
747 u16 reg;
748 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) & 0x7fff;
749 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg);
750 }
751 }
752
753 wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig[1]);
754 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2]);
755
756 wm97xx_reg_write(wm, AC97_GPIO_CFG, wm->gpio[0]);
757 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, wm->gpio[1]);
758 wm97xx_reg_write(wm, AC97_GPIO_STICKY, wm->gpio[2]);
759 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, wm->gpio[3]);
760 wm97xx_reg_write(wm, AC97_GPIO_STATUS, wm->gpio[4]);
761 wm97xx_reg_write(wm, AC97_MISC_AFE, wm->gpio[5]);
762
763 if (wm->input_dev->users && !wm->pen_irq) {
764 wm->ts_reader_interval = wm->ts_reader_min_interval;
765 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
766 wm->ts_reader_interval);
767 }
768
769 return 0;
770}
771
772#else
773#define wm97xx_suspend NULL
774#define wm97xx_resume NULL
775#endif
776
777/*
778 * Machine specific operations
779 */
780int wm97xx_register_mach_ops(struct wm97xx *wm,
781 struct wm97xx_mach_ops *mach_ops)
782{
783 mutex_lock(&wm->codec_mutex);
784 if (wm->mach_ops) {
785 mutex_unlock(&wm->codec_mutex);
786 return -EINVAL;
787 }
788 wm->mach_ops = mach_ops;
789 mutex_unlock(&wm->codec_mutex);
790
791 return 0;
792}
793EXPORT_SYMBOL_GPL(wm97xx_register_mach_ops);
794
795void wm97xx_unregister_mach_ops(struct wm97xx *wm)
796{
797 mutex_lock(&wm->codec_mutex);
798 wm->mach_ops = NULL;
799 mutex_unlock(&wm->codec_mutex);
800}
801EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops);
802
803static struct device_driver wm97xx_driver = {
804 .name = "ac97",
805 .bus = &ac97_bus_type,
806 .owner = THIS_MODULE,
807 .probe = wm97xx_probe,
808 .remove = wm97xx_remove,
809 .suspend = wm97xx_suspend,
810 .resume = wm97xx_resume,
811};
812
813static int __init wm97xx_init(void)
814{
815 return driver_register(&wm97xx_driver);
816}
817
818static void __exit wm97xx_exit(void)
819{
820 driver_unregister(&wm97xx_driver);
821}
822
823module_init(wm97xx_init);
824module_exit(wm97xx_exit);
825
826/* Module information */
827MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
828MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");
829MODULE_LICENSE("GPL");
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/xen-kbdfront.c
new file mode 100644
index 000000000000..0f47f4697cdf
--- /dev/null
+++ b/drivers/input/xen-kbdfront.c
@@ -0,0 +1,340 @@
1/*
2 * Xen para-virtual input device
3 *
4 * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
5 * Copyright (C) 2006-2008 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
6 *
7 * Based on linux/drivers/input/mouse/sermouse.c
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 */
13
14/*
15 * TODO:
16 *
17 * Switch to grant tables together with xen-fbfront.c.
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/module.h>
23#include <linux/input.h>
24#include <asm/xen/hypervisor.h>
25#include <xen/events.h>
26#include <xen/page.h>
27#include <xen/interface/io/fbif.h>
28#include <xen/interface/io/kbdif.h>
29#include <xen/xenbus.h>
30
31struct xenkbd_info {
32 struct input_dev *kbd;
33 struct input_dev *ptr;
34 struct xenkbd_page *page;
35 int irq;
36 struct xenbus_device *xbdev;
37 char phys[32];
38};
39
40static int xenkbd_remove(struct xenbus_device *);
41static int xenkbd_connect_backend(struct xenbus_device *, struct xenkbd_info *);
42static void xenkbd_disconnect_backend(struct xenkbd_info *);
43
44/*
45 * Note: if you need to send out events, see xenfb_do_update() for how
46 * to do that.
47 */
48
49static irqreturn_t input_handler(int rq, void *dev_id)
50{
51 struct xenkbd_info *info = dev_id;
52 struct xenkbd_page *page = info->page;
53 __u32 cons, prod;
54
55 prod = page->in_prod;
56 if (prod == page->in_cons)
57 return IRQ_HANDLED;
58 rmb(); /* ensure we see ring contents up to prod */
59 for (cons = page->in_cons; cons != prod; cons++) {
60 union xenkbd_in_event *event;
61 struct input_dev *dev;
62 event = &XENKBD_IN_RING_REF(page, cons);
63
64 dev = info->ptr;
65 switch (event->type) {
66 case XENKBD_TYPE_MOTION:
67 input_report_rel(dev, REL_X, event->motion.rel_x);
68 input_report_rel(dev, REL_Y, event->motion.rel_y);
69 break;
70 case XENKBD_TYPE_KEY:
71 dev = NULL;
72 if (test_bit(event->key.keycode, info->kbd->keybit))
73 dev = info->kbd;
74 if (test_bit(event->key.keycode, info->ptr->keybit))
75 dev = info->ptr;
76 if (dev)
77 input_report_key(dev, event->key.keycode,
78 event->key.pressed);
79 else
80 printk(KERN_WARNING
81 "xenkbd: unhandled keycode 0x%x\n",
82 event->key.keycode);
83 break;
84 case XENKBD_TYPE_POS:
85 input_report_abs(dev, ABS_X, event->pos.abs_x);
86 input_report_abs(dev, ABS_Y, event->pos.abs_y);
87 break;
88 }
89 if (dev)
90 input_sync(dev);
91 }
92 mb(); /* ensure we got ring contents */
93 page->in_cons = cons;
94 notify_remote_via_irq(info->irq);
95
96 return IRQ_HANDLED;
97}
98
99static int __devinit xenkbd_probe(struct xenbus_device *dev,
100 const struct xenbus_device_id *id)
101{
102 int ret, i;
103 struct xenkbd_info *info;
104 struct input_dev *kbd, *ptr;
105
106 info = kzalloc(sizeof(*info), GFP_KERNEL);
107 if (!info) {
108 xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
109 return -ENOMEM;
110 }
111 dev->dev.driver_data = info;
112 info->xbdev = dev;
113 info->irq = -1;
114 snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename);
115
116 info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
117 if (!info->page)
118 goto error_nomem;
119
120 /* keyboard */
121 kbd = input_allocate_device();
122 if (!kbd)
123 goto error_nomem;
124 kbd->name = "Xen Virtual Keyboard";
125 kbd->phys = info->phys;
126 kbd->id.bustype = BUS_PCI;
127 kbd->id.vendor = 0x5853;
128 kbd->id.product = 0xffff;
129 kbd->evbit[0] = BIT(EV_KEY);
130 for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
131 set_bit(i, kbd->keybit);
132 for (i = KEY_OK; i < KEY_MAX; i++)
133 set_bit(i, kbd->keybit);
134
135 ret = input_register_device(kbd);
136 if (ret) {
137 input_free_device(kbd);
138 xenbus_dev_fatal(dev, ret, "input_register_device(kbd)");
139 goto error;
140 }
141 info->kbd = kbd;
142
143 /* pointing device */
144 ptr = input_allocate_device();
145 if (!ptr)
146 goto error_nomem;
147 ptr->name = "Xen Virtual Pointer";
148 ptr->phys = info->phys;
149 ptr->id.bustype = BUS_PCI;
150 ptr->id.vendor = 0x5853;
151 ptr->id.product = 0xfffe;
152 ptr->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
153 for (i = BTN_LEFT; i <= BTN_TASK; i++)
154 set_bit(i, ptr->keybit);
155 ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y);
156 input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0);
157 input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0);
158
159 ret = input_register_device(ptr);
160 if (ret) {
161 input_free_device(ptr);
162 xenbus_dev_fatal(dev, ret, "input_register_device(ptr)");
163 goto error;
164 }
165 info->ptr = ptr;
166
167 ret = xenkbd_connect_backend(dev, info);
168 if (ret < 0)
169 goto error;
170
171 return 0;
172
173 error_nomem:
174 ret = -ENOMEM;
175 xenbus_dev_fatal(dev, ret, "allocating device memory");
176 error:
177 xenkbd_remove(dev);
178 return ret;
179}
180
181static int xenkbd_resume(struct xenbus_device *dev)
182{
183 struct xenkbd_info *info = dev->dev.driver_data;
184
185 xenkbd_disconnect_backend(info);
186 memset(info->page, 0, PAGE_SIZE);
187 return xenkbd_connect_backend(dev, info);
188}
189
190static int xenkbd_remove(struct xenbus_device *dev)
191{
192 struct xenkbd_info *info = dev->dev.driver_data;
193
194 xenkbd_disconnect_backend(info);
195 if (info->kbd)
196 input_unregister_device(info->kbd);
197 if (info->ptr)
198 input_unregister_device(info->ptr);
199 free_page((unsigned long)info->page);
200 kfree(info);
201 return 0;
202}
203
204static int xenkbd_connect_backend(struct xenbus_device *dev,
205 struct xenkbd_info *info)
206{
207 int ret, evtchn;
208 struct xenbus_transaction xbt;
209
210 ret = xenbus_alloc_evtchn(dev, &evtchn);
211 if (ret)
212 return ret;
213 ret = bind_evtchn_to_irqhandler(evtchn, input_handler,
214 0, dev->devicetype, info);
215 if (ret < 0) {
216 xenbus_free_evtchn(dev, evtchn);
217 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
218 return ret;
219 }
220 info->irq = ret;
221
222 again:
223 ret = xenbus_transaction_start(&xbt);
224 if (ret) {
225 xenbus_dev_fatal(dev, ret, "starting transaction");
226 return ret;
227 }
228 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
229 virt_to_mfn(info->page));
230 if (ret)
231 goto error_xenbus;
232 ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
233 evtchn);
234 if (ret)
235 goto error_xenbus;
236 ret = xenbus_transaction_end(xbt, 0);
237 if (ret) {
238 if (ret == -EAGAIN)
239 goto again;
240 xenbus_dev_fatal(dev, ret, "completing transaction");
241 return ret;
242 }
243
244 xenbus_switch_state(dev, XenbusStateInitialised);
245 return 0;
246
247 error_xenbus:
248 xenbus_transaction_end(xbt, 1);
249 xenbus_dev_fatal(dev, ret, "writing xenstore");
250 return ret;
251}
252
253static void xenkbd_disconnect_backend(struct xenkbd_info *info)
254{
255 if (info->irq >= 0)
256 unbind_from_irqhandler(info->irq, info);
257 info->irq = -1;
258}
259
260static void xenkbd_backend_changed(struct xenbus_device *dev,
261 enum xenbus_state backend_state)
262{
263 struct xenkbd_info *info = dev->dev.driver_data;
264 int ret, val;
265
266 switch (backend_state) {
267 case XenbusStateInitialising:
268 case XenbusStateInitialised:
269 case XenbusStateUnknown:
270 case XenbusStateClosed:
271 break;
272
273 case XenbusStateInitWait:
274InitWait:
275 ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
276 "feature-abs-pointer", "%d", &val);
277 if (ret < 0)
278 val = 0;
279 if (val) {
280 ret = xenbus_printf(XBT_NIL, info->xbdev->nodename,
281 "request-abs-pointer", "1");
282 if (ret)
283 printk(KERN_WARNING
284 "xenkbd: can't request abs-pointer");
285 }
286 xenbus_switch_state(dev, XenbusStateConnected);
287 break;
288
289 case XenbusStateConnected:
290 /*
291 * Work around xenbus race condition: If backend goes
292 * through InitWait to Connected fast enough, we can
293 * get Connected twice here.
294 */
295 if (dev->state != XenbusStateConnected)
296 goto InitWait; /* no InitWait seen yet, fudge it */
297 break;
298
299 case XenbusStateClosing:
300 xenbus_frontend_closed(dev);
301 break;
302 }
303}
304
305static struct xenbus_device_id xenkbd_ids[] = {
306 { "vkbd" },
307 { "" }
308};
309
310static struct xenbus_driver xenkbd = {
311 .name = "vkbd",
312 .owner = THIS_MODULE,
313 .ids = xenkbd_ids,
314 .probe = xenkbd_probe,
315 .remove = xenkbd_remove,
316 .resume = xenkbd_resume,
317 .otherend_changed = xenkbd_backend_changed,
318};
319
320static int __init xenkbd_init(void)
321{
322 if (!is_running_on_xen())
323 return -ENODEV;
324
325 /* Nothing to do if running in dom0. */
326 if (is_initial_xendomain())
327 return -ENODEV;
328
329 return xenbus_register_frontend(&xenkbd);
330}
331
332static void __exit xenkbd_cleanup(void)
333{
334 xenbus_unregister_driver(&xenkbd);
335}
336
337module_init(xenkbd_init);
338module_exit(xenkbd_cleanup);
339
340MODULE_LICENSE("GPL");
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index eb97c4113d78..86a369bc57d6 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -65,6 +65,12 @@ config LEDS_NET48XX
65 This option enables support for the Soekris net4801 and net4826 error 65 This option enables support for the Soekris net4801 and net4826 error
66 LED. 66 LED.
67 67
68config LEDS_FSG
69 tristate "LED Support for the Freecom FSG-3"
70 depends on LEDS_CLASS && MACH_FSG
71 help
72 This option enables support for the LEDs on the Freecom FSG-3.
73
68config LEDS_WRAP 74config LEDS_WRAP
69 tristate "LED Support for the WRAP series LEDs" 75 tristate "LED Support for the WRAP series LEDs"
70 depends on LEDS_CLASS && SCx200_GPIO 76 depends on LEDS_CLASS && SCx200_GPIO
@@ -127,6 +133,7 @@ config LEDS_CLEVO_MAIL
127 133
128 This module can drive the mail LED for the following notebooks: 134 This module can drive the mail LED for the following notebooks:
129 135
136 Clevo D400P
130 Clevo D410J 137 Clevo D410J
131 Clevo D410V 138 Clevo D410V
132 Clevo D400V/D470V (not tested, but might work) 139 Clevo D400V/D470V (not tested, but might work)
@@ -134,6 +141,9 @@ config LEDS_CLEVO_MAIL
134 Clevo M5x0N (not tested, but might work) 141 Clevo M5x0N (not tested, but might work)
135 Positivo Mobile (Clevo M5x0V) 142 Positivo Mobile (Clevo M5x0V)
136 143
144 If your model is not listed here you can try the "nodetect"
145 module paramter.
146
137 To compile this driver as a module, choose M here: the 147 To compile this driver as a module, choose M here: the
138 module will be called leds-clevo-mail. 148 module will be called leds-clevo-mail.
139 149
@@ -173,4 +183,11 @@ config LEDS_TRIGGER_HEARTBEAT
173 load average. 183 load average.
174 If unsure, say Y. 184 If unsure, say Y.
175 185
186config LEDS_TRIGGER_DEFAULT_ON
187 tristate "LED Default ON Trigger"
188 depends on LEDS_TRIGGERS
189 help
190 This allows LEDs to be initialised in the ON state.
191 If unsure, say Y.
192
176endif # NEW_LEDS 193endif # NEW_LEDS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index e54f42da21a2..973d626f5f4a 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -20,8 +20,10 @@ obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
20obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o 20obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o
21obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o 21obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
22obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o 22obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
23obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
23 24
24# LED Triggers 25# LED Triggers
25obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o 26obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
26obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o 27obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
27obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o 28obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
29obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 63aad90247c4..ac05a928f764 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -24,6 +24,12 @@
24 24
25static struct class *leds_class; 25static struct class *leds_class;
26 26
27static void led_update_brightness(struct led_classdev *led_cdev)
28{
29 if (led_cdev->brightness_get)
30 led_cdev->brightness = led_cdev->brightness_get(led_cdev);
31}
32
27static ssize_t led_brightness_show(struct device *dev, 33static ssize_t led_brightness_show(struct device *dev,
28 struct device_attribute *attr, char *buf) 34 struct device_attribute *attr, char *buf)
29{ 35{
@@ -31,6 +37,7 @@ static ssize_t led_brightness_show(struct device *dev,
31 ssize_t ret = 0; 37 ssize_t ret = 0;
32 38
33 /* no lock needed for this */ 39 /* no lock needed for this */
40 led_update_brightness(led_cdev);
34 sprintf(buf, "%u\n", led_cdev->brightness); 41 sprintf(buf, "%u\n", led_cdev->brightness);
35 ret = strlen(buf) + 1; 42 ret = strlen(buf) + 1;
36 43
@@ -51,6 +58,9 @@ static ssize_t led_brightness_store(struct device *dev,
51 58
52 if (count == size) { 59 if (count == size) {
53 ret = count; 60 ret = count;
61
62 if (state == LED_OFF)
63 led_trigger_remove(led_cdev);
54 led_set_brightness(led_cdev, state); 64 led_set_brightness(led_cdev, state);
55 } 65 }
56 66
@@ -110,6 +120,8 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
110 list_add_tail(&led_cdev->node, &leds_list); 120 list_add_tail(&led_cdev->node, &leds_list);
111 up_write(&leds_list_lock); 121 up_write(&leds_list_lock);
112 122
123 led_update_brightness(led_cdev);
124
113#ifdef CONFIG_LEDS_TRIGGERS 125#ifdef CONFIG_LEDS_TRIGGERS
114 init_rwsem(&led_cdev->trigger_lock); 126 init_rwsem(&led_cdev->trigger_lock);
115 127
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 5d1ca10524b6..016d19f5486f 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -19,7 +19,7 @@
19#include "leds.h" 19#include "leds.h"
20 20
21DECLARE_RWSEM(leds_list_lock); 21DECLARE_RWSEM(leds_list_lock);
22LIST_HEAD(leds_list); 22EXPORT_SYMBOL_GPL(leds_list_lock);
23 23
24LIST_HEAD(leds_list);
24EXPORT_SYMBOL_GPL(leds_list); 25EXPORT_SYMBOL_GPL(leds_list);
25EXPORT_SYMBOL_GPL(leds_list_lock);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 13c9026d68af..0f242b3f09b6 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -29,6 +29,8 @@
29static DECLARE_RWSEM(triggers_list_lock); 29static DECLARE_RWSEM(triggers_list_lock);
30static LIST_HEAD(trigger_list); 30static LIST_HEAD(trigger_list);
31 31
32 /* Used by LED Class */
33
32ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, 34ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
33 const char *buf, size_t count) 35 const char *buf, size_t count)
34{ 36{
@@ -45,9 +47,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
45 trigger_name[len - 1] = '\0'; 47 trigger_name[len - 1] = '\0';
46 48
47 if (!strcmp(trigger_name, "none")) { 49 if (!strcmp(trigger_name, "none")) {
48 down_write(&led_cdev->trigger_lock); 50 led_trigger_remove(led_cdev);
49 led_trigger_set(led_cdev, NULL);
50 up_write(&led_cdev->trigger_lock);
51 return count; 51 return count;
52 } 52 }
53 53
@@ -66,7 +66,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
66 66
67 return -EINVAL; 67 return -EINVAL;
68} 68}
69 69EXPORT_SYMBOL_GPL(led_trigger_store);
70 70
71ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, 71ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
72 char *buf) 72 char *buf)
@@ -96,24 +96,7 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
96 len += sprintf(len+buf, "\n"); 96 len += sprintf(len+buf, "\n");
97 return len; 97 return len;
98} 98}
99 99EXPORT_SYMBOL_GPL(led_trigger_show);
100void led_trigger_event(struct led_trigger *trigger,
101 enum led_brightness brightness)
102{
103 struct list_head *entry;
104
105 if (!trigger)
106 return;
107
108 read_lock(&trigger->leddev_list_lock);
109 list_for_each(entry, &trigger->led_cdevs) {
110 struct led_classdev *led_cdev;
111
112 led_cdev = list_entry(entry, struct led_classdev, trig_list);
113 led_set_brightness(led_cdev, brightness);
114 }
115 read_unlock(&trigger->leddev_list_lock);
116}
117 100
118/* Caller must ensure led_cdev->trigger_lock held */ 101/* Caller must ensure led_cdev->trigger_lock held */
119void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) 102void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
@@ -124,7 +107,8 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
124 if (led_cdev->trigger) { 107 if (led_cdev->trigger) {
125 write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags); 108 write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags);
126 list_del(&led_cdev->trig_list); 109 list_del(&led_cdev->trig_list);
127 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags); 110 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock,
111 flags);
128 if (led_cdev->trigger->deactivate) 112 if (led_cdev->trigger->deactivate)
129 led_cdev->trigger->deactivate(led_cdev); 113 led_cdev->trigger->deactivate(led_cdev);
130 led_set_brightness(led_cdev, LED_OFF); 114 led_set_brightness(led_cdev, LED_OFF);
@@ -138,6 +122,15 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
138 } 122 }
139 led_cdev->trigger = trigger; 123 led_cdev->trigger = trigger;
140} 124}
125EXPORT_SYMBOL_GPL(led_trigger_set);
126
127void led_trigger_remove(struct led_classdev *led_cdev)
128{
129 down_write(&led_cdev->trigger_lock);
130 led_trigger_set(led_cdev, NULL);
131 up_write(&led_cdev->trigger_lock);
132}
133EXPORT_SYMBOL_GPL(led_trigger_remove);
141 134
142void led_trigger_set_default(struct led_classdev *led_cdev) 135void led_trigger_set_default(struct led_classdev *led_cdev)
143{ 136{
@@ -155,6 +148,9 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
155 up_write(&led_cdev->trigger_lock); 148 up_write(&led_cdev->trigger_lock);
156 up_read(&triggers_list_lock); 149 up_read(&triggers_list_lock);
157} 150}
151EXPORT_SYMBOL_GPL(led_trigger_set_default);
152
153/* LED Trigger Interface */
158 154
159int led_trigger_register(struct led_trigger *trigger) 155int led_trigger_register(struct led_trigger *trigger)
160{ 156{
@@ -181,26 +177,7 @@ int led_trigger_register(struct led_trigger *trigger)
181 177
182 return 0; 178 return 0;
183} 179}
184 180EXPORT_SYMBOL_GPL(led_trigger_register);
185void led_trigger_register_simple(const char *name, struct led_trigger **tp)
186{
187 struct led_trigger *trigger;
188 int err;
189
190 trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
191
192 if (trigger) {
193 trigger->name = name;
194 err = led_trigger_register(trigger);
195 if (err < 0)
196 printk(KERN_WARNING "LED trigger %s failed to register"
197 " (%d)\n", name, err);
198 } else
199 printk(KERN_WARNING "LED trigger %s failed to register"
200 " (no memory)\n", name);
201
202 *tp = trigger;
203}
204 181
205void led_trigger_unregister(struct led_trigger *trigger) 182void led_trigger_unregister(struct led_trigger *trigger)
206{ 183{
@@ -221,6 +198,49 @@ void led_trigger_unregister(struct led_trigger *trigger)
221 } 198 }
222 up_read(&leds_list_lock); 199 up_read(&leds_list_lock);
223} 200}
201EXPORT_SYMBOL_GPL(led_trigger_unregister);
202
203/* Simple LED Tigger Interface */
204
205void led_trigger_event(struct led_trigger *trigger,
206 enum led_brightness brightness)
207{
208 struct list_head *entry;
209
210 if (!trigger)
211 return;
212
213 read_lock(&trigger->leddev_list_lock);
214 list_for_each(entry, &trigger->led_cdevs) {
215 struct led_classdev *led_cdev;
216
217 led_cdev = list_entry(entry, struct led_classdev, trig_list);
218 led_set_brightness(led_cdev, brightness);
219 }
220 read_unlock(&trigger->leddev_list_lock);
221}
222EXPORT_SYMBOL_GPL(led_trigger_event);
223
224void led_trigger_register_simple(const char *name, struct led_trigger **tp)
225{
226 struct led_trigger *trigger;
227 int err;
228
229 trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
230
231 if (trigger) {
232 trigger->name = name;
233 err = led_trigger_register(trigger);
234 if (err < 0)
235 printk(KERN_WARNING "LED trigger %s failed to register"
236 " (%d)\n", name, err);
237 } else
238 printk(KERN_WARNING "LED trigger %s failed to register"
239 " (no memory)\n", name);
240
241 *tp = trigger;
242}
243EXPORT_SYMBOL_GPL(led_trigger_register_simple);
224 244
225void led_trigger_unregister_simple(struct led_trigger *trigger) 245void led_trigger_unregister_simple(struct led_trigger *trigger)
226{ 246{
@@ -228,21 +248,7 @@ void led_trigger_unregister_simple(struct led_trigger *trigger)
228 led_trigger_unregister(trigger); 248 led_trigger_unregister(trigger);
229 kfree(trigger); 249 kfree(trigger);
230} 250}
231
232/* Used by LED Class */
233EXPORT_SYMBOL_GPL(led_trigger_set);
234EXPORT_SYMBOL_GPL(led_trigger_set_default);
235EXPORT_SYMBOL_GPL(led_trigger_show);
236EXPORT_SYMBOL_GPL(led_trigger_store);
237
238/* LED Trigger Interface */
239EXPORT_SYMBOL_GPL(led_trigger_register);
240EXPORT_SYMBOL_GPL(led_trigger_unregister);
241
242/* Simple LED Tigger Interface */
243EXPORT_SYMBOL_GPL(led_trigger_register_simple);
244EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); 251EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);
245EXPORT_SYMBOL_GPL(led_trigger_event);
246 252
247MODULE_AUTHOR("Richard Purdie"); 253MODULE_AUTHOR("Richard Purdie");
248MODULE_LICENSE("GPL"); 254MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
index 5750b08b601f..eb3415e88f43 100644
--- a/drivers/leds/leds-clevo-mail.c
+++ b/drivers/leds/leds-clevo-mail.c
@@ -14,7 +14,7 @@
14#define CLEVO_MAIL_LED_BLINK_1HZ 0x008A 14#define CLEVO_MAIL_LED_BLINK_1HZ 0x008A
15#define CLEVO_MAIL_LED_BLINK_0_5HZ 0x0083 15#define CLEVO_MAIL_LED_BLINK_0_5HZ 0x0083
16 16
17MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>"); 17MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>");
18MODULE_DESCRIPTION("Clevo mail LED driver"); 18MODULE_DESCRIPTION("Clevo mail LED driver");
19MODULE_LICENSE("GPL"); 19MODULE_LICENSE("GPL");
20 20
@@ -69,6 +69,16 @@ static struct dmi_system_id __initdata mail_led_whitelist[] = {
69 }, 69 },
70 { 70 {
71 .callback = clevo_mail_led_dmi_callback, 71 .callback = clevo_mail_led_dmi_callback,
72 .ident = "Clevo D400P",
73 .matches = {
74 DMI_MATCH(DMI_BOARD_VENDOR, "Clevo"),
75 DMI_MATCH(DMI_BOARD_NAME, "D400P"),
76 DMI_MATCH(DMI_BOARD_VERSION, "Rev.A"),
77 DMI_MATCH(DMI_PRODUCT_VERSION, "0106")
78 }
79 },
80 {
81 .callback = clevo_mail_led_dmi_callback,
72 .ident = "Clevo D410V", 82 .ident = "Clevo D410V",
73 .matches = { 83 .matches = {
74 DMI_MATCH(DMI_BOARD_VENDOR, "Clevo, Co."), 84 DMI_MATCH(DMI_BOARD_VENDOR, "Clevo, Co."),
@@ -93,8 +103,8 @@ static void clevo_mail_led_set(struct led_classdev *led_cdev,
93} 103}
94 104
95static int clevo_mail_led_blink(struct led_classdev *led_cdev, 105static int clevo_mail_led_blink(struct led_classdev *led_cdev,
96 unsigned long* delay_on, 106 unsigned long *delay_on,
97 unsigned long* delay_off) 107 unsigned long *delay_off)
98{ 108{
99 int status = -EINVAL; 109 int status = -EINVAL;
100 110
diff --git a/drivers/leds/leds-cobalt-qube.c b/drivers/leds/leds-cobalt-qube.c
index 096881a11b1a..059aa2924b1c 100644
--- a/drivers/leds/leds-cobalt-qube.c
+++ b/drivers/leds/leds-cobalt-qube.c
@@ -18,7 +18,7 @@ static void __iomem *led_port;
18static u8 led_value; 18static u8 led_value;
19 19
20static void qube_front_led_set(struct led_classdev *led_cdev, 20static void qube_front_led_set(struct led_classdev *led_cdev,
21 enum led_brightness brightness) 21 enum led_brightness brightness)
22{ 22{
23 if (brightness) 23 if (brightness)
24 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT; 24 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
diff --git a/drivers/leds/leds-cobalt-raq.c b/drivers/leds/leds-cobalt-raq.c
index 6ebfff341e6c..ff0e8c3fbf9b 100644
--- a/drivers/leds/leds-cobalt-raq.c
+++ b/drivers/leds/leds-cobalt-raq.c
@@ -15,7 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/io.h> 21#include <linux/io.h>
@@ -33,7 +33,7 @@ static u8 led_value;
33static DEFINE_SPINLOCK(led_value_lock); 33static DEFINE_SPINLOCK(led_value_lock);
34 34
35static void raq_web_led_set(struct led_classdev *led_cdev, 35static void raq_web_led_set(struct led_classdev *led_cdev,
36 enum led_brightness brightness) 36 enum led_brightness brightness)
37{ 37{
38 unsigned long flags; 38 unsigned long flags;
39 39
@@ -54,7 +54,7 @@ static struct led_classdev raq_web_led = {
54}; 54};
55 55
56static void raq_power_off_led_set(struct led_classdev *led_cdev, 56static void raq_power_off_led_set(struct led_classdev *led_cdev,
57 enum led_brightness brightness) 57 enum led_brightness brightness)
58{ 58{
59 unsigned long flags; 59 unsigned long flags;
60 60
diff --git a/drivers/leds/leds-corgi.c b/drivers/leds/leds-corgi.c
index 29e931f89f9c..a709704b9f93 100644
--- a/drivers/leds/leds-corgi.c
+++ b/drivers/leds/leds-corgi.c
@@ -21,7 +21,8 @@
21#include <asm/arch/pxa-regs.h> 21#include <asm/arch/pxa-regs.h>
22#include <asm/hardware/scoop.h> 22#include <asm/hardware/scoop.h>
23 23
24static void corgiled_amber_set(struct led_classdev *led_cdev, enum led_brightness value) 24static void corgiled_amber_set(struct led_classdev *led_cdev,
25 enum led_brightness value)
25{ 26{
26 if (value) 27 if (value)
27 GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE); 28 GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
@@ -29,7 +30,8 @@ static void corgiled_amber_set(struct led_classdev *led_cdev, enum led_brightnes
29 GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE); 30 GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
30} 31}
31 32
32static void corgiled_green_set(struct led_classdev *led_cdev, enum led_brightness value) 33static void corgiled_green_set(struct led_classdev *led_cdev,
34 enum led_brightness value)
33{ 35{
34 if (value) 36 if (value)
35 set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN); 37 set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
@@ -53,7 +55,8 @@ static struct led_classdev corgi_green_led = {
53static int corgiled_suspend(struct platform_device *dev, pm_message_t state) 55static int corgiled_suspend(struct platform_device *dev, pm_message_t state)
54{ 56{
55#ifdef CONFIG_LEDS_TRIGGERS 57#ifdef CONFIG_LEDS_TRIGGERS
56 if (corgi_amber_led.trigger && strcmp(corgi_amber_led.trigger->name, "sharpsl-charge")) 58 if (corgi_amber_led.trigger &&
59 strcmp(corgi_amber_led.trigger->name, "sharpsl-charge"))
57#endif 60#endif
58 led_classdev_suspend(&corgi_amber_led); 61 led_classdev_suspend(&corgi_amber_led);
59 led_classdev_suspend(&corgi_green_led); 62 led_classdev_suspend(&corgi_green_led);
@@ -110,7 +113,7 @@ static int __init corgiled_init(void)
110 113
111static void __exit corgiled_exit(void) 114static void __exit corgiled_exit(void)
112{ 115{
113 platform_driver_unregister(&corgiled_driver); 116 platform_driver_unregister(&corgiled_driver);
114} 117}
115 118
116module_init(corgiled_init); 119module_init(corgiled_init);
diff --git a/drivers/leds/leds-fsg.c b/drivers/leds/leds-fsg.c
new file mode 100644
index 000000000000..a7421b8c47d8
--- /dev/null
+++ b/drivers/leds/leds-fsg.c
@@ -0,0 +1,261 @@
1/*
2 * LED Driver for the Freecom FSG-3
3 *
4 * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
5 *
6 * Author: Rod Whitby <rod@whitby.id.au>
7 *
8 * Based on leds-spitz.c
9 * Copyright 2005-2006 Openedhand Ltd.
10 * Author: Richard Purdie <rpurdie@openedhand.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 */
17
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/platform_device.h>
21#include <linux/leds.h>
22#include <asm/arch/hardware.h>
23#include <asm/io.h>
24
25static short __iomem *latch_address;
26static unsigned short latch_value;
27
28
29static void fsg_led_wlan_set(struct led_classdev *led_cdev,
30 enum led_brightness value)
31{
32 if (value) {
33 latch_value &= ~(1 << FSG_LED_WLAN_BIT);
34 *latch_address = latch_value;
35 } else {
36 latch_value |= (1 << FSG_LED_WLAN_BIT);
37 *latch_address = latch_value;
38 }
39}
40
41static void fsg_led_wan_set(struct led_classdev *led_cdev,
42 enum led_brightness value)
43{
44 if (value) {
45 latch_value &= ~(1 << FSG_LED_WAN_BIT);
46 *latch_address = latch_value;
47 } else {
48 latch_value |= (1 << FSG_LED_WAN_BIT);
49 *latch_address = latch_value;
50 }
51}
52
53static void fsg_led_sata_set(struct led_classdev *led_cdev,
54 enum led_brightness value)
55{
56 if (value) {
57 latch_value &= ~(1 << FSG_LED_SATA_BIT);
58 *latch_address = latch_value;
59 } else {
60 latch_value |= (1 << FSG_LED_SATA_BIT);
61 *latch_address = latch_value;
62 }
63}
64
65static void fsg_led_usb_set(struct led_classdev *led_cdev,
66 enum led_brightness value)
67{
68 if (value) {
69 latch_value &= ~(1 << FSG_LED_USB_BIT);
70 *latch_address = latch_value;
71 } else {
72 latch_value |= (1 << FSG_LED_USB_BIT);
73 *latch_address = latch_value;
74 }
75}
76
77static void fsg_led_sync_set(struct led_classdev *led_cdev,
78 enum led_brightness value)
79{
80 if (value) {
81 latch_value &= ~(1 << FSG_LED_SYNC_BIT);
82 *latch_address = latch_value;
83 } else {
84 latch_value |= (1 << FSG_LED_SYNC_BIT);
85 *latch_address = latch_value;
86 }
87}
88
89static void fsg_led_ring_set(struct led_classdev *led_cdev,
90 enum led_brightness value)
91{
92 if (value) {
93 latch_value &= ~(1 << FSG_LED_RING_BIT);
94 *latch_address = latch_value;
95 } else {
96 latch_value |= (1 << FSG_LED_RING_BIT);
97 *latch_address = latch_value;
98 }
99}
100
101
102
103static struct led_classdev fsg_wlan_led = {
104 .name = "fsg:blue:wlan",
105 .brightness_set = fsg_led_wlan_set,
106};
107
108static struct led_classdev fsg_wan_led = {
109 .name = "fsg:blue:wan",
110 .brightness_set = fsg_led_wan_set,
111};
112
113static struct led_classdev fsg_sata_led = {
114 .name = "fsg:blue:sata",
115 .brightness_set = fsg_led_sata_set,
116};
117
118static struct led_classdev fsg_usb_led = {
119 .name = "fsg:blue:usb",
120 .brightness_set = fsg_led_usb_set,
121};
122
123static struct led_classdev fsg_sync_led = {
124 .name = "fsg:blue:sync",
125 .brightness_set = fsg_led_sync_set,
126};
127
128static struct led_classdev fsg_ring_led = {
129 .name = "fsg:blue:ring",
130 .brightness_set = fsg_led_ring_set,
131};
132
133
134
135#ifdef CONFIG_PM
136static int fsg_led_suspend(struct platform_device *dev, pm_message_t state)
137{
138 led_classdev_suspend(&fsg_wlan_led);
139 led_classdev_suspend(&fsg_wan_led);
140 led_classdev_suspend(&fsg_sata_led);
141 led_classdev_suspend(&fsg_usb_led);
142 led_classdev_suspend(&fsg_sync_led);
143 led_classdev_suspend(&fsg_ring_led);
144 return 0;
145}
146
147static int fsg_led_resume(struct platform_device *dev)
148{
149 led_classdev_resume(&fsg_wlan_led);
150 led_classdev_resume(&fsg_wan_led);
151 led_classdev_resume(&fsg_sata_led);
152 led_classdev_resume(&fsg_usb_led);
153 led_classdev_resume(&fsg_sync_led);
154 led_classdev_resume(&fsg_ring_led);
155 return 0;
156}
157#endif
158
159
160static int fsg_led_probe(struct platform_device *pdev)
161{
162 int ret;
163
164 ret = led_classdev_register(&pdev->dev, &fsg_wlan_led);
165 if (ret < 0)
166 goto failwlan;
167
168 ret = led_classdev_register(&pdev->dev, &fsg_wan_led);
169 if (ret < 0)
170 goto failwan;
171
172 ret = led_classdev_register(&pdev->dev, &fsg_sata_led);
173 if (ret < 0)
174 goto failsata;
175
176 ret = led_classdev_register(&pdev->dev, &fsg_usb_led);
177 if (ret < 0)
178 goto failusb;
179
180 ret = led_classdev_register(&pdev->dev, &fsg_sync_led);
181 if (ret < 0)
182 goto failsync;
183
184 ret = led_classdev_register(&pdev->dev, &fsg_ring_led);
185 if (ret < 0)
186 goto failring;
187
188 /* Map the LED chip select address space */
189 latch_address = (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
190 if (!latch_address) {
191 ret = -ENOMEM;
192 goto failremap;
193 }
194
195 latch_value = 0xffff;
196 *latch_address = latch_value;
197
198 return ret;
199
200 failremap:
201 led_classdev_unregister(&fsg_ring_led);
202 failring:
203 led_classdev_unregister(&fsg_sync_led);
204 failsync:
205 led_classdev_unregister(&fsg_usb_led);
206 failusb:
207 led_classdev_unregister(&fsg_sata_led);
208 failsata:
209 led_classdev_unregister(&fsg_wan_led);
210 failwan:
211 led_classdev_unregister(&fsg_wlan_led);
212 failwlan:
213
214 return ret;
215}
216
217static int fsg_led_remove(struct platform_device *pdev)
218{
219 iounmap(latch_address);
220
221 led_classdev_unregister(&fsg_wlan_led);
222 led_classdev_unregister(&fsg_wan_led);
223 led_classdev_unregister(&fsg_sata_led);
224 led_classdev_unregister(&fsg_usb_led);
225 led_classdev_unregister(&fsg_sync_led);
226 led_classdev_unregister(&fsg_ring_led);
227
228 return 0;
229}
230
231
232static struct platform_driver fsg_led_driver = {
233 .probe = fsg_led_probe,
234 .remove = fsg_led_remove,
235#ifdef CONFIG_PM
236 .suspend = fsg_led_suspend,
237 .resume = fsg_led_resume,
238#endif
239 .driver = {
240 .name = "fsg-led",
241 },
242};
243
244
245static int __init fsg_led_init(void)
246{
247 return platform_driver_register(&fsg_led_driver);
248}
249
250static void __exit fsg_led_exit(void)
251{
252 platform_driver_unregister(&fsg_led_driver);
253}
254
255
256module_init(fsg_led_init);
257module_exit(fsg_led_exit);
258
259MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
260MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
261MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 1aae8b332134..b13bd2950e95 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -24,6 +24,8 @@ struct gpio_led_data {
24 u8 new_level; 24 u8 new_level;
25 u8 can_sleep; 25 u8 can_sleep;
26 u8 active_low; 26 u8 active_low;
27 int (*platform_gpio_blink_set)(unsigned gpio,
28 unsigned long *delay_on, unsigned long *delay_off);
27}; 29};
28 30
29static void gpio_led_work(struct work_struct *work) 31static void gpio_led_work(struct work_struct *work)
@@ -60,6 +62,15 @@ static void gpio_led_set(struct led_classdev *led_cdev,
60 gpio_set_value(led_dat->gpio, level); 62 gpio_set_value(led_dat->gpio, level);
61} 63}
62 64
65static int gpio_blink_set(struct led_classdev *led_cdev,
66 unsigned long *delay_on, unsigned long *delay_off)
67{
68 struct gpio_led_data *led_dat =
69 container_of(led_cdev, struct gpio_led_data, cdev);
70
71 return led_dat->platform_gpio_blink_set(led_dat->gpio, delay_on, delay_off);
72}
73
63static int gpio_led_probe(struct platform_device *pdev) 74static int gpio_led_probe(struct platform_device *pdev)
64{ 75{
65 struct gpio_led_platform_data *pdata = pdev->dev.platform_data; 76 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
@@ -88,6 +99,10 @@ static int gpio_led_probe(struct platform_device *pdev)
88 led_dat->gpio = cur_led->gpio; 99 led_dat->gpio = cur_led->gpio;
89 led_dat->can_sleep = gpio_cansleep(cur_led->gpio); 100 led_dat->can_sleep = gpio_cansleep(cur_led->gpio);
90 led_dat->active_low = cur_led->active_low; 101 led_dat->active_low = cur_led->active_low;
102 if (pdata->gpio_blink_set) {
103 led_dat->platform_gpio_blink_set = pdata->gpio_blink_set;
104 led_dat->cdev.blink_set = gpio_blink_set;
105 }
91 led_dat->cdev.brightness_set = gpio_led_set; 106 led_dat->cdev.brightness_set = gpio_led_set;
92 led_dat->cdev.brightness = LED_OFF; 107 led_dat->cdev.brightness = LED_OFF;
93 108
diff --git a/drivers/leds/leds-h1940.c b/drivers/leds/leds-h1940.c
index 6e51c9b61027..bcec42230389 100644
--- a/drivers/leds/leds-h1940.c
+++ b/drivers/leds/leds-h1940.c
@@ -26,20 +26,20 @@
26void h1940_greenled_set(struct led_classdev *led_dev, enum led_brightness value) 26void h1940_greenled_set(struct led_classdev *led_dev, enum led_brightness value)
27{ 27{
28 switch (value) { 28 switch (value) {
29 case LED_HALF: 29 case LED_HALF:
30 h1940_latch_control(0,H1940_LATCH_LED_FLASH); 30 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
31 s3c2410_gpio_setpin(S3C2410_GPA7,1); 31 s3c2410_gpio_setpin(S3C2410_GPA7, 1);
32 break; 32 break;
33 case LED_FULL: 33 case LED_FULL:
34 h1940_latch_control(0,H1940_LATCH_LED_GREEN); 34 h1940_latch_control(0, H1940_LATCH_LED_GREEN);
35 s3c2410_gpio_setpin(S3C2410_GPA7,1); 35 s3c2410_gpio_setpin(S3C2410_GPA7, 1);
36 break; 36 break;
37 default: 37 default:
38 case LED_OFF: 38 case LED_OFF:
39 h1940_latch_control(H1940_LATCH_LED_FLASH,0); 39 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
40 h1940_latch_control(H1940_LATCH_LED_GREEN,0); 40 h1940_latch_control(H1940_LATCH_LED_GREEN, 0);
41 s3c2410_gpio_setpin(S3C2410_GPA7,0); 41 s3c2410_gpio_setpin(S3C2410_GPA7, 0);
42 break; 42 break;
43 } 43 }
44} 44}
45 45
@@ -55,20 +55,20 @@ static struct led_classdev h1940_greenled = {
55void h1940_redled_set(struct led_classdev *led_dev, enum led_brightness value) 55void h1940_redled_set(struct led_classdev *led_dev, enum led_brightness value)
56{ 56{
57 switch (value) { 57 switch (value) {
58 case LED_HALF: 58 case LED_HALF:
59 h1940_latch_control(0,H1940_LATCH_LED_FLASH); 59 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
60 s3c2410_gpio_setpin(S3C2410_GPA1,1); 60 s3c2410_gpio_setpin(S3C2410_GPA1, 1);
61 break; 61 break;
62 case LED_FULL: 62 case LED_FULL:
63 h1940_latch_control(0,H1940_LATCH_LED_RED); 63 h1940_latch_control(0, H1940_LATCH_LED_RED);
64 s3c2410_gpio_setpin(S3C2410_GPA1,1); 64 s3c2410_gpio_setpin(S3C2410_GPA1, 1);
65 break; 65 break;
66 default: 66 default:
67 case LED_OFF: 67 case LED_OFF:
68 h1940_latch_control(H1940_LATCH_LED_FLASH,0); 68 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
69 h1940_latch_control(H1940_LATCH_LED_RED,0); 69 h1940_latch_control(H1940_LATCH_LED_RED, 0);
70 s3c2410_gpio_setpin(S3C2410_GPA1,0); 70 s3c2410_gpio_setpin(S3C2410_GPA1, 0);
71 break; 71 break;
72 } 72 }
73} 73}
74 74
@@ -86,11 +86,11 @@ void h1940_blueled_set(struct led_classdev *led_dev, enum led_brightness value)
86{ 86{
87 if (value) { 87 if (value) {
88 /* flashing Blue */ 88 /* flashing Blue */
89 h1940_latch_control(0,H1940_LATCH_LED_FLASH); 89 h1940_latch_control(0, H1940_LATCH_LED_FLASH);
90 s3c2410_gpio_setpin(S3C2410_GPA3,1); 90 s3c2410_gpio_setpin(S3C2410_GPA3, 1);
91 } else { 91 } else {
92 h1940_latch_control(H1940_LATCH_LED_FLASH,0); 92 h1940_latch_control(H1940_LATCH_LED_FLASH, 0);
93 s3c2410_gpio_setpin(S3C2410_GPA3,0); 93 s3c2410_gpio_setpin(S3C2410_GPA3, 0);
94 } 94 }
95 95
96} 96}
diff --git a/drivers/leds/leds-hp6xx.c b/drivers/leds/leds-hp6xx.c
index 870f5a3789e8..844d5979c904 100644
--- a/drivers/leds/leds-hp6xx.c
+++ b/drivers/leds/leds-hp6xx.c
@@ -17,7 +17,8 @@
17#include <asm/hd64461.h> 17#include <asm/hd64461.h>
18#include <asm/hp6xx.h> 18#include <asm/hp6xx.h>
19 19
20static void hp6xxled_green_set(struct led_classdev *led_cdev, enum led_brightness value) 20static void hp6xxled_green_set(struct led_classdev *led_cdev,
21 enum led_brightness value)
21{ 22{
22 u8 v8; 23 u8 v8;
23 24
@@ -28,7 +29,8 @@ static void hp6xxled_green_set(struct led_classdev *led_cdev, enum led_brightnes
28 outb(v8 | PKDR_LED_GREEN, PKDR); 29 outb(v8 | PKDR_LED_GREEN, PKDR);
29} 30}
30 31
31static void hp6xxled_red_set(struct led_classdev *led_cdev, enum led_brightness value) 32static void hp6xxled_red_set(struct led_classdev *led_cdev,
33 enum led_brightness value)
32{ 34{
33 u16 v16; 35 u16 v16;
34 36
diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
index 0d10e119d8f5..d4f5021dccbf 100644
--- a/drivers/leds/leds-s3c24xx.c
+++ b/drivers/leds/leds-s3c24xx.c
@@ -51,7 +51,7 @@ static void s3c24xx_led_set(struct led_classdev *led_cdev,
51 51
52 if (pd->flags & S3C24XX_LEDF_TRISTATE) 52 if (pd->flags & S3C24XX_LEDF_TRISTATE)
53 s3c2410_gpio_cfgpin(pd->gpio, 53 s3c2410_gpio_cfgpin(pd->gpio,
54 value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT); 54 value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT);
55 55
56} 56}
57 57
@@ -151,7 +151,7 @@ static int __init s3c24xx_led_init(void)
151 151
152static void __exit s3c24xx_led_exit(void) 152static void __exit s3c24xx_led_exit(void)
153{ 153{
154 platform_driver_unregister(&s3c24xx_led_driver); 154 platform_driver_unregister(&s3c24xx_led_driver);
155} 155}
156 156
157module_init(s3c24xx_led_init); 157module_init(s3c24xx_led_init);
diff --git a/drivers/leds/leds-spitz.c b/drivers/leds/leds-spitz.c
index 87007cc362c1..e75e8543bc5a 100644
--- a/drivers/leds/leds-spitz.c
+++ b/drivers/leds/leds-spitz.c
@@ -21,7 +21,8 @@
21#include <asm/arch/pxa-regs.h> 21#include <asm/arch/pxa-regs.h>
22#include <asm/arch/spitz.h> 22#include <asm/arch/spitz.h>
23 23
24static void spitzled_amber_set(struct led_classdev *led_cdev, enum led_brightness value) 24static void spitzled_amber_set(struct led_classdev *led_cdev,
25 enum led_brightness value)
25{ 26{
26 if (value) 27 if (value)
27 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE); 28 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
@@ -29,7 +30,8 @@ static void spitzled_amber_set(struct led_classdev *led_cdev, enum led_brightnes
29 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE); 30 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
30} 31}
31 32
32static void spitzled_green_set(struct led_classdev *led_cdev, enum led_brightness value) 33static void spitzled_green_set(struct led_classdev *led_cdev,
34 enum led_brightness value)
33{ 35{
34 if (value) 36 if (value)
35 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN); 37 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN);
@@ -53,7 +55,8 @@ static struct led_classdev spitz_green_led = {
53static int spitzled_suspend(struct platform_device *dev, pm_message_t state) 55static int spitzled_suspend(struct platform_device *dev, pm_message_t state)
54{ 56{
55#ifdef CONFIG_LEDS_TRIGGERS 57#ifdef CONFIG_LEDS_TRIGGERS
56 if (spitz_amber_led.trigger && strcmp(spitz_amber_led.trigger->name, "sharpsl-charge")) 58 if (spitz_amber_led.trigger &&
59 strcmp(spitz_amber_led.trigger->name, "sharpsl-charge"))
57#endif 60#endif
58 led_classdev_suspend(&spitz_amber_led); 61 led_classdev_suspend(&spitz_amber_led);
59 led_classdev_suspend(&spitz_green_led); 62 led_classdev_suspend(&spitz_green_led);
@@ -116,7 +119,7 @@ static int __init spitzled_init(void)
116 119
117static void __exit spitzled_exit(void) 120static void __exit spitzled_exit(void)
118{ 121{
119 platform_driver_unregister(&spitzled_driver); 122 platform_driver_unregister(&spitzled_driver);
120} 123}
121 124
122module_init(spitzled_init); 125module_init(spitzled_init);
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index 12b6fe93b135..5edbf52c4fa7 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -27,6 +27,11 @@ static inline void led_set_brightness(struct led_classdev *led_cdev,
27 led_cdev->brightness_set(led_cdev, value); 27 led_cdev->brightness_set(led_cdev, value);
28} 28}
29 29
30static inline int led_get_brightness(struct led_classdev *led_cdev)
31{
32 return led_cdev->brightness;
33}
34
30extern struct rw_semaphore leds_list_lock; 35extern struct rw_semaphore leds_list_lock;
31extern struct list_head leds_list; 36extern struct list_head leds_list;
32 37
@@ -34,9 +39,11 @@ extern struct list_head leds_list;
34void led_trigger_set_default(struct led_classdev *led_cdev); 39void led_trigger_set_default(struct led_classdev *led_cdev);
35void led_trigger_set(struct led_classdev *led_cdev, 40void led_trigger_set(struct led_classdev *led_cdev,
36 struct led_trigger *trigger); 41 struct led_trigger *trigger);
42void led_trigger_remove(struct led_classdev *led_cdev);
37#else 43#else
38#define led_trigger_set_default(x) do {} while(0) 44#define led_trigger_set_default(x) do {} while (0)
39#define led_trigger_set(x, y) do {} while(0) 45#define led_trigger_set(x, y) do {} while (0)
46#define led_trigger_remove(x) do {} while (0)
40#endif 47#endif
41 48
42ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, 49ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
diff --git a/drivers/leds/ledtrig-default-on.c b/drivers/leds/ledtrig-default-on.c
new file mode 100644
index 000000000000..92995e40cfa4
--- /dev/null
+++ b/drivers/leds/ledtrig-default-on.c
@@ -0,0 +1,45 @@
1/*
2 * LED Kernel Default ON Trigger
3 *
4 * Copyright 2008 Nick Forbes <nick.forbes@incepta.com>
5 *
6 * Based on Richard Purdie's ledtrig-timer.c.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/leds.h>
18#include "leds.h"
19
20static void defon_trig_activate(struct led_classdev *led_cdev)
21{
22 led_set_brightness(led_cdev, LED_FULL);
23}
24
25static struct led_trigger defon_led_trigger = {
26 .name = "default-on",
27 .activate = defon_trig_activate,
28};
29
30static int __init defon_trig_init(void)
31{
32 return led_trigger_register(&defon_led_trigger);
33}
34
35static void __exit defon_trig_exit(void)
36{
37 led_trigger_unregister(&defon_led_trigger);
38}
39
40module_init(defon_trig_init);
41module_exit(defon_trig_exit);
42
43MODULE_AUTHOR("Nick Forbes <nick.forbes@incepta.com>");
44MODULE_DESCRIPTION("Default-ON LED trigger");
45MODULE_LICENSE("GPL");
diff --git a/drivers/leds/ledtrig-ide-disk.c b/drivers/leds/ledtrig-ide-disk.c
index 54b155c7026f..883a577b1b97 100644
--- a/drivers/leds/ledtrig-ide-disk.c
+++ b/drivers/leds/ledtrig-ide-disk.c
@@ -38,7 +38,7 @@ static void ledtrig_ide_timerfunc(unsigned long data)
38 if (ide_lastactivity != ide_activity) { 38 if (ide_lastactivity != ide_activity) {
39 ide_lastactivity = ide_activity; 39 ide_lastactivity = ide_activity;
40 led_trigger_event(ledtrig_ide, LED_FULL); 40 led_trigger_event(ledtrig_ide, LED_FULL);
41 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10)); 41 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
42 } else { 42 } else {
43 led_trigger_event(ledtrig_ide, LED_OFF); 43 led_trigger_event(ledtrig_ide, LED_OFF);
44 } 44 }
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index 82c55d6e4902..5c99f4f0c692 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -25,6 +25,9 @@
25#include "leds.h" 25#include "leds.h"
26 26
27struct timer_trig_data { 27struct timer_trig_data {
28 int brightness_on; /* LED brightness during "on" period.
29 * (LED_OFF < brightness_on <= LED_FULL)
30 */
28 unsigned long delay_on; /* milliseconds on */ 31 unsigned long delay_on; /* milliseconds on */
29 unsigned long delay_off; /* milliseconds off */ 32 unsigned long delay_off; /* milliseconds off */
30 struct timer_list timer; 33 struct timer_list timer;
@@ -34,17 +37,26 @@ static void led_timer_function(unsigned long data)
34{ 37{
35 struct led_classdev *led_cdev = (struct led_classdev *) data; 38 struct led_classdev *led_cdev = (struct led_classdev *) data;
36 struct timer_trig_data *timer_data = led_cdev->trigger_data; 39 struct timer_trig_data *timer_data = led_cdev->trigger_data;
37 unsigned long brightness = LED_OFF; 40 unsigned long brightness;
38 unsigned long delay = timer_data->delay_off; 41 unsigned long delay;
39 42
40 if (!timer_data->delay_on || !timer_data->delay_off) { 43 if (!timer_data->delay_on || !timer_data->delay_off) {
41 led_set_brightness(led_cdev, LED_OFF); 44 led_set_brightness(led_cdev, LED_OFF);
42 return; 45 return;
43 } 46 }
44 47
45 if (!led_cdev->brightness) { 48 brightness = led_get_brightness(led_cdev);
46 brightness = LED_FULL; 49 if (!brightness) {
50 /* Time to switch the LED on. */
51 brightness = timer_data->brightness_on;
47 delay = timer_data->delay_on; 52 delay = timer_data->delay_on;
53 } else {
54 /* Store the current brightness value to be able
55 * to restore it when the delay_off period is over.
56 */
57 timer_data->brightness_on = brightness;
58 brightness = LED_OFF;
59 delay = timer_data->delay_off;
48 } 60 }
49 61
50 led_set_brightness(led_cdev, brightness); 62 led_set_brightness(led_cdev, brightness);
@@ -52,7 +64,7 @@ static void led_timer_function(unsigned long data)
52 mod_timer(&timer_data->timer, jiffies + msecs_to_jiffies(delay)); 64 mod_timer(&timer_data->timer, jiffies + msecs_to_jiffies(delay));
53} 65}
54 66
55static ssize_t led_delay_on_show(struct device *dev, 67static ssize_t led_delay_on_show(struct device *dev,
56 struct device_attribute *attr, char *buf) 68 struct device_attribute *attr, char *buf)
57{ 69{
58 struct led_classdev *led_cdev = dev_get_drvdata(dev); 70 struct led_classdev *led_cdev = dev_get_drvdata(dev);
@@ -63,7 +75,7 @@ static ssize_t led_delay_on_show(struct device *dev,
63 return strlen(buf) + 1; 75 return strlen(buf) + 1;
64} 76}
65 77
66static ssize_t led_delay_on_store(struct device *dev, 78static ssize_t led_delay_on_store(struct device *dev,
67 struct device_attribute *attr, const char *buf, size_t size) 79 struct device_attribute *attr, const char *buf, size_t size)
68{ 80{
69 struct led_classdev *led_cdev = dev_get_drvdata(dev); 81 struct led_classdev *led_cdev = dev_get_drvdata(dev);
@@ -87,7 +99,7 @@ static ssize_t led_delay_on_store(struct device *dev,
87 /* try to activate hardware acceleration, if any */ 99 /* try to activate hardware acceleration, if any */
88 if (!led_cdev->blink_set || 100 if (!led_cdev->blink_set ||
89 led_cdev->blink_set(led_cdev, 101 led_cdev->blink_set(led_cdev,
90 &timer_data->delay_on, &timer_data->delay_off)) { 102 &timer_data->delay_on, &timer_data->delay_off)) {
91 /* no hardware acceleration, blink via timer */ 103 /* no hardware acceleration, blink via timer */
92 mod_timer(&timer_data->timer, jiffies + 1); 104 mod_timer(&timer_data->timer, jiffies + 1);
93 } 105 }
@@ -98,7 +110,7 @@ static ssize_t led_delay_on_store(struct device *dev,
98 return ret; 110 return ret;
99} 111}
100 112
101static ssize_t led_delay_off_show(struct device *dev, 113static ssize_t led_delay_off_show(struct device *dev,
102 struct device_attribute *attr, char *buf) 114 struct device_attribute *attr, char *buf)
103{ 115{
104 struct led_classdev *led_cdev = dev_get_drvdata(dev); 116 struct led_classdev *led_cdev = dev_get_drvdata(dev);
@@ -109,7 +121,7 @@ static ssize_t led_delay_off_show(struct device *dev,
109 return strlen(buf) + 1; 121 return strlen(buf) + 1;
110} 122}
111 123
112static ssize_t led_delay_off_store(struct device *dev, 124static ssize_t led_delay_off_store(struct device *dev,
113 struct device_attribute *attr, const char *buf, size_t size) 125 struct device_attribute *attr, const char *buf, size_t size)
114{ 126{
115 struct led_classdev *led_cdev = dev_get_drvdata(dev); 127 struct led_classdev *led_cdev = dev_get_drvdata(dev);
@@ -133,7 +145,7 @@ static ssize_t led_delay_off_store(struct device *dev,
133 /* try to activate hardware acceleration, if any */ 145 /* try to activate hardware acceleration, if any */
134 if (!led_cdev->blink_set || 146 if (!led_cdev->blink_set ||
135 led_cdev->blink_set(led_cdev, 147 led_cdev->blink_set(led_cdev,
136 &timer_data->delay_on, &timer_data->delay_off)) { 148 &timer_data->delay_on, &timer_data->delay_off)) {
137 /* no hardware acceleration, blink via timer */ 149 /* no hardware acceleration, blink via timer */
138 mod_timer(&timer_data->timer, jiffies + 1); 150 mod_timer(&timer_data->timer, jiffies + 1);
139 } 151 }
@@ -156,6 +168,9 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
156 if (!timer_data) 168 if (!timer_data)
157 return; 169 return;
158 170
171 timer_data->brightness_on = led_get_brightness(led_cdev);
172 if (timer_data->brightness_on == LED_OFF)
173 timer_data->brightness_on = LED_FULL;
159 led_cdev->trigger_data = timer_data; 174 led_cdev->trigger_data = timer_data;
160 175
161 init_timer(&timer_data->timer); 176 init_timer(&timer_data->timer);
diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index 89302309da92..f972ff377b63 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -103,6 +103,9 @@ int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
103 return 0; 103 return 0;
104} 104}
105 105
106static struct lock_class_key emumousebtn_event_class;
107static struct lock_class_key emumousebtn_mutex_class;
108
106static int emumousebtn_input_register(void) 109static int emumousebtn_input_register(void)
107{ 110{
108 int ret; 111 int ret;
@@ -111,6 +114,9 @@ static int emumousebtn_input_register(void)
111 if (!emumousebtn) 114 if (!emumousebtn)
112 return -ENOMEM; 115 return -ENOMEM;
113 116
117 lockdep_set_class(emumousebtn->event_lock, &emumousebtn_event_class);
118 lockdep_set_class(emumousebtn->mutex, &emumousebtn_mutex_class);
119
114 emumousebtn->name = "Macintosh mouse button emulation"; 120 emumousebtn->name = "Macintosh mouse button emulation";
115 emumousebtn->id.bustype = BUS_ADB; 121 emumousebtn->id.bustype = BUS_ADB;
116 emumousebtn->id.vendor = 0x0001; 122 emumousebtn->id.vendor = 0x0001;
diff --git a/drivers/macintosh/windfarm_pm112.c b/drivers/macintosh/windfarm_pm112.c
index b3fbb45bc90a..73d695dc9e50 100644
--- a/drivers/macintosh/windfarm_pm112.c
+++ b/drivers/macintosh/windfarm_pm112.c
@@ -668,7 +668,7 @@ static struct platform_driver wf_pm112_driver = {
668 .remove = __devexit_p(wf_pm112_remove), 668 .remove = __devexit_p(wf_pm112_remove),
669 .driver = { 669 .driver = {
670 .name = "windfarm", 670 .name = "windfarm",
671 .bus = &platform_bus_type, 671 .owner = THIS_MODULE,
672 }, 672 },
673}; 673};
674 674
@@ -711,3 +711,4 @@ module_exit(wf_pm112_exit);
711MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>"); 711MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
712MODULE_DESCRIPTION("Thermal control for PowerMac11,2"); 712MODULE_DESCRIPTION("Thermal control for PowerMac11,2");
713MODULE_LICENSE("GPL"); 713MODULE_LICENSE("GPL");
714MODULE_ALIAS("platform:windfarm");
diff --git a/drivers/macintosh/windfarm_pm81.c b/drivers/macintosh/windfarm_pm81.c
index f24fa734046a..abbe206474f5 100644
--- a/drivers/macintosh/windfarm_pm81.c
+++ b/drivers/macintosh/windfarm_pm81.c
@@ -770,7 +770,7 @@ static struct platform_driver wf_smu_driver = {
770 .remove = __devexit_p(wf_smu_remove), 770 .remove = __devexit_p(wf_smu_remove),
771 .driver = { 771 .driver = {
772 .name = "windfarm", 772 .name = "windfarm",
773 .bus = &platform_bus_type, 773 .owner = THIS_MODULE,
774 }, 774 },
775}; 775};
776 776
@@ -810,4 +810,4 @@ module_exit(wf_smu_exit);
810MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); 810MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
811MODULE_DESCRIPTION("Thermal control logic for iMac G5"); 811MODULE_DESCRIPTION("Thermal control logic for iMac G5");
812MODULE_LICENSE("GPL"); 812MODULE_LICENSE("GPL");
813 813MODULE_ALIAS("platform:windfarm");
diff --git a/drivers/macintosh/windfarm_pm91.c b/drivers/macintosh/windfarm_pm91.c
index 26eee69ebe6d..764c525b2117 100644
--- a/drivers/macintosh/windfarm_pm91.c
+++ b/drivers/macintosh/windfarm_pm91.c
@@ -702,7 +702,7 @@ static struct platform_driver wf_smu_driver = {
702 .remove = __devexit_p(wf_smu_remove), 702 .remove = __devexit_p(wf_smu_remove),
703 .driver = { 703 .driver = {
704 .name = "windfarm", 704 .name = "windfarm",
705 .bus = &platform_bus_type, 705 .owner = THIS_MODULE,
706 }, 706 },
707}; 707};
708 708
@@ -742,3 +742,4 @@ MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
742MODULE_DESCRIPTION("Thermal control logic for PowerMac9,1"); 742MODULE_DESCRIPTION("Thermal control logic for PowerMac9,1");
743MODULE_LICENSE("GPL"); 743MODULE_LICENSE("GPL");
744 744
745MODULE_ALIAS("platform:windfarm");
diff --git a/drivers/md/Makefile b/drivers/md/Makefile
index d9aa7edb8780..7be09eeea293 100644
--- a/drivers/md/Makefile
+++ b/drivers/md/Makefile
@@ -3,10 +3,10 @@
3# 3#
4 4
5dm-mod-objs := dm.o dm-table.o dm-target.o dm-linear.o dm-stripe.o \ 5dm-mod-objs := dm.o dm-table.o dm-target.o dm-linear.o dm-stripe.o \
6 dm-ioctl.o dm-io.o kcopyd.o 6 dm-ioctl.o dm-io.o dm-kcopyd.o
7dm-multipath-objs := dm-hw-handler.o dm-path-selector.o dm-mpath.o 7dm-multipath-objs := dm-hw-handler.o dm-path-selector.o dm-mpath.o
8dm-snapshot-objs := dm-snap.o dm-exception-store.o 8dm-snapshot-objs := dm-snap.o dm-exception-store.o
9dm-mirror-objs := dm-log.o dm-raid1.o 9dm-mirror-objs := dm-raid1.o
10dm-rdac-objs := dm-mpath-rdac.o 10dm-rdac-objs := dm-mpath-rdac.o
11dm-hp-sw-objs := dm-mpath-hp-sw.o 11dm-hp-sw-objs := dm-mpath-hp-sw.o
12md-mod-objs := md.o bitmap.o 12md-mod-objs := md.o bitmap.o
@@ -39,7 +39,7 @@ obj-$(CONFIG_DM_MULTIPATH_EMC) += dm-emc.o
39obj-$(CONFIG_DM_MULTIPATH_HP) += dm-hp-sw.o 39obj-$(CONFIG_DM_MULTIPATH_HP) += dm-hp-sw.o
40obj-$(CONFIG_DM_MULTIPATH_RDAC) += dm-rdac.o 40obj-$(CONFIG_DM_MULTIPATH_RDAC) += dm-rdac.o
41obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o 41obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o
42obj-$(CONFIG_DM_MIRROR) += dm-mirror.o 42obj-$(CONFIG_DM_MIRROR) += dm-mirror.o dm-log.o
43obj-$(CONFIG_DM_ZERO) += dm-zero.o 43obj-$(CONFIG_DM_ZERO) += dm-zero.o
44 44
45quiet_cmd_unroll = UNROLL $@ 45quiet_cmd_unroll = UNROLL $@
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 5bbce29f143a..41f408068a7c 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -9,13 +9,13 @@
9 9
10#include "dm.h" 10#include "dm.h"
11#include "dm-snap.h" 11#include "dm-snap.h"
12#include "dm-io.h"
13#include "kcopyd.h"
14 12
15#include <linux/mm.h> 13#include <linux/mm.h>
16#include <linux/pagemap.h> 14#include <linux/pagemap.h>
17#include <linux/vmalloc.h> 15#include <linux/vmalloc.h>
18#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/dm-io.h>
18#include <linux/dm-kcopyd.h>
19 19
20#define DM_MSG_PREFIX "snapshots" 20#define DM_MSG_PREFIX "snapshots"
21#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */ 21#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */
@@ -131,7 +131,7 @@ struct pstore {
131 131
132static unsigned sectors_to_pages(unsigned sectors) 132static unsigned sectors_to_pages(unsigned sectors)
133{ 133{
134 return sectors / (PAGE_SIZE >> 9); 134 return DIV_ROUND_UP(sectors, PAGE_SIZE >> 9);
135} 135}
136 136
137static int alloc_area(struct pstore *ps) 137static int alloc_area(struct pstore *ps)
@@ -159,7 +159,7 @@ static void free_area(struct pstore *ps)
159} 159}
160 160
161struct mdata_req { 161struct mdata_req {
162 struct io_region *where; 162 struct dm_io_region *where;
163 struct dm_io_request *io_req; 163 struct dm_io_request *io_req;
164 struct work_struct work; 164 struct work_struct work;
165 int result; 165 int result;
@@ -177,7 +177,7 @@ static void do_metadata(struct work_struct *work)
177 */ 177 */
178static int chunk_io(struct pstore *ps, uint32_t chunk, int rw, int metadata) 178static int chunk_io(struct pstore *ps, uint32_t chunk, int rw, int metadata)
179{ 179{
180 struct io_region where = { 180 struct dm_io_region where = {
181 .bdev = ps->snap->cow->bdev, 181 .bdev = ps->snap->cow->bdev,
182 .sector = ps->snap->chunk_size * chunk, 182 .sector = ps->snap->chunk_size * chunk,
183 .count = ps->snap->chunk_size, 183 .count = ps->snap->chunk_size,
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 8f25f628ef16..4789c42d9a3a 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -5,13 +5,14 @@
5 * This file is released under the GPL. 5 * This file is released under the GPL.
6 */ 6 */
7 7
8#include "dm-io.h" 8#include "dm.h"
9 9
10#include <linux/bio.h> 10#include <linux/bio.h>
11#include <linux/mempool.h> 11#include <linux/mempool.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/dm-io.h>
15 16
16struct dm_io_client { 17struct dm_io_client {
17 mempool_t *pool; 18 mempool_t *pool;
@@ -20,7 +21,7 @@ struct dm_io_client {
20 21
21/* FIXME: can we shrink this ? */ 22/* FIXME: can we shrink this ? */
22struct io { 23struct io {
23 unsigned long error; 24 unsigned long error_bits;
24 atomic_t count; 25 atomic_t count;
25 struct task_struct *sleeper; 26 struct task_struct *sleeper;
26 struct dm_io_client *client; 27 struct dm_io_client *client;
@@ -107,14 +108,14 @@ static inline unsigned bio_get_region(struct bio *bio)
107static void dec_count(struct io *io, unsigned int region, int error) 108static void dec_count(struct io *io, unsigned int region, int error)
108{ 109{
109 if (error) 110 if (error)
110 set_bit(region, &io->error); 111 set_bit(region, &io->error_bits);
111 112
112 if (atomic_dec_and_test(&io->count)) { 113 if (atomic_dec_and_test(&io->count)) {
113 if (io->sleeper) 114 if (io->sleeper)
114 wake_up_process(io->sleeper); 115 wake_up_process(io->sleeper);
115 116
116 else { 117 else {
117 unsigned long r = io->error; 118 unsigned long r = io->error_bits;
118 io_notify_fn fn = io->callback; 119 io_notify_fn fn = io->callback;
119 void *context = io->context; 120 void *context = io->context;
120 121
@@ -271,7 +272,7 @@ static void km_dp_init(struct dpages *dp, void *data)
271/*----------------------------------------------------------------- 272/*-----------------------------------------------------------------
272 * IO routines that accept a list of pages. 273 * IO routines that accept a list of pages.
273 *---------------------------------------------------------------*/ 274 *---------------------------------------------------------------*/
274static void do_region(int rw, unsigned int region, struct io_region *where, 275static void do_region(int rw, unsigned region, struct dm_io_region *where,
275 struct dpages *dp, struct io *io) 276 struct dpages *dp, struct io *io)
276{ 277{
277 struct bio *bio; 278 struct bio *bio;
@@ -320,7 +321,7 @@ static void do_region(int rw, unsigned int region, struct io_region *where,
320} 321}
321 322
322static void dispatch_io(int rw, unsigned int num_regions, 323static void dispatch_io(int rw, unsigned int num_regions,
323 struct io_region *where, struct dpages *dp, 324 struct dm_io_region *where, struct dpages *dp,
324 struct io *io, int sync) 325 struct io *io, int sync)
325{ 326{
326 int i; 327 int i;
@@ -347,17 +348,17 @@ static void dispatch_io(int rw, unsigned int num_regions,
347} 348}
348 349
349static int sync_io(struct dm_io_client *client, unsigned int num_regions, 350static int sync_io(struct dm_io_client *client, unsigned int num_regions,
350 struct io_region *where, int rw, struct dpages *dp, 351 struct dm_io_region *where, int rw, struct dpages *dp,
351 unsigned long *error_bits) 352 unsigned long *error_bits)
352{ 353{
353 struct io io; 354 struct io io;
354 355
355 if (num_regions > 1 && rw != WRITE) { 356 if (num_regions > 1 && (rw & RW_MASK) != WRITE) {
356 WARN_ON(1); 357 WARN_ON(1);
357 return -EIO; 358 return -EIO;
358 } 359 }
359 360
360 io.error = 0; 361 io.error_bits = 0;
361 atomic_set(&io.count, 1); /* see dispatch_io() */ 362 atomic_set(&io.count, 1); /* see dispatch_io() */
362 io.sleeper = current; 363 io.sleeper = current;
363 io.client = client; 364 io.client = client;
@@ -378,25 +379,25 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
378 return -EINTR; 379 return -EINTR;
379 380
380 if (error_bits) 381 if (error_bits)
381 *error_bits = io.error; 382 *error_bits = io.error_bits;
382 383
383 return io.error ? -EIO : 0; 384 return io.error_bits ? -EIO : 0;
384} 385}
385 386
386static int async_io(struct dm_io_client *client, unsigned int num_regions, 387static int async_io(struct dm_io_client *client, unsigned int num_regions,
387 struct io_region *where, int rw, struct dpages *dp, 388 struct dm_io_region *where, int rw, struct dpages *dp,
388 io_notify_fn fn, void *context) 389 io_notify_fn fn, void *context)
389{ 390{
390 struct io *io; 391 struct io *io;
391 392
392 if (num_regions > 1 && rw != WRITE) { 393 if (num_regions > 1 && (rw & RW_MASK) != WRITE) {
393 WARN_ON(1); 394 WARN_ON(1);
394 fn(1, context); 395 fn(1, context);
395 return -EIO; 396 return -EIO;
396 } 397 }
397 398
398 io = mempool_alloc(client->pool, GFP_NOIO); 399 io = mempool_alloc(client->pool, GFP_NOIO);
399 io->error = 0; 400 io->error_bits = 0;
400 atomic_set(&io->count, 1); /* see dispatch_io() */ 401 atomic_set(&io->count, 1); /* see dispatch_io() */
401 io->sleeper = NULL; 402 io->sleeper = NULL;
402 io->client = client; 403 io->client = client;
@@ -435,10 +436,15 @@ static int dp_init(struct dm_io_request *io_req, struct dpages *dp)
435} 436}
436 437
437/* 438/*
438 * New collapsed (a)synchronous interface 439 * New collapsed (a)synchronous interface.
440 *
441 * If the IO is asynchronous (i.e. it has notify.fn), you must either unplug
442 * the queue with blk_unplug() some time later or set the BIO_RW_SYNC bit in
443 * io_req->bi_rw. If you fail to do one of these, the IO will be submitted to
444 * the disk after q->unplug_delay, which defaults to 3ms in blk-settings.c.
439 */ 445 */
440int dm_io(struct dm_io_request *io_req, unsigned num_regions, 446int dm_io(struct dm_io_request *io_req, unsigned num_regions,
441 struct io_region *where, unsigned long *sync_error_bits) 447 struct dm_io_region *where, unsigned long *sync_error_bits)
442{ 448{
443 int r; 449 int r;
444 struct dpages dp; 450 struct dpages dp;
diff --git a/drivers/md/dm-io.h b/drivers/md/dm-io.h
deleted file mode 100644
index f647e2cceaa6..000000000000
--- a/drivers/md/dm-io.h
+++ /dev/null
@@ -1,79 +0,0 @@
1/*
2 * Copyright (C) 2003 Sistina Software
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef _DM_IO_H
8#define _DM_IO_H
9
10#include "dm.h"
11
12struct io_region {
13 struct block_device *bdev;
14 sector_t sector;
15 sector_t count; /* If this is zero the region is ignored. */
16};
17
18struct page_list {
19 struct page_list *next;
20 struct page *page;
21};
22
23typedef void (*io_notify_fn)(unsigned long error, void *context);
24
25enum dm_io_mem_type {
26 DM_IO_PAGE_LIST,/* Page list */
27 DM_IO_BVEC, /* Bio vector */
28 DM_IO_VMA, /* Virtual memory area */
29 DM_IO_KMEM, /* Kernel memory */
30};
31
32struct dm_io_memory {
33 enum dm_io_mem_type type;
34
35 union {
36 struct page_list *pl;
37 struct bio_vec *bvec;
38 void *vma;
39 void *addr;
40 } ptr;
41
42 unsigned offset;
43};
44
45struct dm_io_notify {
46 io_notify_fn fn; /* Callback for asynchronous requests */
47 void *context; /* Passed to callback */
48};
49
50/*
51 * IO request structure
52 */
53struct dm_io_client;
54struct dm_io_request {
55 int bi_rw; /* READ|WRITE - not READA */
56 struct dm_io_memory mem; /* Memory to use for io */
57 struct dm_io_notify notify; /* Synchronous if notify.fn is NULL */
58 struct dm_io_client *client; /* Client memory handler */
59};
60
61/*
62 * For async io calls, users can alternatively use the dm_io() function below
63 * and dm_io_client_create() to create private mempools for the client.
64 *
65 * Create/destroy may block.
66 */
67struct dm_io_client *dm_io_client_create(unsigned num_pages);
68int dm_io_client_resize(unsigned num_pages, struct dm_io_client *client);
69void dm_io_client_destroy(struct dm_io_client *client);
70
71/*
72 * IO interface using private per-client pools.
73 * Each bit in the optional 'sync_error_bits' bitset indicates whether an
74 * error occurred doing io to the corresponding region.
75 */
76int dm_io(struct dm_io_request *io_req, unsigned num_regions,
77 struct io_region *region, unsigned long *sync_error_bits);
78
79#endif
diff --git a/drivers/md/kcopyd.c b/drivers/md/dm-kcopyd.c
index e76b52ade690..996802b8a452 100644
--- a/drivers/md/kcopyd.c
+++ b/drivers/md/dm-kcopyd.c
@@ -9,9 +9,8 @@
9 * completion notification. 9 * completion notification.
10 */ 10 */
11 11
12#include <asm/types.h> 12#include <linux/types.h>
13#include <asm/atomic.h> 13#include <asm/atomic.h>
14
15#include <linux/blkdev.h> 14#include <linux/blkdev.h>
16#include <linux/fs.h> 15#include <linux/fs.h>
17#include <linux/init.h> 16#include <linux/init.h>
@@ -23,24 +22,15 @@
23#include <linux/vmalloc.h> 22#include <linux/vmalloc.h>
24#include <linux/workqueue.h> 23#include <linux/workqueue.h>
25#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/dm-kcopyd.h>
26 26
27#include "kcopyd.h" 27#include "dm.h"
28
29static struct workqueue_struct *_kcopyd_wq;
30static struct work_struct _kcopyd_work;
31
32static void wake(void)
33{
34 queue_work(_kcopyd_wq, &_kcopyd_work);
35}
36 28
37/*----------------------------------------------------------------- 29/*-----------------------------------------------------------------
38 * Each kcopyd client has its own little pool of preallocated 30 * Each kcopyd client has its own little pool of preallocated
39 * pages for kcopyd io. 31 * pages for kcopyd io.
40 *---------------------------------------------------------------*/ 32 *---------------------------------------------------------------*/
41struct kcopyd_client { 33struct dm_kcopyd_client {
42 struct list_head list;
43
44 spinlock_t lock; 34 spinlock_t lock;
45 struct page_list *pages; 35 struct page_list *pages;
46 unsigned int nr_pages; 36 unsigned int nr_pages;
@@ -50,8 +40,32 @@ struct kcopyd_client {
50 40
51 wait_queue_head_t destroyq; 41 wait_queue_head_t destroyq;
52 atomic_t nr_jobs; 42 atomic_t nr_jobs;
43
44 mempool_t *job_pool;
45
46 struct workqueue_struct *kcopyd_wq;
47 struct work_struct kcopyd_work;
48
49/*
50 * We maintain three lists of jobs:
51 *
52 * i) jobs waiting for pages
53 * ii) jobs that have pages, and are waiting for the io to be issued.
54 * iii) jobs that have completed.
55 *
56 * All three of these are protected by job_lock.
57 */
58 spinlock_t job_lock;
59 struct list_head complete_jobs;
60 struct list_head io_jobs;
61 struct list_head pages_jobs;
53}; 62};
54 63
64static void wake(struct dm_kcopyd_client *kc)
65{
66 queue_work(kc->kcopyd_wq, &kc->kcopyd_work);
67}
68
55static struct page_list *alloc_pl(void) 69static struct page_list *alloc_pl(void)
56{ 70{
57 struct page_list *pl; 71 struct page_list *pl;
@@ -75,7 +89,7 @@ static void free_pl(struct page_list *pl)
75 kfree(pl); 89 kfree(pl);
76} 90}
77 91
78static int kcopyd_get_pages(struct kcopyd_client *kc, 92static int kcopyd_get_pages(struct dm_kcopyd_client *kc,
79 unsigned int nr, struct page_list **pages) 93 unsigned int nr, struct page_list **pages)
80{ 94{
81 struct page_list *pl; 95 struct page_list *pl;
@@ -98,7 +112,7 @@ static int kcopyd_get_pages(struct kcopyd_client *kc,
98 return 0; 112 return 0;
99} 113}
100 114
101static void kcopyd_put_pages(struct kcopyd_client *kc, struct page_list *pl) 115static void kcopyd_put_pages(struct dm_kcopyd_client *kc, struct page_list *pl)
102{ 116{
103 struct page_list *cursor; 117 struct page_list *cursor;
104 118
@@ -126,7 +140,7 @@ static void drop_pages(struct page_list *pl)
126 } 140 }
127} 141}
128 142
129static int client_alloc_pages(struct kcopyd_client *kc, unsigned int nr) 143static int client_alloc_pages(struct dm_kcopyd_client *kc, unsigned int nr)
130{ 144{
131 unsigned int i; 145 unsigned int i;
132 struct page_list *pl = NULL, *next; 146 struct page_list *pl = NULL, *next;
@@ -147,7 +161,7 @@ static int client_alloc_pages(struct kcopyd_client *kc, unsigned int nr)
147 return 0; 161 return 0;
148} 162}
149 163
150static void client_free_pages(struct kcopyd_client *kc) 164static void client_free_pages(struct dm_kcopyd_client *kc)
151{ 165{
152 BUG_ON(kc->nr_free_pages != kc->nr_pages); 166 BUG_ON(kc->nr_free_pages != kc->nr_pages);
153 drop_pages(kc->pages); 167 drop_pages(kc->pages);
@@ -161,7 +175,7 @@ static void client_free_pages(struct kcopyd_client *kc)
161 * ever having to do io (which could cause a deadlock). 175 * ever having to do io (which could cause a deadlock).
162 *---------------------------------------------------------------*/ 176 *---------------------------------------------------------------*/
163struct kcopyd_job { 177struct kcopyd_job {
164 struct kcopyd_client *kc; 178 struct dm_kcopyd_client *kc;
165 struct list_head list; 179 struct list_head list;
166 unsigned long flags; 180 unsigned long flags;
167 181
@@ -175,13 +189,13 @@ struct kcopyd_job {
175 * Either READ or WRITE 189 * Either READ or WRITE
176 */ 190 */
177 int rw; 191 int rw;
178 struct io_region source; 192 struct dm_io_region source;
179 193
180 /* 194 /*
181 * The destinations for the transfer. 195 * The destinations for the transfer.
182 */ 196 */
183 unsigned int num_dests; 197 unsigned int num_dests;
184 struct io_region dests[KCOPYD_MAX_REGIONS]; 198 struct dm_io_region dests[DM_KCOPYD_MAX_REGIONS];
185 199
186 sector_t offset; 200 sector_t offset;
187 unsigned int nr_pages; 201 unsigned int nr_pages;
@@ -191,7 +205,7 @@ struct kcopyd_job {
191 * Set this to ensure you are notified when the job has 205 * Set this to ensure you are notified when the job has
192 * completed. 'context' is for callback to use. 206 * completed. 'context' is for callback to use.
193 */ 207 */
194 kcopyd_notify_fn fn; 208 dm_kcopyd_notify_fn fn;
195 void *context; 209 void *context;
196 210
197 /* 211 /*
@@ -207,47 +221,19 @@ struct kcopyd_job {
207#define MIN_JOBS 512 221#define MIN_JOBS 512
208 222
209static struct kmem_cache *_job_cache; 223static struct kmem_cache *_job_cache;
210static mempool_t *_job_pool;
211 224
212/* 225int __init dm_kcopyd_init(void)
213 * We maintain three lists of jobs:
214 *
215 * i) jobs waiting for pages
216 * ii) jobs that have pages, and are waiting for the io to be issued.
217 * iii) jobs that have completed.
218 *
219 * All three of these are protected by job_lock.
220 */
221static DEFINE_SPINLOCK(_job_lock);
222
223static LIST_HEAD(_complete_jobs);
224static LIST_HEAD(_io_jobs);
225static LIST_HEAD(_pages_jobs);
226
227static int jobs_init(void)
228{ 226{
229 _job_cache = KMEM_CACHE(kcopyd_job, 0); 227 _job_cache = KMEM_CACHE(kcopyd_job, 0);
230 if (!_job_cache) 228 if (!_job_cache)
231 return -ENOMEM; 229 return -ENOMEM;
232 230
233 _job_pool = mempool_create_slab_pool(MIN_JOBS, _job_cache);
234 if (!_job_pool) {
235 kmem_cache_destroy(_job_cache);
236 return -ENOMEM;
237 }
238
239 return 0; 231 return 0;
240} 232}
241 233
242static void jobs_exit(void) 234void dm_kcopyd_exit(void)
243{ 235{
244 BUG_ON(!list_empty(&_complete_jobs));
245 BUG_ON(!list_empty(&_io_jobs));
246 BUG_ON(!list_empty(&_pages_jobs));
247
248 mempool_destroy(_job_pool);
249 kmem_cache_destroy(_job_cache); 236 kmem_cache_destroy(_job_cache);
250 _job_pool = NULL;
251 _job_cache = NULL; 237 _job_cache = NULL;
252} 238}
253 239
@@ -255,18 +241,19 @@ static void jobs_exit(void)
255 * Functions to push and pop a job onto the head of a given job 241 * Functions to push and pop a job onto the head of a given job
256 * list. 242 * list.
257 */ 243 */
258static struct kcopyd_job *pop(struct list_head *jobs) 244static struct kcopyd_job *pop(struct list_head *jobs,
245 struct dm_kcopyd_client *kc)
259{ 246{
260 struct kcopyd_job *job = NULL; 247 struct kcopyd_job *job = NULL;
261 unsigned long flags; 248 unsigned long flags;
262 249
263 spin_lock_irqsave(&_job_lock, flags); 250 spin_lock_irqsave(&kc->job_lock, flags);
264 251
265 if (!list_empty(jobs)) { 252 if (!list_empty(jobs)) {
266 job = list_entry(jobs->next, struct kcopyd_job, list); 253 job = list_entry(jobs->next, struct kcopyd_job, list);
267 list_del(&job->list); 254 list_del(&job->list);
268 } 255 }
269 spin_unlock_irqrestore(&_job_lock, flags); 256 spin_unlock_irqrestore(&kc->job_lock, flags);
270 257
271 return job; 258 return job;
272} 259}
@@ -274,10 +261,11 @@ static struct kcopyd_job *pop(struct list_head *jobs)
274static void push(struct list_head *jobs, struct kcopyd_job *job) 261static void push(struct list_head *jobs, struct kcopyd_job *job)
275{ 262{
276 unsigned long flags; 263 unsigned long flags;
264 struct dm_kcopyd_client *kc = job->kc;
277 265
278 spin_lock_irqsave(&_job_lock, flags); 266 spin_lock_irqsave(&kc->job_lock, flags);
279 list_add_tail(&job->list, jobs); 267 list_add_tail(&job->list, jobs);
280 spin_unlock_irqrestore(&_job_lock, flags); 268 spin_unlock_irqrestore(&kc->job_lock, flags);
281} 269}
282 270
283/* 271/*
@@ -294,11 +282,11 @@ static int run_complete_job(struct kcopyd_job *job)
294 void *context = job->context; 282 void *context = job->context;
295 int read_err = job->read_err; 283 int read_err = job->read_err;
296 unsigned long write_err = job->write_err; 284 unsigned long write_err = job->write_err;
297 kcopyd_notify_fn fn = job->fn; 285 dm_kcopyd_notify_fn fn = job->fn;
298 struct kcopyd_client *kc = job->kc; 286 struct dm_kcopyd_client *kc = job->kc;
299 287
300 kcopyd_put_pages(kc, job->pages); 288 kcopyd_put_pages(kc, job->pages);
301 mempool_free(job, _job_pool); 289 mempool_free(job, kc->job_pool);
302 fn(read_err, write_err, context); 290 fn(read_err, write_err, context);
303 291
304 if (atomic_dec_and_test(&kc->nr_jobs)) 292 if (atomic_dec_and_test(&kc->nr_jobs))
@@ -310,6 +298,7 @@ static int run_complete_job(struct kcopyd_job *job)
310static void complete_io(unsigned long error, void *context) 298static void complete_io(unsigned long error, void *context)
311{ 299{
312 struct kcopyd_job *job = (struct kcopyd_job *) context; 300 struct kcopyd_job *job = (struct kcopyd_job *) context;
301 struct dm_kcopyd_client *kc = job->kc;
313 302
314 if (error) { 303 if (error) {
315 if (job->rw == WRITE) 304 if (job->rw == WRITE)
@@ -317,22 +306,22 @@ static void complete_io(unsigned long error, void *context)
317 else 306 else
318 job->read_err = 1; 307 job->read_err = 1;
319 308
320 if (!test_bit(KCOPYD_IGNORE_ERROR, &job->flags)) { 309 if (!test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
321 push(&_complete_jobs, job); 310 push(&kc->complete_jobs, job);
322 wake(); 311 wake(kc);
323 return; 312 return;
324 } 313 }
325 } 314 }
326 315
327 if (job->rw == WRITE) 316 if (job->rw == WRITE)
328 push(&_complete_jobs, job); 317 push(&kc->complete_jobs, job);
329 318
330 else { 319 else {
331 job->rw = WRITE; 320 job->rw = WRITE;
332 push(&_io_jobs, job); 321 push(&kc->io_jobs, job);
333 } 322 }
334 323
335 wake(); 324 wake(kc);
336} 325}
337 326
338/* 327/*
@@ -343,7 +332,7 @@ static int run_io_job(struct kcopyd_job *job)
343{ 332{
344 int r; 333 int r;
345 struct dm_io_request io_req = { 334 struct dm_io_request io_req = {
346 .bi_rw = job->rw, 335 .bi_rw = job->rw | (1 << BIO_RW_SYNC),
347 .mem.type = DM_IO_PAGE_LIST, 336 .mem.type = DM_IO_PAGE_LIST,
348 .mem.ptr.pl = job->pages, 337 .mem.ptr.pl = job->pages,
349 .mem.offset = job->offset, 338 .mem.offset = job->offset,
@@ -369,7 +358,7 @@ static int run_pages_job(struct kcopyd_job *job)
369 r = kcopyd_get_pages(job->kc, job->nr_pages, &job->pages); 358 r = kcopyd_get_pages(job->kc, job->nr_pages, &job->pages);
370 if (!r) { 359 if (!r) {
371 /* this job is ready for io */ 360 /* this job is ready for io */
372 push(&_io_jobs, job); 361 push(&job->kc->io_jobs, job);
373 return 0; 362 return 0;
374 } 363 }
375 364
@@ -384,12 +373,13 @@ static int run_pages_job(struct kcopyd_job *job)
384 * Run through a list for as long as possible. Returns the count 373 * Run through a list for as long as possible. Returns the count
385 * of successful jobs. 374 * of successful jobs.
386 */ 375 */
387static int process_jobs(struct list_head *jobs, int (*fn) (struct kcopyd_job *)) 376static int process_jobs(struct list_head *jobs, struct dm_kcopyd_client *kc,
377 int (*fn) (struct kcopyd_job *))
388{ 378{
389 struct kcopyd_job *job; 379 struct kcopyd_job *job;
390 int r, count = 0; 380 int r, count = 0;
391 381
392 while ((job = pop(jobs))) { 382 while ((job = pop(jobs, kc))) {
393 383
394 r = fn(job); 384 r = fn(job);
395 385
@@ -399,7 +389,7 @@ static int process_jobs(struct list_head *jobs, int (*fn) (struct kcopyd_job *))
399 job->write_err = (unsigned long) -1L; 389 job->write_err = (unsigned long) -1L;
400 else 390 else
401 job->read_err = 1; 391 job->read_err = 1;
402 push(&_complete_jobs, job); 392 push(&kc->complete_jobs, job);
403 break; 393 break;
404 } 394 }
405 395
@@ -421,8 +411,11 @@ static int process_jobs(struct list_head *jobs, int (*fn) (struct kcopyd_job *))
421/* 411/*
422 * kcopyd does this every time it's woken up. 412 * kcopyd does this every time it's woken up.
423 */ 413 */
424static void do_work(struct work_struct *ignored) 414static void do_work(struct work_struct *work)
425{ 415{
416 struct dm_kcopyd_client *kc = container_of(work,
417 struct dm_kcopyd_client, kcopyd_work);
418
426 /* 419 /*
427 * The order that these are called is *very* important. 420 * The order that these are called is *very* important.
428 * complete jobs can free some pages for pages jobs. 421 * complete jobs can free some pages for pages jobs.
@@ -430,9 +423,9 @@ static void do_work(struct work_struct *ignored)
430 * list. io jobs call wake when they complete and it all 423 * list. io jobs call wake when they complete and it all
431 * starts again. 424 * starts again.
432 */ 425 */
433 process_jobs(&_complete_jobs, run_complete_job); 426 process_jobs(&kc->complete_jobs, kc, run_complete_job);
434 process_jobs(&_pages_jobs, run_pages_job); 427 process_jobs(&kc->pages_jobs, kc, run_pages_job);
435 process_jobs(&_io_jobs, run_io_job); 428 process_jobs(&kc->io_jobs, kc, run_io_job);
436} 429}
437 430
438/* 431/*
@@ -442,9 +435,10 @@ static void do_work(struct work_struct *ignored)
442 */ 435 */
443static void dispatch_job(struct kcopyd_job *job) 436static void dispatch_job(struct kcopyd_job *job)
444{ 437{
445 atomic_inc(&job->kc->nr_jobs); 438 struct dm_kcopyd_client *kc = job->kc;
446 push(&_pages_jobs, job); 439 atomic_inc(&kc->nr_jobs);
447 wake(); 440 push(&kc->pages_jobs, job);
441 wake(kc);
448} 442}
449 443
450#define SUB_JOB_SIZE 128 444#define SUB_JOB_SIZE 128
@@ -469,7 +463,7 @@ static void segment_complete(int read_err, unsigned long write_err,
469 * Only dispatch more work if there hasn't been an error. 463 * Only dispatch more work if there hasn't been an error.
470 */ 464 */
471 if ((!job->read_err && !job->write_err) || 465 if ((!job->read_err && !job->write_err) ||
472 test_bit(KCOPYD_IGNORE_ERROR, &job->flags)) { 466 test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
473 /* get the next chunk of work */ 467 /* get the next chunk of work */
474 progress = job->progress; 468 progress = job->progress;
475 count = job->source.count - progress; 469 count = job->source.count - progress;
@@ -484,7 +478,8 @@ static void segment_complete(int read_err, unsigned long write_err,
484 478
485 if (count) { 479 if (count) {
486 int i; 480 int i;
487 struct kcopyd_job *sub_job = mempool_alloc(_job_pool, GFP_NOIO); 481 struct kcopyd_job *sub_job = mempool_alloc(job->kc->job_pool,
482 GFP_NOIO);
488 483
489 *sub_job = *job; 484 *sub_job = *job;
490 sub_job->source.sector += progress; 485 sub_job->source.sector += progress;
@@ -508,7 +503,7 @@ static void segment_complete(int read_err, unsigned long write_err,
508 * after we've completed. 503 * after we've completed.
509 */ 504 */
510 job->fn(read_err, write_err, job->context); 505 job->fn(read_err, write_err, job->context);
511 mempool_free(job, _job_pool); 506 mempool_free(job, job->kc->job_pool);
512 } 507 }
513} 508}
514 509
@@ -526,16 +521,16 @@ static void split_job(struct kcopyd_job *job)
526 segment_complete(0, 0u, job); 521 segment_complete(0, 0u, job);
527} 522}
528 523
529int kcopyd_copy(struct kcopyd_client *kc, struct io_region *from, 524int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
530 unsigned int num_dests, struct io_region *dests, 525 unsigned int num_dests, struct dm_io_region *dests,
531 unsigned int flags, kcopyd_notify_fn fn, void *context) 526 unsigned int flags, dm_kcopyd_notify_fn fn, void *context)
532{ 527{
533 struct kcopyd_job *job; 528 struct kcopyd_job *job;
534 529
535 /* 530 /*
536 * Allocate a new job. 531 * Allocate a new job.
537 */ 532 */
538 job = mempool_alloc(_job_pool, GFP_NOIO); 533 job = mempool_alloc(kc->job_pool, GFP_NOIO);
539 534
540 /* 535 /*
541 * set up for the read. 536 * set up for the read.
@@ -569,6 +564,7 @@ int kcopyd_copy(struct kcopyd_client *kc, struct io_region *from,
569 564
570 return 0; 565 return 0;
571} 566}
567EXPORT_SYMBOL(dm_kcopyd_copy);
572 568
573/* 569/*
574 * Cancels a kcopyd job, eg. someone might be deactivating a 570 * Cancels a kcopyd job, eg. someone might be deactivating a
@@ -583,126 +579,76 @@ int kcopyd_cancel(struct kcopyd_job *job, int block)
583#endif /* 0 */ 579#endif /* 0 */
584 580
585/*----------------------------------------------------------------- 581/*-----------------------------------------------------------------
586 * Unit setup 582 * Client setup
587 *---------------------------------------------------------------*/ 583 *---------------------------------------------------------------*/
588static DEFINE_MUTEX(_client_lock); 584int dm_kcopyd_client_create(unsigned int nr_pages,
589static LIST_HEAD(_clients); 585 struct dm_kcopyd_client **result)
590
591static void client_add(struct kcopyd_client *kc)
592{ 586{
593 mutex_lock(&_client_lock); 587 int r = -ENOMEM;
594 list_add(&kc->list, &_clients); 588 struct dm_kcopyd_client *kc;
595 mutex_unlock(&_client_lock);
596}
597
598static void client_del(struct kcopyd_client *kc)
599{
600 mutex_lock(&_client_lock);
601 list_del(&kc->list);
602 mutex_unlock(&_client_lock);
603}
604
605static DEFINE_MUTEX(kcopyd_init_lock);
606static int kcopyd_clients = 0;
607 589
608static int kcopyd_init(void) 590 kc = kmalloc(sizeof(*kc), GFP_KERNEL);
609{ 591 if (!kc)
610 int r;
611
612 mutex_lock(&kcopyd_init_lock);
613
614 if (kcopyd_clients) {
615 /* Already initialized. */
616 kcopyd_clients++;
617 mutex_unlock(&kcopyd_init_lock);
618 return 0;
619 }
620
621 r = jobs_init();
622 if (r) {
623 mutex_unlock(&kcopyd_init_lock);
624 return r;
625 }
626
627 _kcopyd_wq = create_singlethread_workqueue("kcopyd");
628 if (!_kcopyd_wq) {
629 jobs_exit();
630 mutex_unlock(&kcopyd_init_lock);
631 return -ENOMEM; 592 return -ENOMEM;
632 }
633
634 kcopyd_clients++;
635 INIT_WORK(&_kcopyd_work, do_work);
636 mutex_unlock(&kcopyd_init_lock);
637 return 0;
638}
639 593
640static void kcopyd_exit(void) 594 spin_lock_init(&kc->lock);
641{ 595 spin_lock_init(&kc->job_lock);
642 mutex_lock(&kcopyd_init_lock); 596 INIT_LIST_HEAD(&kc->complete_jobs);
643 kcopyd_clients--; 597 INIT_LIST_HEAD(&kc->io_jobs);
644 if (!kcopyd_clients) { 598 INIT_LIST_HEAD(&kc->pages_jobs);
645 jobs_exit();
646 destroy_workqueue(_kcopyd_wq);
647 _kcopyd_wq = NULL;
648 }
649 mutex_unlock(&kcopyd_init_lock);
650}
651
652int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result)
653{
654 int r = 0;
655 struct kcopyd_client *kc;
656 599
657 r = kcopyd_init(); 600 kc->job_pool = mempool_create_slab_pool(MIN_JOBS, _job_cache);
658 if (r) 601 if (!kc->job_pool)
659 return r; 602 goto bad_slab;
660 603
661 kc = kmalloc(sizeof(*kc), GFP_KERNEL); 604 INIT_WORK(&kc->kcopyd_work, do_work);
662 if (!kc) { 605 kc->kcopyd_wq = create_singlethread_workqueue("kcopyd");
663 kcopyd_exit(); 606 if (!kc->kcopyd_wq)
664 return -ENOMEM; 607 goto bad_workqueue;
665 }
666 608
667 spin_lock_init(&kc->lock);
668 kc->pages = NULL; 609 kc->pages = NULL;
669 kc->nr_pages = kc->nr_free_pages = 0; 610 kc->nr_pages = kc->nr_free_pages = 0;
670 r = client_alloc_pages(kc, nr_pages); 611 r = client_alloc_pages(kc, nr_pages);
671 if (r) { 612 if (r)
672 kfree(kc); 613 goto bad_client_pages;
673 kcopyd_exit();
674 return r;
675 }
676 614
677 kc->io_client = dm_io_client_create(nr_pages); 615 kc->io_client = dm_io_client_create(nr_pages);
678 if (IS_ERR(kc->io_client)) { 616 if (IS_ERR(kc->io_client)) {
679 r = PTR_ERR(kc->io_client); 617 r = PTR_ERR(kc->io_client);
680 client_free_pages(kc); 618 goto bad_io_client;
681 kfree(kc);
682 kcopyd_exit();
683 return r;
684 } 619 }
685 620
686 init_waitqueue_head(&kc->destroyq); 621 init_waitqueue_head(&kc->destroyq);
687 atomic_set(&kc->nr_jobs, 0); 622 atomic_set(&kc->nr_jobs, 0);
688 623
689 client_add(kc);
690 *result = kc; 624 *result = kc;
691 return 0; 625 return 0;
626
627bad_io_client:
628 client_free_pages(kc);
629bad_client_pages:
630 destroy_workqueue(kc->kcopyd_wq);
631bad_workqueue:
632 mempool_destroy(kc->job_pool);
633bad_slab:
634 kfree(kc);
635
636 return r;
692} 637}
638EXPORT_SYMBOL(dm_kcopyd_client_create);
693 639
694void kcopyd_client_destroy(struct kcopyd_client *kc) 640void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc)
695{ 641{
696 /* Wait for completion of all jobs submitted by this client. */ 642 /* Wait for completion of all jobs submitted by this client. */
697 wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs)); 643 wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs));
698 644
645 BUG_ON(!list_empty(&kc->complete_jobs));
646 BUG_ON(!list_empty(&kc->io_jobs));
647 BUG_ON(!list_empty(&kc->pages_jobs));
648 destroy_workqueue(kc->kcopyd_wq);
699 dm_io_client_destroy(kc->io_client); 649 dm_io_client_destroy(kc->io_client);
700 client_free_pages(kc); 650 client_free_pages(kc);
701 client_del(kc); 651 mempool_destroy(kc->job_pool);
702 kfree(kc); 652 kfree(kc);
703 kcopyd_exit();
704} 653}
705 654EXPORT_SYMBOL(dm_kcopyd_client_destroy);
706EXPORT_SYMBOL(kcopyd_client_create);
707EXPORT_SYMBOL(kcopyd_client_destroy);
708EXPORT_SYMBOL(kcopyd_copy);
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 2a74b2142f50..67a6f31b7fc3 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (C) 2003 Sistina Software 2 * Copyright (C) 2003 Sistina Software
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
3 * 4 *
4 * This file is released under the LGPL. 5 * This file is released under the LGPL.
5 */ 6 */
@@ -8,64 +9,58 @@
8#include <linux/slab.h> 9#include <linux/slab.h>
9#include <linux/module.h> 10#include <linux/module.h>
10#include <linux/vmalloc.h> 11#include <linux/vmalloc.h>
12#include <linux/dm-io.h>
13#include <linux/dm-dirty-log.h>
11 14
12#include "dm-log.h" 15#include "dm.h"
13#include "dm-io.h"
14 16
15#define DM_MSG_PREFIX "mirror log" 17#define DM_MSG_PREFIX "dirty region log"
16 18
17static LIST_HEAD(_log_types); 19struct dm_dirty_log_internal {
18static DEFINE_SPINLOCK(_lock); 20 struct dm_dirty_log_type *type;
19 21
20int dm_register_dirty_log_type(struct dirty_log_type *type) 22 struct list_head list;
21{ 23 long use;
22 spin_lock(&_lock); 24};
23 type->use_count = 0;
24 list_add(&type->list, &_log_types);
25 spin_unlock(&_lock);
26 25
27 return 0; 26static LIST_HEAD(_log_types);
28} 27static DEFINE_SPINLOCK(_lock);
29 28
30int dm_unregister_dirty_log_type(struct dirty_log_type *type) 29static struct dm_dirty_log_internal *__find_dirty_log_type(const char *name)
31{ 30{
32 spin_lock(&_lock); 31 struct dm_dirty_log_internal *log_type;
33
34 if (type->use_count)
35 DMWARN("Attempt to unregister a log type that is still in use");
36 else
37 list_del(&type->list);
38 32
39 spin_unlock(&_lock); 33 list_for_each_entry(log_type, &_log_types, list)
34 if (!strcmp(name, log_type->type->name))
35 return log_type;
40 36
41 return 0; 37 return NULL;
42} 38}
43 39
44static struct dirty_log_type *_get_type(const char *type_name) 40static struct dm_dirty_log_internal *_get_dirty_log_type(const char *name)
45{ 41{
46 struct dirty_log_type *type; 42 struct dm_dirty_log_internal *log_type;
47 43
48 spin_lock(&_lock); 44 spin_lock(&_lock);
49 list_for_each_entry (type, &_log_types, list) 45
50 if (!strcmp(type_name, type->name)) { 46 log_type = __find_dirty_log_type(name);
51 if (!type->use_count && !try_module_get(type->module)){ 47 if (log_type) {
52 spin_unlock(&_lock); 48 if (!log_type->use && !try_module_get(log_type->type->module))
53 return NULL; 49 log_type = NULL;
54 } 50 else
55 type->use_count++; 51 log_type->use++;
56 spin_unlock(&_lock); 52 }
57 return type;
58 }
59 53
60 spin_unlock(&_lock); 54 spin_unlock(&_lock);
61 return NULL; 55
56 return log_type;
62} 57}
63 58
64/* 59/*
65 * get_type 60 * get_type
66 * @type_name 61 * @type_name
67 * 62 *
68 * Attempt to retrieve the dirty_log_type by name. If not already 63 * Attempt to retrieve the dm_dirty_log_type by name. If not already
69 * available, attempt to load the appropriate module. 64 * available, attempt to load the appropriate module.
70 * 65 *
71 * Log modules are named "dm-log-" followed by the 'type_name'. 66 * Log modules are named "dm-log-" followed by the 'type_name'.
@@ -78,14 +73,17 @@ static struct dirty_log_type *_get_type(const char *type_name)
78 * 73 *
79 * Returns: dirty_log_type* on success, NULL on failure 74 * Returns: dirty_log_type* on success, NULL on failure
80 */ 75 */
81static struct dirty_log_type *get_type(const char *type_name) 76static struct dm_dirty_log_type *get_type(const char *type_name)
82{ 77{
83 char *p, *type_name_dup; 78 char *p, *type_name_dup;
84 struct dirty_log_type *type; 79 struct dm_dirty_log_internal *log_type;
80
81 if (!type_name)
82 return NULL;
85 83
86 type = _get_type(type_name); 84 log_type = _get_dirty_log_type(type_name);
87 if (type) 85 if (log_type)
88 return type; 86 return log_type->type;
89 87
90 type_name_dup = kstrdup(type_name, GFP_KERNEL); 88 type_name_dup = kstrdup(type_name, GFP_KERNEL);
91 if (!type_name_dup) { 89 if (!type_name_dup) {
@@ -95,34 +93,106 @@ static struct dirty_log_type *get_type(const char *type_name)
95 } 93 }
96 94
97 while (request_module("dm-log-%s", type_name_dup) || 95 while (request_module("dm-log-%s", type_name_dup) ||
98 !(type = _get_type(type_name))) { 96 !(log_type = _get_dirty_log_type(type_name))) {
99 p = strrchr(type_name_dup, '-'); 97 p = strrchr(type_name_dup, '-');
100 if (!p) 98 if (!p)
101 break; 99 break;
102 p[0] = '\0'; 100 p[0] = '\0';
103 } 101 }
104 102
105 if (!type) 103 if (!log_type)
106 DMWARN("Module for logging type \"%s\" not found.", type_name); 104 DMWARN("Module for logging type \"%s\" not found.", type_name);
107 105
108 kfree(type_name_dup); 106 kfree(type_name_dup);
109 107
110 return type; 108 return log_type ? log_type->type : NULL;
111} 109}
112 110
113static void put_type(struct dirty_log_type *type) 111static void put_type(struct dm_dirty_log_type *type)
114{ 112{
113 struct dm_dirty_log_internal *log_type;
114
115 if (!type)
116 return;
117
115 spin_lock(&_lock); 118 spin_lock(&_lock);
116 if (!--type->use_count) 119 log_type = __find_dirty_log_type(type->name);
120 if (!log_type)
121 goto out;
122
123 if (!--log_type->use)
117 module_put(type->module); 124 module_put(type->module);
125
126 BUG_ON(log_type->use < 0);
127
128out:
118 spin_unlock(&_lock); 129 spin_unlock(&_lock);
119} 130}
120 131
121struct dirty_log *dm_create_dirty_log(const char *type_name, struct dm_target *ti, 132static struct dm_dirty_log_internal *_alloc_dirty_log_type(struct dm_dirty_log_type *type)
122 unsigned int argc, char **argv)
123{ 133{
124 struct dirty_log_type *type; 134 struct dm_dirty_log_internal *log_type = kzalloc(sizeof(*log_type),
125 struct dirty_log *log; 135 GFP_KERNEL);
136
137 if (log_type)
138 log_type->type = type;
139
140 return log_type;
141}
142
143int dm_dirty_log_type_register(struct dm_dirty_log_type *type)
144{
145 struct dm_dirty_log_internal *log_type = _alloc_dirty_log_type(type);
146 int r = 0;
147
148 if (!log_type)
149 return -ENOMEM;
150
151 spin_lock(&_lock);
152 if (!__find_dirty_log_type(type->name))
153 list_add(&log_type->list, &_log_types);
154 else {
155 kfree(log_type);
156 r = -EEXIST;
157 }
158 spin_unlock(&_lock);
159
160 return r;
161}
162EXPORT_SYMBOL(dm_dirty_log_type_register);
163
164int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type)
165{
166 struct dm_dirty_log_internal *log_type;
167
168 spin_lock(&_lock);
169
170 log_type = __find_dirty_log_type(type->name);
171 if (!log_type) {
172 spin_unlock(&_lock);
173 return -EINVAL;
174 }
175
176 if (log_type->use) {
177 spin_unlock(&_lock);
178 return -ETXTBSY;
179 }
180
181 list_del(&log_type->list);
182
183 spin_unlock(&_lock);
184 kfree(log_type);
185
186 return 0;
187}
188EXPORT_SYMBOL(dm_dirty_log_type_unregister);
189
190struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
191 struct dm_target *ti,
192 unsigned int argc, char **argv)
193{
194 struct dm_dirty_log_type *type;
195 struct dm_dirty_log *log;
126 196
127 log = kmalloc(sizeof(*log), GFP_KERNEL); 197 log = kmalloc(sizeof(*log), GFP_KERNEL);
128 if (!log) 198 if (!log)
@@ -143,13 +213,15 @@ struct dirty_log *dm_create_dirty_log(const char *type_name, struct dm_target *t
143 213
144 return log; 214 return log;
145} 215}
216EXPORT_SYMBOL(dm_dirty_log_create);
146 217
147void dm_destroy_dirty_log(struct dirty_log *log) 218void dm_dirty_log_destroy(struct dm_dirty_log *log)
148{ 219{
149 log->type->dtr(log); 220 log->type->dtr(log);
150 put_type(log->type); 221 put_type(log->type);
151 kfree(log); 222 kfree(log);
152} 223}
224EXPORT_SYMBOL(dm_dirty_log_destroy);
153 225
154/*----------------------------------------------------------------- 226/*-----------------------------------------------------------------
155 * Persistent and core logs share a lot of their implementation. 227 * Persistent and core logs share a lot of their implementation.
@@ -207,7 +279,7 @@ struct log_c {
207 struct dm_dev *log_dev; 279 struct dm_dev *log_dev;
208 struct log_header header; 280 struct log_header header;
209 281
210 struct io_region header_location; 282 struct dm_io_region header_location;
211 struct log_header *disk_header; 283 struct log_header *disk_header;
212}; 284};
213 285
@@ -215,7 +287,7 @@ struct log_c {
215 * The touched member needs to be updated every time we access 287 * The touched member needs to be updated every time we access
216 * one of the bitsets. 288 * one of the bitsets.
217 */ 289 */
218static inline int log_test_bit(uint32_t *bs, unsigned bit) 290static inline int log_test_bit(uint32_t *bs, unsigned bit)
219{ 291{
220 return ext2_test_bit(bit, (unsigned long *) bs) ? 1 : 0; 292 return ext2_test_bit(bit, (unsigned long *) bs) ? 1 : 0;
221} 293}
@@ -302,7 +374,7 @@ static inline int write_header(struct log_c *log)
302 * argv contains region_size followed optionally by [no]sync 374 * argv contains region_size followed optionally by [no]sync
303 *--------------------------------------------------------------*/ 375 *--------------------------------------------------------------*/
304#define BYTE_SHIFT 3 376#define BYTE_SHIFT 3
305static int create_log_context(struct dirty_log *log, struct dm_target *ti, 377static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
306 unsigned int argc, char **argv, 378 unsigned int argc, char **argv,
307 struct dm_dev *dev) 379 struct dm_dev *dev)
308{ 380{
@@ -315,7 +387,7 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
315 int r; 387 int r;
316 388
317 if (argc < 1 || argc > 2) { 389 if (argc < 1 || argc > 2) {
318 DMWARN("wrong number of arguments to mirror log"); 390 DMWARN("wrong number of arguments to dirty region log");
319 return -EINVAL; 391 return -EINVAL;
320 } 392 }
321 393
@@ -325,8 +397,8 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
325 else if (!strcmp(argv[1], "nosync")) 397 else if (!strcmp(argv[1], "nosync"))
326 sync = NOSYNC; 398 sync = NOSYNC;
327 else { 399 else {
328 DMWARN("unrecognised sync argument to mirror log: %s", 400 DMWARN("unrecognised sync argument to "
329 argv[1]); 401 "dirty region log: %s", argv[1]);
330 return -EINVAL; 402 return -EINVAL;
331 } 403 }
332 } 404 }
@@ -434,7 +506,7 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
434 return 0; 506 return 0;
435} 507}
436 508
437static int core_ctr(struct dirty_log *log, struct dm_target *ti, 509static int core_ctr(struct dm_dirty_log *log, struct dm_target *ti,
438 unsigned int argc, char **argv) 510 unsigned int argc, char **argv)
439{ 511{
440 return create_log_context(log, ti, argc, argv, NULL); 512 return create_log_context(log, ti, argc, argv, NULL);
@@ -447,7 +519,7 @@ static void destroy_log_context(struct log_c *lc)
447 kfree(lc); 519 kfree(lc);
448} 520}
449 521
450static void core_dtr(struct dirty_log *log) 522static void core_dtr(struct dm_dirty_log *log)
451{ 523{
452 struct log_c *lc = (struct log_c *) log->context; 524 struct log_c *lc = (struct log_c *) log->context;
453 525
@@ -460,14 +532,14 @@ static void core_dtr(struct dirty_log *log)
460 * 532 *
461 * argv contains log_device region_size followed optionally by [no]sync 533 * argv contains log_device region_size followed optionally by [no]sync
462 *--------------------------------------------------------------*/ 534 *--------------------------------------------------------------*/
463static int disk_ctr(struct dirty_log *log, struct dm_target *ti, 535static int disk_ctr(struct dm_dirty_log *log, struct dm_target *ti,
464 unsigned int argc, char **argv) 536 unsigned int argc, char **argv)
465{ 537{
466 int r; 538 int r;
467 struct dm_dev *dev; 539 struct dm_dev *dev;
468 540
469 if (argc < 2 || argc > 3) { 541 if (argc < 2 || argc > 3) {
470 DMWARN("wrong number of arguments to disk mirror log"); 542 DMWARN("wrong number of arguments to disk dirty region log");
471 return -EINVAL; 543 return -EINVAL;
472 } 544 }
473 545
@@ -485,7 +557,7 @@ static int disk_ctr(struct dirty_log *log, struct dm_target *ti,
485 return 0; 557 return 0;
486} 558}
487 559
488static void disk_dtr(struct dirty_log *log) 560static void disk_dtr(struct dm_dirty_log *log)
489{ 561{
490 struct log_c *lc = (struct log_c *) log->context; 562 struct log_c *lc = (struct log_c *) log->context;
491 563
@@ -514,7 +586,7 @@ static void fail_log_device(struct log_c *lc)
514 dm_table_event(lc->ti->table); 586 dm_table_event(lc->ti->table);
515} 587}
516 588
517static int disk_resume(struct dirty_log *log) 589static int disk_resume(struct dm_dirty_log *log)
518{ 590{
519 int r; 591 int r;
520 unsigned i; 592 unsigned i;
@@ -524,7 +596,7 @@ static int disk_resume(struct dirty_log *log)
524 /* read the disk header */ 596 /* read the disk header */
525 r = read_header(lc); 597 r = read_header(lc);
526 if (r) { 598 if (r) {
527 DMWARN("%s: Failed to read header on mirror log device", 599 DMWARN("%s: Failed to read header on dirty region log device",
528 lc->log_dev->name); 600 lc->log_dev->name);
529 fail_log_device(lc); 601 fail_log_device(lc);
530 /* 602 /*
@@ -562,7 +634,7 @@ static int disk_resume(struct dirty_log *log)
562 /* write the new header */ 634 /* write the new header */
563 r = write_header(lc); 635 r = write_header(lc);
564 if (r) { 636 if (r) {
565 DMWARN("%s: Failed to write header on mirror log device", 637 DMWARN("%s: Failed to write header on dirty region log device",
566 lc->log_dev->name); 638 lc->log_dev->name);
567 fail_log_device(lc); 639 fail_log_device(lc);
568 } 640 }
@@ -570,38 +642,38 @@ static int disk_resume(struct dirty_log *log)
570 return r; 642 return r;
571} 643}
572 644
573static uint32_t core_get_region_size(struct dirty_log *log) 645static uint32_t core_get_region_size(struct dm_dirty_log *log)
574{ 646{
575 struct log_c *lc = (struct log_c *) log->context; 647 struct log_c *lc = (struct log_c *) log->context;
576 return lc->region_size; 648 return lc->region_size;
577} 649}
578 650
579static int core_resume(struct dirty_log *log) 651static int core_resume(struct dm_dirty_log *log)
580{ 652{
581 struct log_c *lc = (struct log_c *) log->context; 653 struct log_c *lc = (struct log_c *) log->context;
582 lc->sync_search = 0; 654 lc->sync_search = 0;
583 return 0; 655 return 0;
584} 656}
585 657
586static int core_is_clean(struct dirty_log *log, region_t region) 658static int core_is_clean(struct dm_dirty_log *log, region_t region)
587{ 659{
588 struct log_c *lc = (struct log_c *) log->context; 660 struct log_c *lc = (struct log_c *) log->context;
589 return log_test_bit(lc->clean_bits, region); 661 return log_test_bit(lc->clean_bits, region);
590} 662}
591 663
592static int core_in_sync(struct dirty_log *log, region_t region, int block) 664static int core_in_sync(struct dm_dirty_log *log, region_t region, int block)
593{ 665{
594 struct log_c *lc = (struct log_c *) log->context; 666 struct log_c *lc = (struct log_c *) log->context;
595 return log_test_bit(lc->sync_bits, region); 667 return log_test_bit(lc->sync_bits, region);
596} 668}
597 669
598static int core_flush(struct dirty_log *log) 670static int core_flush(struct dm_dirty_log *log)
599{ 671{
600 /* no op */ 672 /* no op */
601 return 0; 673 return 0;
602} 674}
603 675
604static int disk_flush(struct dirty_log *log) 676static int disk_flush(struct dm_dirty_log *log)
605{ 677{
606 int r; 678 int r;
607 struct log_c *lc = (struct log_c *) log->context; 679 struct log_c *lc = (struct log_c *) log->context;
@@ -619,19 +691,19 @@ static int disk_flush(struct dirty_log *log)
619 return r; 691 return r;
620} 692}
621 693
622static void core_mark_region(struct dirty_log *log, region_t region) 694static void core_mark_region(struct dm_dirty_log *log, region_t region)
623{ 695{
624 struct log_c *lc = (struct log_c *) log->context; 696 struct log_c *lc = (struct log_c *) log->context;
625 log_clear_bit(lc, lc->clean_bits, region); 697 log_clear_bit(lc, lc->clean_bits, region);
626} 698}
627 699
628static void core_clear_region(struct dirty_log *log, region_t region) 700static void core_clear_region(struct dm_dirty_log *log, region_t region)
629{ 701{
630 struct log_c *lc = (struct log_c *) log->context; 702 struct log_c *lc = (struct log_c *) log->context;
631 log_set_bit(lc, lc->clean_bits, region); 703 log_set_bit(lc, lc->clean_bits, region);
632} 704}
633 705
634static int core_get_resync_work(struct dirty_log *log, region_t *region) 706static int core_get_resync_work(struct dm_dirty_log *log, region_t *region)
635{ 707{
636 struct log_c *lc = (struct log_c *) log->context; 708 struct log_c *lc = (struct log_c *) log->context;
637 709
@@ -654,7 +726,7 @@ static int core_get_resync_work(struct dirty_log *log, region_t *region)
654 return 1; 726 return 1;
655} 727}
656 728
657static void core_set_region_sync(struct dirty_log *log, region_t region, 729static void core_set_region_sync(struct dm_dirty_log *log, region_t region,
658 int in_sync) 730 int in_sync)
659{ 731{
660 struct log_c *lc = (struct log_c *) log->context; 732 struct log_c *lc = (struct log_c *) log->context;
@@ -669,7 +741,7 @@ static void core_set_region_sync(struct dirty_log *log, region_t region,
669 } 741 }
670} 742}
671 743
672static region_t core_get_sync_count(struct dirty_log *log) 744static region_t core_get_sync_count(struct dm_dirty_log *log)
673{ 745{
674 struct log_c *lc = (struct log_c *) log->context; 746 struct log_c *lc = (struct log_c *) log->context;
675 747
@@ -680,7 +752,7 @@ static region_t core_get_sync_count(struct dirty_log *log)
680 if (lc->sync != DEFAULTSYNC) \ 752 if (lc->sync != DEFAULTSYNC) \
681 DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "") 753 DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "")
682 754
683static int core_status(struct dirty_log *log, status_type_t status, 755static int core_status(struct dm_dirty_log *log, status_type_t status,
684 char *result, unsigned int maxlen) 756 char *result, unsigned int maxlen)
685{ 757{
686 int sz = 0; 758 int sz = 0;
@@ -700,7 +772,7 @@ static int core_status(struct dirty_log *log, status_type_t status,
700 return sz; 772 return sz;
701} 773}
702 774
703static int disk_status(struct dirty_log *log, status_type_t status, 775static int disk_status(struct dm_dirty_log *log, status_type_t status,
704 char *result, unsigned int maxlen) 776 char *result, unsigned int maxlen)
705{ 777{
706 int sz = 0; 778 int sz = 0;
@@ -722,7 +794,7 @@ static int disk_status(struct dirty_log *log, status_type_t status,
722 return sz; 794 return sz;
723} 795}
724 796
725static struct dirty_log_type _core_type = { 797static struct dm_dirty_log_type _core_type = {
726 .name = "core", 798 .name = "core",
727 .module = THIS_MODULE, 799 .module = THIS_MODULE,
728 .ctr = core_ctr, 800 .ctr = core_ctr,
@@ -740,7 +812,7 @@ static struct dirty_log_type _core_type = {
740 .status = core_status, 812 .status = core_status,
741}; 813};
742 814
743static struct dirty_log_type _disk_type = { 815static struct dm_dirty_log_type _disk_type = {
744 .name = "disk", 816 .name = "disk",
745 .module = THIS_MODULE, 817 .module = THIS_MODULE,
746 .ctr = disk_ctr, 818 .ctr = disk_ctr,
@@ -763,26 +835,28 @@ int __init dm_dirty_log_init(void)
763{ 835{
764 int r; 836 int r;
765 837
766 r = dm_register_dirty_log_type(&_core_type); 838 r = dm_dirty_log_type_register(&_core_type);
767 if (r) 839 if (r)
768 DMWARN("couldn't register core log"); 840 DMWARN("couldn't register core log");
769 841
770 r = dm_register_dirty_log_type(&_disk_type); 842 r = dm_dirty_log_type_register(&_disk_type);
771 if (r) { 843 if (r) {
772 DMWARN("couldn't register disk type"); 844 DMWARN("couldn't register disk type");
773 dm_unregister_dirty_log_type(&_core_type); 845 dm_dirty_log_type_unregister(&_core_type);
774 } 846 }
775 847
776 return r; 848 return r;
777} 849}
778 850
779void dm_dirty_log_exit(void) 851void __exit dm_dirty_log_exit(void)
780{ 852{
781 dm_unregister_dirty_log_type(&_disk_type); 853 dm_dirty_log_type_unregister(&_disk_type);
782 dm_unregister_dirty_log_type(&_core_type); 854 dm_dirty_log_type_unregister(&_core_type);
783} 855}
784 856
785EXPORT_SYMBOL(dm_register_dirty_log_type); 857module_init(dm_dirty_log_init);
786EXPORT_SYMBOL(dm_unregister_dirty_log_type); 858module_exit(dm_dirty_log_exit);
787EXPORT_SYMBOL(dm_create_dirty_log); 859
788EXPORT_SYMBOL(dm_destroy_dirty_log); 860MODULE_DESCRIPTION(DM_NAME " dirty region log");
861MODULE_AUTHOR("Joe Thornber, Heinz Mauelshagen <dm-devel@redhat.com>");
862MODULE_LICENSE("GPL");
diff --git a/drivers/md/dm-log.h b/drivers/md/dm-log.h
deleted file mode 100644
index 3fae87eb5963..000000000000
--- a/drivers/md/dm-log.h
+++ /dev/null
@@ -1,131 +0,0 @@
1/*
2 * Copyright (C) 2003 Sistina Software
3 *
4 * This file is released under the LGPL.
5 */
6
7#ifndef DM_DIRTY_LOG
8#define DM_DIRTY_LOG
9
10#include "dm.h"
11
12typedef sector_t region_t;
13
14struct dirty_log_type;
15
16struct dirty_log {
17 struct dirty_log_type *type;
18 void *context;
19};
20
21struct dirty_log_type {
22 struct list_head list;
23 const char *name;
24 struct module *module;
25 unsigned int use_count;
26
27 int (*ctr)(struct dirty_log *log, struct dm_target *ti,
28 unsigned int argc, char **argv);
29 void (*dtr)(struct dirty_log *log);
30
31 /*
32 * There are times when we don't want the log to touch
33 * the disk.
34 */
35 int (*presuspend)(struct dirty_log *log);
36 int (*postsuspend)(struct dirty_log *log);
37 int (*resume)(struct dirty_log *log);
38
39 /*
40 * Retrieves the smallest size of region that the log can
41 * deal with.
42 */
43 uint32_t (*get_region_size)(struct dirty_log *log);
44
45 /*
46 * A predicate to say whether a region is clean or not.
47 * May block.
48 */
49 int (*is_clean)(struct dirty_log *log, region_t region);
50
51 /*
52 * Returns: 0, 1, -EWOULDBLOCK, < 0
53 *
54 * A predicate function to check the area given by
55 * [sector, sector + len) is in sync.
56 *
57 * If -EWOULDBLOCK is returned the state of the region is
58 * unknown, typically this will result in a read being
59 * passed to a daemon to deal with, since a daemon is
60 * allowed to block.
61 */
62 int (*in_sync)(struct dirty_log *log, region_t region, int can_block);
63
64 /*
65 * Flush the current log state (eg, to disk). This
66 * function may block.
67 */
68 int (*flush)(struct dirty_log *log);
69
70 /*
71 * Mark an area as clean or dirty. These functions may
72 * block, though for performance reasons blocking should
73 * be extremely rare (eg, allocating another chunk of
74 * memory for some reason).
75 */
76 void (*mark_region)(struct dirty_log *log, region_t region);
77 void (*clear_region)(struct dirty_log *log, region_t region);
78
79 /*
80 * Returns: <0 (error), 0 (no region), 1 (region)
81 *
82 * The mirrord will need perform recovery on regions of
83 * the mirror that are in the NOSYNC state. This
84 * function asks the log to tell the caller about the
85 * next region that this machine should recover.
86 *
87 * Do not confuse this function with 'in_sync()', one
88 * tells you if an area is synchronised, the other
89 * assigns recovery work.
90 */
91 int (*get_resync_work)(struct dirty_log *log, region_t *region);
92
93 /*
94 * This notifies the log that the resync status of a region
95 * has changed. It also clears the region from the recovering
96 * list (if present).
97 */
98 void (*set_region_sync)(struct dirty_log *log,
99 region_t region, int in_sync);
100
101 /*
102 * Returns the number of regions that are in sync.
103 */
104 region_t (*get_sync_count)(struct dirty_log *log);
105
106 /*
107 * Support function for mirror status requests.
108 */
109 int (*status)(struct dirty_log *log, status_type_t status_type,
110 char *result, unsigned int maxlen);
111};
112
113int dm_register_dirty_log_type(struct dirty_log_type *type);
114int dm_unregister_dirty_log_type(struct dirty_log_type *type);
115
116
117/*
118 * Make sure you use these two functions, rather than calling
119 * type->constructor/destructor() directly.
120 */
121struct dirty_log *dm_create_dirty_log(const char *type_name, struct dm_target *ti,
122 unsigned int argc, char **argv);
123void dm_destroy_dirty_log(struct dirty_log *log);
124
125/*
126 * init/exit functions.
127 */
128int dm_dirty_log_init(void);
129void dm_dirty_log_exit(void);
130
131#endif
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 762cb086bb7f..ff05fe893083 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -7,9 +7,6 @@
7#include "dm.h" 7#include "dm.h"
8#include "dm-bio-list.h" 8#include "dm-bio-list.h"
9#include "dm-bio-record.h" 9#include "dm-bio-record.h"
10#include "dm-io.h"
11#include "dm-log.h"
12#include "kcopyd.h"
13 10
14#include <linux/ctype.h> 11#include <linux/ctype.h>
15#include <linux/init.h> 12#include <linux/init.h>
@@ -22,6 +19,9 @@
22#include <linux/workqueue.h> 19#include <linux/workqueue.h>
23#include <linux/log2.h> 20#include <linux/log2.h>
24#include <linux/hardirq.h> 21#include <linux/hardirq.h>
22#include <linux/dm-io.h>
23#include <linux/dm-dirty-log.h>
24#include <linux/dm-kcopyd.h>
25 25
26#define DM_MSG_PREFIX "raid1" 26#define DM_MSG_PREFIX "raid1"
27#define DM_IO_PAGES 64 27#define DM_IO_PAGES 64
@@ -74,7 +74,7 @@ struct region_hash {
74 unsigned region_shift; 74 unsigned region_shift;
75 75
76 /* holds persistent region state */ 76 /* holds persistent region state */
77 struct dirty_log *log; 77 struct dm_dirty_log *log;
78 78
79 /* hash table */ 79 /* hash table */
80 rwlock_t hash_lock; 80 rwlock_t hash_lock;
@@ -133,7 +133,7 @@ struct mirror_set {
133 struct dm_target *ti; 133 struct dm_target *ti;
134 struct list_head list; 134 struct list_head list;
135 struct region_hash rh; 135 struct region_hash rh;
136 struct kcopyd_client *kcopyd_client; 136 struct dm_kcopyd_client *kcopyd_client;
137 uint64_t features; 137 uint64_t features;
138 138
139 spinlock_t lock; /* protects the lists */ 139 spinlock_t lock; /* protects the lists */
@@ -154,6 +154,9 @@ struct mirror_set {
154 154
155 struct workqueue_struct *kmirrord_wq; 155 struct workqueue_struct *kmirrord_wq;
156 struct work_struct kmirrord_work; 156 struct work_struct kmirrord_work;
157 struct timer_list timer;
158 unsigned long timer_pending;
159
157 struct work_struct trigger_event; 160 struct work_struct trigger_event;
158 161
159 unsigned int nr_mirrors; 162 unsigned int nr_mirrors;
@@ -178,13 +181,32 @@ static void wake(struct mirror_set *ms)
178 queue_work(ms->kmirrord_wq, &ms->kmirrord_work); 181 queue_work(ms->kmirrord_wq, &ms->kmirrord_work);
179} 182}
180 183
184static void delayed_wake_fn(unsigned long data)
185{
186 struct mirror_set *ms = (struct mirror_set *) data;
187
188 clear_bit(0, &ms->timer_pending);
189 wake(ms);
190}
191
192static void delayed_wake(struct mirror_set *ms)
193{
194 if (test_and_set_bit(0, &ms->timer_pending))
195 return;
196
197 ms->timer.expires = jiffies + HZ / 5;
198 ms->timer.data = (unsigned long) ms;
199 ms->timer.function = delayed_wake_fn;
200 add_timer(&ms->timer);
201}
202
181/* FIXME move this */ 203/* FIXME move this */
182static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw); 204static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw);
183 205
184#define MIN_REGIONS 64 206#define MIN_REGIONS 64
185#define MAX_RECOVERY 1 207#define MAX_RECOVERY 1
186static int rh_init(struct region_hash *rh, struct mirror_set *ms, 208static int rh_init(struct region_hash *rh, struct mirror_set *ms,
187 struct dirty_log *log, uint32_t region_size, 209 struct dm_dirty_log *log, uint32_t region_size,
188 region_t nr_regions) 210 region_t nr_regions)
189{ 211{
190 unsigned int nr_buckets, max_buckets; 212 unsigned int nr_buckets, max_buckets;
@@ -249,7 +271,7 @@ static void rh_exit(struct region_hash *rh)
249 } 271 }
250 272
251 if (rh->log) 273 if (rh->log)
252 dm_destroy_dirty_log(rh->log); 274 dm_dirty_log_destroy(rh->log);
253 if (rh->region_pool) 275 if (rh->region_pool)
254 mempool_destroy(rh->region_pool); 276 mempool_destroy(rh->region_pool);
255 vfree(rh->buckets); 277 vfree(rh->buckets);
@@ -405,24 +427,22 @@ static void rh_update_states(struct region_hash *rh)
405 write_lock_irq(&rh->hash_lock); 427 write_lock_irq(&rh->hash_lock);
406 spin_lock(&rh->region_lock); 428 spin_lock(&rh->region_lock);
407 if (!list_empty(&rh->clean_regions)) { 429 if (!list_empty(&rh->clean_regions)) {
408 list_splice(&rh->clean_regions, &clean); 430 list_splice_init(&rh->clean_regions, &clean);
409 INIT_LIST_HEAD(&rh->clean_regions);
410 431
411 list_for_each_entry(reg, &clean, list) 432 list_for_each_entry(reg, &clean, list)
412 list_del(&reg->hash_list); 433 list_del(&reg->hash_list);
413 } 434 }
414 435
415 if (!list_empty(&rh->recovered_regions)) { 436 if (!list_empty(&rh->recovered_regions)) {
416 list_splice(&rh->recovered_regions, &recovered); 437 list_splice_init(&rh->recovered_regions, &recovered);
417 INIT_LIST_HEAD(&rh->recovered_regions);
418 438
419 list_for_each_entry (reg, &recovered, list) 439 list_for_each_entry (reg, &recovered, list)
420 list_del(&reg->hash_list); 440 list_del(&reg->hash_list);
421 } 441 }
422 442
423 if (!list_empty(&rh->failed_recovered_regions)) { 443 if (!list_empty(&rh->failed_recovered_regions)) {
424 list_splice(&rh->failed_recovered_regions, &failed_recovered); 444 list_splice_init(&rh->failed_recovered_regions,
425 INIT_LIST_HEAD(&rh->failed_recovered_regions); 445 &failed_recovered);
426 446
427 list_for_each_entry(reg, &failed_recovered, list) 447 list_for_each_entry(reg, &failed_recovered, list)
428 list_del(&reg->hash_list); 448 list_del(&reg->hash_list);
@@ -790,7 +810,7 @@ static int recover(struct mirror_set *ms, struct region *reg)
790{ 810{
791 int r; 811 int r;
792 unsigned int i; 812 unsigned int i;
793 struct io_region from, to[KCOPYD_MAX_REGIONS], *dest; 813 struct dm_io_region from, to[DM_KCOPYD_MAX_REGIONS], *dest;
794 struct mirror *m; 814 struct mirror *m;
795 unsigned long flags = 0; 815 unsigned long flags = 0;
796 816
@@ -822,9 +842,9 @@ static int recover(struct mirror_set *ms, struct region *reg)
822 } 842 }
823 843
824 /* hand to kcopyd */ 844 /* hand to kcopyd */
825 set_bit(KCOPYD_IGNORE_ERROR, &flags); 845 set_bit(DM_KCOPYD_IGNORE_ERROR, &flags);
826 r = kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to, flags, 846 r = dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to,
827 recovery_complete, reg); 847 flags, recovery_complete, reg);
828 848
829 return r; 849 return r;
830} 850}
@@ -833,7 +853,7 @@ static void do_recovery(struct mirror_set *ms)
833{ 853{
834 int r; 854 int r;
835 struct region *reg; 855 struct region *reg;
836 struct dirty_log *log = ms->rh.log; 856 struct dm_dirty_log *log = ms->rh.log;
837 857
838 /* 858 /*
839 * Start quiescing some regions. 859 * Start quiescing some regions.
@@ -909,7 +929,7 @@ static void map_bio(struct mirror *m, struct bio *bio)
909 bio->bi_sector = map_sector(m, bio); 929 bio->bi_sector = map_sector(m, bio);
910} 930}
911 931
912static void map_region(struct io_region *io, struct mirror *m, 932static void map_region(struct dm_io_region *io, struct mirror *m,
913 struct bio *bio) 933 struct bio *bio)
914{ 934{
915 io->bdev = m->dev->bdev; 935 io->bdev = m->dev->bdev;
@@ -951,7 +971,7 @@ static void read_callback(unsigned long error, void *context)
951/* Asynchronous read. */ 971/* Asynchronous read. */
952static void read_async_bio(struct mirror *m, struct bio *bio) 972static void read_async_bio(struct mirror *m, struct bio *bio)
953{ 973{
954 struct io_region io; 974 struct dm_io_region io;
955 struct dm_io_request io_req = { 975 struct dm_io_request io_req = {
956 .bi_rw = READ, 976 .bi_rw = READ,
957 .mem.type = DM_IO_BVEC, 977 .mem.type = DM_IO_BVEC,
@@ -1019,7 +1039,7 @@ static void __bio_mark_nosync(struct mirror_set *ms,
1019{ 1039{
1020 unsigned long flags; 1040 unsigned long flags;
1021 struct region_hash *rh = &ms->rh; 1041 struct region_hash *rh = &ms->rh;
1022 struct dirty_log *log = ms->rh.log; 1042 struct dm_dirty_log *log = ms->rh.log;
1023 struct region *reg; 1043 struct region *reg;
1024 region_t region = bio_to_region(rh, bio); 1044 region_t region = bio_to_region(rh, bio);
1025 int recovering = 0; 1045 int recovering = 0;
@@ -1107,7 +1127,7 @@ out:
1107static void do_write(struct mirror_set *ms, struct bio *bio) 1127static void do_write(struct mirror_set *ms, struct bio *bio)
1108{ 1128{
1109 unsigned int i; 1129 unsigned int i;
1110 struct io_region io[ms->nr_mirrors], *dest = io; 1130 struct dm_io_region io[ms->nr_mirrors], *dest = io;
1111 struct mirror *m; 1131 struct mirror *m;
1112 struct dm_io_request io_req = { 1132 struct dm_io_request io_req = {
1113 .bi_rw = WRITE, 1133 .bi_rw = WRITE,
@@ -1182,6 +1202,7 @@ static void do_writes(struct mirror_set *ms, struct bio_list *writes)
1182 spin_lock_irq(&ms->lock); 1202 spin_lock_irq(&ms->lock);
1183 bio_list_merge(&ms->failures, &sync); 1203 bio_list_merge(&ms->failures, &sync);
1184 spin_unlock_irq(&ms->lock); 1204 spin_unlock_irq(&ms->lock);
1205 wake(ms);
1185 } else 1206 } else
1186 while ((bio = bio_list_pop(&sync))) 1207 while ((bio = bio_list_pop(&sync)))
1187 do_write(ms, bio); 1208 do_write(ms, bio);
@@ -1241,7 +1262,7 @@ static void do_failures(struct mirror_set *ms, struct bio_list *failures)
1241 bio_list_merge(&ms->failures, failures); 1262 bio_list_merge(&ms->failures, failures);
1242 spin_unlock_irq(&ms->lock); 1263 spin_unlock_irq(&ms->lock);
1243 1264
1244 wake(ms); 1265 delayed_wake(ms);
1245} 1266}
1246 1267
1247static void trigger_event(struct work_struct *work) 1268static void trigger_event(struct work_struct *work)
@@ -1255,7 +1276,7 @@ static void trigger_event(struct work_struct *work)
1255/*----------------------------------------------------------------- 1276/*-----------------------------------------------------------------
1256 * kmirrord 1277 * kmirrord
1257 *---------------------------------------------------------------*/ 1278 *---------------------------------------------------------------*/
1258static int _do_mirror(struct work_struct *work) 1279static void do_mirror(struct work_struct *work)
1259{ 1280{
1260 struct mirror_set *ms =container_of(work, struct mirror_set, 1281 struct mirror_set *ms =container_of(work, struct mirror_set,
1261 kmirrord_work); 1282 kmirrord_work);
@@ -1277,23 +1298,7 @@ static int _do_mirror(struct work_struct *work)
1277 do_writes(ms, &writes); 1298 do_writes(ms, &writes);
1278 do_failures(ms, &failures); 1299 do_failures(ms, &failures);
1279 1300
1280 return (ms->failures.head) ? 1 : 0; 1301 dm_table_unplug_all(ms->ti->table);
1281}
1282
1283static void do_mirror(struct work_struct *work)
1284{
1285 /*
1286 * If _do_mirror returns 1, we give it
1287 * another shot. This helps for cases like
1288 * 'suspend' where we call flush_workqueue
1289 * and expect all work to be finished. If
1290 * a failure happens during a suspend, we
1291 * couldn't issue a 'wake' because it would
1292 * not be honored. Therefore, we return '1'
1293 * from _do_mirror, and retry here.
1294 */
1295 while (_do_mirror(work))
1296 schedule();
1297} 1302}
1298 1303
1299 1304
@@ -1303,7 +1308,7 @@ static void do_mirror(struct work_struct *work)
1303static struct mirror_set *alloc_context(unsigned int nr_mirrors, 1308static struct mirror_set *alloc_context(unsigned int nr_mirrors,
1304 uint32_t region_size, 1309 uint32_t region_size,
1305 struct dm_target *ti, 1310 struct dm_target *ti,
1306 struct dirty_log *dl) 1311 struct dm_dirty_log *dl)
1307{ 1312{
1308 size_t len; 1313 size_t len;
1309 struct mirror_set *ms = NULL; 1314 struct mirror_set *ms = NULL;
@@ -1403,12 +1408,12 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
1403/* 1408/*
1404 * Create dirty log: log_type #log_params <log_params> 1409 * Create dirty log: log_type #log_params <log_params>
1405 */ 1410 */
1406static struct dirty_log *create_dirty_log(struct dm_target *ti, 1411static struct dm_dirty_log *create_dirty_log(struct dm_target *ti,
1407 unsigned int argc, char **argv, 1412 unsigned int argc, char **argv,
1408 unsigned int *args_used) 1413 unsigned int *args_used)
1409{ 1414{
1410 unsigned int param_count; 1415 unsigned int param_count;
1411 struct dirty_log *dl; 1416 struct dm_dirty_log *dl;
1412 1417
1413 if (argc < 2) { 1418 if (argc < 2) {
1414 ti->error = "Insufficient mirror log arguments"; 1419 ti->error = "Insufficient mirror log arguments";
@@ -1427,7 +1432,7 @@ static struct dirty_log *create_dirty_log(struct dm_target *ti,
1427 return NULL; 1432 return NULL;
1428 } 1433 }
1429 1434
1430 dl = dm_create_dirty_log(argv[0], ti, param_count, argv + 2); 1435 dl = dm_dirty_log_create(argv[0], ti, param_count, argv + 2);
1431 if (!dl) { 1436 if (!dl) {
1432 ti->error = "Error creating mirror dirty log"; 1437 ti->error = "Error creating mirror dirty log";
1433 return NULL; 1438 return NULL;
@@ -1435,7 +1440,7 @@ static struct dirty_log *create_dirty_log(struct dm_target *ti,
1435 1440
1436 if (!_check_region_size(ti, dl->type->get_region_size(dl))) { 1441 if (!_check_region_size(ti, dl->type->get_region_size(dl))) {
1437 ti->error = "Invalid region size"; 1442 ti->error = "Invalid region size";
1438 dm_destroy_dirty_log(dl); 1443 dm_dirty_log_destroy(dl);
1439 return NULL; 1444 return NULL;
1440 } 1445 }
1441 1446
@@ -1496,7 +1501,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1496 int r; 1501 int r;
1497 unsigned int nr_mirrors, m, args_used; 1502 unsigned int nr_mirrors, m, args_used;
1498 struct mirror_set *ms; 1503 struct mirror_set *ms;
1499 struct dirty_log *dl; 1504 struct dm_dirty_log *dl;
1500 1505
1501 dl = create_dirty_log(ti, argc, argv, &args_used); 1506 dl = create_dirty_log(ti, argc, argv, &args_used);
1502 if (!dl) 1507 if (!dl)
@@ -1506,9 +1511,9 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1506 argc -= args_used; 1511 argc -= args_used;
1507 1512
1508 if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 || 1513 if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 ||
1509 nr_mirrors < 2 || nr_mirrors > KCOPYD_MAX_REGIONS + 1) { 1514 nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) {
1510 ti->error = "Invalid number of mirrors"; 1515 ti->error = "Invalid number of mirrors";
1511 dm_destroy_dirty_log(dl); 1516 dm_dirty_log_destroy(dl);
1512 return -EINVAL; 1517 return -EINVAL;
1513 } 1518 }
1514 1519
@@ -1516,13 +1521,13 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1516 1521
1517 if (argc < nr_mirrors * 2) { 1522 if (argc < nr_mirrors * 2) {
1518 ti->error = "Too few mirror arguments"; 1523 ti->error = "Too few mirror arguments";
1519 dm_destroy_dirty_log(dl); 1524 dm_dirty_log_destroy(dl);
1520 return -EINVAL; 1525 return -EINVAL;
1521 } 1526 }
1522 1527
1523 ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl); 1528 ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl);
1524 if (!ms) { 1529 if (!ms) {
1525 dm_destroy_dirty_log(dl); 1530 dm_dirty_log_destroy(dl);
1526 return -ENOMEM; 1531 return -ENOMEM;
1527 } 1532 }
1528 1533
@@ -1547,6 +1552,8 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1547 goto err_free_context; 1552 goto err_free_context;
1548 } 1553 }
1549 INIT_WORK(&ms->kmirrord_work, do_mirror); 1554 INIT_WORK(&ms->kmirrord_work, do_mirror);
1555 init_timer(&ms->timer);
1556 ms->timer_pending = 0;
1550 INIT_WORK(&ms->trigger_event, trigger_event); 1557 INIT_WORK(&ms->trigger_event, trigger_event);
1551 1558
1552 r = parse_features(ms, argc, argv, &args_used); 1559 r = parse_features(ms, argc, argv, &args_used);
@@ -1571,7 +1578,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1571 goto err_destroy_wq; 1578 goto err_destroy_wq;
1572 } 1579 }
1573 1580
1574 r = kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client); 1581 r = dm_kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client);
1575 if (r) 1582 if (r)
1576 goto err_destroy_wq; 1583 goto err_destroy_wq;
1577 1584
@@ -1589,8 +1596,9 @@ static void mirror_dtr(struct dm_target *ti)
1589{ 1596{
1590 struct mirror_set *ms = (struct mirror_set *) ti->private; 1597 struct mirror_set *ms = (struct mirror_set *) ti->private;
1591 1598
1599 del_timer_sync(&ms->timer);
1592 flush_workqueue(ms->kmirrord_wq); 1600 flush_workqueue(ms->kmirrord_wq);
1593 kcopyd_client_destroy(ms->kcopyd_client); 1601 dm_kcopyd_client_destroy(ms->kcopyd_client);
1594 destroy_workqueue(ms->kmirrord_wq); 1602 destroy_workqueue(ms->kmirrord_wq);
1595 free_context(ms, ti, ms->nr_mirrors); 1603 free_context(ms, ti, ms->nr_mirrors);
1596} 1604}
@@ -1734,7 +1742,7 @@ out:
1734static void mirror_presuspend(struct dm_target *ti) 1742static void mirror_presuspend(struct dm_target *ti)
1735{ 1743{
1736 struct mirror_set *ms = (struct mirror_set *) ti->private; 1744 struct mirror_set *ms = (struct mirror_set *) ti->private;
1737 struct dirty_log *log = ms->rh.log; 1745 struct dm_dirty_log *log = ms->rh.log;
1738 1746
1739 atomic_set(&ms->suspend, 1); 1747 atomic_set(&ms->suspend, 1);
1740 1748
@@ -1763,7 +1771,7 @@ static void mirror_presuspend(struct dm_target *ti)
1763static void mirror_postsuspend(struct dm_target *ti) 1771static void mirror_postsuspend(struct dm_target *ti)
1764{ 1772{
1765 struct mirror_set *ms = ti->private; 1773 struct mirror_set *ms = ti->private;
1766 struct dirty_log *log = ms->rh.log; 1774 struct dm_dirty_log *log = ms->rh.log;
1767 1775
1768 if (log->type->postsuspend && log->type->postsuspend(log)) 1776 if (log->type->postsuspend && log->type->postsuspend(log))
1769 /* FIXME: need better error handling */ 1777 /* FIXME: need better error handling */
@@ -1773,7 +1781,7 @@ static void mirror_postsuspend(struct dm_target *ti)
1773static void mirror_resume(struct dm_target *ti) 1781static void mirror_resume(struct dm_target *ti)
1774{ 1782{
1775 struct mirror_set *ms = ti->private; 1783 struct mirror_set *ms = ti->private;
1776 struct dirty_log *log = ms->rh.log; 1784 struct dm_dirty_log *log = ms->rh.log;
1777 1785
1778 atomic_set(&ms->suspend, 0); 1786 atomic_set(&ms->suspend, 0);
1779 if (log->type->resume && log->type->resume(log)) 1787 if (log->type->resume && log->type->resume(log))
@@ -1811,7 +1819,7 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
1811{ 1819{
1812 unsigned int m, sz = 0; 1820 unsigned int m, sz = 0;
1813 struct mirror_set *ms = (struct mirror_set *) ti->private; 1821 struct mirror_set *ms = (struct mirror_set *) ti->private;
1814 struct dirty_log *log = ms->rh.log; 1822 struct dm_dirty_log *log = ms->rh.log;
1815 char buffer[ms->nr_mirrors + 1]; 1823 char buffer[ms->nr_mirrors + 1];
1816 1824
1817 switch (type) { 1825 switch (type) {
@@ -1864,15 +1872,9 @@ static int __init dm_mirror_init(void)
1864{ 1872{
1865 int r; 1873 int r;
1866 1874
1867 r = dm_dirty_log_init();
1868 if (r)
1869 return r;
1870
1871 r = dm_register_target(&mirror_target); 1875 r = dm_register_target(&mirror_target);
1872 if (r < 0) { 1876 if (r < 0)
1873 DMERR("Failed to register mirror target"); 1877 DMERR("Failed to register mirror target");
1874 dm_dirty_log_exit();
1875 }
1876 1878
1877 return r; 1879 return r;
1878} 1880}
@@ -1884,8 +1886,6 @@ static void __exit dm_mirror_exit(void)
1884 r = dm_unregister_target(&mirror_target); 1886 r = dm_unregister_target(&mirror_target);
1885 if (r < 0) 1887 if (r < 0)
1886 DMERR("unregister failed %d", r); 1888 DMERR("unregister failed %d", r);
1887
1888 dm_dirty_log_exit();
1889} 1889}
1890 1890
1891/* Module hooks */ 1891/* Module hooks */
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 4dc8a43c034b..1ba8a47d61b1 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -18,10 +18,10 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
20#include <linux/log2.h> 20#include <linux/log2.h>
21#include <linux/dm-kcopyd.h>
21 22
22#include "dm-snap.h" 23#include "dm-snap.h"
23#include "dm-bio-list.h" 24#include "dm-bio-list.h"
24#include "kcopyd.h"
25 25
26#define DM_MSG_PREFIX "snapshots" 26#define DM_MSG_PREFIX "snapshots"
27 27
@@ -36,9 +36,9 @@
36#define SNAPSHOT_COPY_PRIORITY 2 36#define SNAPSHOT_COPY_PRIORITY 2
37 37
38/* 38/*
39 * Each snapshot reserves this many pages for io 39 * Reserve 1MB for each snapshot initially (with minimum of 1 page).
40 */ 40 */
41#define SNAPSHOT_PAGES 256 41#define SNAPSHOT_PAGES (((1UL << 20) >> PAGE_SHIFT) ? : 1)
42 42
43static struct workqueue_struct *ksnapd; 43static struct workqueue_struct *ksnapd;
44static void flush_queued_bios(struct work_struct *work); 44static void flush_queued_bios(struct work_struct *work);
@@ -536,7 +536,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
536 s->last_percent = 0; 536 s->last_percent = 0;
537 init_rwsem(&s->lock); 537 init_rwsem(&s->lock);
538 spin_lock_init(&s->pe_lock); 538 spin_lock_init(&s->pe_lock);
539 s->table = ti->table; 539 s->ti = ti;
540 540
541 /* Allocate hash table for COW data */ 541 /* Allocate hash table for COW data */
542 if (init_hash_tables(s)) { 542 if (init_hash_tables(s)) {
@@ -558,7 +558,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
558 goto bad4; 558 goto bad4;
559 } 559 }
560 560
561 r = kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client); 561 r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client);
562 if (r) { 562 if (r) {
563 ti->error = "Could not create kcopyd client"; 563 ti->error = "Could not create kcopyd client";
564 goto bad5; 564 goto bad5;
@@ -591,7 +591,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
591 return 0; 591 return 0;
592 592
593 bad6: 593 bad6:
594 kcopyd_client_destroy(s->kcopyd_client); 594 dm_kcopyd_client_destroy(s->kcopyd_client);
595 595
596 bad5: 596 bad5:
597 s->store.destroy(&s->store); 597 s->store.destroy(&s->store);
@@ -613,7 +613,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
613 613
614static void __free_exceptions(struct dm_snapshot *s) 614static void __free_exceptions(struct dm_snapshot *s)
615{ 615{
616 kcopyd_client_destroy(s->kcopyd_client); 616 dm_kcopyd_client_destroy(s->kcopyd_client);
617 s->kcopyd_client = NULL; 617 s->kcopyd_client = NULL;
618 618
619 exit_exception_table(&s->pending, pending_cache); 619 exit_exception_table(&s->pending, pending_cache);
@@ -699,7 +699,7 @@ static void __invalidate_snapshot(struct dm_snapshot *s, int err)
699 699
700 s->valid = 0; 700 s->valid = 0;
701 701
702 dm_table_event(s->table); 702 dm_table_event(s->ti->table);
703} 703}
704 704
705static void get_pending_exception(struct dm_snap_pending_exception *pe) 705static void get_pending_exception(struct dm_snap_pending_exception *pe)
@@ -824,7 +824,7 @@ static void copy_callback(int read_err, unsigned long write_err, void *context)
824static void start_copy(struct dm_snap_pending_exception *pe) 824static void start_copy(struct dm_snap_pending_exception *pe)
825{ 825{
826 struct dm_snapshot *s = pe->snap; 826 struct dm_snapshot *s = pe->snap;
827 struct io_region src, dest; 827 struct dm_io_region src, dest;
828 struct block_device *bdev = s->origin->bdev; 828 struct block_device *bdev = s->origin->bdev;
829 sector_t dev_size; 829 sector_t dev_size;
830 830
@@ -839,7 +839,7 @@ static void start_copy(struct dm_snap_pending_exception *pe)
839 dest.count = src.count; 839 dest.count = src.count;
840 840
841 /* Hand over to kcopyd */ 841 /* Hand over to kcopyd */
842 kcopyd_copy(s->kcopyd_client, 842 dm_kcopyd_copy(s->kcopyd_client,
843 &src, 1, &dest, 0, copy_callback, pe); 843 &src, 1, &dest, 0, copy_callback, pe);
844} 844}
845 845
@@ -1060,7 +1060,7 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1060 goto next_snapshot; 1060 goto next_snapshot;
1061 1061
1062 /* Nothing to do if writing beyond end of snapshot */ 1062 /* Nothing to do if writing beyond end of snapshot */
1063 if (bio->bi_sector >= dm_table_get_size(snap->table)) 1063 if (bio->bi_sector >= dm_table_get_size(snap->ti->table))
1064 goto next_snapshot; 1064 goto next_snapshot;
1065 1065
1066 /* 1066 /*
diff --git a/drivers/md/dm-snap.h b/drivers/md/dm-snap.h
index 93bce5d49742..24f9fb73b982 100644
--- a/drivers/md/dm-snap.h
+++ b/drivers/md/dm-snap.h
@@ -132,7 +132,7 @@ struct exception_store {
132 132
133struct dm_snapshot { 133struct dm_snapshot {
134 struct rw_semaphore lock; 134 struct rw_semaphore lock;
135 struct dm_table *table; 135 struct dm_target *ti;
136 136
137 struct dm_dev *origin; 137 struct dm_dev *origin;
138 struct dm_dev *cow; 138 struct dm_dev *cow;
@@ -169,7 +169,7 @@ struct dm_snapshot {
169 /* The on disk metadata handler */ 169 /* The on disk metadata handler */
170 struct exception_store store; 170 struct exception_store store;
171 171
172 struct kcopyd_client *kcopyd_client; 172 struct dm_kcopyd_client *kcopyd_client;
173 173
174 /* Queue of snapshot writes for ksnapd to flush */ 174 /* Queue of snapshot writes for ksnapd to flush */
175 struct bio_list queued_bios; 175 struct bio_list queued_bios;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index e75b1437b58b..51be53344214 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -245,44 +245,6 @@ int dm_table_create(struct dm_table **result, int mode,
245 return 0; 245 return 0;
246} 246}
247 247
248int dm_create_error_table(struct dm_table **result, struct mapped_device *md)
249{
250 struct dm_table *t;
251 sector_t dev_size = 1;
252 int r;
253
254 /*
255 * Find current size of device.
256 * Default to 1 sector if inactive.
257 */
258 t = dm_get_table(md);
259 if (t) {
260 dev_size = dm_table_get_size(t);
261 dm_table_put(t);
262 }
263
264 r = dm_table_create(&t, FMODE_READ, 1, md);
265 if (r)
266 return r;
267
268 r = dm_table_add_target(t, "error", 0, dev_size, NULL);
269 if (r)
270 goto out;
271
272 r = dm_table_complete(t);
273 if (r)
274 goto out;
275
276 *result = t;
277
278out:
279 if (r)
280 dm_table_put(t);
281
282 return r;
283}
284EXPORT_SYMBOL_GPL(dm_create_error_table);
285
286static void free_devices(struct list_head *devices) 248static void free_devices(struct list_head *devices)
287{ 249{
288 struct list_head *tmp, *next; 250 struct list_head *tmp, *next;
@@ -954,7 +916,7 @@ void dm_table_presuspend_targets(struct dm_table *t)
954 if (!t) 916 if (!t)
955 return; 917 return;
956 918
957 return suspend_targets(t, 0); 919 suspend_targets(t, 0);
958} 920}
959 921
960void dm_table_postsuspend_targets(struct dm_table *t) 922void dm_table_postsuspend_targets(struct dm_table *t)
@@ -962,7 +924,7 @@ void dm_table_postsuspend_targets(struct dm_table *t)
962 if (!t) 924 if (!t)
963 return; 925 return;
964 926
965 return suspend_targets(t, 1); 927 suspend_targets(t, 1);
966} 928}
967 929
968int dm_table_resume_targets(struct dm_table *t) 930int dm_table_resume_targets(struct dm_table *t)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 6617ce4af095..372369b1cc20 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -204,6 +204,7 @@ static int (*_inits[])(void) __initdata = {
204 dm_target_init, 204 dm_target_init,
205 dm_linear_init, 205 dm_linear_init,
206 dm_stripe_init, 206 dm_stripe_init,
207 dm_kcopyd_init,
207 dm_interface_init, 208 dm_interface_init,
208}; 209};
209 210
@@ -212,6 +213,7 @@ static void (*_exits[])(void) = {
212 dm_target_exit, 213 dm_target_exit,
213 dm_linear_exit, 214 dm_linear_exit,
214 dm_stripe_exit, 215 dm_stripe_exit,
216 dm_kcopyd_exit,
215 dm_interface_exit, 217 dm_interface_exit,
216}; 218};
217 219
@@ -922,7 +924,7 @@ static void free_minor(int minor)
922/* 924/*
923 * See if the device with a specific minor # is free. 925 * See if the device with a specific minor # is free.
924 */ 926 */
925static int specific_minor(struct mapped_device *md, int minor) 927static int specific_minor(int minor)
926{ 928{
927 int r, m; 929 int r, m;
928 930
@@ -955,7 +957,7 @@ out:
955 return r; 957 return r;
956} 958}
957 959
958static int next_free_minor(struct mapped_device *md, int *minor) 960static int next_free_minor(int *minor)
959{ 961{
960 int r, m; 962 int r, m;
961 963
@@ -966,9 +968,8 @@ static int next_free_minor(struct mapped_device *md, int *minor)
966 spin_lock(&_minor_lock); 968 spin_lock(&_minor_lock);
967 969
968 r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m); 970 r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
969 if (r) { 971 if (r)
970 goto out; 972 goto out;
971 }
972 973
973 if (m >= (1 << MINORBITS)) { 974 if (m >= (1 << MINORBITS)) {
974 idr_remove(&_minor_idr, m); 975 idr_remove(&_minor_idr, m);
@@ -991,7 +992,7 @@ static struct block_device_operations dm_blk_dops;
991static struct mapped_device *alloc_dev(int minor) 992static struct mapped_device *alloc_dev(int minor)
992{ 993{
993 int r; 994 int r;
994 struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL); 995 struct mapped_device *md = kzalloc(sizeof(*md), GFP_KERNEL);
995 void *old_md; 996 void *old_md;
996 997
997 if (!md) { 998 if (!md) {
@@ -1004,13 +1005,12 @@ static struct mapped_device *alloc_dev(int minor)
1004 1005
1005 /* get a minor number for the dev */ 1006 /* get a minor number for the dev */
1006 if (minor == DM_ANY_MINOR) 1007 if (minor == DM_ANY_MINOR)
1007 r = next_free_minor(md, &minor); 1008 r = next_free_minor(&minor);
1008 else 1009 else
1009 r = specific_minor(md, minor); 1010 r = specific_minor(minor);
1010 if (r < 0) 1011 if (r < 0)
1011 goto bad_minor; 1012 goto bad_minor;
1012 1013
1013 memset(md, 0, sizeof(*md));
1014 init_rwsem(&md->io_lock); 1014 init_rwsem(&md->io_lock);
1015 mutex_init(&md->suspend_lock); 1015 mutex_init(&md->suspend_lock);
1016 spin_lock_init(&md->pushback_lock); 1016 spin_lock_init(&md->pushback_lock);
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index b4584a39383b..8c03b634e62e 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -16,67 +16,6 @@
16#include <linux/blkdev.h> 16#include <linux/blkdev.h>
17#include <linux/hdreg.h> 17#include <linux/hdreg.h>
18 18
19#define DM_NAME "device-mapper"
20
21#define DMERR(f, arg...) \
22 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
23#define DMERR_LIMIT(f, arg...) \
24 do { \
25 if (printk_ratelimit()) \
26 printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
27 f "\n", ## arg); \
28 } while (0)
29
30#define DMWARN(f, arg...) \
31 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
32#define DMWARN_LIMIT(f, arg...) \
33 do { \
34 if (printk_ratelimit()) \
35 printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
36 f "\n", ## arg); \
37 } while (0)
38
39#define DMINFO(f, arg...) \
40 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
41#define DMINFO_LIMIT(f, arg...) \
42 do { \
43 if (printk_ratelimit()) \
44 printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
45 "\n", ## arg); \
46 } while (0)
47
48#ifdef CONFIG_DM_DEBUG
49# define DMDEBUG(f, arg...) \
50 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
51# define DMDEBUG_LIMIT(f, arg...) \
52 do { \
53 if (printk_ratelimit()) \
54 printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
55 "\n", ## arg); \
56 } while (0)
57#else
58# define DMDEBUG(f, arg...) do {} while (0)
59# define DMDEBUG_LIMIT(f, arg...) do {} while (0)
60#endif
61
62#define DMEMIT(x...) sz += ((sz >= maxlen) ? \
63 0 : scnprintf(result + sz, maxlen - sz, x))
64
65#define SECTOR_SHIFT 9
66
67/*
68 * Definitions of return values from target end_io function.
69 */
70#define DM_ENDIO_INCOMPLETE 1
71#define DM_ENDIO_REQUEUE 2
72
73/*
74 * Definitions of return values from target map function.
75 */
76#define DM_MAPIO_SUBMITTED 0
77#define DM_MAPIO_REMAPPED 1
78#define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE
79
80/* 19/*
81 * Suspend feature flags 20 * Suspend feature flags
82 */ 21 */
@@ -136,34 +75,6 @@ static inline int array_too_big(unsigned long fixed, unsigned long obj,
136 return (num > (ULONG_MAX - fixed) / obj); 75 return (num > (ULONG_MAX - fixed) / obj);
137} 76}
138 77
139/*
140 * Ceiling(n / sz)
141 */
142#define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
143
144#define dm_sector_div_up(n, sz) ( \
145{ \
146 sector_t _r = ((n) + (sz) - 1); \
147 sector_div(_r, (sz)); \
148 _r; \
149} \
150)
151
152/*
153 * ceiling(n / size) * size
154 */
155#define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
156
157static inline sector_t to_sector(unsigned long n)
158{
159 return (n >> 9);
160}
161
162static inline unsigned long to_bytes(sector_t n)
163{
164 return (n << 9);
165}
166
167int dm_split_args(int *argc, char ***argvp, char *input); 78int dm_split_args(int *argc, char ***argvp, char *input);
168 79
169/* 80/*
@@ -189,4 +100,13 @@ int dm_lock_for_deletion(struct mapped_device *md);
189 100
190void dm_kobject_uevent(struct mapped_device *md); 101void dm_kobject_uevent(struct mapped_device *md);
191 102
103/*
104 * Dirty log
105 */
106int dm_dirty_log_init(void);
107void dm_dirty_log_exit(void);
108
109int dm_kcopyd_init(void);
110void dm_kcopyd_exit(void);
111
192#endif 112#endif
diff --git a/drivers/md/kcopyd.h b/drivers/md/kcopyd.h
deleted file mode 100644
index 4845f2a0c676..000000000000
--- a/drivers/md/kcopyd.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright (C) 2001 Sistina Software
3 *
4 * This file is released under the GPL.
5 *
6 * Kcopyd provides a simple interface for copying an area of one
7 * block-device to one or more other block-devices, with an asynchronous
8 * completion notification.
9 */
10
11#ifndef DM_KCOPYD_H
12#define DM_KCOPYD_H
13
14#include "dm-io.h"
15
16/* FIXME: make this configurable */
17#define KCOPYD_MAX_REGIONS 8
18
19#define KCOPYD_IGNORE_ERROR 1
20
21/*
22 * To use kcopyd you must first create a kcopyd client object.
23 */
24struct kcopyd_client;
25int kcopyd_client_create(unsigned int num_pages, struct kcopyd_client **result);
26void kcopyd_client_destroy(struct kcopyd_client *kc);
27
28/*
29 * Submit a copy job to kcopyd. This is built on top of the
30 * previous three fns.
31 *
32 * read_err is a boolean,
33 * write_err is a bitset, with 1 bit for each destination region
34 */
35typedef void (*kcopyd_notify_fn)(int read_err, unsigned long write_err,
36 void *context);
37
38int kcopyd_copy(struct kcopyd_client *kc, struct io_region *from,
39 unsigned int num_dests, struct io_region *dests,
40 unsigned int flags, kcopyd_notify_fn fn, void *context);
41
42#endif
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index e8503341e3b1..eed06d068fd1 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -158,6 +158,12 @@ config MTD_OF_PARTS
158 the partition map from the children of the flash node, 158 the partition map from the children of the flash node,
159 as described in Documentation/powerpc/booting-without-of.txt. 159 as described in Documentation/powerpc/booting-without-of.txt.
160 160
161config MTD_AR7_PARTS
162 tristate "TI AR7 partitioning support"
163 depends on MTD_PARTITIONS
164 ---help---
165 TI AR7 partitioning support
166
161comment "User Modules And Translation Layers" 167comment "User Modules And Translation Layers"
162 168
163config MTD_CHAR 169config MTD_CHAR
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 538e33d11d46..4b77335715f0 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
11obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o 11obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
12obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o 12obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
13obj-$(CONFIG_MTD_AFS_PARTS) += afs.o 13obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
14obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
14obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o 15obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
15 16
16# 'Users' - code which presents functionality to userspace. 17# 'Users' - code which presents functionality to userspace.
diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c
new file mode 100644
index 000000000000..ecf170b55c32
--- /dev/null
+++ b/drivers/mtd/ar7part.c
@@ -0,0 +1,151 @@
1/*
2 * Copyright © 2007 Eugene Konev <ejka@openwrt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * TI AR7 flash partition table.
19 * Based on ar7 map by Felix Fietkau <nbd@openwrt.org>
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/slab.h>
25
26#include <linux/mtd/mtd.h>
27#include <linux/mtd/partitions.h>
28#include <linux/bootmem.h>
29#include <linux/magic.h>
30
31#define AR7_PARTS 4
32#define ROOT_OFFSET 0xe0000
33
34#define LOADER_MAGIC1 le32_to_cpu(0xfeedfa42)
35#define LOADER_MAGIC2 le32_to_cpu(0xfeed1281)
36
37#ifndef SQUASHFS_MAGIC
38#define SQUASHFS_MAGIC 0x73717368
39#endif
40
41struct ar7_bin_rec {
42 unsigned int checksum;
43 unsigned int length;
44 unsigned int address;
45};
46
47static struct mtd_partition ar7_parts[AR7_PARTS];
48
49static int create_mtd_partitions(struct mtd_info *master,
50 struct mtd_partition **pparts,
51 unsigned long origin)
52{
53 struct ar7_bin_rec header;
54 unsigned int offset;
55 size_t len;
56 unsigned int pre_size = master->erasesize, post_size = 0;
57 unsigned int root_offset = ROOT_OFFSET;
58
59 int retries = 10;
60
61 ar7_parts[0].name = "loader";
62 ar7_parts[0].offset = 0;
63 ar7_parts[0].size = master->erasesize;
64 ar7_parts[0].mask_flags = MTD_WRITEABLE;
65
66 ar7_parts[1].name = "config";
67 ar7_parts[1].offset = 0;
68 ar7_parts[1].size = master->erasesize;
69 ar7_parts[1].mask_flags = 0;
70
71 do { /* Try 10 blocks starting from master->erasesize */
72 offset = pre_size;
73 master->read(master, offset,
74 sizeof(header), &len, (uint8_t *)&header);
75 if (!strncmp((char *)&header, "TIENV0.8", 8))
76 ar7_parts[1].offset = pre_size;
77 if (header.checksum == LOADER_MAGIC1)
78 break;
79 if (header.checksum == LOADER_MAGIC2)
80 break;
81 pre_size += master->erasesize;
82 } while (retries--);
83
84 pre_size = offset;
85
86 if (!ar7_parts[1].offset) {
87 ar7_parts[1].offset = master->size - master->erasesize;
88 post_size = master->erasesize;
89 }
90
91 switch (header.checksum) {
92 case LOADER_MAGIC1:
93 while (header.length) {
94 offset += sizeof(header) + header.length;
95 master->read(master, offset, sizeof(header),
96 &len, (uint8_t *)&header);
97 }
98 root_offset = offset + sizeof(header) + 4;
99 break;
100 case LOADER_MAGIC2:
101 while (header.length) {
102 offset += sizeof(header) + header.length;
103 master->read(master, offset, sizeof(header),
104 &len, (uint8_t *)&header);
105 }
106 root_offset = offset + sizeof(header) + 4 + 0xff;
107 root_offset &= ~(uint32_t)0xff;
108 break;
109 default:
110 printk(KERN_WARNING "Unknown magic: %08x\n", header.checksum);
111 break;
112 }
113
114 master->read(master, root_offset,
115 sizeof(header), &len, (u8 *)&header);
116 if (header.checksum != SQUASHFS_MAGIC) {
117 root_offset += master->erasesize - 1;
118 root_offset &= ~(master->erasesize - 1);
119 }
120
121 ar7_parts[2].name = "linux";
122 ar7_parts[2].offset = pre_size;
123 ar7_parts[2].size = master->size - pre_size - post_size;
124 ar7_parts[2].mask_flags = 0;
125
126 ar7_parts[3].name = "rootfs";
127 ar7_parts[3].offset = root_offset;
128 ar7_parts[3].size = master->size - root_offset - post_size;
129 ar7_parts[3].mask_flags = 0;
130
131 *pparts = ar7_parts;
132 return AR7_PARTS;
133}
134
135static struct mtd_part_parser ar7_parser = {
136 .owner = THIS_MODULE,
137 .parse_fn = create_mtd_partitions,
138 .name = "ar7part",
139};
140
141static int __init ar7_parser_init(void)
142{
143 return register_mtd_parser(&ar7_parser);
144}
145
146module_init(ar7_parser_init);
147
148MODULE_LICENSE("GPL");
149MODULE_AUTHOR( "Felix Fietkau <nbd@openwrt.org>, "
150 "Eugene Konev <ejka@openwrt.org>");
151MODULE_DESCRIPTION("MTD partitioning for TI AR7");
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 0080452531d6..e812df607a5c 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -384,7 +384,7 @@ read_pri_intelext(struct map_info *map, __u16 adr)
384 if (extp_size > 4096) { 384 if (extp_size > 4096) {
385 printk(KERN_ERR 385 printk(KERN_ERR
386 "%s: cfi_pri_intelext is too fat\n", 386 "%s: cfi_pri_intelext is too fat\n",
387 __FUNCTION__); 387 __func__);
388 return NULL; 388 return NULL;
389 } 389 }
390 goto again; 390 goto again;
@@ -619,6 +619,9 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
619 sizeof(struct cfi_intelext_blockinfo); 619 sizeof(struct cfi_intelext_blockinfo);
620 } 620 }
621 621
622 if (!numparts)
623 numparts = 1;
624
622 /* Programming Region info */ 625 /* Programming Region info */
623 if (extp->MinorVersion >= '4') { 626 if (extp->MinorVersion >= '4') {
624 struct cfi_intelext_programming_regioninfo *prinfo; 627 struct cfi_intelext_programming_regioninfo *prinfo;
@@ -641,7 +644,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
641 if ((1 << partshift) < mtd->erasesize) { 644 if ((1 << partshift) < mtd->erasesize) {
642 printk( KERN_ERR 645 printk( KERN_ERR
643 "%s: bad number of hw partitions (%d)\n", 646 "%s: bad number of hw partitions (%d)\n",
644 __FUNCTION__, numparts); 647 __func__, numparts);
645 return -EINVAL; 648 return -EINVAL;
646 } 649 }
647 650
@@ -1071,10 +1074,10 @@ static int __xipram xip_wait_for_operation(
1071 chip->state = newstate; 1074 chip->state = newstate;
1072 map_write(map, CMD(0xff), adr); 1075 map_write(map, CMD(0xff), adr);
1073 (void) map_read(map, adr); 1076 (void) map_read(map, adr);
1074 asm volatile (".rep 8; nop; .endr"); 1077 xip_iprefetch();
1075 local_irq_enable(); 1078 local_irq_enable();
1076 spin_unlock(chip->mutex); 1079 spin_unlock(chip->mutex);
1077 asm volatile (".rep 8; nop; .endr"); 1080 xip_iprefetch();
1078 cond_resched(); 1081 cond_resched();
1079 1082
1080 /* 1083 /*
@@ -2013,7 +2016,7 @@ static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
2013 2016
2014#ifdef DEBUG_LOCK_BITS 2017#ifdef DEBUG_LOCK_BITS
2015 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n", 2018 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n",
2016 __FUNCTION__, ofs, len); 2019 __func__, ofs, len);
2017 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2020 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2018 ofs, len, NULL); 2021 ofs, len, NULL);
2019#endif 2022#endif
@@ -2023,7 +2026,7 @@ static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
2023 2026
2024#ifdef DEBUG_LOCK_BITS 2027#ifdef DEBUG_LOCK_BITS
2025 printk(KERN_DEBUG "%s: lock status after, ret=%d\n", 2028 printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
2026 __FUNCTION__, ret); 2029 __func__, ret);
2027 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2030 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2028 ofs, len, NULL); 2031 ofs, len, NULL);
2029#endif 2032#endif
@@ -2037,7 +2040,7 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
2037 2040
2038#ifdef DEBUG_LOCK_BITS 2041#ifdef DEBUG_LOCK_BITS
2039 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n", 2042 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n",
2040 __FUNCTION__, ofs, len); 2043 __func__, ofs, len);
2041 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2044 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2042 ofs, len, NULL); 2045 ofs, len, NULL);
2043#endif 2046#endif
@@ -2047,7 +2050,7 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
2047 2050
2048#ifdef DEBUG_LOCK_BITS 2051#ifdef DEBUG_LOCK_BITS
2049 printk(KERN_DEBUG "%s: lock status after, ret=%d\n", 2052 printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
2050 __FUNCTION__, ret); 2053 __func__, ret);
2051 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2054 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2052 ofs, len, NULL); 2055 ofs, len, NULL);
2053#endif 2056#endif
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 458d477614d6..f7fcc6389533 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -220,6 +220,28 @@ static void fixup_use_atmel_lock(struct mtd_info *mtd, void *param)
220 mtd->flags |= MTD_POWERUP_LOCK; 220 mtd->flags |= MTD_POWERUP_LOCK;
221} 221}
222 222
223static void fixup_s29gl064n_sectors(struct mtd_info *mtd, void *param)
224{
225 struct map_info *map = mtd->priv;
226 struct cfi_private *cfi = map->fldrv_priv;
227
228 if ((cfi->cfiq->EraseRegionInfo[0] & 0xffff) == 0x003f) {
229 cfi->cfiq->EraseRegionInfo[0] |= 0x0040;
230 pr_warning("%s: Bad S29GL064N CFI data, adjust from 64 to 128 sectors\n", mtd->name);
231 }
232}
233
234static void fixup_s29gl032n_sectors(struct mtd_info *mtd, void *param)
235{
236 struct map_info *map = mtd->priv;
237 struct cfi_private *cfi = map->fldrv_priv;
238
239 if ((cfi->cfiq->EraseRegionInfo[1] & 0xffff) == 0x007e) {
240 cfi->cfiq->EraseRegionInfo[1] &= ~0x0040;
241 pr_warning("%s: Bad S29GL032N CFI data, adjust from 127 to 63 sectors\n", mtd->name);
242 }
243}
244
223static struct cfi_fixup cfi_fixup_table[] = { 245static struct cfi_fixup cfi_fixup_table[] = {
224 { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL }, 246 { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
225#ifdef AMD_BOOTLOC_BUG 247#ifdef AMD_BOOTLOC_BUG
@@ -231,6 +253,10 @@ static struct cfi_fixup cfi_fixup_table[] = {
231 { CFI_MFR_AMD, 0x0056, fixup_use_secsi, NULL, }, 253 { CFI_MFR_AMD, 0x0056, fixup_use_secsi, NULL, },
232 { CFI_MFR_AMD, 0x005C, fixup_use_secsi, NULL, }, 254 { CFI_MFR_AMD, 0x005C, fixup_use_secsi, NULL, },
233 { CFI_MFR_AMD, 0x005F, fixup_use_secsi, NULL, }, 255 { CFI_MFR_AMD, 0x005F, fixup_use_secsi, NULL, },
256 { CFI_MFR_AMD, 0x0c01, fixup_s29gl064n_sectors, NULL, },
257 { CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors, NULL, },
258 { CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors, NULL, },
259 { CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors, NULL, },
234#if !FORCE_WORD_WRITE 260#if !FORCE_WORD_WRITE
235 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, }, 261 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
236#endif 262#endif
@@ -723,10 +749,10 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
723 chip->erase_suspended = 1; 749 chip->erase_suspended = 1;
724 map_write(map, CMD(0xf0), adr); 750 map_write(map, CMD(0xf0), adr);
725 (void) map_read(map, adr); 751 (void) map_read(map, adr);
726 asm volatile (".rep 8; nop; .endr"); 752 xip_iprefetch();
727 local_irq_enable(); 753 local_irq_enable();
728 spin_unlock(chip->mutex); 754 spin_unlock(chip->mutex);
729 asm volatile (".rep 8; nop; .endr"); 755 xip_iprefetch();
730 cond_resched(); 756 cond_resched();
731 757
732 /* 758 /*
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index 492e2ab27420..1b720cc571f3 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -445,7 +445,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
445 retry: 445 retry:
446 446
447#ifdef DEBUG_CFI_FEATURES 447#ifdef DEBUG_CFI_FEATURES
448 printk("%s: chip->state[%d]\n", __FUNCTION__, chip->state); 448 printk("%s: chip->state[%d]\n", __func__, chip->state);
449#endif 449#endif
450 spin_lock_bh(chip->mutex); 450 spin_lock_bh(chip->mutex);
451 451
@@ -463,7 +463,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
463 map_write(map, CMD(0x70), cmd_adr); 463 map_write(map, CMD(0x70), cmd_adr);
464 chip->state = FL_STATUS; 464 chip->state = FL_STATUS;
465#ifdef DEBUG_CFI_FEATURES 465#ifdef DEBUG_CFI_FEATURES
466 printk("%s: 1 status[%x]\n", __FUNCTION__, map_read(map, cmd_adr)); 466 printk("%s: 1 status[%x]\n", __func__, map_read(map, cmd_adr));
467#endif 467#endif
468 468
469 case FL_STATUS: 469 case FL_STATUS:
@@ -591,7 +591,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
591 /* check for errors: 'lock bit', 'VPP', 'dead cell'/'unerased cell' or 'incorrect cmd' -- saw */ 591 /* check for errors: 'lock bit', 'VPP', 'dead cell'/'unerased cell' or 'incorrect cmd' -- saw */
592 if (map_word_bitsset(map, status, CMD(0x3a))) { 592 if (map_word_bitsset(map, status, CMD(0x3a))) {
593#ifdef DEBUG_CFI_FEATURES 593#ifdef DEBUG_CFI_FEATURES
594 printk("%s: 2 status[%lx]\n", __FUNCTION__, status.x[0]); 594 printk("%s: 2 status[%lx]\n", __func__, status.x[0]);
595#endif 595#endif
596 /* clear status */ 596 /* clear status */
597 map_write(map, CMD(0x50), cmd_adr); 597 map_write(map, CMD(0x50), cmd_adr);
@@ -625,9 +625,9 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
625 ofs = to - (chipnum << cfi->chipshift); 625 ofs = to - (chipnum << cfi->chipshift);
626 626
627#ifdef DEBUG_CFI_FEATURES 627#ifdef DEBUG_CFI_FEATURES
628 printk("%s: map_bankwidth(map)[%x]\n", __FUNCTION__, map_bankwidth(map)); 628 printk("%s: map_bankwidth(map)[%x]\n", __func__, map_bankwidth(map));
629 printk("%s: chipnum[%x] wbufsize[%x]\n", __FUNCTION__, chipnum, wbufsize); 629 printk("%s: chipnum[%x] wbufsize[%x]\n", __func__, chipnum, wbufsize);
630 printk("%s: ofs[%x] len[%x]\n", __FUNCTION__, ofs, len); 630 printk("%s: ofs[%x] len[%x]\n", __func__, ofs, len);
631#endif 631#endif
632 632
633 /* Write buffer is worth it only if more than one word to write... */ 633 /* Write buffer is worth it only if more than one word to write... */
@@ -893,7 +893,8 @@ retry:
893 return ret; 893 return ret;
894} 894}
895 895
896int cfi_staa_erase_varsize(struct mtd_info *mtd, struct erase_info *instr) 896static int cfi_staa_erase_varsize(struct mtd_info *mtd,
897 struct erase_info *instr)
897{ struct map_info *map = mtd->priv; 898{ struct map_info *map = mtd->priv;
898 struct cfi_private *cfi = map->fldrv_priv; 899 struct cfi_private *cfi = map->fldrv_priv;
899 unsigned long adr, len; 900 unsigned long adr, len;
diff --git a/drivers/mtd/chips/cfi_probe.c b/drivers/mtd/chips/cfi_probe.c
index f651b6ef1c5d..a4463a91ce31 100644
--- a/drivers/mtd/chips/cfi_probe.c
+++ b/drivers/mtd/chips/cfi_probe.c
@@ -39,7 +39,7 @@ struct mtd_info *cfi_probe(struct map_info *map);
39#define xip_allowed(base, map) \ 39#define xip_allowed(base, map) \
40do { \ 40do { \
41 (void) map_read(map, base); \ 41 (void) map_read(map, base); \
42 asm volatile (".rep 8; nop; .endr"); \ 42 xip_iprefetch(); \
43 local_irq_enable(); \ 43 local_irq_enable(); \
44} while (0) 44} while (0)
45 45
@@ -232,6 +232,11 @@ static int __xipram cfi_chip_setup(struct map_info *map,
232 cfi->mfr = cfi_read_query16(map, base); 232 cfi->mfr = cfi_read_query16(map, base);
233 cfi->id = cfi_read_query16(map, base + ofs_factor); 233 cfi->id = cfi_read_query16(map, base + ofs_factor);
234 234
235 /* Get AMD/Spansion extended JEDEC ID */
236 if (cfi->mfr == CFI_MFR_AMD && (cfi->id & 0xff) == 0x7e)
237 cfi->id = cfi_read_query(map, base + 0xe * ofs_factor) << 8 |
238 cfi_read_query(map, base + 0xf * ofs_factor);
239
235 /* Put it back into Read Mode */ 240 /* Put it back into Read Mode */
236 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); 241 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
237 /* ... even if it's an Intel chip */ 242 /* ... even if it's an Intel chip */
diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c
index 2e51496c248e..72e0022a47bf 100644
--- a/drivers/mtd/chips/cfi_util.c
+++ b/drivers/mtd/chips/cfi_util.c
@@ -65,7 +65,7 @@ __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* n
65 65
66#ifdef CONFIG_MTD_XIP 66#ifdef CONFIG_MTD_XIP
67 (void) map_read(map, base); 67 (void) map_read(map, base);
68 asm volatile (".rep 8; nop; .endr"); 68 xip_iprefetch();
69 local_irq_enable(); 69 local_irq_enable();
70#endif 70#endif
71 71
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 4be51a86a85c..aa07575eb288 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -132,6 +132,8 @@
132#define M29F800AB 0x0058 132#define M29F800AB 0x0058
133#define M29W800DT 0x00D7 133#define M29W800DT 0x00D7
134#define M29W800DB 0x005B 134#define M29W800DB 0x005B
135#define M29W400DT 0x00EE
136#define M29W400DB 0x00EF
135#define M29W160DT 0x22C4 137#define M29W160DT 0x22C4
136#define M29W160DB 0x2249 138#define M29W160DB 0x2249
137#define M29W040B 0x00E3 139#define M29W040B 0x00E3
@@ -160,6 +162,7 @@
160#define SST49LF030A 0x001C 162#define SST49LF030A 0x001C
161#define SST49LF040A 0x0051 163#define SST49LF040A 0x0051
162#define SST49LF080A 0x005B 164#define SST49LF080A 0x005B
165#define SST36VF3203 0x7354
163 166
164/* Toshiba */ 167/* Toshiba */
165#define TC58FVT160 0x00C2 168#define TC58FVT160 0x00C2
@@ -1113,7 +1116,7 @@ static const struct amd_flash_info jedec_table[] = {
1113 .regions = { 1116 .regions = {
1114 ERASEINFO(0x10000,8), 1117 ERASEINFO(0x10000,8),
1115 } 1118 }
1116 }, { 1119 }, {
1117 .mfr_id = MANUFACTURER_MACRONIX, 1120 .mfr_id = MANUFACTURER_MACRONIX,
1118 .dev_id = MX29F016, 1121 .dev_id = MX29F016,
1119 .name = "Macronix MX29F016", 1122 .name = "Macronix MX29F016",
@@ -1125,7 +1128,7 @@ static const struct amd_flash_info jedec_table[] = {
1125 .regions = { 1128 .regions = {
1126 ERASEINFO(0x10000,32), 1129 ERASEINFO(0x10000,32),
1127 } 1130 }
1128 }, { 1131 }, {
1129 .mfr_id = MANUFACTURER_MACRONIX, 1132 .mfr_id = MANUFACTURER_MACRONIX,
1130 .dev_id = MX29F004T, 1133 .dev_id = MX29F004T,
1131 .name = "Macronix MX29F004T", 1134 .name = "Macronix MX29F004T",
@@ -1140,7 +1143,7 @@ static const struct amd_flash_info jedec_table[] = {
1140 ERASEINFO(0x02000,2), 1143 ERASEINFO(0x02000,2),
1141 ERASEINFO(0x04000,1), 1144 ERASEINFO(0x04000,1),
1142 } 1145 }
1143 }, { 1146 }, {
1144 .mfr_id = MANUFACTURER_MACRONIX, 1147 .mfr_id = MANUFACTURER_MACRONIX,
1145 .dev_id = MX29F004B, 1148 .dev_id = MX29F004B,
1146 .name = "Macronix MX29F004B", 1149 .name = "Macronix MX29F004B",
@@ -1218,7 +1221,7 @@ static const struct amd_flash_info jedec_table[] = {
1218 .regions = { 1221 .regions = {
1219 ERASEINFO(0x40000,16), 1222 ERASEINFO(0x40000,16),
1220 } 1223 }
1221 }, { 1224 }, {
1222 .mfr_id = MANUFACTURER_SST, 1225 .mfr_id = MANUFACTURER_SST,
1223 .dev_id = SST39LF512, 1226 .dev_id = SST39LF512,
1224 .name = "SST 39LF512", 1227 .name = "SST 39LF512",
@@ -1230,7 +1233,7 @@ static const struct amd_flash_info jedec_table[] = {
1230 .regions = { 1233 .regions = {
1231 ERASEINFO(0x01000,16), 1234 ERASEINFO(0x01000,16),
1232 } 1235 }
1233 }, { 1236 }, {
1234 .mfr_id = MANUFACTURER_SST, 1237 .mfr_id = MANUFACTURER_SST,
1235 .dev_id = SST39LF010, 1238 .dev_id = SST39LF010,
1236 .name = "SST 39LF010", 1239 .name = "SST 39LF010",
@@ -1242,7 +1245,7 @@ static const struct amd_flash_info jedec_table[] = {
1242 .regions = { 1245 .regions = {
1243 ERASEINFO(0x01000,32), 1246 ERASEINFO(0x01000,32),
1244 } 1247 }
1245 }, { 1248 }, {
1246 .mfr_id = MANUFACTURER_SST, 1249 .mfr_id = MANUFACTURER_SST,
1247 .dev_id = SST29EE020, 1250 .dev_id = SST29EE020,
1248 .name = "SST 29EE020", 1251 .name = "SST 29EE020",
@@ -1276,7 +1279,7 @@ static const struct amd_flash_info jedec_table[] = {
1276 .regions = { 1279 .regions = {
1277 ERASEINFO(0x01000,64), 1280 ERASEINFO(0x01000,64),
1278 } 1281 }
1279 }, { 1282 }, {
1280 .mfr_id = MANUFACTURER_SST, 1283 .mfr_id = MANUFACTURER_SST,
1281 .dev_id = SST39LF040, 1284 .dev_id = SST39LF040,
1282 .name = "SST 39LF040", 1285 .name = "SST 39LF040",
@@ -1288,7 +1291,7 @@ static const struct amd_flash_info jedec_table[] = {
1288 .regions = { 1291 .regions = {
1289 ERASEINFO(0x01000,128), 1292 ERASEINFO(0x01000,128),
1290 } 1293 }
1291 }, { 1294 }, {
1292 .mfr_id = MANUFACTURER_SST, 1295 .mfr_id = MANUFACTURER_SST,
1293 .dev_id = SST39SF010A, 1296 .dev_id = SST39SF010A,
1294 .name = "SST 39SF010A", 1297 .name = "SST 39SF010A",
@@ -1300,7 +1303,7 @@ static const struct amd_flash_info jedec_table[] = {
1300 .regions = { 1303 .regions = {
1301 ERASEINFO(0x01000,32), 1304 ERASEINFO(0x01000,32),
1302 } 1305 }
1303 }, { 1306 }, {
1304 .mfr_id = MANUFACTURER_SST, 1307 .mfr_id = MANUFACTURER_SST,
1305 .dev_id = SST39SF020A, 1308 .dev_id = SST39SF020A,
1306 .name = "SST 39SF020A", 1309 .name = "SST 39SF020A",
@@ -1412,6 +1415,18 @@ static const struct amd_flash_info jedec_table[] = {
1412 ERASEINFO(0x1000,256) 1415 ERASEINFO(0x1000,256)
1413 } 1416 }
1414 }, { 1417 }, {
1418 .mfr_id = MANUFACTURER_SST,
1419 .dev_id = SST36VF3203,
1420 .name = "SST 36VF3203",
1421 .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8,
1422 .uaddr = MTD_UADDR_0x0AAA_0x0555,
1423 .dev_size = SIZE_4MiB,
1424 .cmd_set = P_ID_AMD_STD,
1425 .nr_regions = 1,
1426 .regions = {
1427 ERASEINFO(0x10000,64),
1428 }
1429 }, {
1415 .mfr_id = MANUFACTURER_ST, 1430 .mfr_id = MANUFACTURER_ST,
1416 .dev_id = M29F800AB, 1431 .dev_id = M29F800AB,
1417 .name = "ST M29F800AB", 1432 .name = "ST M29F800AB",
@@ -1426,7 +1441,7 @@ static const struct amd_flash_info jedec_table[] = {
1426 ERASEINFO(0x08000,1), 1441 ERASEINFO(0x08000,1),
1427 ERASEINFO(0x10000,15), 1442 ERASEINFO(0x10000,15),
1428 } 1443 }
1429 }, { 1444 }, {
1430 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */ 1445 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */
1431 .dev_id = M29W800DT, 1446 .dev_id = M29W800DT,
1432 .name = "ST M29W800DT", 1447 .name = "ST M29W800DT",
@@ -1456,6 +1471,36 @@ static const struct amd_flash_info jedec_table[] = {
1456 ERASEINFO(0x08000,1), 1471 ERASEINFO(0x08000,1),
1457 ERASEINFO(0x10000,15) 1472 ERASEINFO(0x10000,15)
1458 } 1473 }
1474 }, {
1475 .mfr_id = MANUFACTURER_ST,
1476 .dev_id = M29W400DT,
1477 .name = "ST M29W400DT",
1478 .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8,
1479 .uaddr = MTD_UADDR_0x0AAA_0x0555,
1480 .dev_size = SIZE_512KiB,
1481 .cmd_set = P_ID_AMD_STD,
1482 .nr_regions = 4,
1483 .regions = {
1484 ERASEINFO(0x04000,7),
1485 ERASEINFO(0x02000,1),
1486 ERASEINFO(0x08000,2),
1487 ERASEINFO(0x10000,1)
1488 }
1489 }, {
1490 .mfr_id = MANUFACTURER_ST,
1491 .dev_id = M29W400DB,
1492 .name = "ST M29W400DB",
1493 .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8,
1494 .uaddr = MTD_UADDR_0x0AAA_0x0555,
1495 .dev_size = SIZE_512KiB,
1496 .cmd_set = P_ID_AMD_STD,
1497 .nr_regions = 4,
1498 .regions = {
1499 ERASEINFO(0x04000,1),
1500 ERASEINFO(0x02000,2),
1501 ERASEINFO(0x08000,1),
1502 ERASEINFO(0x10000,7)
1503 }
1459 }, { 1504 }, {
1460 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */ 1505 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */
1461 .dev_id = M29W160DT, 1506 .dev_id = M29W160DT,
@@ -1486,7 +1531,7 @@ static const struct amd_flash_info jedec_table[] = {
1486 ERASEINFO(0x08000,1), 1531 ERASEINFO(0x08000,1),
1487 ERASEINFO(0x10000,31) 1532 ERASEINFO(0x10000,31)
1488 } 1533 }
1489 }, { 1534 }, {
1490 .mfr_id = MANUFACTURER_ST, 1535 .mfr_id = MANUFACTURER_ST,
1491 .dev_id = M29W040B, 1536 .dev_id = M29W040B,
1492 .name = "ST M29W040B", 1537 .name = "ST M29W040B",
@@ -1498,7 +1543,7 @@ static const struct amd_flash_info jedec_table[] = {
1498 .regions = { 1543 .regions = {
1499 ERASEINFO(0x10000,8), 1544 ERASEINFO(0x10000,8),
1500 } 1545 }
1501 }, { 1546 }, {
1502 .mfr_id = MANUFACTURER_ST, 1547 .mfr_id = MANUFACTURER_ST,
1503 .dev_id = M50FW040, 1548 .dev_id = M50FW040,
1504 .name = "ST M50FW040", 1549 .name = "ST M50FW040",
@@ -1510,7 +1555,7 @@ static const struct amd_flash_info jedec_table[] = {
1510 .regions = { 1555 .regions = {
1511 ERASEINFO(0x10000,8), 1556 ERASEINFO(0x10000,8),
1512 } 1557 }
1513 }, { 1558 }, {
1514 .mfr_id = MANUFACTURER_ST, 1559 .mfr_id = MANUFACTURER_ST,
1515 .dev_id = M50FW080, 1560 .dev_id = M50FW080,
1516 .name = "ST M50FW080", 1561 .name = "ST M50FW080",
@@ -1522,7 +1567,7 @@ static const struct amd_flash_info jedec_table[] = {
1522 .regions = { 1567 .regions = {
1523 ERASEINFO(0x10000,16), 1568 ERASEINFO(0x10000,16),
1524 } 1569 }
1525 }, { 1570 }, {
1526 .mfr_id = MANUFACTURER_ST, 1571 .mfr_id = MANUFACTURER_ST,
1527 .dev_id = M50FW016, 1572 .dev_id = M50FW016,
1528 .name = "ST M50FW016", 1573 .name = "ST M50FW016",
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index b44292abd9f7..e472a0e9de9d 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -119,7 +119,8 @@ static struct mtd_partition * newpart(char *s,
119 char *p; 119 char *p;
120 120
121 name = ++s; 121 name = ++s;
122 if ((p = strchr(name, delim)) == 0) 122 p = strchr(name, delim);
123 if (!p)
123 { 124 {
124 printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim); 125 printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
125 return NULL; 126 return NULL;
@@ -159,9 +160,10 @@ static struct mtd_partition * newpart(char *s,
159 return NULL; 160 return NULL;
160 } 161 }
161 /* more partitions follow, parse them */ 162 /* more partitions follow, parse them */
162 if ((parts = newpart(s + 1, &s, num_parts, 163 parts = newpart(s + 1, &s, num_parts, this_part + 1,
163 this_part + 1, &extra_mem, extra_mem_size)) == 0) 164 &extra_mem, extra_mem_size);
164 return NULL; 165 if (!parts)
166 return NULL;
165 } 167 }
166 else 168 else
167 { /* this is the last partition: allocate space for all */ 169 { /* this is the last partition: allocate space for all */
@@ -308,9 +310,6 @@ static int parse_cmdline_partitions(struct mtd_info *master,
308 struct cmdline_mtd_partition *part; 310 struct cmdline_mtd_partition *part;
309 char *mtd_id = master->name; 311 char *mtd_id = master->name;
310 312
311 if(!cmdline)
312 return -EINVAL;
313
314 /* parse command line */ 313 /* parse command line */
315 if (!cmdline_parsed) 314 if (!cmdline_parsed)
316 mtdpart_setup_real(cmdline); 315 mtdpart_setup_real(cmdline);
@@ -341,7 +340,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
341 return part->num_parts; 340 return part->num_parts;
342 } 341 }
343 } 342 }
344 return -EINVAL; 343 return 0;
345} 344}
346 345
347 346
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index 811d56fd890f..35ed1103dbb2 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -77,6 +77,13 @@ config MTD_M25P80
77 if you want to specify device partitioning or to use a device which 77 if you want to specify device partitioning or to use a device which
78 doesn't support the JEDEC ID instruction. 78 doesn't support the JEDEC ID instruction.
79 79
80config M25PXX_USE_FAST_READ
81 bool "Use FAST_READ OPCode allowing SPI CLK <= 50MHz"
82 depends on MTD_M25P80
83 default y
84 help
85 This option enables FAST_READ access supported by ST M25Pxx.
86
80config MTD_SLRAM 87config MTD_SLRAM
81 tristate "Uncached system RAM" 88 tristate "Uncached system RAM"
82 help 89 help
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index ad1880c67518..519d942e7940 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -305,7 +305,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
305 } 305 }
306 list_add(&dev->list, &blkmtd_device_list); 306 list_add(&dev->list, &blkmtd_device_list);
307 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index, 307 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
308 dev->mtd.name + strlen("blkmtd: "), 308 dev->mtd.name + strlen("block2mtd: "),
309 dev->mtd.erasesize >> 10, dev->mtd.erasesize); 309 dev->mtd.erasesize >> 10, dev->mtd.erasesize);
310 return dev; 310 return dev;
311 311
@@ -366,9 +366,9 @@ static inline void kill_final_newline(char *str)
366} 366}
367 367
368 368
369#define parse_err(fmt, args...) do { \ 369#define parse_err(fmt, args...) do { \
370 ERROR("block2mtd: " fmt "\n", ## args); \ 370 ERROR(fmt, ## args); \
371 return 0; \ 371 return 0; \
372} while (0) 372} while (0)
373 373
374#ifndef MODULE 374#ifndef MODULE
@@ -473,7 +473,7 @@ static void __devexit block2mtd_exit(void)
473 block2mtd_sync(&dev->mtd); 473 block2mtd_sync(&dev->mtd);
474 del_mtd_device(&dev->mtd); 474 del_mtd_device(&dev->mtd);
475 INFO("mtd%d: [%s] removed", dev->mtd.index, 475 INFO("mtd%d: [%s] removed", dev->mtd.index,
476 dev->mtd.name + strlen("blkmtd: ")); 476 dev->mtd.name + strlen("block2mtd: "));
477 list_del(&dev->list); 477 list_del(&dev->list);
478 block2mtd_free_device(dev); 478 block2mtd_free_device(dev);
479 } 479 }
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 99fd210feaec..1d324e5c412d 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -275,7 +275,7 @@ static __u8 read8 (__u32 offset)
275{ 275{
276 volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset); 276 volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset);
277#ifdef LART_DEBUG 277#ifdef LART_DEBUG
278 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n",__FUNCTION__,offset,*data); 278 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n", __func__, offset, *data);
279#endif 279#endif
280 return (*data); 280 return (*data);
281} 281}
@@ -284,7 +284,7 @@ static __u32 read32 (__u32 offset)
284{ 284{
285 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); 285 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset);
286#ifdef LART_DEBUG 286#ifdef LART_DEBUG
287 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n",__FUNCTION__,offset,*data); 287 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n", __func__, offset, *data);
288#endif 288#endif
289 return (*data); 289 return (*data);
290} 290}
@@ -294,7 +294,7 @@ static void write32 (__u32 x,__u32 offset)
294 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); 294 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset);
295 *data = x; 295 *data = x;
296#ifdef LART_DEBUG 296#ifdef LART_DEBUG
297 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n",__FUNCTION__,offset,*data); 297 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, *data);
298#endif 298#endif
299} 299}
300 300
@@ -337,7 +337,7 @@ static inline int erase_block (__u32 offset)
337 __u32 status; 337 __u32 status;
338 338
339#ifdef LART_DEBUG 339#ifdef LART_DEBUG
340 printk (KERN_DEBUG "%s(): 0x%.8x\n",__FUNCTION__,offset); 340 printk (KERN_DEBUG "%s(): 0x%.8x\n", __func__, offset);
341#endif 341#endif
342 342
343 /* erase and confirm */ 343 /* erase and confirm */
@@ -371,7 +371,7 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
371 int i,first; 371 int i,first;
372 372
373#ifdef LART_DEBUG 373#ifdef LART_DEBUG
374 printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n",__FUNCTION__,instr->addr,instr->len); 374 printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len);
375#endif 375#endif
376 376
377 /* sanity checks */ 377 /* sanity checks */
@@ -442,7 +442,7 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
442static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf) 442static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf)
443{ 443{
444#ifdef LART_DEBUG 444#ifdef LART_DEBUG
445 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n",__FUNCTION__,(__u32) from,len); 445 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len);
446#endif 446#endif
447 447
448 /* sanity checks */ 448 /* sanity checks */
@@ -488,7 +488,7 @@ static inline int write_dword (__u32 offset,__u32 x)
488 __u32 status; 488 __u32 status;
489 489
490#ifdef LART_DEBUG 490#ifdef LART_DEBUG
491 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n",__FUNCTION__,offset,x); 491 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, x);
492#endif 492#endif
493 493
494 /* setup writing */ 494 /* setup writing */
@@ -524,7 +524,7 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen
524 int i,n; 524 int i,n;
525 525
526#ifdef LART_DEBUG 526#ifdef LART_DEBUG
527 printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n",__FUNCTION__,(__u32) to,len); 527 printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len);
528#endif 528#endif
529 529
530 *retlen = 0; 530 *retlen = 0;
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 98df5bcc02f3..25efd331ef28 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -33,7 +33,7 @@
33/* Flash opcodes. */ 33/* Flash opcodes. */
34#define OPCODE_WREN 0x06 /* Write enable */ 34#define OPCODE_WREN 0x06 /* Write enable */
35#define OPCODE_RDSR 0x05 /* Read status register */ 35#define OPCODE_RDSR 0x05 /* Read status register */
36#define OPCODE_READ 0x03 /* Read data bytes (low frequency) */ 36#define OPCODE_NORM_READ 0x03 /* Read data bytes (low frequency) */
37#define OPCODE_FAST_READ 0x0b /* Read data bytes (high frequency) */ 37#define OPCODE_FAST_READ 0x0b /* Read data bytes (high frequency) */
38#define OPCODE_PP 0x02 /* Page program (up to 256 bytes) */ 38#define OPCODE_PP 0x02 /* Page program (up to 256 bytes) */
39#define OPCODE_BE_4K 0x20 /* Erase 4KiB block */ 39#define OPCODE_BE_4K 0x20 /* Erase 4KiB block */
@@ -52,7 +52,15 @@
52 52
53/* Define max times to check status register before we give up. */ 53/* Define max times to check status register before we give up. */
54#define MAX_READY_WAIT_COUNT 100000 54#define MAX_READY_WAIT_COUNT 100000
55#define CMD_SIZE 4
55 56
57#ifdef CONFIG_M25PXX_USE_FAST_READ
58#define OPCODE_READ OPCODE_FAST_READ
59#define FAST_READ_DUMMY_BYTE 1
60#else
61#define OPCODE_READ OPCODE_NORM_READ
62#define FAST_READ_DUMMY_BYTE 0
63#endif
56 64
57#ifdef CONFIG_MTD_PARTITIONS 65#ifdef CONFIG_MTD_PARTITIONS
58#define mtd_has_partitions() (1) 66#define mtd_has_partitions() (1)
@@ -68,7 +76,7 @@ struct m25p {
68 struct mtd_info mtd; 76 struct mtd_info mtd;
69 unsigned partitioned:1; 77 unsigned partitioned:1;
70 u8 erase_opcode; 78 u8 erase_opcode;
71 u8 command[4]; 79 u8 command[CMD_SIZE + FAST_READ_DUMMY_BYTE];
72}; 80};
73 81
74static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd) 82static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
@@ -151,7 +159,7 @@ static int wait_till_ready(struct m25p *flash)
151static int erase_sector(struct m25p *flash, u32 offset) 159static int erase_sector(struct m25p *flash, u32 offset)
152{ 160{
153 DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %dKiB at 0x%08x\n", 161 DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %dKiB at 0x%08x\n",
154 flash->spi->dev.bus_id, __FUNCTION__, 162 flash->spi->dev.bus_id, __func__,
155 flash->mtd.erasesize / 1024, offset); 163 flash->mtd.erasesize / 1024, offset);
156 164
157 /* Wait until finished previous write command. */ 165 /* Wait until finished previous write command. */
@@ -167,7 +175,7 @@ static int erase_sector(struct m25p *flash, u32 offset)
167 flash->command[2] = offset >> 8; 175 flash->command[2] = offset >> 8;
168 flash->command[3] = offset; 176 flash->command[3] = offset;
169 177
170 spi_write(flash->spi, flash->command, sizeof(flash->command)); 178 spi_write(flash->spi, flash->command, CMD_SIZE);
171 179
172 return 0; 180 return 0;
173} 181}
@@ -188,7 +196,7 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
188 u32 addr,len; 196 u32 addr,len;
189 197
190 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n", 198 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n",
191 flash->spi->dev.bus_id, __FUNCTION__, "at", 199 flash->spi->dev.bus_id, __func__, "at",
192 (u32)instr->addr, instr->len); 200 (u32)instr->addr, instr->len);
193 201
194 /* sanity checks */ 202 /* sanity checks */
@@ -240,7 +248,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
240 struct spi_message m; 248 struct spi_message m;
241 249
242 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 250 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n",
243 flash->spi->dev.bus_id, __FUNCTION__, "from", 251 flash->spi->dev.bus_id, __func__, "from",
244 (u32)from, len); 252 (u32)from, len);
245 253
246 /* sanity checks */ 254 /* sanity checks */
@@ -253,8 +261,12 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
253 spi_message_init(&m); 261 spi_message_init(&m);
254 memset(t, 0, (sizeof t)); 262 memset(t, 0, (sizeof t));
255 263
264 /* NOTE:
265 * OPCODE_FAST_READ (if available) is faster.
266 * Should add 1 byte DUMMY_BYTE.
267 */
256 t[0].tx_buf = flash->command; 268 t[0].tx_buf = flash->command;
257 t[0].len = sizeof(flash->command); 269 t[0].len = CMD_SIZE + FAST_READ_DUMMY_BYTE;
258 spi_message_add_tail(&t[0], &m); 270 spi_message_add_tail(&t[0], &m);
259 271
260 t[1].rx_buf = buf; 272 t[1].rx_buf = buf;
@@ -287,7 +299,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
287 299
288 spi_sync(flash->spi, &m); 300 spi_sync(flash->spi, &m);
289 301
290 *retlen = m.actual_length - sizeof(flash->command); 302 *retlen = m.actual_length - CMD_SIZE - FAST_READ_DUMMY_BYTE;
291 303
292 mutex_unlock(&flash->lock); 304 mutex_unlock(&flash->lock);
293 305
@@ -308,7 +320,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
308 struct spi_message m; 320 struct spi_message m;
309 321
310 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 322 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n",
311 flash->spi->dev.bus_id, __FUNCTION__, "to", 323 flash->spi->dev.bus_id, __func__, "to",
312 (u32)to, len); 324 (u32)to, len);
313 325
314 if (retlen) 326 if (retlen)
@@ -325,7 +337,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
325 memset(t, 0, (sizeof t)); 337 memset(t, 0, (sizeof t));
326 338
327 t[0].tx_buf = flash->command; 339 t[0].tx_buf = flash->command;
328 t[0].len = sizeof(flash->command); 340 t[0].len = CMD_SIZE;
329 spi_message_add_tail(&t[0], &m); 341 spi_message_add_tail(&t[0], &m);
330 342
331 t[1].tx_buf = buf; 343 t[1].tx_buf = buf;
@@ -354,7 +366,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
354 366
355 spi_sync(flash->spi, &m); 367 spi_sync(flash->spi, &m);
356 368
357 *retlen = m.actual_length - sizeof(flash->command); 369 *retlen = m.actual_length - CMD_SIZE;
358 } else { 370 } else {
359 u32 i; 371 u32 i;
360 372
@@ -364,7 +376,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
364 t[1].len = page_size; 376 t[1].len = page_size;
365 spi_sync(flash->spi, &m); 377 spi_sync(flash->spi, &m);
366 378
367 *retlen = m.actual_length - sizeof(flash->command); 379 *retlen = m.actual_length - CMD_SIZE;
368 380
369 /* write everything in PAGESIZE chunks */ 381 /* write everything in PAGESIZE chunks */
370 for (i = page_size; i < len; i += page_size) { 382 for (i = page_size; i < len; i += page_size) {
@@ -387,8 +399,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
387 spi_sync(flash->spi, &m); 399 spi_sync(flash->spi, &m);
388 400
389 if (retlen) 401 if (retlen)
390 *retlen += m.actual_length 402 *retlen += m.actual_length - CMD_SIZE;
391 - sizeof(flash->command);
392 } 403 }
393 } 404 }
394 405
@@ -435,6 +446,7 @@ static struct flash_info __devinitdata m25p_data [] = {
435 { "at25fs040", 0x1f6604, 64 * 1024, 8, SECT_4K, }, 446 { "at25fs040", 0x1f6604, 64 * 1024, 8, SECT_4K, },
436 447
437 { "at25df041a", 0x1f4401, 64 * 1024, 8, SECT_4K, }, 448 { "at25df041a", 0x1f4401, 64 * 1024, 8, SECT_4K, },
449 { "at25df641", 0x1f4800, 64 * 1024, 128, SECT_4K, },
438 450
439 { "at26f004", 0x1f0400, 64 * 1024, 8, SECT_4K, }, 451 { "at26f004", 0x1f0400, 64 * 1024, 8, SECT_4K, },
440 { "at26df081a", 0x1f4501, 64 * 1024, 16, SECT_4K, }, 452 { "at26df081a", 0x1f4501, 64 * 1024, 16, SECT_4K, },
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index e427c82d5f4c..bf485ff49457 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -17,6 +17,7 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/mtd/mtdram.h>
20 21
21static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE; 22static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE;
22static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE; 23static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE;
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 180298b92a7a..5f960182da95 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -282,7 +282,7 @@ static int phram_setup(const char *val, struct kernel_param *kp)
282} 282}
283 283
284module_param_call(phram, phram_setup, NULL, NULL, 000); 284module_param_call(phram, phram_setup, NULL, NULL, 000);
285MODULE_PARM_DESC(phram,"Memory region to map. \"map=<name>,<start>,<length>\""); 285MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>\"");
286 286
287 287
288static int __init init_phram(void) 288static int __init init_phram(void)
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index c815d0f38577..4a79b187b568 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -136,8 +136,6 @@ typedef struct partition_t {
136#endif 136#endif
137} partition_t; 137} partition_t;
138 138
139void ftl_freepart(partition_t *part);
140
141/* Partition state flags */ 139/* Partition state flags */
142#define FTL_FORMATTED 0x01 140#define FTL_FORMATTED 0x01
143 141
@@ -1014,7 +1012,7 @@ static int ftl_writesect(struct mtd_blktrans_dev *dev,
1014 1012
1015/*====================================================================*/ 1013/*====================================================================*/
1016 1014
1017void ftl_freepart(partition_t *part) 1015static void ftl_freepart(partition_t *part)
1018{ 1016{
1019 vfree(part->VirtualBlockMap); 1017 vfree(part->VirtualBlockMap);
1020 part->VirtualBlockMap = NULL; 1018 part->VirtualBlockMap = NULL;
@@ -1069,7 +1067,7 @@ static void ftl_remove_dev(struct mtd_blktrans_dev *dev)
1069 kfree(dev); 1067 kfree(dev);
1070} 1068}
1071 1069
1072struct mtd_blktrans_ops ftl_tr = { 1070static struct mtd_blktrans_ops ftl_tr = {
1073 .name = "ftl", 1071 .name = "ftl",
1074 .major = FTL_MAJOR, 1072 .major = FTL_MAJOR,
1075 .part_bits = PART_BITS, 1073 .part_bits = PART_BITS,
diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index b8917beeb650..c551d2f0779c 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -41,11 +41,6 @@
41 41
42char inftlmountrev[]="$Revision: 1.18 $"; 42char inftlmountrev[]="$Revision: 1.18 $";
43 43
44extern int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
45 size_t *retlen, uint8_t *buf);
46extern int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
47 size_t *retlen, uint8_t *buf);
48
49/* 44/*
50 * find_boot_record: Find the INFTL Media Header and its Spare copy which 45 * find_boot_record: Find the INFTL Media Header and its Spare copy which
51 * contains the various device information of the INFTL partition and 46 * contains the various device information of the INFTL partition and
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 12c253664eb2..1bd69aa9e22a 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -21,6 +21,9 @@ config MTD_PHYSMAP
21 particular board as well as the bus width, either statically 21 particular board as well as the bus width, either statically
22 with config options or at run-time. 22 with config options or at run-time.
23 23
24 To compile this driver as a module, choose M here: the
25 module will be called physmap.
26
24config MTD_PHYSMAP_START 27config MTD_PHYSMAP_START
25 hex "Physical start address of flash mapping" 28 hex "Physical start address of flash mapping"
26 depends on MTD_PHYSMAP 29 depends on MTD_PHYSMAP
diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
index fc3b2672d1e2..1f492062f8ca 100644
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -137,7 +137,7 @@ static int bast_flash_probe(struct platform_device *pdev)
137 if (info->map.size > AREA_MAXSIZE) 137 if (info->map.size > AREA_MAXSIZE)
138 info->map.size = AREA_MAXSIZE; 138 info->map.size = AREA_MAXSIZE;
139 139
140 pr_debug("%s: area %08lx, size %ld\n", __FUNCTION__, 140 pr_debug("%s: area %08lx, size %ld\n", __func__,
141 info->map.phys, info->map.size); 141 info->map.phys, info->map.size);
142 142
143 info->area = request_mem_region(res->start, info->map.size, 143 info->area = request_mem_region(res->start, info->map.size,
@@ -149,7 +149,7 @@ static int bast_flash_probe(struct platform_device *pdev)
149 } 149 }
150 150
151 info->map.virt = ioremap(res->start, info->map.size); 151 info->map.virt = ioremap(res->start, info->map.size);
152 pr_debug("%s: virt at %08x\n", __FUNCTION__, (int)info->map.virt); 152 pr_debug("%s: virt at %08x\n", __func__, (int)info->map.virt);
153 153
154 if (info->map.virt == 0) { 154 if (info->map.virt == 0) {
155 printk(KERN_ERR PFX "failed to ioremap() region\n"); 155 printk(KERN_ERR PFX "failed to ioremap() region\n");
@@ -223,3 +223,4 @@ module_exit(bast_flash_exit);
223MODULE_LICENSE("GPL"); 223MODULE_LICENSE("GPL");
224MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 224MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
225MODULE_DESCRIPTION("BAST MTD Map driver"); 225MODULE_DESCRIPTION("BAST MTD Map driver");
226MODULE_ALIAS("platform:bast-nor");
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 688ef495888a..59d8fb49270a 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -28,6 +28,9 @@
28 28
29#define ROM_PROBE_STEP_SIZE (64*1024) 29#define ROM_PROBE_STEP_SIZE (64*1024)
30 30
31#define DEV_CK804 1
32#define DEV_MCP55 2
33
31struct ck804xrom_window { 34struct ck804xrom_window {
32 void __iomem *virt; 35 void __iomem *virt;
33 unsigned long phys; 36 unsigned long phys;
@@ -45,8 +48,9 @@ struct ck804xrom_map_info {
45 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN]; 48 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
46}; 49};
47 50
48 51/*
49/* The 2 bits controlling the window size are often set to allow reading 52 * The following applies to ck804 only:
53 * The 2 bits controlling the window size are often set to allow reading
50 * the BIOS, but too small to allow writing, since the lock registers are 54 * the BIOS, but too small to allow writing, since the lock registers are
51 * 4MiB lower in the address space than the data. 55 * 4MiB lower in the address space than the data.
52 * 56 *
@@ -58,10 +62,17 @@ struct ck804xrom_map_info {
58 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a 62 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a
59 * 64KiB window. 63 * 64KiB window.
60 * 64 *
65 * The following applies to mcp55 only:
66 * The 15 bits controlling the window size are distributed as follows:
67 * byte @0x88: bit 0..7
68 * byte @0x8c: bit 8..15
69 * word @0x90: bit 16..30
70 * If all bits are enabled, we have a 16? MiB window
71 * Please set win_size_bits to 0x7fffffff if you actually want to do something
61 */ 72 */
62static uint win_size_bits = 0; 73static uint win_size_bits = 0;
63module_param(win_size_bits, uint, 0); 74module_param(win_size_bits, uint, 0);
64MODULE_PARM_DESC(win_size_bits, "ROM window size bits override for 0x88 byte, normally set by BIOS."); 75MODULE_PARM_DESC(win_size_bits, "ROM window size bits override, normally set by BIOS.");
65 76
66static struct ck804xrom_window ck804xrom_window = { 77static struct ck804xrom_window ck804xrom_window = {
67 .maps = LIST_HEAD_INIT(ck804xrom_window.maps), 78 .maps = LIST_HEAD_INIT(ck804xrom_window.maps),
@@ -102,10 +113,11 @@ static void ck804xrom_cleanup(struct ck804xrom_window *window)
102 113
103 114
104static int __devinit ck804xrom_init_one (struct pci_dev *pdev, 115static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
105 const struct pci_device_id *ent) 116 const struct pci_device_id *ent)
106{ 117{
107 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL }; 118 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
108 u8 byte; 119 u8 byte;
120 u16 word;
109 struct ck804xrom_window *window = &ck804xrom_window; 121 struct ck804xrom_window *window = &ck804xrom_window;
110 struct ck804xrom_map_info *map = NULL; 122 struct ck804xrom_map_info *map = NULL;
111 unsigned long map_top; 123 unsigned long map_top;
@@ -113,26 +125,42 @@ static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
113 /* Remember the pci dev I find the window in */ 125 /* Remember the pci dev I find the window in */
114 window->pdev = pci_dev_get(pdev); 126 window->pdev = pci_dev_get(pdev);
115 127
116 /* Enable the selected rom window. This is often incorrectly 128 switch (ent->driver_data) {
117 * set up by the BIOS, and the 4MiB offset for the lock registers 129 case DEV_CK804:
118 * requires the full 5MiB of window space. 130 /* Enable the selected rom window. This is often incorrectly
119 * 131 * set up by the BIOS, and the 4MiB offset for the lock registers
120 * This 'write, then read' approach leaves the bits for 132 * requires the full 5MiB of window space.
121 * other uses of the hardware info. 133 *
122 */ 134 * This 'write, then read' approach leaves the bits for
123 pci_read_config_byte(pdev, 0x88, &byte); 135 * other uses of the hardware info.
124 pci_write_config_byte(pdev, 0x88, byte | win_size_bits ); 136 */
125 137 pci_read_config_byte(pdev, 0x88, &byte);
126 138 pci_write_config_byte(pdev, 0x88, byte | win_size_bits );
127 /* Assume the rom window is properly setup, and find it's size */ 139
128 pci_read_config_byte(pdev, 0x88, &byte); 140 /* Assume the rom window is properly setup, and find it's size */
129 141 pci_read_config_byte(pdev, 0x88, &byte);
130 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6))) 142
131 window->phys = 0xffb00000; /* 5MiB */ 143 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6)))
132 else if ((byte & (1<<7)) == (1<<7)) 144 window->phys = 0xffb00000; /* 5MiB */
133 window->phys = 0xffc00000; /* 4MiB */ 145 else if ((byte & (1<<7)) == (1<<7))
134 else 146 window->phys = 0xffc00000; /* 4MiB */
135 window->phys = 0xffff0000; /* 64KiB */ 147 else
148 window->phys = 0xffff0000; /* 64KiB */
149 break;
150
151 case DEV_MCP55:
152 pci_read_config_byte(pdev, 0x88, &byte);
153 pci_write_config_byte(pdev, 0x88, byte | (win_size_bits & 0xff));
154
155 pci_read_config_byte(pdev, 0x8c, &byte);
156 pci_write_config_byte(pdev, 0x8c, byte | ((win_size_bits & 0xff00) >> 8));
157
158 pci_read_config_word(pdev, 0x90, &word);
159 pci_write_config_word(pdev, 0x90, word | ((win_size_bits & 0x7fff0000) >> 16));
160
161 window->phys = 0xff000000; /* 16MiB, hardcoded for now */
162 break;
163 }
136 164
137 window->size = 0xffffffffUL - window->phys + 1UL; 165 window->size = 0xffffffffUL - window->phys + 1UL;
138 166
@@ -303,8 +331,15 @@ static void __devexit ck804xrom_remove_one (struct pci_dev *pdev)
303} 331}
304 332
305static struct pci_device_id ck804xrom_pci_tbl[] = { 333static struct pci_device_id ck804xrom_pci_tbl[] = {
306 { PCI_VENDOR_ID_NVIDIA, 0x0051, 334 { PCI_VENDOR_ID_NVIDIA, 0x0051, PCI_ANY_ID, PCI_ANY_ID, DEV_CK804 },
307 PCI_ANY_ID, PCI_ANY_ID, }, /* nvidia ck804 */ 335 { PCI_VENDOR_ID_NVIDIA, 0x0360, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
336 { PCI_VENDOR_ID_NVIDIA, 0x0361, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
337 { PCI_VENDOR_ID_NVIDIA, 0x0362, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
338 { PCI_VENDOR_ID_NVIDIA, 0x0363, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
339 { PCI_VENDOR_ID_NVIDIA, 0x0364, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
340 { PCI_VENDOR_ID_NVIDIA, 0x0365, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
341 { PCI_VENDOR_ID_NVIDIA, 0x0366, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
342 { PCI_VENDOR_ID_NVIDIA, 0x0367, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
308 { 0, } 343 { 0, }
309}; 344};
310 345
@@ -332,7 +367,7 @@ static int __init init_ck804xrom(void)
332 break; 367 break;
333 } 368 }
334 if (pdev) { 369 if (pdev) {
335 retVal = ck804xrom_init_one(pdev, &ck804xrom_pci_tbl[0]); 370 retVal = ck804xrom_init_one(pdev, id);
336 pci_dev_put(pdev); 371 pci_dev_put(pdev);
337 return retVal; 372 return retVal;
338 } 373 }
diff --git a/drivers/mtd/maps/integrator-flash.c b/drivers/mtd/maps/integrator-flash.c
index 6946d802e6f6..325c8880c437 100644
--- a/drivers/mtd/maps/integrator-flash.c
+++ b/drivers/mtd/maps/integrator-flash.c
@@ -190,6 +190,7 @@ static struct platform_driver armflash_driver = {
190 .remove = armflash_remove, 190 .remove = armflash_remove,
191 .driver = { 191 .driver = {
192 .name = "armflash", 192 .name = "armflash",
193 .owner = THIS_MODULE,
193 }, 194 },
194}; 195};
195 196
@@ -209,3 +210,4 @@ module_exit(armflash_exit);
209MODULE_AUTHOR("ARM Ltd"); 210MODULE_AUTHOR("ARM Ltd");
210MODULE_DESCRIPTION("ARM Integrator CFI map driver"); 211MODULE_DESCRIPTION("ARM Integrator CFI map driver");
211MODULE_LICENSE("GPL"); 212MODULE_LICENSE("GPL");
213MODULE_ALIAS("platform:armflash");
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
index c26488a1793a..c8396b8574c4 100644
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -253,6 +253,7 @@ static struct platform_driver ixp2000_flash_driver = {
253 .remove = ixp2000_flash_remove, 253 .remove = ixp2000_flash_remove,
254 .driver = { 254 .driver = {
255 .name = "IXP2000-Flash", 255 .name = "IXP2000-Flash",
256 .owner = THIS_MODULE,
256 }, 257 },
257}; 258};
258 259
@@ -270,4 +271,4 @@ module_init(ixp2000_flash_init);
270module_exit(ixp2000_flash_exit); 271module_exit(ixp2000_flash_exit);
271MODULE_LICENSE("GPL"); 272MODULE_LICENSE("GPL");
272MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>"); 273MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
273 274MODULE_ALIAS("platform:IXP2000-Flash");
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
index 7a828e3e6446..01f19a4714b5 100644
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -275,6 +275,7 @@ static struct platform_driver ixp4xx_flash_driver = {
275 .remove = ixp4xx_flash_remove, 275 .remove = ixp4xx_flash_remove,
276 .driver = { 276 .driver = {
277 .name = "IXP4XX-Flash", 277 .name = "IXP4XX-Flash",
278 .owner = THIS_MODULE,
278 }, 279 },
279}; 280};
280 281
@@ -295,3 +296,4 @@ module_exit(ixp4xx_flash_exit);
295MODULE_LICENSE("GPL"); 296MODULE_LICENSE("GPL");
296MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems"); 297MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
297MODULE_AUTHOR("Deepak Saxena"); 298MODULE_AUTHOR("Deepak Saxena");
299MODULE_ALIAS("platform:IXP4XX-Flash");
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
index e8d9ae535673..240b0e2d095d 100644
--- a/drivers/mtd/maps/omap_nor.c
+++ b/drivers/mtd/maps/omap_nor.c
@@ -70,7 +70,7 @@ static void omap_set_vpp(struct map_info *map, int enable)
70 } 70 }
71} 71}
72 72
73static int __devinit omapflash_probe(struct platform_device *pdev) 73static int __init omapflash_probe(struct platform_device *pdev)
74{ 74{
75 int err; 75 int err;
76 struct omapflash_info *info; 76 struct omapflash_info *info;
@@ -130,7 +130,7 @@ out_free_info:
130 return err; 130 return err;
131} 131}
132 132
133static int __devexit omapflash_remove(struct platform_device *pdev) 133static int __exit omapflash_remove(struct platform_device *pdev)
134{ 134{
135 struct omapflash_info *info = platform_get_drvdata(pdev); 135 struct omapflash_info *info = platform_get_drvdata(pdev);
136 136
@@ -152,16 +152,16 @@ static int __devexit omapflash_remove(struct platform_device *pdev)
152} 152}
153 153
154static struct platform_driver omapflash_driver = { 154static struct platform_driver omapflash_driver = {
155 .probe = omapflash_probe, 155 .remove = __exit_p(omapflash_remove),
156 .remove = __devexit_p(omapflash_remove),
157 .driver = { 156 .driver = {
158 .name = "omapflash", 157 .name = "omapflash",
158 .owner = THIS_MODULE,
159 }, 159 },
160}; 160};
161 161
162static int __init omapflash_init(void) 162static int __init omapflash_init(void)
163{ 163{
164 return platform_driver_register(&omapflash_driver); 164 return platform_driver_probe(&omapflash_driver, omapflash_probe);
165} 165}
166 166
167static void __exit omapflash_exit(void) 167static void __exit omapflash_exit(void)
@@ -174,4 +174,4 @@ module_exit(omapflash_exit);
174 174
175MODULE_LICENSE("GPL"); 175MODULE_LICENSE("GPL");
176MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards"); 176MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");
177 177MODULE_ALIAS("platform:omapflash");
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index eaeb56a4070a..1912d968718b 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -33,7 +33,7 @@ MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy");
33#undef DEBUG 33#undef DEBUG
34#define DEBUG(n, format, arg...) \ 34#define DEBUG(n, format, arg...) \
35 if (n <= debug) { \ 35 if (n <= debug) { \
36 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __FUNCTION__ , ## arg); \ 36 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
37 } 37 }
38 38
39#else 39#else
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index bc4649a17b9d..183255fcfdcb 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -242,6 +242,7 @@ static struct platform_driver physmap_flash_driver = {
242 .shutdown = physmap_flash_shutdown, 242 .shutdown = physmap_flash_shutdown,
243 .driver = { 243 .driver = {
244 .name = "physmap-flash", 244 .name = "physmap-flash",
245 .owner = THIS_MODULE,
245 }, 246 },
246}; 247};
247 248
@@ -319,3 +320,10 @@ module_exit(physmap_exit);
319MODULE_LICENSE("GPL"); 320MODULE_LICENSE("GPL");
320MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 321MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
321MODULE_DESCRIPTION("Generic configurable MTD map driver"); 322MODULE_DESCRIPTION("Generic configurable MTD map driver");
323
324/* legacy platform drivers can't hotplug or coldplg */
325#ifndef PHYSMAP_COMPAT
326/* work with hotplug and coldplug */
327MODULE_ALIAS("platform:physmap-flash");
328#endif
329
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 894c0b271289..f0b10ca05029 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -47,6 +47,7 @@ struct platram_info {
47 struct mtd_info *mtd; 47 struct mtd_info *mtd;
48 struct map_info map; 48 struct map_info map;
49 struct mtd_partition *partitions; 49 struct mtd_partition *partitions;
50 bool free_partitions;
50 struct resource *area; 51 struct resource *area;
51 struct platdata_mtd_ram *pdata; 52 struct platdata_mtd_ram *pdata;
52}; 53};
@@ -98,7 +99,8 @@ static int platram_remove(struct platform_device *pdev)
98#ifdef CONFIG_MTD_PARTITIONS 99#ifdef CONFIG_MTD_PARTITIONS
99 if (info->partitions) { 100 if (info->partitions) {
100 del_mtd_partitions(info->mtd); 101 del_mtd_partitions(info->mtd);
101 kfree(info->partitions); 102 if (info->free_partitions)
103 kfree(info->partitions);
102 } 104 }
103#endif 105#endif
104 del_mtd_device(info->mtd); 106 del_mtd_device(info->mtd);
@@ -176,7 +178,8 @@ static int platram_probe(struct platform_device *pdev)
176 178
177 info->map.phys = res->start; 179 info->map.phys = res->start;
178 info->map.size = (res->end - res->start) + 1; 180 info->map.size = (res->end - res->start) + 1;
179 info->map.name = pdata->mapname != NULL ? pdata->mapname : (char *)pdev->name; 181 info->map.name = pdata->mapname != NULL ?
182 (char *)pdata->mapname : (char *)pdev->name;
180 info->map.bankwidth = pdata->bankwidth; 183 info->map.bankwidth = pdata->bankwidth;
181 184
182 /* register our usage of the memory area */ 185 /* register our usage of the memory area */
@@ -203,9 +206,19 @@ static int platram_probe(struct platform_device *pdev)
203 206
204 dev_dbg(&pdev->dev, "initialised map, probing for mtd\n"); 207 dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
205 208
206 /* probe for the right mtd map driver */ 209 /* probe for the right mtd map driver
210 * supplied by the platform_data struct */
211
212 if (pdata->map_probes != 0) {
213 const char **map_probes = pdata->map_probes;
214
215 for ( ; !info->mtd && *map_probes; map_probes++)
216 info->mtd = do_map_probe(*map_probes , &info->map);
217 }
218 /* fallback to map_ram */
219 else
220 info->mtd = do_map_probe("map_ram", &info->map);
207 221
208 info->mtd = do_map_probe("map_ram" , &info->map);
209 if (info->mtd == NULL) { 222 if (info->mtd == NULL) {
210 dev_err(&pdev->dev, "failed to probe for map_ram\n"); 223 dev_err(&pdev->dev, "failed to probe for map_ram\n");
211 err = -ENOMEM; 224 err = -ENOMEM;
@@ -220,19 +233,21 @@ static int platram_probe(struct platform_device *pdev)
220 * to add this device whole */ 233 * to add this device whole */
221 234
222#ifdef CONFIG_MTD_PARTITIONS 235#ifdef CONFIG_MTD_PARTITIONS
223 if (pdata->nr_partitions > 0) { 236 if (!pdata->nr_partitions) {
224 const char **probes = { NULL }; 237 /* try to probe using the supplied probe type */
225 238 if (pdata->probes) {
226 if (pdata->probes) 239 err = parse_mtd_partitions(info->mtd, pdata->probes,
227 probes = (const char **)pdata->probes;
228
229 err = parse_mtd_partitions(info->mtd, probes,
230 &info->partitions, 0); 240 &info->partitions, 0);
231 if (err > 0) { 241 info->free_partitions = 1;
232 err = add_mtd_partitions(info->mtd, info->partitions, 242 if (err > 0)
233 err); 243 err = add_mtd_partitions(info->mtd,
244 info->partitions, err);
234 } 245 }
235 } 246 }
247 /* use the static mapping */
248 else
249 err = add_mtd_partitions(info->mtd, pdata->partitions,
250 pdata->nr_partitions);
236#endif /* CONFIG_MTD_PARTITIONS */ 251#endif /* CONFIG_MTD_PARTITIONS */
237 252
238 if (add_mtd_device(info->mtd)) { 253 if (add_mtd_device(info->mtd)) {
@@ -240,7 +255,9 @@ static int platram_probe(struct platform_device *pdev)
240 err = -ENOMEM; 255 err = -ENOMEM;
241 } 256 }
242 257
243 dev_info(&pdev->dev, "registered mtd device\n"); 258 if (!err)
259 dev_info(&pdev->dev, "registered mtd device\n");
260
244 return err; 261 return err;
245 262
246 exit_free: 263 exit_free:
@@ -251,6 +268,9 @@ static int platram_probe(struct platform_device *pdev)
251 268
252/* device driver info */ 269/* device driver info */
253 270
271/* work with hotplug and coldplug */
272MODULE_ALIAS("platform:mtd-ram");
273
254static struct platform_driver platram_driver = { 274static struct platform_driver platram_driver = {
255 .probe = platram_probe, 275 .probe = platram_probe,
256 .remove = platram_remove, 276 .remove = platram_remove,
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c
index 02bde8c982ec..f43ba2815cbb 100644
--- a/drivers/mtd/maps/pmcmsp-flash.c
+++ b/drivers/mtd/maps/pmcmsp-flash.c
@@ -46,7 +46,7 @@ static struct mtd_partition **msp_parts;
46static struct map_info *msp_maps; 46static struct map_info *msp_maps;
47static int fcnt; 47static int fcnt;
48 48
49#define DEBUG_MARKER printk(KERN_NOTICE "%s[%d]\n",__FUNCTION__,__LINE__) 49#define DEBUG_MARKER printk(KERN_NOTICE "%s[%d]\n", __func__, __LINE__)
50 50
51int __init init_msp_flash(void) 51int __init init_msp_flash(void)
52{ 52{
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index f904e6bd02e0..c7d5a52a2d55 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -456,6 +456,7 @@ static struct platform_driver sa1100_mtd_driver = {
456 .shutdown = sa1100_mtd_shutdown, 456 .shutdown = sa1100_mtd_shutdown,
457 .driver = { 457 .driver = {
458 .name = "flash", 458 .name = "flash",
459 .owner = THIS_MODULE,
459 }, 460 },
460}; 461};
461 462
@@ -475,3 +476,4 @@ module_exit(sa1100_mtd_exit);
475MODULE_AUTHOR("Nicolas Pitre"); 476MODULE_AUTHOR("Nicolas Pitre");
476MODULE_DESCRIPTION("SA1100 CFI map driver"); 477MODULE_DESCRIPTION("SA1100 CFI map driver");
477MODULE_LICENSE("GPL"); 478MODULE_LICENSE("GPL");
479MODULE_ALIAS("platform:flash");
diff --git a/drivers/mtd/maps/sharpsl-flash.c b/drivers/mtd/maps/sharpsl-flash.c
index 12fe53c0d2fc..917dc778f24e 100644
--- a/drivers/mtd/maps/sharpsl-flash.c
+++ b/drivers/mtd/maps/sharpsl-flash.c
@@ -92,7 +92,7 @@ int __init init_sharpsl(void)
92 parts = sharpsl_partitions; 92 parts = sharpsl_partitions;
93 nb_parts = ARRAY_SIZE(sharpsl_partitions); 93 nb_parts = ARRAY_SIZE(sharpsl_partitions);
94 94
95 printk(KERN_NOTICE "Using %s partision definition\n", part_type); 95 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
96 add_mtd_partitions(mymtd, parts, nb_parts); 96 add_mtd_partitions(mymtd, parts, nb_parts);
97 97
98 return 0; 98 return 0;
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 37e4ded9b600..521734057314 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -124,7 +124,7 @@ int __init init_tqm_mtd(void)
124 //request maximum flash size address space 124 //request maximum flash size address space
125 start_scan_addr = ioremap(flash_addr, flash_size); 125 start_scan_addr = ioremap(flash_addr, flash_size);
126 if (!start_scan_addr) { 126 if (!start_scan_addr) {
127 printk(KERN_WARNING "%s:Failed to ioremap address:0x%x\n", __FUNCTION__, flash_addr); 127 printk(KERN_WARNING "%s:Failed to ioremap address:0x%x\n", __func__, flash_addr);
128 return -EIO; 128 return -EIO;
129 } 129 }
130 130
@@ -132,7 +132,7 @@ int __init init_tqm_mtd(void)
132 if(mtd_size >= flash_size) 132 if(mtd_size >= flash_size)
133 break; 133 break;
134 134
135 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx); 135 printk(KERN_INFO "%s: chip probing count %d\n", __func__, idx);
136 136
137 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL); 137 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
138 if(map_banks[idx] == NULL) { 138 if(map_banks[idx] == NULL) {
@@ -178,7 +178,7 @@ int __init init_tqm_mtd(void)
178 mtd_size += mtd_banks[idx]->size; 178 mtd_size += mtd_banks[idx]->size;
179 num_banks++; 179 num_banks++;
180 180
181 printk(KERN_INFO "%s: bank%d, name:%s, size:%dbytes \n", __FUNCTION__, num_banks, 181 printk(KERN_INFO "%s: bank%d, name:%s, size:%dbytes \n", __func__, num_banks,
182 mtd_banks[idx]->name, mtd_banks[idx]->size); 182 mtd_banks[idx]->name, mtd_banks[idx]->size);
183 } 183 }
184 } 184 }
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index d3cf05012b46..5a680e1e61f1 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -35,7 +35,7 @@
35 35
36#define OOPS_PAGE_SIZE 4096 36#define OOPS_PAGE_SIZE 4096
37 37
38struct mtdoops_context { 38static struct mtdoops_context {
39 int mtd_index; 39 int mtd_index;
40 struct work_struct work_erase; 40 struct work_struct work_erase;
41 struct work_struct work_write; 41 struct work_struct work_write;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 959fb86cda01..5076faf9ca66 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -278,6 +278,54 @@ config MTD_NAND_AT91
278 help 278 help
279 Enables support for NAND Flash / Smart Media Card interface 279 Enables support for NAND Flash / Smart Media Card interface
280 on Atmel AT91 processors. 280 on Atmel AT91 processors.
281choice
282 prompt "ECC management for NAND Flash / SmartMedia on AT91"
283 depends on MTD_NAND_AT91
284
285config MTD_NAND_AT91_ECC_HW
286 bool "Hardware ECC"
287 depends on ARCH_AT91SAM9263 || ARCH_AT91SAM9260
288 help
289 Uses hardware ECC provided by the at91sam9260/at91sam9263 chip
290 instead of software ECC.
291 The hardware ECC controller is capable of single bit error
292 correction and 2-bit random detection per page.
293
294 NB : hardware and software ECC schemes are incompatible.
295 If you switch from one to another, you'll have to erase your
296 mtd partition.
297
298 If unsure, say Y
299
300config MTD_NAND_AT91_ECC_SOFT
301 bool "Software ECC"
302 help
303 Uses software ECC.
304
305 NB : hardware and software ECC schemes are incompatible.
306 If you switch from one to another, you'll have to erase your
307 mtd partition.
308
309config MTD_NAND_AT91_ECC_NONE
310 bool "No ECC (testing only, DANGEROUS)"
311 depends on DEBUG_KERNEL
312 help
313 No ECC will be used.
314 It's not a good idea and it should be reserved for testing
315 purpose only.
316
317 If unsure, say N
318
319 endchoice
320
321endchoice
322
323config MTD_NAND_PXA3xx
324 bool "Support for NAND flash devices on PXA3xx"
325 depends on MTD_NAND && PXA3xx
326 help
327 This enables the driver for the NAND flash device found on
328 PXA3xx processors
281 329
282config MTD_NAND_CM_X270 330config MTD_NAND_CM_X270
283 tristate "Support for NAND Flash on CM-X270 modules" 331 tristate "Support for NAND Flash on CM-X270 modules"
@@ -330,4 +378,12 @@ config MTD_NAND_FSL_ELBC
330 Enabling this option will enable you to use this to control 378 Enabling this option will enable you to use this to control
331 external NAND devices. 379 external NAND devices.
332 380
381config MTD_NAND_FSL_UPM
382 tristate "Support for NAND on Freescale UPM"
383 depends on MTD_NAND && OF_GPIO && (PPC_83xx || PPC_85xx)
384 select FSL_LBC
385 help
386 Enables support for NAND Flash chips wired onto Freescale PowerPC
387 processor localbus with User-Programmable Machine support.
388
333endif # MTD_NAND 389endif # MTD_NAND
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 80d575eeee96..a6e74a46992a 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -27,10 +27,12 @@ obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
27obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o 27obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
28obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o 28obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o
29obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o 29obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o
30obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o
30obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o 31obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o
31obj-$(CONFIG_MTD_ALAUDA) += alauda.o 32obj-$(CONFIG_MTD_ALAUDA) += alauda.o
32obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o 33obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o
33obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o 34obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o
34obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o 35obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o
36obj-$(CONFIG_MTD_NAND_FSL_UPM) += fsl_upm.o
35 37
36nand-objs := nand_base.o nand_bbt.o 38nand-objs := nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/at91_nand.c b/drivers/mtd/nand/at91_nand.c
index c9fb2acf4056..414ceaecdb3a 100644
--- a/drivers/mtd/nand/at91_nand.c
+++ b/drivers/mtd/nand/at91_nand.c
@@ -9,6 +9,15 @@
9 * Derived from drivers/mtd/spia.c 9 * Derived from drivers/mtd/spia.c
10 * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com) 10 * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com)
11 * 11 *
12 *
13 * Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
14 * Richard Genoud (richard.genoud@gmail.com), Adeneo Copyright (C) 2007
15 *
16 * Derived from Das U-Boot source code
17 * (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
18 * (C) Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
19 *
20 *
12 * This program is free software; you can redistribute it and/or modify 21 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as 22 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation. 23 * published by the Free Software Foundation.
@@ -29,11 +38,59 @@
29#include <asm/arch/board.h> 38#include <asm/arch/board.h>
30#include <asm/arch/gpio.h> 39#include <asm/arch/gpio.h>
31 40
41#ifdef CONFIG_MTD_NAND_AT91_ECC_HW
42#define hard_ecc 1
43#else
44#define hard_ecc 0
45#endif
46
47#ifdef CONFIG_MTD_NAND_AT91_ECC_NONE
48#define no_ecc 1
49#else
50#define no_ecc 0
51#endif
52
53/* Register access macros */
54#define ecc_readl(add, reg) \
55 __raw_readl(add + AT91_ECC_##reg)
56#define ecc_writel(add, reg, value) \
57 __raw_writel((value), add + AT91_ECC_##reg)
58
59#include <asm/arch/at91_ecc.h> /* AT91SAM9260/3 ECC registers */
60
61/* oob layout for large page size
62 * bad block info is on bytes 0 and 1
63 * the bytes have to be consecutives to avoid
64 * several NAND_CMD_RNDOUT during read
65 */
66static struct nand_ecclayout at91_oobinfo_large = {
67 .eccbytes = 4,
68 .eccpos = {60, 61, 62, 63},
69 .oobfree = {
70 {2, 58}
71 },
72};
73
74/* oob layout for small page size
75 * bad block info is on bytes 4 and 5
76 * the bytes have to be consecutives to avoid
77 * several NAND_CMD_RNDOUT during read
78 */
79static struct nand_ecclayout at91_oobinfo_small = {
80 .eccbytes = 4,
81 .eccpos = {0, 1, 2, 3},
82 .oobfree = {
83 {6, 10}
84 },
85};
86
32struct at91_nand_host { 87struct at91_nand_host {
33 struct nand_chip nand_chip; 88 struct nand_chip nand_chip;
34 struct mtd_info mtd; 89 struct mtd_info mtd;
35 void __iomem *io_base; 90 void __iomem *io_base;
36 struct at91_nand_data *board; 91 struct at91_nand_data *board;
92 struct device *dev;
93 void __iomem *ecc;
37}; 94};
38 95
39/* 96/*
@@ -44,6 +101,12 @@ static void at91_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
44 struct nand_chip *nand_chip = mtd->priv; 101 struct nand_chip *nand_chip = mtd->priv;
45 struct at91_nand_host *host = nand_chip->priv; 102 struct at91_nand_host *host = nand_chip->priv;
46 103
104 if (host->board->enable_pin && (ctrl & NAND_CTRL_CHANGE)) {
105 if (ctrl & NAND_NCE)
106 at91_set_gpio_value(host->board->enable_pin, 0);
107 else
108 at91_set_gpio_value(host->board->enable_pin, 1);
109 }
47 if (cmd == NAND_CMD_NONE) 110 if (cmd == NAND_CMD_NONE)
48 return; 111 return;
49 112
@@ -82,8 +145,217 @@ static void at91_nand_disable(struct at91_nand_host *host)
82 at91_set_gpio_value(host->board->enable_pin, 1); 145 at91_set_gpio_value(host->board->enable_pin, 1);
83} 146}
84 147
148/*
149 * write oob for small pages
150 */
151static int at91_nand_write_oob_512(struct mtd_info *mtd,
152 struct nand_chip *chip, int page)
153{
154 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
155 int eccsize = chip->ecc.size, length = mtd->oobsize;
156 int len, pos, status = 0;
157 const uint8_t *bufpoi = chip->oob_poi;
158
159 pos = eccsize + chunk;
160
161 chip->cmdfunc(mtd, NAND_CMD_SEQIN, pos, page);
162 len = min_t(int, length, chunk);
163 chip->write_buf(mtd, bufpoi, len);
164 bufpoi += len;
165 length -= len;
166 if (length > 0)
167 chip->write_buf(mtd, bufpoi, length);
168
169 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
170 status = chip->waitfunc(mtd, chip);
171
172 return status & NAND_STATUS_FAIL ? -EIO : 0;
173
174}
175
176/*
177 * read oob for small pages
178 */
179static int at91_nand_read_oob_512(struct mtd_info *mtd,
180 struct nand_chip *chip, int page, int sndcmd)
181{
182 if (sndcmd) {
183 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
184 sndcmd = 0;
185 }
186 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
187 return sndcmd;
188}
189
190/*
191 * Calculate HW ECC
192 *
193 * function called after a write
194 *
195 * mtd: MTD block structure
196 * dat: raw data (unused)
197 * ecc_code: buffer for ECC
198 */
199static int at91_nand_calculate(struct mtd_info *mtd,
200 const u_char *dat, unsigned char *ecc_code)
201{
202 struct nand_chip *nand_chip = mtd->priv;
203 struct at91_nand_host *host = nand_chip->priv;
204 uint32_t *eccpos = nand_chip->ecc.layout->eccpos;
205 unsigned int ecc_value;
206
207 /* get the first 2 ECC bytes */
208 ecc_value = ecc_readl(host->ecc, PR);
209
210 ecc_code[eccpos[0]] = ecc_value & 0xFF;
211 ecc_code[eccpos[1]] = (ecc_value >> 8) & 0xFF;
212
213 /* get the last 2 ECC bytes */
214 ecc_value = ecc_readl(host->ecc, NPR) & AT91_ECC_NPARITY;
215
216 ecc_code[eccpos[2]] = ecc_value & 0xFF;
217 ecc_code[eccpos[3]] = (ecc_value >> 8) & 0xFF;
218
219 return 0;
220}
221
222/*
223 * HW ECC read page function
224 *
225 * mtd: mtd info structure
226 * chip: nand chip info structure
227 * buf: buffer to store read data
228 */
229static int at91_nand_read_page(struct mtd_info *mtd,
230 struct nand_chip *chip, uint8_t *buf)
231{
232 int eccsize = chip->ecc.size;
233 int eccbytes = chip->ecc.bytes;
234 uint32_t *eccpos = chip->ecc.layout->eccpos;
235 uint8_t *p = buf;
236 uint8_t *oob = chip->oob_poi;
237 uint8_t *ecc_pos;
238 int stat;
239
240 /* read the page */
241 chip->read_buf(mtd, p, eccsize);
242
243 /* move to ECC position if needed */
244 if (eccpos[0] != 0) {
245 /* This only works on large pages
246 * because the ECC controller waits for
247 * NAND_CMD_RNDOUTSTART after the
248 * NAND_CMD_RNDOUT.
249 * anyway, for small pages, the eccpos[0] == 0
250 */
251 chip->cmdfunc(mtd, NAND_CMD_RNDOUT,
252 mtd->writesize + eccpos[0], -1);
253 }
254
255 /* the ECC controller needs to read the ECC just after the data */
256 ecc_pos = oob + eccpos[0];
257 chip->read_buf(mtd, ecc_pos, eccbytes);
258
259 /* check if there's an error */
260 stat = chip->ecc.correct(mtd, p, oob, NULL);
261
262 if (stat < 0)
263 mtd->ecc_stats.failed++;
264 else
265 mtd->ecc_stats.corrected += stat;
266
267 /* get back to oob start (end of page) */
268 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
269
270 /* read the oob */
271 chip->read_buf(mtd, oob, mtd->oobsize);
272
273 return 0;
274}
275
276/*
277 * HW ECC Correction
278 *
279 * function called after a read
280 *
281 * mtd: MTD block structure
282 * dat: raw data read from the chip
283 * read_ecc: ECC from the chip (unused)
284 * isnull: unused
285 *
286 * Detect and correct a 1 bit error for a page
287 */
288static int at91_nand_correct(struct mtd_info *mtd, u_char *dat,
289 u_char *read_ecc, u_char *isnull)
290{
291 struct nand_chip *nand_chip = mtd->priv;
292 struct at91_nand_host *host = nand_chip->priv;
293 unsigned int ecc_status;
294 unsigned int ecc_word, ecc_bit;
295
296 /* get the status from the Status Register */
297 ecc_status = ecc_readl(host->ecc, SR);
298
299 /* if there's no error */
300 if (likely(!(ecc_status & AT91_ECC_RECERR)))
301 return 0;
302
303 /* get error bit offset (4 bits) */
304 ecc_bit = ecc_readl(host->ecc, PR) & AT91_ECC_BITADDR;
305 /* get word address (12 bits) */
306 ecc_word = ecc_readl(host->ecc, PR) & AT91_ECC_WORDADDR;
307 ecc_word >>= 4;
308
309 /* if there are multiple errors */
310 if (ecc_status & AT91_ECC_MULERR) {
311 /* check if it is a freshly erased block
312 * (filled with 0xff) */
313 if ((ecc_bit == AT91_ECC_BITADDR)
314 && (ecc_word == (AT91_ECC_WORDADDR >> 4))) {
315 /* the block has just been erased, return OK */
316 return 0;
317 }
318 /* it doesn't seems to be a freshly
319 * erased block.
320 * We can't correct so many errors */
321 dev_dbg(host->dev, "at91_nand : multiple errors detected."
322 " Unable to correct.\n");
323 return -EIO;
324 }
325
326 /* if there's a single bit error : we can correct it */
327 if (ecc_status & AT91_ECC_ECCERR) {
328 /* there's nothing much to do here.
329 * the bit error is on the ECC itself.
330 */
331 dev_dbg(host->dev, "at91_nand : one bit error on ECC code."
332 " Nothing to correct\n");
333 return 0;
334 }
335
336 dev_dbg(host->dev, "at91_nand : one bit error on data."
337 " (word offset in the page :"
338 " 0x%x bit offset : 0x%x)\n",
339 ecc_word, ecc_bit);
340 /* correct the error */
341 if (nand_chip->options & NAND_BUSWIDTH_16) {
342 /* 16 bits words */
343 ((unsigned short *) dat)[ecc_word] ^= (1 << ecc_bit);
344 } else {
345 /* 8 bits words */
346 dat[ecc_word] ^= (1 << ecc_bit);
347 }
348 dev_dbg(host->dev, "at91_nand : error corrected\n");
349 return 1;
350}
351
352/*
353 * Enable HW ECC : unsused
354 */
355static void at91_nand_hwctl(struct mtd_info *mtd, int mode) { ; }
356
85#ifdef CONFIG_MTD_PARTITIONS 357#ifdef CONFIG_MTD_PARTITIONS
86const char *part_probes[] = { "cmdlinepart", NULL }; 358static const char *part_probes[] = { "cmdlinepart", NULL };
87#endif 359#endif
88 360
89/* 361/*
@@ -94,6 +366,8 @@ static int __init at91_nand_probe(struct platform_device *pdev)
94 struct at91_nand_host *host; 366 struct at91_nand_host *host;
95 struct mtd_info *mtd; 367 struct mtd_info *mtd;
96 struct nand_chip *nand_chip; 368 struct nand_chip *nand_chip;
369 struct resource *regs;
370 struct resource *mem;
97 int res; 371 int res;
98 372
99#ifdef CONFIG_MTD_PARTITIONS 373#ifdef CONFIG_MTD_PARTITIONS
@@ -108,8 +382,13 @@ static int __init at91_nand_probe(struct platform_device *pdev)
108 return -ENOMEM; 382 return -ENOMEM;
109 } 383 }
110 384
111 host->io_base = ioremap(pdev->resource[0].start, 385 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
112 pdev->resource[0].end - pdev->resource[0].start + 1); 386 if (!mem) {
387 printk(KERN_ERR "at91_nand: can't get I/O resource mem\n");
388 return -ENXIO;
389 }
390
391 host->io_base = ioremap(mem->start, mem->end - mem->start + 1);
113 if (host->io_base == NULL) { 392 if (host->io_base == NULL) {
114 printk(KERN_ERR "at91_nand: ioremap failed\n"); 393 printk(KERN_ERR "at91_nand: ioremap failed\n");
115 kfree(host); 394 kfree(host);
@@ -119,6 +398,7 @@ static int __init at91_nand_probe(struct platform_device *pdev)
119 mtd = &host->mtd; 398 mtd = &host->mtd;
120 nand_chip = &host->nand_chip; 399 nand_chip = &host->nand_chip;
121 host->board = pdev->dev.platform_data; 400 host->board = pdev->dev.platform_data;
401 host->dev = &pdev->dev;
122 402
123 nand_chip->priv = host; /* link the private data structures */ 403 nand_chip->priv = host; /* link the private data structures */
124 mtd->priv = nand_chip; 404 mtd->priv = nand_chip;
@@ -132,7 +412,32 @@ static int __init at91_nand_probe(struct platform_device *pdev)
132 if (host->board->rdy_pin) 412 if (host->board->rdy_pin)
133 nand_chip->dev_ready = at91_nand_device_ready; 413 nand_chip->dev_ready = at91_nand_device_ready;
134 414
415 regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
416 if (!regs && hard_ecc) {
417 printk(KERN_ERR "at91_nand: can't get I/O resource "
418 "regs\nFalling back on software ECC\n");
419 }
420
135 nand_chip->ecc.mode = NAND_ECC_SOFT; /* enable ECC */ 421 nand_chip->ecc.mode = NAND_ECC_SOFT; /* enable ECC */
422 if (no_ecc)
423 nand_chip->ecc.mode = NAND_ECC_NONE;
424 if (hard_ecc && regs) {
425 host->ecc = ioremap(regs->start, regs->end - regs->start + 1);
426 if (host->ecc == NULL) {
427 printk(KERN_ERR "at91_nand: ioremap failed\n");
428 res = -EIO;
429 goto err_ecc_ioremap;
430 }
431 nand_chip->ecc.mode = NAND_ECC_HW_SYNDROME;
432 nand_chip->ecc.calculate = at91_nand_calculate;
433 nand_chip->ecc.correct = at91_nand_correct;
434 nand_chip->ecc.hwctl = at91_nand_hwctl;
435 nand_chip->ecc.read_page = at91_nand_read_page;
436 nand_chip->ecc.bytes = 4;
437 nand_chip->ecc.prepad = 0;
438 nand_chip->ecc.postpad = 0;
439 }
440
136 nand_chip->chip_delay = 20; /* 20us command delay time */ 441 nand_chip->chip_delay = 20; /* 20us command delay time */
137 442
138 if (host->board->bus_width_16) /* 16-bit bus width */ 443 if (host->board->bus_width_16) /* 16-bit bus width */
@@ -149,8 +454,53 @@ static int __init at91_nand_probe(struct platform_device *pdev)
149 } 454 }
150 } 455 }
151 456
152 /* Scan to find existance of the device */ 457 /* first scan to find the device and get the page size */
153 if (nand_scan(mtd, 1)) { 458 if (nand_scan_ident(mtd, 1)) {
459 res = -ENXIO;
460 goto out;
461 }
462
463 if (nand_chip->ecc.mode == NAND_ECC_HW_SYNDROME) {
464 /* ECC is calculated for the whole page (1 step) */
465 nand_chip->ecc.size = mtd->writesize;
466
467 /* set ECC page size and oob layout */
468 switch (mtd->writesize) {
469 case 512:
470 nand_chip->ecc.layout = &at91_oobinfo_small;
471 nand_chip->ecc.read_oob = at91_nand_read_oob_512;
472 nand_chip->ecc.write_oob = at91_nand_write_oob_512;
473 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_528);
474 break;
475 case 1024:
476 nand_chip->ecc.layout = &at91_oobinfo_large;
477 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_1056);
478 break;
479 case 2048:
480 nand_chip->ecc.layout = &at91_oobinfo_large;
481 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_2112);
482 break;
483 case 4096:
484 nand_chip->ecc.layout = &at91_oobinfo_large;
485 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_4224);
486 break;
487 default:
488 /* page size not handled by HW ECC */
489 /* switching back to soft ECC */
490 nand_chip->ecc.mode = NAND_ECC_SOFT;
491 nand_chip->ecc.calculate = NULL;
492 nand_chip->ecc.correct = NULL;
493 nand_chip->ecc.hwctl = NULL;
494 nand_chip->ecc.read_page = NULL;
495 nand_chip->ecc.postpad = 0;
496 nand_chip->ecc.prepad = 0;
497 nand_chip->ecc.bytes = 0;
498 break;
499 }
500 }
501
502 /* second phase scan */
503 if (nand_scan_tail(mtd)) {
154 res = -ENXIO; 504 res = -ENXIO;
155 goto out; 505 goto out;
156 } 506 }
@@ -179,9 +529,15 @@ static int __init at91_nand_probe(struct platform_device *pdev)
179 if (!res) 529 if (!res)
180 return res; 530 return res;
181 531
532#ifdef CONFIG_MTD_PARTITIONS
182release: 533release:
534#endif
183 nand_release(mtd); 535 nand_release(mtd);
536
184out: 537out:
538 iounmap(host->ecc);
539
540err_ecc_ioremap:
185 at91_nand_disable(host); 541 at91_nand_disable(host);
186 platform_set_drvdata(pdev, NULL); 542 platform_set_drvdata(pdev, NULL);
187 iounmap(host->io_base); 543 iounmap(host->io_base);
@@ -202,6 +558,7 @@ static int __devexit at91_nand_remove(struct platform_device *pdev)
202 at91_nand_disable(host); 558 at91_nand_disable(host);
203 559
204 iounmap(host->io_base); 560 iounmap(host->io_base);
561 iounmap(host->ecc);
205 kfree(host); 562 kfree(host);
206 563
207 return 0; 564 return 0;
@@ -233,4 +590,5 @@ module_exit(at91_nand_exit);
233 590
234MODULE_LICENSE("GPL"); 591MODULE_LICENSE("GPL");
235MODULE_AUTHOR("Rick Bronson"); 592MODULE_AUTHOR("Rick Bronson");
236MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91RM9200"); 593MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91RM9200 / AT91SAM9");
594MODULE_ALIAS("platform:at91_nand");
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 747042ab094a..e87a57297328 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -1,6 +1,6 @@
1/* linux/drivers/mtd/nand/bf5xx_nand.c 1/* linux/drivers/mtd/nand/bf5xx_nand.c
2 * 2 *
3 * Copyright 2006-2007 Analog Devices Inc. 3 * Copyright 2006-2008 Analog Devices Inc.
4 * http://blackfin.uclinux.org/ 4 * http://blackfin.uclinux.org/
5 * Bryan Wu <bryan.wu@analog.com> 5 * Bryan Wu <bryan.wu@analog.com>
6 * 6 *
@@ -74,7 +74,7 @@ static int hardware_ecc = 1;
74static int hardware_ecc; 74static int hardware_ecc;
75#endif 75#endif
76 76
77static unsigned short bfin_nfc_pin_req[] = 77static const unsigned short bfin_nfc_pin_req[] =
78 {P_NAND_CE, 78 {P_NAND_CE,
79 P_NAND_RB, 79 P_NAND_RB,
80 P_NAND_D0, 80 P_NAND_D0,
@@ -581,12 +581,6 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
581 bfin_write_NFC_IRQSTAT(val); 581 bfin_write_NFC_IRQSTAT(val);
582 SSYNC(); 582 SSYNC();
583 583
584 if (peripheral_request_list(bfin_nfc_pin_req, DRV_NAME)) {
585 printk(KERN_ERR DRV_NAME
586 ": Requesting Peripherals failed\n");
587 return -EFAULT;
588 }
589
590 /* DMA initialization */ 584 /* DMA initialization */
591 if (bf5xx_nand_dma_init(info)) 585 if (bf5xx_nand_dma_init(info))
592 err = -ENXIO; 586 err = -ENXIO;
@@ -654,6 +648,12 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
654 648
655 dev_dbg(&pdev->dev, "(%p)\n", pdev); 649 dev_dbg(&pdev->dev, "(%p)\n", pdev);
656 650
651 if (peripheral_request_list(bfin_nfc_pin_req, DRV_NAME)) {
652 printk(KERN_ERR DRV_NAME
653 ": Requesting Peripherals failed\n");
654 return -EFAULT;
655 }
656
657 if (!plat) { 657 if (!plat) {
658 dev_err(&pdev->dev, "no platform specific information\n"); 658 dev_err(&pdev->dev, "no platform specific information\n");
659 goto exit_error; 659 goto exit_error;
@@ -803,3 +803,4 @@ module_exit(bf5xx_nand_exit);
803MODULE_LICENSE("GPL"); 803MODULE_LICENSE("GPL");
804MODULE_AUTHOR(DRV_AUTHOR); 804MODULE_AUTHOR(DRV_AUTHOR);
805MODULE_DESCRIPTION(DRV_DESC); 805MODULE_DESCRIPTION(DRV_DESC);
806MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 8dab69657b19..3370a800fd36 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -279,7 +279,7 @@ static int is_geode(void)
279 279
280 280
281#ifdef CONFIG_MTD_PARTITIONS 281#ifdef CONFIG_MTD_PARTITIONS
282const char *part_probes[] = { "cmdlinepart", NULL }; 282static const char *part_probes[] = { "cmdlinepart", NULL };
283#endif 283#endif
284 284
285 285
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 378b7aa63812..4b69aacdf5ca 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -184,11 +184,11 @@ static int fsl_elbc_run_command(struct mtd_info *mtd)
184 in_be32(&lbc->fbar), in_be32(&lbc->fpar), 184 in_be32(&lbc->fbar), in_be32(&lbc->fpar),
185 in_be32(&lbc->fbcr), priv->bank); 185 in_be32(&lbc->fbcr), priv->bank);
186 186
187 ctrl->irq_status = 0;
187 /* execute special operation */ 188 /* execute special operation */
188 out_be32(&lbc->lsor, priv->bank); 189 out_be32(&lbc->lsor, priv->bank);
189 190
190 /* wait for FCM complete flag or timeout */ 191 /* wait for FCM complete flag or timeout */
191 ctrl->irq_status = 0;
192 wait_event_timeout(ctrl->irq_wait, ctrl->irq_status, 192 wait_event_timeout(ctrl->irq_wait, ctrl->irq_status,
193 FCM_TIMEOUT_MSECS * HZ/1000); 193 FCM_TIMEOUT_MSECS * HZ/1000);
194 ctrl->status = ctrl->irq_status; 194 ctrl->status = ctrl->irq_status;
@@ -346,19 +346,20 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command,
346 ctrl->column = column; 346 ctrl->column = column;
347 ctrl->oob = 0; 347 ctrl->oob = 0;
348 348
349 fcr = (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT) |
350 (NAND_CMD_SEQIN << FCR_CMD2_SHIFT);
351
352 if (priv->page_size) { 349 if (priv->page_size) {
350 fcr = (NAND_CMD_SEQIN << FCR_CMD0_SHIFT) |
351 (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT);
352
353 out_be32(&lbc->fir, 353 out_be32(&lbc->fir,
354 (FIR_OP_CW0 << FIR_OP0_SHIFT) | 354 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
355 (FIR_OP_CA << FIR_OP1_SHIFT) | 355 (FIR_OP_CA << FIR_OP1_SHIFT) |
356 (FIR_OP_PA << FIR_OP2_SHIFT) | 356 (FIR_OP_PA << FIR_OP2_SHIFT) |
357 (FIR_OP_WB << FIR_OP3_SHIFT) | 357 (FIR_OP_WB << FIR_OP3_SHIFT) |
358 (FIR_OP_CW1 << FIR_OP4_SHIFT)); 358 (FIR_OP_CW1 << FIR_OP4_SHIFT));
359
360 fcr |= NAND_CMD_READ0 << FCR_CMD0_SHIFT;
361 } else { 359 } else {
360 fcr = (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT) |
361 (NAND_CMD_SEQIN << FCR_CMD2_SHIFT);
362
362 out_be32(&lbc->fir, 363 out_be32(&lbc->fir,
363 (FIR_OP_CW0 << FIR_OP0_SHIFT) | 364 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
364 (FIR_OP_CM2 << FIR_OP1_SHIFT) | 365 (FIR_OP_CM2 << FIR_OP1_SHIFT) |
@@ -480,7 +481,7 @@ static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
480 struct fsl_elbc_ctrl *ctrl = priv->ctrl; 481 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
481 unsigned int bufsize = mtd->writesize + mtd->oobsize; 482 unsigned int bufsize = mtd->writesize + mtd->oobsize;
482 483
483 if (len < 0) { 484 if (len <= 0) {
484 dev_err(ctrl->dev, "write_buf of %d bytes", len); 485 dev_err(ctrl->dev, "write_buf of %d bytes", len);
485 ctrl->status = 0; 486 ctrl->status = 0;
486 return; 487 return;
@@ -495,6 +496,15 @@ static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
495 } 496 }
496 497
497 memcpy_toio(&ctrl->addr[ctrl->index], buf, len); 498 memcpy_toio(&ctrl->addr[ctrl->index], buf, len);
499 /*
500 * This is workaround for the weird elbc hangs during nand write,
501 * Scott Wood says: "...perhaps difference in how long it takes a
502 * write to make it through the localbus compared to a write to IMMR
503 * is causing problems, and sync isn't helping for some reason."
504 * Reading back the last byte helps though.
505 */
506 in_8(&ctrl->addr[ctrl->index] + len - 1);
507
498 ctrl->index += len; 508 ctrl->index += len;
499} 509}
500 510
@@ -666,7 +676,7 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
666 /* adjust Option Register and ECC to match Flash page size */ 676 /* adjust Option Register and ECC to match Flash page size */
667 if (mtd->writesize == 512) { 677 if (mtd->writesize == 512) {
668 priv->page_size = 0; 678 priv->page_size = 0;
669 clrbits32(&lbc->bank[priv->bank].or, ~OR_FCM_PGS); 679 clrbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS);
670 } else if (mtd->writesize == 2048) { 680 } else if (mtd->writesize == 2048) {
671 priv->page_size = 1; 681 priv->page_size = 1;
672 setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS); 682 setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS);
@@ -687,11 +697,6 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
687 return -1; 697 return -1;
688 } 698 }
689 699
690 /* The default u-boot configuration on MPC8313ERDB causes errors;
691 * more delay is needed. This should be safe for other boards
692 * as well.
693 */
694 setbits32(&lbc->bank[priv->bank].or, 0x70);
695 return 0; 700 return 0;
696} 701}
697 702
@@ -779,6 +784,8 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
779 784
780 nand_release(&priv->mtd); 785 nand_release(&priv->mtd);
781 786
787 kfree(priv->mtd.name);
788
782 if (priv->vbase) 789 if (priv->vbase)
783 iounmap(priv->vbase); 790 iounmap(priv->vbase);
784 791
@@ -839,6 +846,12 @@ static int fsl_elbc_chip_probe(struct fsl_elbc_ctrl *ctrl,
839 goto err; 846 goto err;
840 } 847 }
841 848
849 priv->mtd.name = kasprintf(GFP_KERNEL, "%x.flash", res.start);
850 if (!priv->mtd.name) {
851 ret = -ENOMEM;
852 goto err;
853 }
854
842 ret = fsl_elbc_chip_init(priv); 855 ret = fsl_elbc_chip_init(priv);
843 if (ret) 856 if (ret)
844 goto err; 857 goto err;
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
new file mode 100644
index 000000000000..1ebfd87f00b4
--- /dev/null
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -0,0 +1,291 @@
1/*
2 * Freescale UPM NAND driver.
3 *
4 * Copyright © 2007-2008 MontaVista Software, Inc.
5 *
6 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/mtd/nand.h>
17#include <linux/mtd/nand_ecc.h>
18#include <linux/mtd/partitions.h>
19#include <linux/mtd/mtd.h>
20#include <linux/of_platform.h>
21#include <linux/of_gpio.h>
22#include <linux/io.h>
23#include <asm/fsl_lbc.h>
24
25struct fsl_upm_nand {
26 struct device *dev;
27 struct mtd_info mtd;
28 struct nand_chip chip;
29 int last_ctrl;
30#ifdef CONFIG_MTD_PARTITIONS
31 struct mtd_partition *parts;
32#endif
33
34 struct fsl_upm upm;
35 uint8_t upm_addr_offset;
36 uint8_t upm_cmd_offset;
37 void __iomem *io_base;
38 int rnb_gpio;
39 const uint32_t *wait_pattern;
40 const uint32_t *wait_write;
41 int chip_delay;
42};
43
44#define to_fsl_upm_nand(mtd) container_of(mtd, struct fsl_upm_nand, mtd)
45
46static int fun_chip_ready(struct mtd_info *mtd)
47{
48 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
49
50 if (gpio_get_value(fun->rnb_gpio))
51 return 1;
52
53 dev_vdbg(fun->dev, "busy\n");
54 return 0;
55}
56
57static void fun_wait_rnb(struct fsl_upm_nand *fun)
58{
59 int cnt = 1000000;
60
61 if (fun->rnb_gpio >= 0) {
62 while (--cnt && !fun_chip_ready(&fun->mtd))
63 cpu_relax();
64 }
65
66 if (!cnt)
67 dev_err(fun->dev, "tired waiting for RNB\n");
68}
69
70static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
71{
72 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
73
74 if (!(ctrl & fun->last_ctrl)) {
75 fsl_upm_end_pattern(&fun->upm);
76
77 if (cmd == NAND_CMD_NONE)
78 return;
79
80 fun->last_ctrl = ctrl & (NAND_ALE | NAND_CLE);
81 }
82
83 if (ctrl & NAND_CTRL_CHANGE) {
84 if (ctrl & NAND_ALE)
85 fsl_upm_start_pattern(&fun->upm, fun->upm_addr_offset);
86 else if (ctrl & NAND_CLE)
87 fsl_upm_start_pattern(&fun->upm, fun->upm_cmd_offset);
88 }
89
90 fsl_upm_run_pattern(&fun->upm, fun->io_base, cmd);
91
92 if (fun->wait_pattern)
93 fun_wait_rnb(fun);
94}
95
96static uint8_t fun_read_byte(struct mtd_info *mtd)
97{
98 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
99
100 return in_8(fun->chip.IO_ADDR_R);
101}
102
103static void fun_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
104{
105 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
106 int i;
107
108 for (i = 0; i < len; i++)
109 buf[i] = in_8(fun->chip.IO_ADDR_R);
110}
111
112static void fun_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
113{
114 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
115 int i;
116
117 for (i = 0; i < len; i++) {
118 out_8(fun->chip.IO_ADDR_W, buf[i]);
119 if (fun->wait_write)
120 fun_wait_rnb(fun);
121 }
122}
123
124static int __devinit fun_chip_init(struct fsl_upm_nand *fun)
125{
126 int ret;
127#ifdef CONFIG_MTD_PARTITIONS
128 static const char *part_types[] = { "cmdlinepart", NULL, };
129#endif
130
131 fun->chip.IO_ADDR_R = fun->io_base;
132 fun->chip.IO_ADDR_W = fun->io_base;
133 fun->chip.cmd_ctrl = fun_cmd_ctrl;
134 fun->chip.chip_delay = fun->chip_delay;
135 fun->chip.read_byte = fun_read_byte;
136 fun->chip.read_buf = fun_read_buf;
137 fun->chip.write_buf = fun_write_buf;
138 fun->chip.ecc.mode = NAND_ECC_SOFT;
139
140 if (fun->rnb_gpio >= 0)
141 fun->chip.dev_ready = fun_chip_ready;
142
143 fun->mtd.priv = &fun->chip;
144 fun->mtd.owner = THIS_MODULE;
145
146 ret = nand_scan(&fun->mtd, 1);
147 if (ret)
148 return ret;
149
150 fun->mtd.name = fun->dev->bus_id;
151
152#ifdef CONFIG_MTD_PARTITIONS
153 ret = parse_mtd_partitions(&fun->mtd, part_types, &fun->parts, 0);
154 if (ret > 0)
155 return add_mtd_partitions(&fun->mtd, fun->parts, ret);
156#endif
157 return add_mtd_device(&fun->mtd);
158}
159
160static int __devinit fun_probe(struct of_device *ofdev,
161 const struct of_device_id *ofid)
162{
163 struct fsl_upm_nand *fun;
164 struct resource io_res;
165 const uint32_t *prop;
166 int ret;
167 int size;
168
169 fun = kzalloc(sizeof(*fun), GFP_KERNEL);
170 if (!fun)
171 return -ENOMEM;
172
173 ret = of_address_to_resource(ofdev->node, 0, &io_res);
174 if (ret) {
175 dev_err(&ofdev->dev, "can't get IO base\n");
176 goto err1;
177 }
178
179 ret = fsl_upm_find(io_res.start, &fun->upm);
180 if (ret) {
181 dev_err(&ofdev->dev, "can't find UPM\n");
182 goto err1;
183 }
184
185 prop = of_get_property(ofdev->node, "fsl,upm-addr-offset", &size);
186 if (!prop || size != sizeof(uint32_t)) {
187 dev_err(&ofdev->dev, "can't get UPM address offset\n");
188 ret = -EINVAL;
189 goto err2;
190 }
191 fun->upm_addr_offset = *prop;
192
193 prop = of_get_property(ofdev->node, "fsl,upm-cmd-offset", &size);
194 if (!prop || size != sizeof(uint32_t)) {
195 dev_err(&ofdev->dev, "can't get UPM command offset\n");
196 ret = -EINVAL;
197 goto err2;
198 }
199 fun->upm_cmd_offset = *prop;
200
201 fun->rnb_gpio = of_get_gpio(ofdev->node, 0);
202 if (fun->rnb_gpio >= 0) {
203 ret = gpio_request(fun->rnb_gpio, ofdev->dev.bus_id);
204 if (ret) {
205 dev_err(&ofdev->dev, "can't request RNB gpio\n");
206 goto err2;
207 }
208 gpio_direction_input(fun->rnb_gpio);
209 } else if (fun->rnb_gpio == -EINVAL) {
210 dev_err(&ofdev->dev, "specified RNB gpio is invalid\n");
211 goto err2;
212 }
213
214 fun->io_base = devm_ioremap_nocache(&ofdev->dev, io_res.start,
215 io_res.end - io_res.start + 1);
216 if (!fun->io_base) {
217 ret = -ENOMEM;
218 goto err2;
219 }
220
221 fun->dev = &ofdev->dev;
222 fun->last_ctrl = NAND_CLE;
223 fun->wait_pattern = of_get_property(ofdev->node, "fsl,wait-pattern",
224 NULL);
225 fun->wait_write = of_get_property(ofdev->node, "fsl,wait-write", NULL);
226
227 prop = of_get_property(ofdev->node, "chip-delay", NULL);
228 if (prop)
229 fun->chip_delay = *prop;
230 else
231 fun->chip_delay = 50;
232
233 ret = fun_chip_init(fun);
234 if (ret)
235 goto err2;
236
237 dev_set_drvdata(&ofdev->dev, fun);
238
239 return 0;
240err2:
241 if (fun->rnb_gpio >= 0)
242 gpio_free(fun->rnb_gpio);
243err1:
244 kfree(fun);
245
246 return ret;
247}
248
249static int __devexit fun_remove(struct of_device *ofdev)
250{
251 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev);
252
253 nand_release(&fun->mtd);
254
255 if (fun->rnb_gpio >= 0)
256 gpio_free(fun->rnb_gpio);
257
258 kfree(fun);
259
260 return 0;
261}
262
263static struct of_device_id of_fun_match[] = {
264 { .compatible = "fsl,upm-nand" },
265 {},
266};
267MODULE_DEVICE_TABLE(of, of_fun_match);
268
269static struct of_platform_driver of_fun_driver = {
270 .name = "fsl,upm-nand",
271 .match_table = of_fun_match,
272 .probe = fun_probe,
273 .remove = __devexit_p(fun_remove),
274};
275
276static int __init fun_module_init(void)
277{
278 return of_register_platform_driver(&of_fun_driver);
279}
280module_init(fun_module_init);
281
282static void __exit fun_module_exit(void)
283{
284 of_unregister_platform_driver(&of_fun_driver);
285}
286module_exit(fun_module_exit);
287
288MODULE_LICENSE("GPL");
289MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
290MODULE_DESCRIPTION("Driver for NAND chips working through Freescale "
291 "LocalBus User-Programmable Machine");
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 7acb1a0e7409..ba1bdf787323 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2229,6 +2229,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2229{ 2229{
2230 struct nand_flash_dev *type = NULL; 2230 struct nand_flash_dev *type = NULL;
2231 int i, dev_id, maf_idx; 2231 int i, dev_id, maf_idx;
2232 int tmp_id, tmp_manf;
2232 2233
2233 /* Select the device */ 2234 /* Select the device */
2234 chip->select_chip(mtd, 0); 2235 chip->select_chip(mtd, 0);
@@ -2240,6 +2241,26 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2240 *maf_id = chip->read_byte(mtd); 2241 *maf_id = chip->read_byte(mtd);
2241 dev_id = chip->read_byte(mtd); 2242 dev_id = chip->read_byte(mtd);
2242 2243
2244 /* Try again to make sure, as some systems the bus-hold or other
2245 * interface concerns can cause random data which looks like a
2246 * possibly credible NAND flash to appear. If the two results do
2247 * not match, ignore the device completely.
2248 */
2249
2250 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
2251
2252 /* Read manufacturer and device IDs */
2253
2254 tmp_manf = chip->read_byte(mtd);
2255 tmp_id = chip->read_byte(mtd);
2256
2257 if (tmp_manf != *maf_id || tmp_id != dev_id) {
2258 printk(KERN_INFO "%s: second ID read did not match "
2259 "%02x,%02x against %02x,%02x\n", __func__,
2260 *maf_id, dev_id, tmp_manf, tmp_id);
2261 return ERR_PTR(-ENODEV);
2262 }
2263
2243 /* Lookup the flash id */ 2264 /* Lookup the flash id */
2244 for (i = 0; nand_flash_ids[i].name != NULL; i++) { 2265 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
2245 if (dev_id == nand_flash_ids[i].id) { 2266 if (dev_id == nand_flash_ids[i].id) {
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 1c0e89f00e8d..955959eb02d4 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -317,3 +317,5 @@ module_exit(ndfc_nand_exit);
317MODULE_LICENSE("GPL"); 317MODULE_LICENSE("GPL");
318MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>"); 318MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
319MODULE_DESCRIPTION("Platform driver for NDFC"); 319MODULE_DESCRIPTION("Platform driver for NDFC");
320MODULE_ALIAS("platform:ndfc-chip");
321MODULE_ALIAS("platform:ndfc-nand");
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index ec5ad28b237e..59e05a1c50cf 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -169,3 +169,4 @@ module_exit(orion_nand_exit);
169MODULE_LICENSE("GPL"); 169MODULE_LICENSE("GPL");
170MODULE_AUTHOR("Tzachi Perelstein"); 170MODULE_AUTHOR("Tzachi Perelstein");
171MODULE_DESCRIPTION("NAND glue for Orion platforms"); 171MODULE_DESCRIPTION("NAND glue for Orion platforms");
172MODULE_ALIAS("platform:orion_nand");
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index f6d5c2adc4fd..f674c5427b17 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -54,6 +54,7 @@ static int __init plat_nand_probe(struct platform_device *pdev)
54 data->chip.priv = &data; 54 data->chip.priv = &data;
55 data->mtd.priv = &data->chip; 55 data->mtd.priv = &data->chip;
56 data->mtd.owner = THIS_MODULE; 56 data->mtd.owner = THIS_MODULE;
57 data->mtd.name = pdev->dev.bus_id;
57 58
58 data->chip.IO_ADDR_R = data->io_base; 59 data->chip.IO_ADDR_R = data->io_base;
59 data->chip.IO_ADDR_W = data->io_base; 60 data->chip.IO_ADDR_W = data->io_base;
@@ -150,3 +151,4 @@ module_exit(plat_nand_exit);
150MODULE_LICENSE("GPL"); 151MODULE_LICENSE("GPL");
151MODULE_AUTHOR("Vitaly Wool"); 152MODULE_AUTHOR("Vitaly Wool");
152MODULE_DESCRIPTION("Simple generic NAND driver"); 153MODULE_DESCRIPTION("Simple generic NAND driver");
154MODULE_ALIAS("platform:gen_nand");
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
new file mode 100644
index 000000000000..fceb468ccdec
--- /dev/null
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -0,0 +1,1249 @@
1/*
2 * drivers/mtd/nand/pxa3xx_nand.c
3 *
4 * Copyright © 2005 Intel Corporation
5 * Copyright © 2006 Marvell International Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/interrupt.h>
14#include <linux/platform_device.h>
15#include <linux/dma-mapping.h>
16#include <linux/delay.h>
17#include <linux/clk.h>
18#include <linux/mtd/mtd.h>
19#include <linux/mtd/nand.h>
20#include <linux/mtd/partitions.h>
21#include <linux/io.h>
22#include <linux/irq.h>
23#include <asm/dma.h>
24
25#include <asm/arch/pxa-regs.h>
26#include <asm/arch/pxa3xx_nand.h>
27
28#define CHIP_DELAY_TIMEOUT (2 * HZ/10)
29
30/* registers and bit definitions */
31#define NDCR (0x00) /* Control register */
32#define NDTR0CS0 (0x04) /* Timing Parameter 0 for CS0 */
33#define NDTR1CS0 (0x0C) /* Timing Parameter 1 for CS0 */
34#define NDSR (0x14) /* Status Register */
35#define NDPCR (0x18) /* Page Count Register */
36#define NDBDR0 (0x1C) /* Bad Block Register 0 */
37#define NDBDR1 (0x20) /* Bad Block Register 1 */
38#define NDDB (0x40) /* Data Buffer */
39#define NDCB0 (0x48) /* Command Buffer0 */
40#define NDCB1 (0x4C) /* Command Buffer1 */
41#define NDCB2 (0x50) /* Command Buffer2 */
42
43#define NDCR_SPARE_EN (0x1 << 31)
44#define NDCR_ECC_EN (0x1 << 30)
45#define NDCR_DMA_EN (0x1 << 29)
46#define NDCR_ND_RUN (0x1 << 28)
47#define NDCR_DWIDTH_C (0x1 << 27)
48#define NDCR_DWIDTH_M (0x1 << 26)
49#define NDCR_PAGE_SZ (0x1 << 24)
50#define NDCR_NCSX (0x1 << 23)
51#define NDCR_ND_MODE (0x3 << 21)
52#define NDCR_NAND_MODE (0x0)
53#define NDCR_CLR_PG_CNT (0x1 << 20)
54#define NDCR_CLR_ECC (0x1 << 19)
55#define NDCR_RD_ID_CNT_MASK (0x7 << 16)
56#define NDCR_RD_ID_CNT(x) (((x) << 16) & NDCR_RD_ID_CNT_MASK)
57
58#define NDCR_RA_START (0x1 << 15)
59#define NDCR_PG_PER_BLK (0x1 << 14)
60#define NDCR_ND_ARB_EN (0x1 << 12)
61
62#define NDSR_MASK (0xfff)
63#define NDSR_RDY (0x1 << 11)
64#define NDSR_CS0_PAGED (0x1 << 10)
65#define NDSR_CS1_PAGED (0x1 << 9)
66#define NDSR_CS0_CMDD (0x1 << 8)
67#define NDSR_CS1_CMDD (0x1 << 7)
68#define NDSR_CS0_BBD (0x1 << 6)
69#define NDSR_CS1_BBD (0x1 << 5)
70#define NDSR_DBERR (0x1 << 4)
71#define NDSR_SBERR (0x1 << 3)
72#define NDSR_WRDREQ (0x1 << 2)
73#define NDSR_RDDREQ (0x1 << 1)
74#define NDSR_WRCMDREQ (0x1)
75
76#define NDCB0_AUTO_RS (0x1 << 25)
77#define NDCB0_CSEL (0x1 << 24)
78#define NDCB0_CMD_TYPE_MASK (0x7 << 21)
79#define NDCB0_CMD_TYPE(x) (((x) << 21) & NDCB0_CMD_TYPE_MASK)
80#define NDCB0_NC (0x1 << 20)
81#define NDCB0_DBC (0x1 << 19)
82#define NDCB0_ADDR_CYC_MASK (0x7 << 16)
83#define NDCB0_ADDR_CYC(x) (((x) << 16) & NDCB0_ADDR_CYC_MASK)
84#define NDCB0_CMD2_MASK (0xff << 8)
85#define NDCB0_CMD1_MASK (0xff)
86#define NDCB0_ADDR_CYC_SHIFT (16)
87
88/* dma-able I/O address for the NAND data and commands */
89#define NDCB0_DMA_ADDR (0x43100048)
90#define NDDB_DMA_ADDR (0x43100040)
91
92/* macros for registers read/write */
93#define nand_writel(info, off, val) \
94 __raw_writel((val), (info)->mmio_base + (off))
95
96#define nand_readl(info, off) \
97 __raw_readl((info)->mmio_base + (off))
98
99/* error code and state */
100enum {
101 ERR_NONE = 0,
102 ERR_DMABUSERR = -1,
103 ERR_SENDCMD = -2,
104 ERR_DBERR = -3,
105 ERR_BBERR = -4,
106};
107
108enum {
109 STATE_READY = 0,
110 STATE_CMD_HANDLE,
111 STATE_DMA_READING,
112 STATE_DMA_WRITING,
113 STATE_DMA_DONE,
114 STATE_PIO_READING,
115 STATE_PIO_WRITING,
116};
117
118struct pxa3xx_nand_timing {
119 unsigned int tCH; /* Enable signal hold time */
120 unsigned int tCS; /* Enable signal setup time */
121 unsigned int tWH; /* ND_nWE high duration */
122 unsigned int tWP; /* ND_nWE pulse time */
123 unsigned int tRH; /* ND_nRE high duration */
124 unsigned int tRP; /* ND_nRE pulse width */
125 unsigned int tR; /* ND_nWE high to ND_nRE low for read */
126 unsigned int tWHR; /* ND_nWE high to ND_nRE low for status read */
127 unsigned int tAR; /* ND_ALE low to ND_nRE low delay */
128};
129
130struct pxa3xx_nand_cmdset {
131 uint16_t read1;
132 uint16_t read2;
133 uint16_t program;
134 uint16_t read_status;
135 uint16_t read_id;
136 uint16_t erase;
137 uint16_t reset;
138 uint16_t lock;
139 uint16_t unlock;
140 uint16_t lock_status;
141};
142
143struct pxa3xx_nand_flash {
144 struct pxa3xx_nand_timing *timing; /* NAND Flash timing */
145 struct pxa3xx_nand_cmdset *cmdset;
146
147 uint32_t page_per_block;/* Pages per block (PG_PER_BLK) */
148 uint32_t page_size; /* Page size in bytes (PAGE_SZ) */
149 uint32_t flash_width; /* Width of Flash memory (DWIDTH_M) */
150 uint32_t dfc_width; /* Width of flash controller(DWIDTH_C) */
151 uint32_t num_blocks; /* Number of physical blocks in Flash */
152 uint32_t chip_id;
153
154 /* NOTE: these are automatically calculated, do not define */
155 size_t oob_size;
156 size_t read_id_bytes;
157
158 unsigned int col_addr_cycles;
159 unsigned int row_addr_cycles;
160};
161
162struct pxa3xx_nand_info {
163 struct nand_chip nand_chip;
164
165 struct platform_device *pdev;
166 struct pxa3xx_nand_flash *flash_info;
167
168 struct clk *clk;
169 void __iomem *mmio_base;
170
171 unsigned int buf_start;
172 unsigned int buf_count;
173
174 /* DMA information */
175 int drcmr_dat;
176 int drcmr_cmd;
177
178 unsigned char *data_buff;
179 dma_addr_t data_buff_phys;
180 size_t data_buff_size;
181 int data_dma_ch;
182 struct pxa_dma_desc *data_desc;
183 dma_addr_t data_desc_addr;
184
185 uint32_t reg_ndcr;
186
187 /* saved column/page_addr during CMD_SEQIN */
188 int seqin_column;
189 int seqin_page_addr;
190
191 /* relate to the command */
192 unsigned int state;
193
194 int use_ecc; /* use HW ECC ? */
195 int use_dma; /* use DMA ? */
196
197 size_t data_size; /* data size in FIFO */
198 int retcode;
199 struct completion cmd_complete;
200
201 /* generated NDCBx register values */
202 uint32_t ndcb0;
203 uint32_t ndcb1;
204 uint32_t ndcb2;
205};
206
207static int use_dma = 1;
208module_param(use_dma, bool, 0444);
209MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
210
211static struct pxa3xx_nand_cmdset smallpage_cmdset = {
212 .read1 = 0x0000,
213 .read2 = 0x0050,
214 .program = 0x1080,
215 .read_status = 0x0070,
216 .read_id = 0x0090,
217 .erase = 0xD060,
218 .reset = 0x00FF,
219 .lock = 0x002A,
220 .unlock = 0x2423,
221 .lock_status = 0x007A,
222};
223
224static struct pxa3xx_nand_cmdset largepage_cmdset = {
225 .read1 = 0x3000,
226 .read2 = 0x0050,
227 .program = 0x1080,
228 .read_status = 0x0070,
229 .read_id = 0x0090,
230 .erase = 0xD060,
231 .reset = 0x00FF,
232 .lock = 0x002A,
233 .unlock = 0x2423,
234 .lock_status = 0x007A,
235};
236
237static struct pxa3xx_nand_timing samsung512MbX16_timing = {
238 .tCH = 10,
239 .tCS = 0,
240 .tWH = 20,
241 .tWP = 40,
242 .tRH = 30,
243 .tRP = 40,
244 .tR = 11123,
245 .tWHR = 110,
246 .tAR = 10,
247};
248
249static struct pxa3xx_nand_flash samsung512MbX16 = {
250 .timing = &samsung512MbX16_timing,
251 .cmdset = &smallpage_cmdset,
252 .page_per_block = 32,
253 .page_size = 512,
254 .flash_width = 16,
255 .dfc_width = 16,
256 .num_blocks = 4096,
257 .chip_id = 0x46ec,
258};
259
260static struct pxa3xx_nand_timing micron_timing = {
261 .tCH = 10,
262 .tCS = 25,
263 .tWH = 15,
264 .tWP = 25,
265 .tRH = 15,
266 .tRP = 25,
267 .tR = 25000,
268 .tWHR = 60,
269 .tAR = 10,
270};
271
272static struct pxa3xx_nand_flash micron1GbX8 = {
273 .timing = &micron_timing,
274 .cmdset = &largepage_cmdset,
275 .page_per_block = 64,
276 .page_size = 2048,
277 .flash_width = 8,
278 .dfc_width = 8,
279 .num_blocks = 1024,
280 .chip_id = 0xa12c,
281};
282
283static struct pxa3xx_nand_flash micron1GbX16 = {
284 .timing = &micron_timing,
285 .cmdset = &largepage_cmdset,
286 .page_per_block = 64,
287 .page_size = 2048,
288 .flash_width = 16,
289 .dfc_width = 16,
290 .num_blocks = 1024,
291 .chip_id = 0xb12c,
292};
293
294static struct pxa3xx_nand_flash *builtin_flash_types[] = {
295 &samsung512MbX16,
296 &micron1GbX8,
297 &micron1GbX16,
298};
299
300#define NDTR0_tCH(c) (min((c), 7) << 19)
301#define NDTR0_tCS(c) (min((c), 7) << 16)
302#define NDTR0_tWH(c) (min((c), 7) << 11)
303#define NDTR0_tWP(c) (min((c), 7) << 8)
304#define NDTR0_tRH(c) (min((c), 7) << 3)
305#define NDTR0_tRP(c) (min((c), 7) << 0)
306
307#define NDTR1_tR(c) (min((c), 65535) << 16)
308#define NDTR1_tWHR(c) (min((c), 15) << 4)
309#define NDTR1_tAR(c) (min((c), 15) << 0)
310
311/* convert nano-seconds to nand flash controller clock cycles */
312#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) + 1)
313
314static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
315 struct pxa3xx_nand_timing *t)
316{
317 unsigned long nand_clk = clk_get_rate(info->clk);
318 uint32_t ndtr0, ndtr1;
319
320 ndtr0 = NDTR0_tCH(ns2cycle(t->tCH, nand_clk)) |
321 NDTR0_tCS(ns2cycle(t->tCS, nand_clk)) |
322 NDTR0_tWH(ns2cycle(t->tWH, nand_clk)) |
323 NDTR0_tWP(ns2cycle(t->tWP, nand_clk)) |
324 NDTR0_tRH(ns2cycle(t->tRH, nand_clk)) |
325 NDTR0_tRP(ns2cycle(t->tRP, nand_clk));
326
327 ndtr1 = NDTR1_tR(ns2cycle(t->tR, nand_clk)) |
328 NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) |
329 NDTR1_tAR(ns2cycle(t->tAR, nand_clk));
330
331 nand_writel(info, NDTR0CS0, ndtr0);
332 nand_writel(info, NDTR1CS0, ndtr1);
333}
334
335#define WAIT_EVENT_TIMEOUT 10
336
337static int wait_for_event(struct pxa3xx_nand_info *info, uint32_t event)
338{
339 int timeout = WAIT_EVENT_TIMEOUT;
340 uint32_t ndsr;
341
342 while (timeout--) {
343 ndsr = nand_readl(info, NDSR) & NDSR_MASK;
344 if (ndsr & event) {
345 nand_writel(info, NDSR, ndsr);
346 return 0;
347 }
348 udelay(10);
349 }
350
351 return -ETIMEDOUT;
352}
353
354static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info,
355 uint16_t cmd, int column, int page_addr)
356{
357 struct pxa3xx_nand_flash *f = info->flash_info;
358 struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
359
360 /* calculate data size */
361 switch (f->page_size) {
362 case 2048:
363 info->data_size = (info->use_ecc) ? 2088 : 2112;
364 break;
365 case 512:
366 info->data_size = (info->use_ecc) ? 520 : 528;
367 break;
368 default:
369 return -EINVAL;
370 }
371
372 /* generate values for NDCBx registers */
373 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
374 info->ndcb1 = 0;
375 info->ndcb2 = 0;
376 info->ndcb0 |= NDCB0_ADDR_CYC(f->row_addr_cycles + f->col_addr_cycles);
377
378 if (f->col_addr_cycles == 2) {
379 /* large block, 2 cycles for column address
380 * row address starts from 3rd cycle
381 */
382 info->ndcb1 |= (page_addr << 16) | (column & 0xffff);
383 if (f->row_addr_cycles == 3)
384 info->ndcb2 = (page_addr >> 16) & 0xff;
385 } else
386 /* small block, 1 cycles for column address
387 * row address starts from 2nd cycle
388 */
389 info->ndcb1 = (page_addr << 8) | (column & 0xff);
390
391 if (cmd == cmdset->program)
392 info->ndcb0 |= NDCB0_CMD_TYPE(1) | NDCB0_AUTO_RS;
393
394 return 0;
395}
396
397static int prepare_erase_cmd(struct pxa3xx_nand_info *info,
398 uint16_t cmd, int page_addr)
399{
400 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
401 info->ndcb0 |= NDCB0_CMD_TYPE(2) | NDCB0_AUTO_RS | NDCB0_ADDR_CYC(3);
402 info->ndcb1 = page_addr;
403 info->ndcb2 = 0;
404 return 0;
405}
406
407static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd)
408{
409 struct pxa3xx_nand_cmdset *cmdset = info->flash_info->cmdset;
410
411 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
412 info->ndcb1 = 0;
413 info->ndcb2 = 0;
414
415 if (cmd == cmdset->read_id) {
416 info->ndcb0 |= NDCB0_CMD_TYPE(3);
417 info->data_size = 8;
418 } else if (cmd == cmdset->read_status) {
419 info->ndcb0 |= NDCB0_CMD_TYPE(4);
420 info->data_size = 8;
421 } else if (cmd == cmdset->reset || cmd == cmdset->lock ||
422 cmd == cmdset->unlock) {
423 info->ndcb0 |= NDCB0_CMD_TYPE(5);
424 } else
425 return -EINVAL;
426
427 return 0;
428}
429
430static void enable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)
431{
432 uint32_t ndcr;
433
434 ndcr = nand_readl(info, NDCR);
435 nand_writel(info, NDCR, ndcr & ~int_mask);
436}
437
438static void disable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)
439{
440 uint32_t ndcr;
441
442 ndcr = nand_readl(info, NDCR);
443 nand_writel(info, NDCR, ndcr | int_mask);
444}
445
446/* NOTE: it is a must to set ND_RUN firstly, then write command buffer
447 * otherwise, it does not work
448 */
449static int write_cmd(struct pxa3xx_nand_info *info)
450{
451 uint32_t ndcr;
452
453 /* clear status bits and run */
454 nand_writel(info, NDSR, NDSR_MASK);
455
456 ndcr = info->reg_ndcr;
457
458 ndcr |= info->use_ecc ? NDCR_ECC_EN : 0;
459 ndcr |= info->use_dma ? NDCR_DMA_EN : 0;
460 ndcr |= NDCR_ND_RUN;
461
462 nand_writel(info, NDCR, ndcr);
463
464 if (wait_for_event(info, NDSR_WRCMDREQ)) {
465 printk(KERN_ERR "timed out writing command\n");
466 return -ETIMEDOUT;
467 }
468
469 nand_writel(info, NDCB0, info->ndcb0);
470 nand_writel(info, NDCB0, info->ndcb1);
471 nand_writel(info, NDCB0, info->ndcb2);
472 return 0;
473}
474
475static int handle_data_pio(struct pxa3xx_nand_info *info)
476{
477 int ret, timeout = CHIP_DELAY_TIMEOUT;
478
479 switch (info->state) {
480 case STATE_PIO_WRITING:
481 __raw_writesl(info->mmio_base + NDDB, info->data_buff,
482 info->data_size << 2);
483
484 enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
485
486 ret = wait_for_completion_timeout(&info->cmd_complete, timeout);
487 if (!ret) {
488 printk(KERN_ERR "program command time out\n");
489 return -1;
490 }
491 break;
492 case STATE_PIO_READING:
493 __raw_readsl(info->mmio_base + NDDB, info->data_buff,
494 info->data_size << 2);
495 break;
496 default:
497 printk(KERN_ERR "%s: invalid state %d\n", __func__,
498 info->state);
499 return -EINVAL;
500 }
501
502 info->state = STATE_READY;
503 return 0;
504}
505
506static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out)
507{
508 struct pxa_dma_desc *desc = info->data_desc;
509 int dma_len = ALIGN(info->data_size, 32);
510
511 desc->ddadr = DDADR_STOP;
512 desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len;
513
514 if (dir_out) {
515 desc->dsadr = info->data_buff_phys;
516 desc->dtadr = NDDB_DMA_ADDR;
517 desc->dcmd |= DCMD_INCSRCADDR | DCMD_FLOWTRG;
518 } else {
519 desc->dtadr = info->data_buff_phys;
520 desc->dsadr = NDDB_DMA_ADDR;
521 desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC;
522 }
523
524 DRCMR(info->drcmr_dat) = DRCMR_MAPVLD | info->data_dma_ch;
525 DDADR(info->data_dma_ch) = info->data_desc_addr;
526 DCSR(info->data_dma_ch) |= DCSR_RUN;
527}
528
529static void pxa3xx_nand_data_dma_irq(int channel, void *data)
530{
531 struct pxa3xx_nand_info *info = data;
532 uint32_t dcsr;
533
534 dcsr = DCSR(channel);
535 DCSR(channel) = dcsr;
536
537 if (dcsr & DCSR_BUSERR) {
538 info->retcode = ERR_DMABUSERR;
539 complete(&info->cmd_complete);
540 }
541
542 if (info->state == STATE_DMA_WRITING) {
543 info->state = STATE_DMA_DONE;
544 enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
545 } else {
546 info->state = STATE_READY;
547 complete(&info->cmd_complete);
548 }
549}
550
551static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)
552{
553 struct pxa3xx_nand_info *info = devid;
554 unsigned int status;
555
556 status = nand_readl(info, NDSR);
557
558 if (status & (NDSR_RDDREQ | NDSR_DBERR)) {
559 if (status & NDSR_DBERR)
560 info->retcode = ERR_DBERR;
561
562 disable_int(info, NDSR_RDDREQ | NDSR_DBERR);
563
564 if (info->use_dma) {
565 info->state = STATE_DMA_READING;
566 start_data_dma(info, 0);
567 } else {
568 info->state = STATE_PIO_READING;
569 complete(&info->cmd_complete);
570 }
571 } else if (status & NDSR_WRDREQ) {
572 disable_int(info, NDSR_WRDREQ);
573 if (info->use_dma) {
574 info->state = STATE_DMA_WRITING;
575 start_data_dma(info, 1);
576 } else {
577 info->state = STATE_PIO_WRITING;
578 complete(&info->cmd_complete);
579 }
580 } else if (status & (NDSR_CS0_BBD | NDSR_CS0_CMDD)) {
581 if (status & NDSR_CS0_BBD)
582 info->retcode = ERR_BBERR;
583
584 disable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
585 info->state = STATE_READY;
586 complete(&info->cmd_complete);
587 }
588 nand_writel(info, NDSR, status);
589 return IRQ_HANDLED;
590}
591
592static int pxa3xx_nand_do_cmd(struct pxa3xx_nand_info *info, uint32_t event)
593{
594 uint32_t ndcr;
595 int ret, timeout = CHIP_DELAY_TIMEOUT;
596
597 if (write_cmd(info)) {
598 info->retcode = ERR_SENDCMD;
599 goto fail_stop;
600 }
601
602 info->state = STATE_CMD_HANDLE;
603
604 enable_int(info, event);
605
606 ret = wait_for_completion_timeout(&info->cmd_complete, timeout);
607 if (!ret) {
608 printk(KERN_ERR "command execution timed out\n");
609 info->retcode = ERR_SENDCMD;
610 goto fail_stop;
611 }
612
613 if (info->use_dma == 0 && info->data_size > 0)
614 if (handle_data_pio(info))
615 goto fail_stop;
616
617 return 0;
618
619fail_stop:
620 ndcr = nand_readl(info, NDCR);
621 nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
622 udelay(10);
623 return -ETIMEDOUT;
624}
625
626static int pxa3xx_nand_dev_ready(struct mtd_info *mtd)
627{
628 struct pxa3xx_nand_info *info = mtd->priv;
629 return (nand_readl(info, NDSR) & NDSR_RDY) ? 1 : 0;
630}
631
632static inline int is_buf_blank(uint8_t *buf, size_t len)
633{
634 for (; len > 0; len--)
635 if (*buf++ != 0xff)
636 return 0;
637 return 1;
638}
639
640static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
641 int column, int page_addr)
642{
643 struct pxa3xx_nand_info *info = mtd->priv;
644 struct pxa3xx_nand_flash *flash_info = info->flash_info;
645 struct pxa3xx_nand_cmdset *cmdset = flash_info->cmdset;
646 int ret;
647
648 info->use_dma = (use_dma) ? 1 : 0;
649 info->use_ecc = 0;
650 info->data_size = 0;
651 info->state = STATE_READY;
652
653 init_completion(&info->cmd_complete);
654
655 switch (command) {
656 case NAND_CMD_READOOB:
657 /* disable HW ECC to get all the OOB data */
658 info->buf_count = mtd->writesize + mtd->oobsize;
659 info->buf_start = mtd->writesize + column;
660
661 if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr))
662 break;
663
664 pxa3xx_nand_do_cmd(info, NDSR_RDDREQ | NDSR_DBERR);
665
666 /* We only are OOB, so if the data has error, does not matter */
667 if (info->retcode == ERR_DBERR)
668 info->retcode = ERR_NONE;
669 break;
670
671 case NAND_CMD_READ0:
672 info->use_ecc = 1;
673 info->retcode = ERR_NONE;
674 info->buf_start = column;
675 info->buf_count = mtd->writesize + mtd->oobsize;
676 memset(info->data_buff, 0xFF, info->buf_count);
677
678 if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr))
679 break;
680
681 pxa3xx_nand_do_cmd(info, NDSR_RDDREQ | NDSR_DBERR);
682
683 if (info->retcode == ERR_DBERR) {
684 /* for blank page (all 0xff), HW will calculate its ECC as
685 * 0, which is different from the ECC information within
686 * OOB, ignore such double bit errors
687 */
688 if (is_buf_blank(info->data_buff, mtd->writesize))
689 info->retcode = ERR_NONE;
690 }
691 break;
692 case NAND_CMD_SEQIN:
693 info->buf_start = column;
694 info->buf_count = mtd->writesize + mtd->oobsize;
695 memset(info->data_buff, 0xff, info->buf_count);
696
697 /* save column/page_addr for next CMD_PAGEPROG */
698 info->seqin_column = column;
699 info->seqin_page_addr = page_addr;
700 break;
701 case NAND_CMD_PAGEPROG:
702 info->use_ecc = (info->seqin_column >= mtd->writesize) ? 0 : 1;
703
704 if (prepare_read_prog_cmd(info, cmdset->program,
705 info->seqin_column, info->seqin_page_addr))
706 break;
707
708 pxa3xx_nand_do_cmd(info, NDSR_WRDREQ);
709 break;
710 case NAND_CMD_ERASE1:
711 if (prepare_erase_cmd(info, cmdset->erase, page_addr))
712 break;
713
714 pxa3xx_nand_do_cmd(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
715 break;
716 case NAND_CMD_ERASE2:
717 break;
718 case NAND_CMD_READID:
719 case NAND_CMD_STATUS:
720 info->use_dma = 0; /* force PIO read */
721 info->buf_start = 0;
722 info->buf_count = (command == NAND_CMD_READID) ?
723 flash_info->read_id_bytes : 1;
724
725 if (prepare_other_cmd(info, (command == NAND_CMD_READID) ?
726 cmdset->read_id : cmdset->read_status))
727 break;
728
729 pxa3xx_nand_do_cmd(info, NDSR_RDDREQ);
730 break;
731 case NAND_CMD_RESET:
732 if (prepare_other_cmd(info, cmdset->reset))
733 break;
734
735 ret = pxa3xx_nand_do_cmd(info, NDSR_CS0_CMDD);
736 if (ret == 0) {
737 int timeout = 2;
738 uint32_t ndcr;
739
740 while (timeout--) {
741 if (nand_readl(info, NDSR) & NDSR_RDY)
742 break;
743 msleep(10);
744 }
745
746 ndcr = nand_readl(info, NDCR);
747 nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
748 }
749 break;
750 default:
751 printk(KERN_ERR "non-supported command.\n");
752 break;
753 }
754
755 if (info->retcode == ERR_DBERR) {
756 printk(KERN_ERR "double bit error @ page %08x\n", page_addr);
757 info->retcode = ERR_NONE;
758 }
759}
760
761static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
762{
763 struct pxa3xx_nand_info *info = mtd->priv;
764 char retval = 0xFF;
765
766 if (info->buf_start < info->buf_count)
767 /* Has just send a new command? */
768 retval = info->data_buff[info->buf_start++];
769
770 return retval;
771}
772
773static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
774{
775 struct pxa3xx_nand_info *info = mtd->priv;
776 u16 retval = 0xFFFF;
777
778 if (!(info->buf_start & 0x01) && info->buf_start < info->buf_count) {
779 retval = *((u16 *)(info->data_buff+info->buf_start));
780 info->buf_start += 2;
781 }
782 return retval;
783}
784
785static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
786{
787 struct pxa3xx_nand_info *info = mtd->priv;
788 int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
789
790 memcpy(buf, info->data_buff + info->buf_start, real_len);
791 info->buf_start += real_len;
792}
793
794static void pxa3xx_nand_write_buf(struct mtd_info *mtd,
795 const uint8_t *buf, int len)
796{
797 struct pxa3xx_nand_info *info = mtd->priv;
798 int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
799
800 memcpy(info->data_buff + info->buf_start, buf, real_len);
801 info->buf_start += real_len;
802}
803
804static int pxa3xx_nand_verify_buf(struct mtd_info *mtd,
805 const uint8_t *buf, int len)
806{
807 return 0;
808}
809
810static void pxa3xx_nand_select_chip(struct mtd_info *mtd, int chip)
811{
812 return;
813}
814
815static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
816{
817 struct pxa3xx_nand_info *info = mtd->priv;
818
819 /* pxa3xx_nand_send_command has waited for command complete */
820 if (this->state == FL_WRITING || this->state == FL_ERASING) {
821 if (info->retcode == ERR_NONE)
822 return 0;
823 else {
824 /*
825 * any error make it return 0x01 which will tell
826 * the caller the erase and write fail
827 */
828 return 0x01;
829 }
830 }
831
832 return 0;
833}
834
835static void pxa3xx_nand_ecc_hwctl(struct mtd_info *mtd, int mode)
836{
837 return;
838}
839
840static int pxa3xx_nand_ecc_calculate(struct mtd_info *mtd,
841 const uint8_t *dat, uint8_t *ecc_code)
842{
843 return 0;
844}
845
846static int pxa3xx_nand_ecc_correct(struct mtd_info *mtd,
847 uint8_t *dat, uint8_t *read_ecc, uint8_t *calc_ecc)
848{
849 struct pxa3xx_nand_info *info = mtd->priv;
850 /*
851 * Any error include ERR_SEND_CMD, ERR_DBERR, ERR_BUSERR, we
852 * consider it as a ecc error which will tell the caller the
853 * read fail We have distinguish all the errors, but the
854 * nand_read_ecc only check this function return value
855 */
856 if (info->retcode != ERR_NONE)
857 return -1;
858
859 return 0;
860}
861
862static int __readid(struct pxa3xx_nand_info *info, uint32_t *id)
863{
864 struct pxa3xx_nand_flash *f = info->flash_info;
865 struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
866 uint32_t ndcr;
867 uint8_t id_buff[8];
868
869 if (prepare_other_cmd(info, cmdset->read_id)) {
870 printk(KERN_ERR "failed to prepare command\n");
871 return -EINVAL;
872 }
873
874 /* Send command */
875 if (write_cmd(info))
876 goto fail_timeout;
877
878 /* Wait for CMDDM(command done successfully) */
879 if (wait_for_event(info, NDSR_RDDREQ))
880 goto fail_timeout;
881
882 __raw_readsl(info->mmio_base + NDDB, id_buff, 2);
883 *id = id_buff[0] | (id_buff[1] << 8);
884 return 0;
885
886fail_timeout:
887 ndcr = nand_readl(info, NDCR);
888 nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
889 udelay(10);
890 return -ETIMEDOUT;
891}
892
893static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
894 struct pxa3xx_nand_flash *f)
895{
896 struct platform_device *pdev = info->pdev;
897 struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data;
898 uint32_t ndcr = 0x00000FFF; /* disable all interrupts */
899
900 if (f->page_size != 2048 && f->page_size != 512)
901 return -EINVAL;
902
903 if (f->flash_width != 16 && f->flash_width != 8)
904 return -EINVAL;
905
906 /* calculate flash information */
907 f->oob_size = (f->page_size == 2048) ? 64 : 16;
908 f->read_id_bytes = (f->page_size == 2048) ? 4 : 2;
909
910 /* calculate addressing information */
911 f->col_addr_cycles = (f->page_size == 2048) ? 2 : 1;
912
913 if (f->num_blocks * f->page_per_block > 65536)
914 f->row_addr_cycles = 3;
915 else
916 f->row_addr_cycles = 2;
917
918 ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
919 ndcr |= (f->col_addr_cycles == 2) ? NDCR_RA_START : 0;
920 ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0;
921 ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0;
922 ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0;
923 ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0;
924
925 ndcr |= NDCR_RD_ID_CNT(f->read_id_bytes);
926 ndcr |= NDCR_SPARE_EN; /* enable spare by default */
927
928 info->reg_ndcr = ndcr;
929
930 pxa3xx_nand_set_timing(info, f->timing);
931 info->flash_info = f;
932 return 0;
933}
934
935static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info)
936{
937 struct pxa3xx_nand_flash *f;
938 uint32_t id;
939 int i;
940
941 for (i = 0; i < ARRAY_SIZE(builtin_flash_types); i++) {
942
943 f = builtin_flash_types[i];
944
945 if (pxa3xx_nand_config_flash(info, f))
946 continue;
947
948 if (__readid(info, &id))
949 continue;
950
951 if (id == f->chip_id)
952 return 0;
953 }
954
955 return -ENODEV;
956}
957
958/* the maximum possible buffer size for large page with OOB data
959 * is: 2048 + 64 = 2112 bytes, allocate a page here for both the
960 * data buffer and the DMA descriptor
961 */
962#define MAX_BUFF_SIZE PAGE_SIZE
963
964static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
965{
966 struct platform_device *pdev = info->pdev;
967 int data_desc_offset = MAX_BUFF_SIZE - sizeof(struct pxa_dma_desc);
968
969 if (use_dma == 0) {
970 info->data_buff = kmalloc(MAX_BUFF_SIZE, GFP_KERNEL);
971 if (info->data_buff == NULL)
972 return -ENOMEM;
973 return 0;
974 }
975
976 info->data_buff = dma_alloc_coherent(&pdev->dev, MAX_BUFF_SIZE,
977 &info->data_buff_phys, GFP_KERNEL);
978 if (info->data_buff == NULL) {
979 dev_err(&pdev->dev, "failed to allocate dma buffer\n");
980 return -ENOMEM;
981 }
982
983 info->data_buff_size = MAX_BUFF_SIZE;
984 info->data_desc = (void *)info->data_buff + data_desc_offset;
985 info->data_desc_addr = info->data_buff_phys + data_desc_offset;
986
987 info->data_dma_ch = pxa_request_dma("nand-data", DMA_PRIO_LOW,
988 pxa3xx_nand_data_dma_irq, info);
989 if (info->data_dma_ch < 0) {
990 dev_err(&pdev->dev, "failed to request data dma\n");
991 dma_free_coherent(&pdev->dev, info->data_buff_size,
992 info->data_buff, info->data_buff_phys);
993 return info->data_dma_ch;
994 }
995
996 return 0;
997}
998
999static struct nand_ecclayout hw_smallpage_ecclayout = {
1000 .eccbytes = 6,
1001 .eccpos = {8, 9, 10, 11, 12, 13 },
1002 .oobfree = { {2, 6} }
1003};
1004
1005static struct nand_ecclayout hw_largepage_ecclayout = {
1006 .eccbytes = 24,
1007 .eccpos = {
1008 40, 41, 42, 43, 44, 45, 46, 47,
1009 48, 49, 50, 51, 52, 53, 54, 55,
1010 56, 57, 58, 59, 60, 61, 62, 63},
1011 .oobfree = { {2, 38} }
1012};
1013
1014static void pxa3xx_nand_init_mtd(struct mtd_info *mtd,
1015 struct pxa3xx_nand_info *info)
1016{
1017 struct pxa3xx_nand_flash *f = info->flash_info;
1018 struct nand_chip *this = &info->nand_chip;
1019
1020 this->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16: 0;
1021
1022 this->waitfunc = pxa3xx_nand_waitfunc;
1023 this->select_chip = pxa3xx_nand_select_chip;
1024 this->dev_ready = pxa3xx_nand_dev_ready;
1025 this->cmdfunc = pxa3xx_nand_cmdfunc;
1026 this->read_word = pxa3xx_nand_read_word;
1027 this->read_byte = pxa3xx_nand_read_byte;
1028 this->read_buf = pxa3xx_nand_read_buf;
1029 this->write_buf = pxa3xx_nand_write_buf;
1030 this->verify_buf = pxa3xx_nand_verify_buf;
1031
1032 this->ecc.mode = NAND_ECC_HW;
1033 this->ecc.hwctl = pxa3xx_nand_ecc_hwctl;
1034 this->ecc.calculate = pxa3xx_nand_ecc_calculate;
1035 this->ecc.correct = pxa3xx_nand_ecc_correct;
1036 this->ecc.size = f->page_size;
1037
1038 if (f->page_size == 2048)
1039 this->ecc.layout = &hw_largepage_ecclayout;
1040 else
1041 this->ecc.layout = &hw_smallpage_ecclayout;
1042
1043 this->chip_delay = 25;
1044}
1045
1046static int pxa3xx_nand_probe(struct platform_device *pdev)
1047{
1048 struct pxa3xx_nand_platform_data *pdata;
1049 struct pxa3xx_nand_info *info;
1050 struct nand_chip *this;
1051 struct mtd_info *mtd;
1052 struct resource *r;
1053 int ret = 0, irq;
1054
1055 pdata = pdev->dev.platform_data;
1056
1057 if (!pdata) {
1058 dev_err(&pdev->dev, "no platform data defined\n");
1059 return -ENODEV;
1060 }
1061
1062 mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct pxa3xx_nand_info),
1063 GFP_KERNEL);
1064 if (!mtd) {
1065 dev_err(&pdev->dev, "failed to allocate memory\n");
1066 return -ENOMEM;
1067 }
1068
1069 info = (struct pxa3xx_nand_info *)(&mtd[1]);
1070 info->pdev = pdev;
1071
1072 this = &info->nand_chip;
1073 mtd->priv = info;
1074
1075 info->clk = clk_get(&pdev->dev, "NANDCLK");
1076 if (IS_ERR(info->clk)) {
1077 dev_err(&pdev->dev, "failed to get nand clock\n");
1078 ret = PTR_ERR(info->clk);
1079 goto fail_free_mtd;
1080 }
1081 clk_enable(info->clk);
1082
1083 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1084 if (r == NULL) {
1085 dev_err(&pdev->dev, "no resource defined for data DMA\n");
1086 ret = -ENXIO;
1087 goto fail_put_clk;
1088 }
1089 info->drcmr_dat = r->start;
1090
1091 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1092 if (r == NULL) {
1093 dev_err(&pdev->dev, "no resource defined for command DMA\n");
1094 ret = -ENXIO;
1095 goto fail_put_clk;
1096 }
1097 info->drcmr_cmd = r->start;
1098
1099 irq = platform_get_irq(pdev, 0);
1100 if (irq < 0) {
1101 dev_err(&pdev->dev, "no IRQ resource defined\n");
1102 ret = -ENXIO;
1103 goto fail_put_clk;
1104 }
1105
1106 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1107 if (r == NULL) {
1108 dev_err(&pdev->dev, "no IO memory resource defined\n");
1109 ret = -ENODEV;
1110 goto fail_put_clk;
1111 }
1112
1113 r = request_mem_region(r->start, r->end - r->start + 1, pdev->name);
1114 if (r == NULL) {
1115 dev_err(&pdev->dev, "failed to request memory resource\n");
1116 ret = -EBUSY;
1117 goto fail_put_clk;
1118 }
1119
1120 info->mmio_base = ioremap(r->start, r->end - r->start + 1);
1121 if (info->mmio_base == NULL) {
1122 dev_err(&pdev->dev, "ioremap() failed\n");
1123 ret = -ENODEV;
1124 goto fail_free_res;
1125 }
1126
1127 ret = pxa3xx_nand_init_buff(info);
1128 if (ret)
1129 goto fail_free_io;
1130
1131 ret = request_irq(IRQ_NAND, pxa3xx_nand_irq, IRQF_DISABLED,
1132 pdev->name, info);
1133 if (ret < 0) {
1134 dev_err(&pdev->dev, "failed to request IRQ\n");
1135 goto fail_free_buf;
1136 }
1137
1138 ret = pxa3xx_nand_detect_flash(info);
1139 if (ret) {
1140 dev_err(&pdev->dev, "failed to detect flash\n");
1141 ret = -ENODEV;
1142 goto fail_free_irq;
1143 }
1144
1145 pxa3xx_nand_init_mtd(mtd, info);
1146
1147 platform_set_drvdata(pdev, mtd);
1148
1149 if (nand_scan(mtd, 1)) {
1150 dev_err(&pdev->dev, "failed to scan nand\n");
1151 ret = -ENXIO;
1152 goto fail_free_irq;
1153 }
1154
1155 return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
1156
1157fail_free_irq:
1158 free_irq(IRQ_NAND, info);
1159fail_free_buf:
1160 if (use_dma) {
1161 pxa_free_dma(info->data_dma_ch);
1162 dma_free_coherent(&pdev->dev, info->data_buff_size,
1163 info->data_buff, info->data_buff_phys);
1164 } else
1165 kfree(info->data_buff);
1166fail_free_io:
1167 iounmap(info->mmio_base);
1168fail_free_res:
1169 release_mem_region(r->start, r->end - r->start + 1);
1170fail_put_clk:
1171 clk_disable(info->clk);
1172 clk_put(info->clk);
1173fail_free_mtd:
1174 kfree(mtd);
1175 return ret;
1176}
1177
1178static int pxa3xx_nand_remove(struct platform_device *pdev)
1179{
1180 struct mtd_info *mtd = platform_get_drvdata(pdev);
1181 struct pxa3xx_nand_info *info = mtd->priv;
1182
1183 platform_set_drvdata(pdev, NULL);
1184
1185 del_mtd_device(mtd);
1186 del_mtd_partitions(mtd);
1187 free_irq(IRQ_NAND, info);
1188 if (use_dma) {
1189 pxa_free_dma(info->data_dma_ch);
1190 dma_free_writecombine(&pdev->dev, info->data_buff_size,
1191 info->data_buff, info->data_buff_phys);
1192 } else
1193 kfree(info->data_buff);
1194 kfree(mtd);
1195 return 0;
1196}
1197
1198#ifdef CONFIG_PM
1199static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state)
1200{
1201 struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev);
1202 struct pxa3xx_nand_info *info = mtd->priv;
1203
1204 if (info->state != STATE_READY) {
1205 dev_err(&pdev->dev, "driver busy, state = %d\n", info->state);
1206 return -EAGAIN;
1207 }
1208
1209 return 0;
1210}
1211
1212static int pxa3xx_nand_resume(struct platform_device *pdev)
1213{
1214 struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev);
1215 struct pxa3xx_nand_info *info = mtd->priv;
1216
1217 clk_enable(info->clk);
1218
1219 return pxa3xx_nand_config_flash(info);
1220}
1221#else
1222#define pxa3xx_nand_suspend NULL
1223#define pxa3xx_nand_resume NULL
1224#endif
1225
1226static struct platform_driver pxa3xx_nand_driver = {
1227 .driver = {
1228 .name = "pxa3xx-nand",
1229 },
1230 .probe = pxa3xx_nand_probe,
1231 .remove = pxa3xx_nand_remove,
1232 .suspend = pxa3xx_nand_suspend,
1233 .resume = pxa3xx_nand_resume,
1234};
1235
1236static int __init pxa3xx_nand_init(void)
1237{
1238 return platform_driver_register(&pxa3xx_nand_driver);
1239}
1240module_init(pxa3xx_nand_init);
1241
1242static void __exit pxa3xx_nand_exit(void)
1243{
1244 platform_driver_unregister(&pxa3xx_nand_driver);
1245}
1246module_exit(pxa3xx_nand_exit);
1247
1248MODULE_LICENSE("GPL");
1249MODULE_DESCRIPTION("PXA3xx NAND controller driver");
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index 0f6ac250f434..26f88215bc47 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -478,6 +478,7 @@ static int __init rtc_from4_init(void)
478 struct nand_chip *this; 478 struct nand_chip *this;
479 unsigned short bcr1, bcr2, wcr2; 479 unsigned short bcr1, bcr2, wcr2;
480 int i; 480 int i;
481 int ret;
481 482
482 /* Allocate memory for MTD device structure and private data */ 483 /* Allocate memory for MTD device structure and private data */
483 rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); 484 rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
@@ -537,6 +538,22 @@ static int __init rtc_from4_init(void)
537 this->ecc.hwctl = rtc_from4_enable_hwecc; 538 this->ecc.hwctl = rtc_from4_enable_hwecc;
538 this->ecc.calculate = rtc_from4_calculate_ecc; 539 this->ecc.calculate = rtc_from4_calculate_ecc;
539 this->ecc.correct = rtc_from4_correct_data; 540 this->ecc.correct = rtc_from4_correct_data;
541
542 /* We could create the decoder on demand, if memory is a concern.
543 * This way we have it handy, if an error happens
544 *
545 * Symbolsize is 10 (bits)
546 * Primitve polynomial is x^10+x^3+1
547 * first consecutive root is 0
548 * primitve element to generate roots = 1
549 * generator polinomial degree = 6
550 */
551 rs_decoder = init_rs(10, 0x409, 0, 1, 6);
552 if (!rs_decoder) {
553 printk(KERN_ERR "Could not create a RS decoder\n");
554 ret = -ENOMEM;
555 goto err_1;
556 }
540#else 557#else
541 printk(KERN_INFO "rtc_from4_init: using software ECC detection.\n"); 558 printk(KERN_INFO "rtc_from4_init: using software ECC detection.\n");
542 559
@@ -549,8 +566,8 @@ static int __init rtc_from4_init(void)
549 566
550 /* Scan to find existence of the device */ 567 /* Scan to find existence of the device */
551 if (nand_scan(rtc_from4_mtd, RTC_FROM4_MAX_CHIPS)) { 568 if (nand_scan(rtc_from4_mtd, RTC_FROM4_MAX_CHIPS)) {
552 kfree(rtc_from4_mtd); 569 ret = -ENXIO;
553 return -ENXIO; 570 goto err_2;
554 } 571 }
555 572
556 /* Perform 'device recovery' for each chip in case there was a power loss. */ 573 /* Perform 'device recovery' for each chip in case there was a power loss. */
@@ -566,28 +583,19 @@ static int __init rtc_from4_init(void)
566#endif 583#endif
567 584
568 /* Register the partitions */ 585 /* Register the partitions */
569 add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS); 586 ret = add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS);
587 if (ret)
588 goto err_3;
570 589
571#ifdef RTC_FROM4_HWECC
572 /* We could create the decoder on demand, if memory is a concern.
573 * This way we have it handy, if an error happens
574 *
575 * Symbolsize is 10 (bits)
576 * Primitve polynomial is x^10+x^3+1
577 * first consecutive root is 0
578 * primitve element to generate roots = 1
579 * generator polinomial degree = 6
580 */
581 rs_decoder = init_rs(10, 0x409, 0, 1, 6);
582 if (!rs_decoder) {
583 printk(KERN_ERR "Could not create a RS decoder\n");
584 nand_release(rtc_from4_mtd);
585 kfree(rtc_from4_mtd);
586 return -ENOMEM;
587 }
588#endif
589 /* Return happy */ 590 /* Return happy */
590 return 0; 591 return 0;
592err_3:
593 nand_release(rtc_from4_mtd);
594err_2:
595 free_rs(rs_decoder);
596err_1:
597 kfree(rtc_from4_mtd);
598 return ret;
591} 599}
592 600
593module_init(rtc_from4_init); 601module_init(rtc_from4_init);
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 9260ad947524..b34a460ab679 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -119,8 +119,7 @@ struct s3c2410_nand_info {
119 void __iomem *sel_reg; 119 void __iomem *sel_reg;
120 int sel_bit; 120 int sel_bit;
121 int mtd_count; 121 int mtd_count;
122 122 unsigned long save_sel;
123 unsigned long save_nfconf;
124 123
125 enum s3c_cpu_type cpu_type; 124 enum s3c_cpu_type cpu_type;
126}; 125};
@@ -358,6 +357,14 @@ static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
358 if (diff0 == 0 && diff1 == 0 && diff2 == 0) 357 if (diff0 == 0 && diff1 == 0 && diff2 == 0)
359 return 0; /* ECC is ok */ 358 return 0; /* ECC is ok */
360 359
360 /* sometimes people do not think about using the ECC, so check
361 * to see if we have an 0xff,0xff,0xff read ECC and then ignore
362 * the error, on the assumption that this is an un-eccd page.
363 */
364 if (read_ecc[0] == 0xff && read_ecc[1] == 0xff && read_ecc[2] == 0xff
365 && info->platform->ignore_unset_ecc)
366 return 0;
367
361 /* Can we correct this ECC (ie, one row and column change). 368 /* Can we correct this ECC (ie, one row and column change).
362 * Note, this is similar to the 256 error code on smartmedia */ 369 * Note, this is similar to the 256 error code on smartmedia */
363 370
@@ -473,7 +480,7 @@ static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u
473 ecc_code[1] = ecc >> 8; 480 ecc_code[1] = ecc >> 8;
474 ecc_code[2] = ecc >> 16; 481 ecc_code[2] = ecc >> 16;
475 482
476 pr_debug("%s: returning ecc %06lx\n", __func__, ecc); 483 pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff);
477 484
478 return 0; 485 return 0;
479} 486}
@@ -644,9 +651,6 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
644 chip->ecc.calculate = s3c2410_nand_calculate_ecc; 651 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
645 chip->ecc.correct = s3c2410_nand_correct_data; 652 chip->ecc.correct = s3c2410_nand_correct_data;
646 chip->ecc.mode = NAND_ECC_HW; 653 chip->ecc.mode = NAND_ECC_HW;
647 chip->ecc.size = 512;
648 chip->ecc.bytes = 3;
649 chip->ecc.layout = &nand_hw_eccoob;
650 654
651 switch (info->cpu_type) { 655 switch (info->cpu_type) {
652 case TYPE_S3C2410: 656 case TYPE_S3C2410:
@@ -668,6 +672,40 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
668 } else { 672 } else {
669 chip->ecc.mode = NAND_ECC_SOFT; 673 chip->ecc.mode = NAND_ECC_SOFT;
670 } 674 }
675
676 if (set->ecc_layout != NULL)
677 chip->ecc.layout = set->ecc_layout;
678
679 if (set->disable_ecc)
680 chip->ecc.mode = NAND_ECC_NONE;
681}
682
683/* s3c2410_nand_update_chip
684 *
685 * post-probe chip update, to change any items, such as the
686 * layout for large page nand
687 */
688
689static void s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
690 struct s3c2410_nand_mtd *nmtd)
691{
692 struct nand_chip *chip = &nmtd->chip;
693
694 printk("%s: chip %p: %d\n", __func__, chip, chip->page_shift);
695
696 if (hardware_ecc) {
697 /* change the behaviour depending on wether we are using
698 * the large or small page nand device */
699
700 if (chip->page_shift > 10) {
701 chip->ecc.size = 256;
702 chip->ecc.bytes = 3;
703 } else {
704 chip->ecc.size = 512;
705 chip->ecc.bytes = 3;
706 chip->ecc.layout = &nand_hw_eccoob;
707 }
708 }
671} 709}
672 710
673/* s3c2410_nand_probe 711/* s3c2410_nand_probe
@@ -776,9 +814,12 @@ static int s3c24xx_nand_probe(struct platform_device *pdev,
776 814
777 s3c2410_nand_init_chip(info, nmtd, sets); 815 s3c2410_nand_init_chip(info, nmtd, sets);
778 816
779 nmtd->scan_res = nand_scan(&nmtd->mtd, (sets) ? sets->nr_chips : 1); 817 nmtd->scan_res = nand_scan_ident(&nmtd->mtd,
818 (sets) ? sets->nr_chips : 1);
780 819
781 if (nmtd->scan_res == 0) { 820 if (nmtd->scan_res == 0) {
821 s3c2410_nand_update_chip(info, nmtd);
822 nand_scan_tail(&nmtd->mtd);
782 s3c2410_nand_add_partition(info, nmtd, sets); 823 s3c2410_nand_add_partition(info, nmtd, sets);
783 } 824 }
784 825
@@ -810,15 +851,14 @@ static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
810 struct s3c2410_nand_info *info = platform_get_drvdata(dev); 851 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
811 852
812 if (info) { 853 if (info) {
813 info->save_nfconf = readl(info->regs + S3C2410_NFCONF); 854 info->save_sel = readl(info->sel_reg);
814 855
815 /* For the moment, we must ensure nFCE is high during 856 /* For the moment, we must ensure nFCE is high during
816 * the time we are suspended. This really should be 857 * the time we are suspended. This really should be
817 * handled by suspending the MTDs we are using, but 858 * handled by suspending the MTDs we are using, but
818 * that is currently not the case. */ 859 * that is currently not the case. */
819 860
820 writel(info->save_nfconf | info->sel_bit, 861 writel(info->save_sel | info->sel_bit, info->sel_reg);
821 info->regs + S3C2410_NFCONF);
822 862
823 if (!allow_clk_stop(info)) 863 if (!allow_clk_stop(info))
824 clk_disable(info->clk); 864 clk_disable(info->clk);
@@ -830,7 +870,7 @@ static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
830static int s3c24xx_nand_resume(struct platform_device *dev) 870static int s3c24xx_nand_resume(struct platform_device *dev)
831{ 871{
832 struct s3c2410_nand_info *info = platform_get_drvdata(dev); 872 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
833 unsigned long nfconf; 873 unsigned long sel;
834 874
835 if (info) { 875 if (info) {
836 clk_enable(info->clk); 876 clk_enable(info->clk);
@@ -838,10 +878,10 @@ static int s3c24xx_nand_resume(struct platform_device *dev)
838 878
839 /* Restore the state of the nFCE line. */ 879 /* Restore the state of the nFCE line. */
840 880
841 nfconf = readl(info->regs + S3C2410_NFCONF); 881 sel = readl(info->sel_reg);
842 nfconf &= ~info->sel_bit; 882 sel &= ~info->sel_bit;
843 nfconf |= info->save_nfconf & info->sel_bit; 883 sel |= info->save_sel & info->sel_bit;
844 writel(nfconf, info->regs + S3C2410_NFCONF); 884 writel(sel, info->sel_reg);
845 885
846 if (allow_clk_stop(info)) 886 if (allow_clk_stop(info))
847 clk_disable(info->clk); 887 clk_disable(info->clk);
@@ -927,3 +967,6 @@ module_exit(s3c2410_nand_exit);
927MODULE_LICENSE("GPL"); 967MODULE_LICENSE("GPL");
928MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 968MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
929MODULE_DESCRIPTION("S3C24XX MTD NAND driver"); 969MODULE_DESCRIPTION("S3C24XX MTD NAND driver");
970MODULE_ALIAS("platform:s3c2410-nand");
971MODULE_ALIAS("platform:s3c2412-nand");
972MODULE_ALIAS("platform:s3c2440-nand");
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index 0513cbc8834d..345e6eff89ce 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -33,11 +33,6 @@
33 33
34char nftlmountrev[]="$Revision: 1.41 $"; 34char nftlmountrev[]="$Revision: 1.41 $";
35 35
36extern int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
37 size_t *retlen, uint8_t *buf);
38extern int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
39 size_t *retlen, uint8_t *buf);
40
41/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the 36/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the
42 * various device information of the NFTL partition and Bad Unit Table. Update 37 * various device information of the NFTL partition and Bad Unit Table. Update
43 * the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[] 38 * the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[]
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index f86e06934cd8..4f80c2fd89af 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -72,3 +72,5 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
72 return nr_parts; 72 return nr_parts;
73} 73}
74EXPORT_SYMBOL(of_mtd_parse_partitions); 74EXPORT_SYMBOL(of_mtd_parse_partitions);
75
76MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 8d7d21be1541..5d7965f7e9ce 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -329,6 +329,21 @@ static int onenand_wait(struct mtd_info *mtd, int state)
329 printk(KERN_ERR "onenand_wait: controller error = 0x%04x\n", ctrl); 329 printk(KERN_ERR "onenand_wait: controller error = 0x%04x\n", ctrl);
330 if (ctrl & ONENAND_CTRL_LOCK) 330 if (ctrl & ONENAND_CTRL_LOCK)
331 printk(KERN_ERR "onenand_wait: it's locked error.\n"); 331 printk(KERN_ERR "onenand_wait: it's locked error.\n");
332 if (state == FL_READING) {
333 /*
334 * A power loss while writing can result in a page
335 * becoming unreadable. When the device is mounted
336 * again, reading that page gives controller errors.
337 * Upper level software like JFFS2 treat -EIO as fatal,
338 * refusing to mount at all. That means it is necessary
339 * to treat the error as an ECC error to allow recovery.
340 * Note that typically in this case, the eraseblock can
341 * still be erased and rewritten i.e. it has not become
342 * a bad block.
343 */
344 mtd->ecc_stats.failed++;
345 return -EBADMSG;
346 }
332 return -EIO; 347 return -EIO;
333 } 348 }
334 349
@@ -1336,7 +1351,7 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
1336 } 1351 }
1337 1352
1338 /* Reject writes, which are not page aligned */ 1353 /* Reject writes, which are not page aligned */
1339 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) { 1354 if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
1340 printk(KERN_ERR "onenand_panic_write: Attempt to write not page aligned data\n"); 1355 printk(KERN_ERR "onenand_panic_write: Attempt to write not page aligned data\n");
1341 return -EINVAL; 1356 return -EINVAL;
1342 } 1357 }
@@ -1466,7 +1481,7 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1466 } 1481 }
1467 1482
1468 /* Reject writes, which are not page aligned */ 1483 /* Reject writes, which are not page aligned */
1469 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) { 1484 if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
1470 printk(KERN_ERR "onenand_write_ops_nolock: Attempt to write not page aligned data\n"); 1485 printk(KERN_ERR "onenand_write_ops_nolock: Attempt to write not page aligned data\n");
1471 return -EINVAL; 1486 return -EINVAL;
1472 } 1487 }
@@ -2052,7 +2067,7 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
2052 * 2067 *
2053 * Check lock status 2068 * Check lock status
2054 */ 2069 */
2055static void onenand_check_lock_status(struct onenand_chip *this) 2070static int onenand_check_lock_status(struct onenand_chip *this)
2056{ 2071{
2057 unsigned int value, block, status; 2072 unsigned int value, block, status;
2058 unsigned int end; 2073 unsigned int end;
@@ -2070,9 +2085,13 @@ static void onenand_check_lock_status(struct onenand_chip *this)
2070 2085
2071 /* Check lock status */ 2086 /* Check lock status */
2072 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); 2087 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
2073 if (!(status & ONENAND_WP_US)) 2088 if (!(status & ONENAND_WP_US)) {
2074 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status); 2089 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status);
2090 return 0;
2091 }
2075 } 2092 }
2093
2094 return 1;
2076} 2095}
2077 2096
2078/** 2097/**
@@ -2081,9 +2100,11 @@ static void onenand_check_lock_status(struct onenand_chip *this)
2081 * 2100 *
2082 * Unlock all blocks 2101 * Unlock all blocks
2083 */ 2102 */
2084static int onenand_unlock_all(struct mtd_info *mtd) 2103static void onenand_unlock_all(struct mtd_info *mtd)
2085{ 2104{
2086 struct onenand_chip *this = mtd->priv; 2105 struct onenand_chip *this = mtd->priv;
2106 loff_t ofs = 0;
2107 size_t len = this->chipsize;
2087 2108
2088 if (this->options & ONENAND_HAS_UNLOCK_ALL) { 2109 if (this->options & ONENAND_HAS_UNLOCK_ALL) {
2089 /* Set start block address */ 2110 /* Set start block address */
@@ -2099,23 +2120,19 @@ static int onenand_unlock_all(struct mtd_info *mtd)
2099 & ONENAND_CTRL_ONGO) 2120 & ONENAND_CTRL_ONGO)
2100 continue; 2121 continue;
2101 2122
2123 /* Check lock status */
2124 if (onenand_check_lock_status(this))
2125 return;
2126
2102 /* Workaround for all block unlock in DDP */ 2127 /* Workaround for all block unlock in DDP */
2103 if (ONENAND_IS_DDP(this)) { 2128 if (ONENAND_IS_DDP(this)) {
2104 /* 1st block on another chip */ 2129 /* All blocks on another chip */
2105 loff_t ofs = this->chipsize >> 1; 2130 ofs = this->chipsize >> 1;
2106 size_t len = mtd->erasesize; 2131 len = this->chipsize >> 1;
2107
2108 onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK);
2109 } 2132 }
2110
2111 onenand_check_lock_status(this);
2112
2113 return 0;
2114 } 2133 }
2115 2134
2116 onenand_do_lock_cmd(mtd, 0x0, this->chipsize, ONENAND_CMD_UNLOCK); 2135 onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK);
2117
2118 return 0;
2119} 2136}
2120 2137
2121#ifdef CONFIG_MTD_ONENAND_OTP 2138#ifdef CONFIG_MTD_ONENAND_OTP
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index aecdd50a1781..2f53b51c6805 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -17,9 +17,6 @@
17#include <linux/mtd/onenand.h> 17#include <linux/mtd/onenand.h>
18#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
19 19
20extern int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
21 struct mtd_oob_ops *ops);
22
23/** 20/**
24 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 21 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
25 * @param buf the buffer to search 22 * @param buf the buffer to search
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 823fba4e6d2f..c84e45465499 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -823,7 +823,7 @@ static void rfd_ftl_remove_dev(struct mtd_blktrans_dev *dev)
823 kfree(part); 823 kfree(part);
824} 824}
825 825
826struct mtd_blktrans_ops rfd_ftl_tr = { 826static struct mtd_blktrans_ops rfd_ftl_tr = {
827 .name = "rfd", 827 .name = "rfd",
828 .major = RFD_FTL_MAJOR, 828 .major = RFD_FTL_MAJOR,
829 .part_bits = PART_BITS, 829 .part_bits = PART_BITS,
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index b9daf159a4a7..3f063108e95f 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -24,8 +24,13 @@ config MTD_UBI_WL_THRESHOLD
24 erase counter value and the lowest erase counter value of eraseblocks 24 erase counter value and the lowest erase counter value of eraseblocks
25 of UBI devices. When this threshold is exceeded, UBI starts performing 25 of UBI devices. When this threshold is exceeded, UBI starts performing
26 wear leveling by means of moving data from eraseblock with low erase 26 wear leveling by means of moving data from eraseblock with low erase
27 counter to eraseblocks with high erase counter. Leave the default 27 counter to eraseblocks with high erase counter.
28 value if unsure. 28
29 The default value should be OK for SLC NAND flashes, NOR flashes and
30 other flashes which have eraseblock life-cycle 100000 or more.
31 However, in case of MLC NAND flashes which typically have eraseblock
32 life-cycle less then 10000, the threshold should be lessened (e.g.,
33 to 128 or 256, although it does not have to be power of 2).
29 34
30config MTD_UBI_BEB_RESERVE 35config MTD_UBI_BEB_RESERVE
31 int "Percentage of reserved eraseblocks for bad eraseblocks handling" 36 int "Percentage of reserved eraseblocks for bad eraseblocks handling"
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 275960462970..961416ac0616 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -606,8 +606,16 @@ static int io_init(struct ubi_device *ubi)
606 ubi->ro_mode = 1; 606 ubi->ro_mode = 1;
607 } 607 }
608 608
609 dbg_msg("leb_size %d", ubi->leb_size); 609 ubi_msg("physical eraseblock size: %d bytes (%d KiB)",
610 dbg_msg("ro_mode %d", ubi->ro_mode); 610 ubi->peb_size, ubi->peb_size >> 10);
611 ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size);
612 ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size);
613 if (ubi->hdrs_min_io_size != ubi->min_io_size)
614 ubi_msg("sub-page size: %d",
615 ubi->hdrs_min_io_size);
616 ubi_msg("VID header offset: %d (aligned %d)",
617 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
618 ubi_msg("data offset: %d", ubi->leb_start);
611 619
612 /* 620 /*
613 * Note, ideally, we have to initialize ubi->bad_peb_count here. But 621 * Note, ideally, we have to initialize ubi->bad_peb_count here. But
@@ -755,8 +763,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
755 mutex_init(&ubi->volumes_mutex); 763 mutex_init(&ubi->volumes_mutex);
756 spin_lock_init(&ubi->volumes_lock); 764 spin_lock_init(&ubi->volumes_lock);
757 765
758 dbg_msg("attaching mtd%d to ubi%d: VID header offset %d", 766 ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num);
759 mtd->index, ubi_num, vid_hdr_offset);
760 767
761 err = io_init(ubi); 768 err = io_init(ubi);
762 if (err) 769 if (err)
@@ -804,15 +811,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
804 ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num); 811 ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num);
805 ubi_msg("MTD device name: \"%s\"", mtd->name); 812 ubi_msg("MTD device name: \"%s\"", mtd->name);
806 ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); 813 ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20);
807 ubi_msg("physical eraseblock size: %d bytes (%d KiB)",
808 ubi->peb_size, ubi->peb_size >> 10);
809 ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size);
810 ubi_msg("number of good PEBs: %d", ubi->good_peb_count); 814 ubi_msg("number of good PEBs: %d", ubi->good_peb_count);
811 ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); 815 ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count);
812 ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size);
813 ubi_msg("VID header offset: %d (aligned %d)",
814 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
815 ubi_msg("data offset: %d", ubi->leb_start);
816 ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); 816 ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots);
817 ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); 817 ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD);
818 ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); 818 ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT);
@@ -950,8 +950,7 @@ static int __init ubi_init(void)
950 BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64); 950 BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64);
951 951
952 if (mtd_devs > UBI_MAX_DEVICES) { 952 if (mtd_devs > UBI_MAX_DEVICES) {
953 printk(KERN_ERR "UBI error: too many MTD devices, " 953 ubi_err("too many MTD devices, maximum is %d", UBI_MAX_DEVICES);
954 "maximum is %d\n", UBI_MAX_DEVICES);
955 return -EINVAL; 954 return -EINVAL;
956 } 955 }
957 956
@@ -959,25 +958,25 @@ static int __init ubi_init(void)
959 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR); 958 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR);
960 if (IS_ERR(ubi_class)) { 959 if (IS_ERR(ubi_class)) {
961 err = PTR_ERR(ubi_class); 960 err = PTR_ERR(ubi_class);
962 printk(KERN_ERR "UBI error: cannot create UBI class\n"); 961 ubi_err("cannot create UBI class");
963 goto out; 962 goto out;
964 } 963 }
965 964
966 err = class_create_file(ubi_class, &ubi_version); 965 err = class_create_file(ubi_class, &ubi_version);
967 if (err) { 966 if (err) {
968 printk(KERN_ERR "UBI error: cannot create sysfs file\n"); 967 ubi_err("cannot create sysfs file");
969 goto out_class; 968 goto out_class;
970 } 969 }
971 970
972 err = misc_register(&ubi_ctrl_cdev); 971 err = misc_register(&ubi_ctrl_cdev);
973 if (err) { 972 if (err) {
974 printk(KERN_ERR "UBI error: cannot register device\n"); 973 ubi_err("cannot register device");
975 goto out_version; 974 goto out_version;
976 } 975 }
977 976
978 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", 977 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab",
979 sizeof(struct ubi_wl_entry), 978 sizeof(struct ubi_wl_entry),
980 0, 0, NULL); 979 0, 0, NULL);
981 if (!ubi_wl_entry_slab) 980 if (!ubi_wl_entry_slab)
982 goto out_dev_unreg; 981 goto out_dev_unreg;
983 982
@@ -1000,8 +999,7 @@ static int __init ubi_init(void)
1000 mutex_unlock(&ubi_devices_mutex); 999 mutex_unlock(&ubi_devices_mutex);
1001 if (err < 0) { 1000 if (err < 0) {
1002 put_mtd_device(mtd); 1001 put_mtd_device(mtd);
1003 printk(KERN_ERR "UBI error: cannot attach mtd%d\n", 1002 ubi_err("cannot attach mtd%d", mtd->index);
1004 mtd->index);
1005 goto out_detach; 1003 goto out_detach;
1006 } 1004 }
1007 } 1005 }
@@ -1023,7 +1021,7 @@ out_version:
1023out_class: 1021out_class:
1024 class_destroy(ubi_class); 1022 class_destroy(ubi_class);
1025out: 1023out:
1026 printk(KERN_ERR "UBI error: cannot initialize UBI, error %d\n", err); 1024 ubi_err("UBI error: cannot initialize UBI, error %d", err);
1027 return err; 1025 return err;
1028} 1026}
1029module_init(ubi_init); 1027module_init(ubi_init);
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index 51c40b17f1ec..8ea99d8c9e1f 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -41,7 +41,7 @@
41/* Generic debugging message */ 41/* Generic debugging message */
42#define dbg_msg(fmt, ...) \ 42#define dbg_msg(fmt, ...) \
43 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ 43 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
44 current->pid, __FUNCTION__, ##__VA_ARGS__) 44 current->pid, __func__, ##__VA_ARGS__)
45 45
46#define ubi_dbg_dump_stack() dump_stack() 46#define ubi_dbg_dump_stack() dump_stack()
47 47
@@ -99,8 +99,10 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
99#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD 99#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
100/* Initialization and build messages */ 100/* Initialization and build messages */
101#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 101#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
102#define UBI_IO_DEBUG 1
102#else 103#else
103#define dbg_bld(fmt, ...) ({}) 104#define dbg_bld(fmt, ...) ({})
105#define UBI_IO_DEBUG 0
104#endif 106#endif
105 107
106#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS 108#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index d397219238d3..e909b390069a 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -291,11 +291,12 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol)
291 /* 291 /*
292 * In case of dynamic volume, MTD device size is just volume size. In 292 * In case of dynamic volume, MTD device size is just volume size. In
293 * case of a static volume the size is equivalent to the amount of data 293 * case of a static volume the size is equivalent to the amount of data
294 * bytes, which is zero at this moment and will be changed after volume 294 * bytes.
295 * update.
296 */ 295 */
297 if (vol->vol_type == UBI_DYNAMIC_VOLUME) 296 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
298 mtd->size = vol->usable_leb_size * vol->reserved_pebs; 297 mtd->size = vol->usable_leb_size * vol->reserved_pebs;
298 else
299 mtd->size = vol->used_bytes;
299 300
300 if (add_mtd_device(mtd)) { 301 if (add_mtd_device(mtd)) {
301 ubi_err("cannot not add MTD device\n"); 302 ubi_err("cannot not add MTD device\n");
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index db3efdef2433..4ac11df7b048 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -631,6 +631,8 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
631 631
632 dbg_io("read EC header from PEB %d", pnum); 632 dbg_io("read EC header from PEB %d", pnum);
633 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 633 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
634 if (UBI_IO_DEBUG)
635 verbose = 1;
634 636
635 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); 637 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
636 if (err) { 638 if (err) {
@@ -904,6 +906,8 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
904 906
905 dbg_io("read VID header from PEB %d", pnum); 907 dbg_io("read VID header from PEB %d", pnum);
906 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 908 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
909 if (UBI_IO_DEBUG)
910 verbose = 1;
907 911
908 p = (char *)vid_hdr - ubi->vid_hdr_shift; 912 p = (char *)vid_hdr - ubi->vid_hdr_shift;
909 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, 913 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 05aa3e7daba1..96d410e106ab 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -42,6 +42,7 @@
42 42
43#include <linux/err.h> 43#include <linux/err.h>
44#include <linux/crc32.h> 44#include <linux/crc32.h>
45#include <asm/div64.h>
45#include "ubi.h" 46#include "ubi.h"
46 47
47#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 48#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
@@ -92,27 +93,6 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec,
92} 93}
93 94
94/** 95/**
95 * commit_to_mean_value - commit intermediate results to the final mean erase
96 * counter value.
97 * @si: scanning information
98 *
99 * This is a helper function which calculates partial mean erase counter mean
100 * value and adds it to the resulting mean value. As we can work only in
101 * integer arithmetic and we want to calculate the mean value of erase counter
102 * accurately, we first sum erase counter values in @si->ec_sum variable and
103 * count these components in @si->ec_count. If this temporary @si->ec_sum is
104 * going to overflow, we calculate the partial mean value
105 * (@si->ec_sum/@si->ec_count) and add it to @si->mean_ec.
106 */
107static void commit_to_mean_value(struct ubi_scan_info *si)
108{
109 si->ec_sum /= si->ec_count;
110 if (si->ec_sum % si->ec_count >= si->ec_count / 2)
111 si->mean_ec += 1;
112 si->mean_ec += si->ec_sum;
113}
114
115/**
116 * validate_vid_hdr - check that volume identifier header is correct and 96 * validate_vid_hdr - check that volume identifier header is correct and
117 * consistent. 97 * consistent.
118 * @vid_hdr: the volume identifier header to check 98 * @vid_hdr: the volume identifier header to check
@@ -901,15 +881,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
901 881
902adjust_mean_ec: 882adjust_mean_ec:
903 if (!ec_corr) { 883 if (!ec_corr) {
904 if (si->ec_sum + ec < ec) { 884 si->ec_sum += ec;
905 commit_to_mean_value(si); 885 si->ec_count += 1;
906 si->ec_sum = 0;
907 si->ec_count = 0;
908 } else {
909 si->ec_sum += ec;
910 si->ec_count += 1;
911 }
912
913 if (ec > si->max_ec) 886 if (ec > si->max_ec)
914 si->max_ec = ec; 887 si->max_ec = ec;
915 if (ec < si->min_ec) 888 if (ec < si->min_ec)
@@ -965,9 +938,11 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
965 938
966 dbg_msg("scanning is finished"); 939 dbg_msg("scanning is finished");
967 940
968 /* Finish mean erase counter calculations */ 941 /* Calculate mean erase counter */
969 if (si->ec_count) 942 if (si->ec_count) {
970 commit_to_mean_value(si); 943 do_div(si->ec_sum, si->ec_count);
944 si->mean_ec = si->ec_sum;
945 }
971 946
972 if (si->is_empty) 947 if (si->is_empty)
973 ubi_msg("empty MTD device detected"); 948 ubi_msg("empty MTD device detected");
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h
index 46d444af471a..966b9b682a42 100644
--- a/drivers/mtd/ubi/scan.h
+++ b/drivers/mtd/ubi/scan.h
@@ -124,7 +124,7 @@ struct ubi_scan_info {
124 int max_ec; 124 int max_ec;
125 unsigned long long max_sqnum; 125 unsigned long long max_sqnum;
126 int mean_ec; 126 int mean_ec;
127 int ec_sum; 127 uint64_t ec_sum;
128 int ec_count; 128 int ec_count;
129}; 129};
130 130
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
new file mode 100644
index 000000000000..c3185d9fd048
--- /dev/null
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -0,0 +1,372 @@
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Artem Bityutskiy (Битюцкий Ðртём)
19 * Thomas Gleixner
20 * Frank Haverkamp
21 * Oliver Lohmann
22 * Andreas Arnez
23 */
24
25/*
26 * This file defines the layout of UBI headers and all the other UBI on-flash
27 * data structures.
28 */
29
30#ifndef __UBI_MEDIA_H__
31#define __UBI_MEDIA_H__
32
33#include <asm/byteorder.h>
34
35/* The version of UBI images supported by this implementation */
36#define UBI_VERSION 1
37
38/* The highest erase counter value supported by this implementation */
39#define UBI_MAX_ERASECOUNTER 0x7FFFFFFF
40
41/* The initial CRC32 value used when calculating CRC checksums */
42#define UBI_CRC32_INIT 0xFFFFFFFFU
43
44/* Erase counter header magic number (ASCII "UBI#") */
45#define UBI_EC_HDR_MAGIC 0x55424923
46/* Volume identifier header magic number (ASCII "UBI!") */
47#define UBI_VID_HDR_MAGIC 0x55424921
48
49/*
50 * Volume type constants used in the volume identifier header.
51 *
52 * @UBI_VID_DYNAMIC: dynamic volume
53 * @UBI_VID_STATIC: static volume
54 */
55enum {
56 UBI_VID_DYNAMIC = 1,
57 UBI_VID_STATIC = 2
58};
59
60/*
61 * Volume flags used in the volume table record.
62 *
63 * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume
64 *
65 * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume
66 * table. UBI automatically re-sizes the volume which has this flag and makes
67 * the volume to be of largest possible size. This means that if after the
68 * initialization UBI finds out that there are available physical eraseblocks
69 * present on the device, it automatically appends all of them to the volume
70 * (the physical eraseblocks reserved for bad eraseblocks handling and other
71 * reserved physical eraseblocks are not taken). So, if there is a volume with
72 * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical
73 * eraseblocks will be zero after UBI is loaded, because all of them will be
74 * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared
75 * after the volume had been initialized.
76 *
77 * The auto-resize feature is useful for device production purposes. For
78 * example, different NAND flash chips may have different amount of initial bad
79 * eraseblocks, depending of particular chip instance. Manufacturers of NAND
80 * chips usually guarantee that the amount of initial bad eraseblocks does not
81 * exceed certain percent, e.g. 2%. When one creates an UBI image which will be
82 * flashed to the end devices in production, he does not know the exact amount
83 * of good physical eraseblocks the NAND chip on the device will have, but this
84 * number is required to calculate the volume sized and put them to the volume
85 * table of the UBI image. In this case, one of the volumes (e.g., the one
86 * which will store the root file system) is marked as "auto-resizable", and
87 * UBI will adjust its size on the first boot if needed.
88 *
89 * Note, first UBI reserves some amount of physical eraseblocks for bad
90 * eraseblock handling, and then re-sizes the volume, not vice-versa. This
91 * means that the pool of reserved physical eraseblocks will always be present.
92 */
93enum {
94 UBI_VTBL_AUTORESIZE_FLG = 0x01,
95};
96
97/*
98 * Compatibility constants used by internal volumes.
99 *
100 * @UBI_COMPAT_DELETE: delete this internal volume before anything is written
101 * to the flash
102 * @UBI_COMPAT_RO: attach this device in read-only mode
103 * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its
104 * physical eraseblocks, don't allow the wear-leveling unit to move them
105 * @UBI_COMPAT_REJECT: reject this UBI image
106 */
107enum {
108 UBI_COMPAT_DELETE = 1,
109 UBI_COMPAT_RO = 2,
110 UBI_COMPAT_PRESERVE = 4,
111 UBI_COMPAT_REJECT = 5
112};
113
114/* Sizes of UBI headers */
115#define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr)
116#define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
117
118/* Sizes of UBI headers without the ending CRC */
119#define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(__be32))
120#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))
121
122/**
123 * struct ubi_ec_hdr - UBI erase counter header.
124 * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC)
125 * @version: version of UBI implementation which is supposed to accept this
126 * UBI image
127 * @padding1: reserved for future, zeroes
128 * @ec: the erase counter
129 * @vid_hdr_offset: where the VID header starts
130 * @data_offset: where the user data start
131 * @padding2: reserved for future, zeroes
132 * @hdr_crc: erase counter header CRC checksum
133 *
134 * The erase counter header takes 64 bytes and has a plenty of unused space for
135 * future usage. The unused fields are zeroed. The @version field is used to
136 * indicate the version of UBI implementation which is supposed to be able to
137 * work with this UBI image. If @version is greater then the current UBI
138 * version, the image is rejected. This may be useful in future if something
139 * is changed radically. This field is duplicated in the volume identifier
140 * header.
141 *
142 * The @vid_hdr_offset and @data_offset fields contain the offset of the the
143 * volume identifier header and user data, relative to the beginning of the
144 * physical eraseblock. These values have to be the same for all physical
145 * eraseblocks.
146 */
147struct ubi_ec_hdr {
148 __be32 magic;
149 __u8 version;
150 __u8 padding1[3];
151 __be64 ec; /* Warning: the current limit is 31-bit anyway! */
152 __be32 vid_hdr_offset;
153 __be32 data_offset;
154 __u8 padding2[36];
155 __be32 hdr_crc;
156} __attribute__ ((packed));
157
158/**
159 * struct ubi_vid_hdr - on-flash UBI volume identifier header.
160 * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC)
161 * @version: UBI implementation version which is supposed to accept this UBI
162 * image (%UBI_VERSION)
163 * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC)
164 * @copy_flag: if this logical eraseblock was copied from another physical
165 * eraseblock (for wear-leveling reasons)
166 * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE,
167 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT)
168 * @vol_id: ID of this volume
169 * @lnum: logical eraseblock number
170 * @leb_ver: version of this logical eraseblock (IMPORTANT: obsolete, to be
171 * removed, kept only for not breaking older UBI users)
172 * @data_size: how many bytes of data this logical eraseblock contains
173 * @used_ebs: total number of used logical eraseblocks in this volume
174 * @data_pad: how many bytes at the end of this physical eraseblock are not
175 * used
176 * @data_crc: CRC checksum of the data stored in this logical eraseblock
177 * @padding1: reserved for future, zeroes
178 * @sqnum: sequence number
179 * @padding2: reserved for future, zeroes
180 * @hdr_crc: volume identifier header CRC checksum
181 *
182 * The @sqnum is the value of the global sequence counter at the time when this
183 * VID header was created. The global sequence counter is incremented each time
184 * UBI writes a new VID header to the flash, i.e. when it maps a logical
185 * eraseblock to a new physical eraseblock. The global sequence counter is an
186 * unsigned 64-bit integer and we assume it never overflows. The @sqnum
187 * (sequence number) is used to distinguish between older and newer versions of
188 * logical eraseblocks.
189 *
190 * There are 2 situations when there may be more then one physical eraseblock
191 * corresponding to the same logical eraseblock, i.e., having the same @vol_id
192 * and @lnum values in the volume identifier header. Suppose we have a logical
193 * eraseblock L and it is mapped to the physical eraseblock P.
194 *
195 * 1. Because UBI may erase physical eraseblocks asynchronously, the following
196 * situation is possible: L is asynchronously erased, so P is scheduled for
197 * erasure, then L is written to,i.e. mapped to another physical eraseblock P1,
198 * so P1 is written to, then an unclean reboot happens. Result - there are 2
199 * physical eraseblocks P and P1 corresponding to the same logical eraseblock
200 * L. But P1 has greater sequence number, so UBI picks P1 when it attaches the
201 * flash.
202 *
203 * 2. From time to time UBI moves logical eraseblocks to other physical
204 * eraseblocks for wear-leveling reasons. If, for example, UBI moves L from P
205 * to P1, and an unclean reboot happens before P is physically erased, there
206 * are two physical eraseblocks P and P1 corresponding to L and UBI has to
207 * select one of them when the flash is attached. The @sqnum field says which
208 * PEB is the original (obviously P will have lower @sqnum) and the copy. But
209 * it is not enough to select the physical eraseblock with the higher sequence
210 * number, because the unclean reboot could have happen in the middle of the
211 * copying process, so the data in P is corrupted. It is also not enough to
212 * just select the physical eraseblock with lower sequence number, because the
213 * data there may be old (consider a case if more data was added to P1 after
214 * the copying). Moreover, the unclean reboot may happen when the erasure of P
215 * was just started, so it result in unstable P, which is "mostly" OK, but
216 * still has unstable bits.
217 *
218 * UBI uses the @copy_flag field to indicate that this logical eraseblock is a
219 * copy. UBI also calculates data CRC when the data is moved and stores it at
220 * the @data_crc field of the copy (P1). So when UBI needs to pick one physical
221 * eraseblock of two (P or P1), the @copy_flag of the newer one (P1) is
222 * examined. If it is cleared, the situation* is simple and the newer one is
223 * picked. If it is set, the data CRC of the copy (P1) is examined. If the CRC
224 * checksum is correct, this physical eraseblock is selected (P1). Otherwise
225 * the older one (P) is selected.
226 *
227 * Note, there is an obsolete @leb_ver field which was used instead of @sqnum
228 * in the past. But it is not used anymore and we keep it in order to be able
229 * to deal with old UBI images. It will be removed at some point.
230 *
231 * There are 2 sorts of volumes in UBI: user volumes and internal volumes.
232 * Internal volumes are not seen from outside and are used for various internal
233 * UBI purposes. In this implementation there is only one internal volume - the
234 * layout volume. Internal volumes are the main mechanism of UBI extensions.
235 * For example, in future one may introduce a journal internal volume. Internal
236 * volumes have their own reserved range of IDs.
237 *
238 * The @compat field is only used for internal volumes and contains the "degree
239 * of their compatibility". It is always zero for user volumes. This field
240 * provides a mechanism to introduce UBI extensions and to be still compatible
241 * with older UBI binaries. For example, if someone introduced a journal in
242 * future, he would probably use %UBI_COMPAT_DELETE compatibility for the
243 * journal volume. And in this case, older UBI binaries, which know nothing
244 * about the journal volume, would just delete this volume and work perfectly
245 * fine. This is similar to what Ext2fs does when it is fed by an Ext3fs image
246 * - it just ignores the Ext3fs journal.
247 *
248 * The @data_crc field contains the CRC checksum of the contents of the logical
249 * eraseblock if this is a static volume. In case of dynamic volumes, it does
250 * not contain the CRC checksum as a rule. The only exception is when the
251 * data of the physical eraseblock was moved by the wear-leveling unit, then
252 * the wear-leveling unit calculates the data CRC and stores it in the
253 * @data_crc field. And of course, the @copy_flag is %in this case.
254 *
255 * The @data_size field is used only for static volumes because UBI has to know
256 * how many bytes of data are stored in this eraseblock. For dynamic volumes,
257 * this field usually contains zero. The only exception is when the data of the
258 * physical eraseblock was moved to another physical eraseblock for
259 * wear-leveling reasons. In this case, UBI calculates CRC checksum of the
260 * contents and uses both @data_crc and @data_size fields. In this case, the
261 * @data_size field contains data size.
262 *
263 * The @used_ebs field is used only for static volumes and indicates how many
264 * eraseblocks the data of the volume takes. For dynamic volumes this field is
265 * not used and always contains zero.
266 *
267 * The @data_pad is calculated when volumes are created using the alignment
268 * parameter. So, effectively, the @data_pad field reduces the size of logical
269 * eraseblocks of this volume. This is very handy when one uses block-oriented
270 * software (say, cramfs) on top of the UBI volume.
271 */
272struct ubi_vid_hdr {
273 __be32 magic;
274 __u8 version;
275 __u8 vol_type;
276 __u8 copy_flag;
277 __u8 compat;
278 __be32 vol_id;
279 __be32 lnum;
280 __be32 leb_ver; /* obsolete, to be removed, don't use */
281 __be32 data_size;
282 __be32 used_ebs;
283 __be32 data_pad;
284 __be32 data_crc;
285 __u8 padding1[4];
286 __be64 sqnum;
287 __u8 padding2[12];
288 __be32 hdr_crc;
289} __attribute__ ((packed));
290
291/* Internal UBI volumes count */
292#define UBI_INT_VOL_COUNT 1
293
294/*
295 * Starting ID of internal volumes. There is reserved room for 4096 internal
296 * volumes.
297 */
298#define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096)
299
300/* The layout volume contains the volume table */
301
302#define UBI_LAYOUT_VOLUME_ID UBI_INTERNAL_VOL_START
303#define UBI_LAYOUT_VOLUME_TYPE UBI_VID_DYNAMIC
304#define UBI_LAYOUT_VOLUME_ALIGN 1
305#define UBI_LAYOUT_VOLUME_EBS 2
306#define UBI_LAYOUT_VOLUME_NAME "layout volume"
307#define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT
308
309/* The maximum number of volumes per one UBI device */
310#define UBI_MAX_VOLUMES 128
311
312/* The maximum volume name length */
313#define UBI_VOL_NAME_MAX 127
314
315/* Size of the volume table record */
316#define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record)
317
318/* Size of the volume table record without the ending CRC */
319#define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(__be32))
320
321/**
322 * struct ubi_vtbl_record - a record in the volume table.
323 * @reserved_pebs: how many physical eraseblocks are reserved for this volume
324 * @alignment: volume alignment
325 * @data_pad: how many bytes are unused at the end of the each physical
326 * eraseblock to satisfy the requested alignment
327 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
328 * @upd_marker: if volume update was started but not finished
329 * @name_len: volume name length
330 * @name: the volume name
331 * @flags: volume flags (%UBI_VTBL_AUTORESIZE_FLG)
332 * @padding: reserved, zeroes
333 * @crc: a CRC32 checksum of the record
334 *
335 * The volume table records are stored in the volume table, which is stored in
336 * the layout volume. The layout volume consists of 2 logical eraseblock, each
337 * of which contains a copy of the volume table (i.e., the volume table is
338 * duplicated). The volume table is an array of &struct ubi_vtbl_record
339 * objects indexed by the volume ID.
340 *
341 * If the size of the logical eraseblock is large enough to fit
342 * %UBI_MAX_VOLUMES records, the volume table contains %UBI_MAX_VOLUMES
343 * records. Otherwise, it contains as many records as it can fit (i.e., size of
344 * logical eraseblock divided by sizeof(struct ubi_vtbl_record)).
345 *
346 * The @upd_marker flag is used to implement volume update. It is set to %1
347 * before update and set to %0 after the update. So if the update operation was
348 * interrupted, UBI knows that the volume is corrupted.
349 *
350 * The @alignment field is specified when the volume is created and cannot be
351 * later changed. It may be useful, for example, when a block-oriented file
352 * system works on top of UBI. The @data_pad field is calculated using the
353 * logical eraseblock size and @alignment. The alignment must be multiple to the
354 * minimal flash I/O unit. If @alignment is 1, all the available space of
355 * the physical eraseblocks is used.
356 *
357 * Empty records contain all zeroes and the CRC checksum of those zeroes.
358 */
359struct ubi_vtbl_record {
360 __be32 reserved_pebs;
361 __be32 alignment;
362 __be32 data_pad;
363 __u8 vol_type;
364 __u8 upd_marker;
365 __be16 name_len;
366 __u8 name[UBI_VOL_NAME_MAX+1];
367 __u8 flags;
368 __u8 padding[23];
369 __be32 crc;
370} __attribute__ ((packed));
371
372#endif /* !__UBI_MEDIA_H__ */
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index a548c1d28fa8..67dcbd11c15c 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -37,10 +37,9 @@
37#include <linux/string.h> 37#include <linux/string.h>
38#include <linux/vmalloc.h> 38#include <linux/vmalloc.h>
39#include <linux/mtd/mtd.h> 39#include <linux/mtd/mtd.h>
40
41#include <mtd/ubi-header.h>
42#include <linux/mtd/ubi.h> 40#include <linux/mtd/ubi.h>
43 41
42#include "ubi-media.h"
44#include "scan.h" 43#include "scan.h"
45#include "debug.h" 44#include "debug.h"
46 45
@@ -54,10 +53,10 @@
54#define ubi_msg(fmt, ...) printk(KERN_NOTICE "UBI: " fmt "\n", ##__VA_ARGS__) 53#define ubi_msg(fmt, ...) printk(KERN_NOTICE "UBI: " fmt "\n", ##__VA_ARGS__)
55/* UBI warning messages */ 54/* UBI warning messages */
56#define ubi_warn(fmt, ...) printk(KERN_WARNING "UBI warning: %s: " fmt "\n", \ 55#define ubi_warn(fmt, ...) printk(KERN_WARNING "UBI warning: %s: " fmt "\n", \
57 __FUNCTION__, ##__VA_ARGS__) 56 __func__, ##__VA_ARGS__)
58/* UBI error messages */ 57/* UBI error messages */
59#define ubi_err(fmt, ...) printk(KERN_ERR "UBI error: %s: " fmt "\n", \ 58#define ubi_err(fmt, ...) printk(KERN_ERR "UBI error: %s: " fmt "\n", \
60 __FUNCTION__, ##__VA_ARGS__) 59 __func__, ##__VA_ARGS__)
61 60
62/* Lowest number PEBs reserved for bad PEB handling */ 61/* Lowest number PEBs reserved for bad PEB handling */
63#define MIN_RESEVED_PEBS 2 62#define MIN_RESEVED_PEBS 2
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 015e16325973..0697aa8ea774 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2278,6 +2278,7 @@ config TSI108_ETH
2278config GELIC_NET 2278config GELIC_NET
2279 tristate "PS3 Gigabit Ethernet driver" 2279 tristate "PS3 Gigabit Ethernet driver"
2280 depends on PPC_PS3 2280 depends on PPC_PS3
2281 select PS3_SYS_MANAGER
2281 help 2282 help
2282 This driver supports the network device on the PS3 game 2283 This driver supports the network device on the PS3 game
2283 console. This driver has built-in support for Ethernet. 2284 console. This driver has built-in support for Ethernet.
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c
index 978e20a1791b..1e39e78f1778 100644
--- a/drivers/net/arm/at91_ether.c
+++ b/drivers/net/arm/at91_ether.c
@@ -1248,3 +1248,4 @@ module_exit(at91ether_exit)
1248MODULE_LICENSE("GPL"); 1248MODULE_LICENSE("GPL");
1249MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver"); 1249MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver");
1250MODULE_AUTHOR("Andrew Victor"); 1250MODULE_AUTHOR("Andrew Victor");
1251MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index 91a6590d107b..ecd8fc6146e9 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -897,6 +897,7 @@ static struct platform_driver ep93xx_eth_driver = {
897 .remove = ep93xx_eth_remove, 897 .remove = ep93xx_eth_remove,
898 .driver = { 898 .driver = {
899 .name = "ep93xx-eth", 899 .name = "ep93xx-eth",
900 .owner = THIS_MODULE,
900 }, 901 },
901}; 902};
902 903
@@ -914,3 +915,4 @@ static void __exit ep93xx_eth_cleanup_module(void)
914module_init(ep93xx_eth_init_module); 915module_init(ep93xx_eth_init_module);
915module_exit(ep93xx_eth_cleanup_module); 916module_exit(ep93xx_eth_cleanup_module);
916MODULE_LICENSE("GPL"); 917MODULE_LICENSE("GPL");
918MODULE_ALIAS("platform:ep93xx-eth");
diff --git a/drivers/net/atlx/atl1.c b/drivers/net/atlx/atl1.c
index 5586fc624688..0afe522b8f7b 100644
--- a/drivers/net/atlx/atl1.c
+++ b/drivers/net/atlx/atl1.c
@@ -91,6 +91,144 @@
91#include "atlx.c" 91#include "atlx.c"
92 92
93/* 93/*
94 * This is the only thing that needs to be changed to adjust the
95 * maximum number of ports that the driver can manage.
96 */
97#define ATL1_MAX_NIC 4
98
99#define OPTION_UNSET -1
100#define OPTION_DISABLED 0
101#define OPTION_ENABLED 1
102
103#define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET }
104
105/*
106 * Interrupt Moderate Timer in units of 2 us
107 *
108 * Valid Range: 10-65535
109 *
110 * Default Value: 100 (200us)
111 */
112static int __devinitdata int_mod_timer[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
113static int num_int_mod_timer;
114module_param_array_named(int_mod_timer, int_mod_timer, int,
115 &num_int_mod_timer, 0);
116MODULE_PARM_DESC(int_mod_timer, "Interrupt moderator timer");
117
118#define DEFAULT_INT_MOD_CNT 100 /* 200us */
119#define MAX_INT_MOD_CNT 65000
120#define MIN_INT_MOD_CNT 50
121
122struct atl1_option {
123 enum { enable_option, range_option, list_option } type;
124 char *name;
125 char *err;
126 int def;
127 union {
128 struct { /* range_option info */
129 int min;
130 int max;
131 } r;
132 struct { /* list_option info */
133 int nr;
134 struct atl1_opt_list {
135 int i;
136 char *str;
137 } *p;
138 } l;
139 } arg;
140};
141
142static int __devinit atl1_validate_option(int *value, struct atl1_option *opt,
143 struct pci_dev *pdev)
144{
145 if (*value == OPTION_UNSET) {
146 *value = opt->def;
147 return 0;
148 }
149
150 switch (opt->type) {
151 case enable_option:
152 switch (*value) {
153 case OPTION_ENABLED:
154 dev_info(&pdev->dev, "%s enabled\n", opt->name);
155 return 0;
156 case OPTION_DISABLED:
157 dev_info(&pdev->dev, "%s disabled\n", opt->name);
158 return 0;
159 }
160 break;
161 case range_option:
162 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
163 dev_info(&pdev->dev, "%s set to %i\n", opt->name,
164 *value);
165 return 0;
166 }
167 break;
168 case list_option:{
169 int i;
170 struct atl1_opt_list *ent;
171
172 for (i = 0; i < opt->arg.l.nr; i++) {
173 ent = &opt->arg.l.p[i];
174 if (*value == ent->i) {
175 if (ent->str[0] != '\0')
176 dev_info(&pdev->dev, "%s\n",
177 ent->str);
178 return 0;
179 }
180 }
181 }
182 break;
183
184 default:
185 break;
186 }
187
188 dev_info(&pdev->dev, "invalid %s specified (%i) %s\n",
189 opt->name, *value, opt->err);
190 *value = opt->def;
191 return -1;
192}
193
194/*
195 * atl1_check_options - Range Checking for Command Line Parameters
196 * @adapter: board private structure
197 *
198 * This routine checks all command line parameters for valid user
199 * input. If an invalid value is given, or if no user specified
200 * value exists, a default value is used. The final value is stored
201 * in a variable in the adapter structure.
202 */
203void __devinit atl1_check_options(struct atl1_adapter *adapter)
204{
205 struct pci_dev *pdev = adapter->pdev;
206 int bd = adapter->bd_number;
207 if (bd >= ATL1_MAX_NIC) {
208 dev_notice(&pdev->dev, "no configuration for board#%i\n", bd);
209 dev_notice(&pdev->dev, "using defaults for all values\n");
210 }
211 { /* Interrupt Moderate Timer */
212 struct atl1_option opt = {
213 .type = range_option,
214 .name = "Interrupt Moderator Timer",
215 .err = "using default of "
216 __MODULE_STRING(DEFAULT_INT_MOD_CNT),
217 .def = DEFAULT_INT_MOD_CNT,
218 .arg = {.r = {.min = MIN_INT_MOD_CNT,
219 .max = MAX_INT_MOD_CNT} }
220 };
221 int val;
222 if (num_int_mod_timer > bd) {
223 val = int_mod_timer[bd];
224 atl1_validate_option(&val, &opt, pdev);
225 adapter->imt = (u16) val;
226 } else
227 adapter->imt = (u16) (opt.def);
228 }
229}
230
231/*
94 * atl1_pci_tbl - PCI Device ID Table 232 * atl1_pci_tbl - PCI Device ID Table
95 */ 233 */
96static const struct pci_device_id atl1_pci_tbl[] = { 234static const struct pci_device_id atl1_pci_tbl[] = {
diff --git a/drivers/net/atlx/atlx.c b/drivers/net/atlx/atlx.c
index 4186326d1b94..f06b854e2501 100644
--- a/drivers/net/atlx/atlx.c
+++ b/drivers/net/atlx/atlx.c
@@ -253,181 +253,4 @@ static void atlx_restore_vlan(struct atlx_adapter *adapter)
253 atlx_vlan_rx_register(adapter->netdev, adapter->vlgrp); 253 atlx_vlan_rx_register(adapter->netdev, adapter->vlgrp);
254} 254}
255 255
256/*
257 * This is the only thing that needs to be changed to adjust the
258 * maximum number of ports that the driver can manage.
259 */
260#define ATL1_MAX_NIC 4
261
262#define OPTION_UNSET -1
263#define OPTION_DISABLED 0
264#define OPTION_ENABLED 1
265
266#define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET }
267
268/*
269 * Interrupt Moderate Timer in units of 2 us
270 *
271 * Valid Range: 10-65535
272 *
273 * Default Value: 100 (200us)
274 */
275static int __devinitdata int_mod_timer[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
276static int num_int_mod_timer;
277module_param_array_named(int_mod_timer, int_mod_timer, int,
278 &num_int_mod_timer, 0);
279MODULE_PARM_DESC(int_mod_timer, "Interrupt moderator timer");
280
281/*
282 * flash_vendor
283 *
284 * Valid Range: 0-2
285 *
286 * 0 - Atmel
287 * 1 - SST
288 * 2 - ST
289 *
290 * Default Value: 0
291 */
292static int __devinitdata flash_vendor[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
293static int num_flash_vendor;
294module_param_array_named(flash_vendor, flash_vendor, int, &num_flash_vendor, 0);
295MODULE_PARM_DESC(flash_vendor, "SPI flash vendor");
296
297#define DEFAULT_INT_MOD_CNT 100 /* 200us */
298#define MAX_INT_MOD_CNT 65000
299#define MIN_INT_MOD_CNT 50
300
301#define FLASH_VENDOR_DEFAULT 0
302#define FLASH_VENDOR_MIN 0
303#define FLASH_VENDOR_MAX 2
304
305struct atl1_option {
306 enum { enable_option, range_option, list_option } type;
307 char *name;
308 char *err;
309 int def;
310 union {
311 struct { /* range_option info */
312 int min;
313 int max;
314 } r;
315 struct { /* list_option info */
316 int nr;
317 struct atl1_opt_list {
318 int i;
319 char *str;
320 } *p;
321 } l;
322 } arg;
323};
324
325static int __devinit atl1_validate_option(int *value, struct atl1_option *opt,
326 struct pci_dev *pdev)
327{
328 if (*value == OPTION_UNSET) {
329 *value = opt->def;
330 return 0;
331 }
332
333 switch (opt->type) {
334 case enable_option:
335 switch (*value) {
336 case OPTION_ENABLED:
337 dev_info(&pdev->dev, "%s enabled\n", opt->name);
338 return 0;
339 case OPTION_DISABLED:
340 dev_info(&pdev->dev, "%s disabled\n", opt->name);
341 return 0;
342 }
343 break;
344 case range_option:
345 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
346 dev_info(&pdev->dev, "%s set to %i\n", opt->name,
347 *value);
348 return 0;
349 }
350 break;
351 case list_option:{
352 int i;
353 struct atl1_opt_list *ent;
354
355 for (i = 0; i < opt->arg.l.nr; i++) {
356 ent = &opt->arg.l.p[i];
357 if (*value == ent->i) {
358 if (ent->str[0] != '\0')
359 dev_info(&pdev->dev, "%s\n",
360 ent->str);
361 return 0;
362 }
363 }
364 }
365 break;
366
367 default:
368 break;
369 }
370
371 dev_info(&pdev->dev, "invalid %s specified (%i) %s\n",
372 opt->name, *value, opt->err);
373 *value = opt->def;
374 return -1;
375}
376
377/*
378 * atl1_check_options - Range Checking for Command Line Parameters
379 * @adapter: board private structure
380 *
381 * This routine checks all command line parameters for valid user
382 * input. If an invalid value is given, or if no user specified
383 * value exists, a default value is used. The final value is stored
384 * in a variable in the adapter structure.
385 */
386void __devinit atl1_check_options(struct atl1_adapter *adapter)
387{
388 struct pci_dev *pdev = adapter->pdev;
389 int bd = adapter->bd_number;
390 if (bd >= ATL1_MAX_NIC) {
391 dev_notice(&pdev->dev, "no configuration for board#%i\n", bd);
392 dev_notice(&pdev->dev, "using defaults for all values\n");
393 }
394 { /* Interrupt Moderate Timer */
395 struct atl1_option opt = {
396 .type = range_option,
397 .name = "Interrupt Moderator Timer",
398 .err = "using default of "
399 __MODULE_STRING(DEFAULT_INT_MOD_CNT),
400 .def = DEFAULT_INT_MOD_CNT,
401 .arg = {.r = {.min = MIN_INT_MOD_CNT,
402 .max = MAX_INT_MOD_CNT} }
403 };
404 int val;
405 if (num_int_mod_timer > bd) {
406 val = int_mod_timer[bd];
407 atl1_validate_option(&val, &opt, pdev);
408 adapter->imt = (u16) val;
409 } else
410 adapter->imt = (u16) (opt.def);
411 }
412
413 { /* Flash Vendor */
414 struct atl1_option opt = {
415 .type = range_option,
416 .name = "SPI Flash Vendor",
417 .err = "using default of "
418 __MODULE_STRING(FLASH_VENDOR_DEFAULT),
419 .def = DEFAULT_INT_MOD_CNT,
420 .arg = {.r = {.min = FLASH_VENDOR_MIN,
421 .max = FLASH_VENDOR_MAX} }
422 };
423 int val;
424 if (num_flash_vendor > bd) {
425 val = flash_vendor[bd];
426 atl1_validate_option(&val, &opt, pdev);
427 adapter->hw.flash_vendor = (u8) val;
428 } else
429 adapter->hw.flash_vendor = (u8) (opt.def);
430 }
431}
432
433#endif /* ATLX_C */ 256#endif /* ATLX_C */
diff --git a/drivers/net/ax88796.c b/drivers/net/ax88796.c
index 194949afacd0..0b4adf4a0f7d 100644
--- a/drivers/net/ax88796.c
+++ b/drivers/net/ax88796.c
@@ -1005,3 +1005,4 @@ module_exit(axdrv_exit);
1005MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver"); 1005MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
1006MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 1006MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1007MODULE_LICENSE("GPL v2"); 1007MODULE_LICENSE("GPL v2");
1008MODULE_ALIAS("platform:ax88796");
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index 717dcc1aa1e9..4fec8581bfd7 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -47,6 +47,7 @@
47MODULE_AUTHOR(DRV_AUTHOR); 47MODULE_AUTHOR(DRV_AUTHOR);
48MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
49MODULE_DESCRIPTION(DRV_DESC); 49MODULE_DESCRIPTION(DRV_DESC);
50MODULE_ALIAS("platform:bfin_mac");
50 51
51#if defined(CONFIG_BFIN_MAC_USE_L1) 52#if defined(CONFIG_BFIN_MAC_USE_L1)
52# define bfin_mac_alloc(dma_handle, size) l1_data_sram_zalloc(size) 53# define bfin_mac_alloc(dma_handle, size) l1_data_sram_zalloc(size)
@@ -1089,8 +1090,9 @@ static struct platform_driver bfin_mac_driver = {
1089 .resume = bfin_mac_resume, 1090 .resume = bfin_mac_resume,
1090 .suspend = bfin_mac_suspend, 1091 .suspend = bfin_mac_suspend,
1091 .driver = { 1092 .driver = {
1092 .name = DRV_NAME, 1093 .name = DRV_NAME,
1093 }, 1094 .owner = THIS_MODULE,
1095 },
1094}; 1096};
1095 1097
1096static int __init bfin_mac_init(void) 1098static int __init bfin_mac_init(void)
@@ -1106,3 +1108,4 @@ static void __exit bfin_mac_cleanup(void)
1106} 1108}
1107 1109
1108module_exit(bfin_mac_cleanup); 1110module_exit(bfin_mac_cleanup);
1111
diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index 9da7ff437031..2b5740b3d182 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -42,6 +42,7 @@
42MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>"); 42MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
43MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)"); 43MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
44MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
45MODULE_ALIAS("platform:cpmac");
45 46
46static int debug_level = 8; 47static int debug_level = 8;
47static int dumb_switch; 48static int dumb_switch;
@@ -1103,6 +1104,7 @@ static int __devexit cpmac_remove(struct platform_device *pdev)
1103 1104
1104static struct platform_driver cpmac_driver = { 1105static struct platform_driver cpmac_driver = {
1105 .driver.name = "cpmac", 1106 .driver.name = "cpmac",
1107 .driver.owner = THIS_MODULE,
1106 .probe = cpmac_probe, 1108 .probe = cpmac_probe,
1107 .remove = __devexit_p(cpmac_remove), 1109 .remove = __devexit_p(cpmac_remove),
1108}; 1110};
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index d63cc93f055d..e6fe2614ea6d 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -1418,3 +1418,4 @@ module_exit(dm9000_cleanup);
1418MODULE_AUTHOR("Sascha Hauer, Ben Dooks"); 1418MODULE_AUTHOR("Sascha Hauer, Ben Dooks");
1419MODULE_DESCRIPTION("Davicom DM9000 network driver"); 1419MODULE_DESCRIPTION("Davicom DM9000 network driver");
1420MODULE_LICENSE("GPL"); 1420MODULE_LICENSE("GPL");
1421MODULE_ALIAS("platform:dm9000");
diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
index 01c88664bad3..462351ca2c81 100644
--- a/drivers/net/e1000e/82571.c
+++ b/drivers/net/e1000e/82571.c
@@ -1326,12 +1326,10 @@ struct e1000_info e1000_82571_info = {
1326 .mac = e1000_82571, 1326 .mac = e1000_82571,
1327 .flags = FLAG_HAS_HW_VLAN_FILTER 1327 .flags = FLAG_HAS_HW_VLAN_FILTER
1328 | FLAG_HAS_JUMBO_FRAMES 1328 | FLAG_HAS_JUMBO_FRAMES
1329 | FLAG_HAS_STATS_PTC_PRC
1330 | FLAG_HAS_WOL 1329 | FLAG_HAS_WOL
1331 | FLAG_APME_IN_CTRL3 1330 | FLAG_APME_IN_CTRL3
1332 | FLAG_RX_CSUM_ENABLED 1331 | FLAG_RX_CSUM_ENABLED
1333 | FLAG_HAS_CTRLEXT_ON_LOAD 1332 | FLAG_HAS_CTRLEXT_ON_LOAD
1334 | FLAG_HAS_STATS_ICR_ICT
1335 | FLAG_HAS_SMART_POWER_DOWN 1333 | FLAG_HAS_SMART_POWER_DOWN
1336 | FLAG_RESET_OVERWRITES_LAA /* errata */ 1334 | FLAG_RESET_OVERWRITES_LAA /* errata */
1337 | FLAG_TARC_SPEED_MODE_BIT /* errata */ 1335 | FLAG_TARC_SPEED_MODE_BIT /* errata */
@@ -1347,12 +1345,10 @@ struct e1000_info e1000_82572_info = {
1347 .mac = e1000_82572, 1345 .mac = e1000_82572,
1348 .flags = FLAG_HAS_HW_VLAN_FILTER 1346 .flags = FLAG_HAS_HW_VLAN_FILTER
1349 | FLAG_HAS_JUMBO_FRAMES 1347 | FLAG_HAS_JUMBO_FRAMES
1350 | FLAG_HAS_STATS_PTC_PRC
1351 | FLAG_HAS_WOL 1348 | FLAG_HAS_WOL
1352 | FLAG_APME_IN_CTRL3 1349 | FLAG_APME_IN_CTRL3
1353 | FLAG_RX_CSUM_ENABLED 1350 | FLAG_RX_CSUM_ENABLED
1354 | FLAG_HAS_CTRLEXT_ON_LOAD 1351 | FLAG_HAS_CTRLEXT_ON_LOAD
1355 | FLAG_HAS_STATS_ICR_ICT
1356 | FLAG_TARC_SPEED_MODE_BIT, /* errata */ 1352 | FLAG_TARC_SPEED_MODE_BIT, /* errata */
1357 .pba = 38, 1353 .pba = 38,
1358 .get_variants = e1000_get_variants_82571, 1354 .get_variants = e1000_get_variants_82571,
@@ -1365,11 +1361,9 @@ struct e1000_info e1000_82573_info = {
1365 .mac = e1000_82573, 1361 .mac = e1000_82573,
1366 .flags = FLAG_HAS_HW_VLAN_FILTER 1362 .flags = FLAG_HAS_HW_VLAN_FILTER
1367 | FLAG_HAS_JUMBO_FRAMES 1363 | FLAG_HAS_JUMBO_FRAMES
1368 | FLAG_HAS_STATS_PTC_PRC
1369 | FLAG_HAS_WOL 1364 | FLAG_HAS_WOL
1370 | FLAG_APME_IN_CTRL3 1365 | FLAG_APME_IN_CTRL3
1371 | FLAG_RX_CSUM_ENABLED 1366 | FLAG_RX_CSUM_ENABLED
1372 | FLAG_HAS_STATS_ICR_ICT
1373 | FLAG_HAS_SMART_POWER_DOWN 1367 | FLAG_HAS_SMART_POWER_DOWN
1374 | FLAG_HAS_AMT 1368 | FLAG_HAS_AMT
1375 | FLAG_HAS_ERT 1369 | FLAG_HAS_ERT
diff --git a/drivers/net/e1000e/defines.h b/drivers/net/e1000e/defines.h
index 572cfd44397a..2a53875cddbf 100644
--- a/drivers/net/e1000e/defines.h
+++ b/drivers/net/e1000e/defines.h
@@ -184,6 +184,7 @@
184#define E1000_SWFW_EEP_SM 0x1 184#define E1000_SWFW_EEP_SM 0x1
185#define E1000_SWFW_PHY0_SM 0x2 185#define E1000_SWFW_PHY0_SM 0x2
186#define E1000_SWFW_PHY1_SM 0x4 186#define E1000_SWFW_PHY1_SM 0x4
187#define E1000_SWFW_CSR_SM 0x8
187 188
188/* Device Control */ 189/* Device Control */
189#define E1000_CTRL_FD 0x00000001 /* Full duplex.0=half; 1=full */ 190#define E1000_CTRL_FD 0x00000001 /* Full duplex.0=half; 1=full */
@@ -527,8 +528,10 @@
527#define PHY_ID2 0x03 /* Phy Id Reg (word 2) */ 528#define PHY_ID2 0x03 /* Phy Id Reg (word 2) */
528#define PHY_AUTONEG_ADV 0x04 /* Autoneg Advertisement */ 529#define PHY_AUTONEG_ADV 0x04 /* Autoneg Advertisement */
529#define PHY_LP_ABILITY 0x05 /* Link Partner Ability (Base Page) */ 530#define PHY_LP_ABILITY 0x05 /* Link Partner Ability (Base Page) */
531#define PHY_AUTONEG_EXP 0x06 /* Autoneg Expansion Reg */
530#define PHY_1000T_CTRL 0x09 /* 1000Base-T Control Reg */ 532#define PHY_1000T_CTRL 0x09 /* 1000Base-T Control Reg */
531#define PHY_1000T_STATUS 0x0A /* 1000Base-T Status Reg */ 533#define PHY_1000T_STATUS 0x0A /* 1000Base-T Status Reg */
534#define PHY_EXT_STATUS 0x0F /* Extended Status Reg */
532 535
533/* NVM Control */ 536/* NVM Control */
534#define E1000_EECD_SK 0x00000001 /* NVM Clock */ 537#define E1000_EECD_SK 0x00000001 /* NVM Clock */
diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
index 5a89dff52264..38bfd0d261fe 100644
--- a/drivers/net/e1000e/e1000.h
+++ b/drivers/net/e1000e/e1000.h
@@ -64,11 +64,14 @@ struct e1000_info;
64/* Tx/Rx descriptor defines */ 64/* Tx/Rx descriptor defines */
65#define E1000_DEFAULT_TXD 256 65#define E1000_DEFAULT_TXD 256
66#define E1000_MAX_TXD 4096 66#define E1000_MAX_TXD 4096
67#define E1000_MIN_TXD 80 67#define E1000_MIN_TXD 64
68 68
69#define E1000_DEFAULT_RXD 256 69#define E1000_DEFAULT_RXD 256
70#define E1000_MAX_RXD 4096 70#define E1000_MAX_RXD 4096
71#define E1000_MIN_RXD 80 71#define E1000_MIN_RXD 64
72
73#define E1000_MIN_ITR_USECS 10 /* 100000 irq/sec */
74#define E1000_MAX_ITR_USECS 10000 /* 100 irq/sec */
72 75
73/* Early Receive defines */ 76/* Early Receive defines */
74#define E1000_ERT_2048 0x100 77#define E1000_ERT_2048 0x100
@@ -147,6 +150,18 @@ struct e1000_ring {
147 struct e1000_queue_stats stats; 150 struct e1000_queue_stats stats;
148}; 151};
149 152
153/* PHY register snapshot values */
154struct e1000_phy_regs {
155 u16 bmcr; /* basic mode control register */
156 u16 bmsr; /* basic mode status register */
157 u16 advertise; /* auto-negotiation advertisement */
158 u16 lpa; /* link partner ability register */
159 u16 expansion; /* auto-negotiation expansion reg */
160 u16 ctrl1000; /* 1000BASE-T control register */
161 u16 stat1000; /* 1000BASE-T status register */
162 u16 estatus; /* extended status register */
163};
164
150/* board specific private data structure */ 165/* board specific private data structure */
151struct e1000_adapter { 166struct e1000_adapter {
152 struct timer_list watchdog_timer; 167 struct timer_list watchdog_timer;
@@ -202,8 +217,8 @@ struct e1000_adapter {
202 /* Tx stats */ 217 /* Tx stats */
203 u64 tpt_old; 218 u64 tpt_old;
204 u64 colc_old; 219 u64 colc_old;
205 u64 gotcl_old; 220 u32 gotc;
206 u32 gotcl; 221 u64 gotc_old;
207 u32 tx_timeout_count; 222 u32 tx_timeout_count;
208 u32 tx_fifo_head; 223 u32 tx_fifo_head;
209 u32 tx_head_addr; 224 u32 tx_head_addr;
@@ -227,8 +242,8 @@ struct e1000_adapter {
227 u64 hw_csum_err; 242 u64 hw_csum_err;
228 u64 hw_csum_good; 243 u64 hw_csum_good;
229 u64 rx_hdr_split; 244 u64 rx_hdr_split;
230 u64 gorcl_old; 245 u32 gorc;
231 u32 gorcl; 246 u64 gorc_old;
232 u32 alloc_rx_buff_failed; 247 u32 alloc_rx_buff_failed;
233 u32 rx_dma_failed; 248 u32 rx_dma_failed;
234 249
@@ -250,6 +265,9 @@ struct e1000_adapter {
250 struct e1000_phy_info phy_info; 265 struct e1000_phy_info phy_info;
251 struct e1000_phy_stats phy_stats; 266 struct e1000_phy_stats phy_stats;
252 267
268 /* Snapshot of PHY registers */
269 struct e1000_phy_regs phy_regs;
270
253 struct e1000_ring test_tx_ring; 271 struct e1000_ring test_tx_ring;
254 struct e1000_ring test_rx_ring; 272 struct e1000_ring test_rx_ring;
255 u32 test_icr; 273 u32 test_icr;
@@ -286,8 +304,6 @@ struct e1000_info {
286#define FLAG_HAS_CTRLEXT_ON_LOAD (1 << 5) 304#define FLAG_HAS_CTRLEXT_ON_LOAD (1 << 5)
287#define FLAG_HAS_SWSM_ON_LOAD (1 << 6) 305#define FLAG_HAS_SWSM_ON_LOAD (1 << 6)
288#define FLAG_HAS_JUMBO_FRAMES (1 << 7) 306#define FLAG_HAS_JUMBO_FRAMES (1 << 7)
289#define FLAG_HAS_STATS_ICR_ICT (1 << 9)
290#define FLAG_HAS_STATS_PTC_PRC (1 << 10)
291#define FLAG_HAS_SMART_POWER_DOWN (1 << 11) 307#define FLAG_HAS_SMART_POWER_DOWN (1 << 11)
292#define FLAG_IS_QUAD_PORT_A (1 << 12) 308#define FLAG_IS_QUAD_PORT_A (1 << 12)
293#define FLAG_IS_QUAD_PORT (1 << 13) 309#define FLAG_IS_QUAD_PORT (1 << 13)
@@ -433,6 +449,8 @@ extern s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data);
433extern s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations, 449extern s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
434 u32 usec_interval, bool *success); 450 u32 usec_interval, bool *success);
435extern s32 e1000e_phy_reset_dsp(struct e1000_hw *hw); 451extern s32 e1000e_phy_reset_dsp(struct e1000_hw *hw);
452extern s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data);
453extern s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data);
436extern s32 e1000e_check_downshift(struct e1000_hw *hw); 454extern s32 e1000e_check_downshift(struct e1000_hw *hw);
437 455
438static inline s32 e1000_phy_hw_reset(struct e1000_hw *hw) 456static inline s32 e1000_phy_hw_reset(struct e1000_hw *hw)
diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
index d59a99ae44be..dc552d7d6fac 100644
--- a/drivers/net/e1000e/es2lan.c
+++ b/drivers/net/e1000e/es2lan.c
@@ -41,6 +41,7 @@
41#define E1000_KMRNCTRLSTA_OFFSET_FIFO_CTRL 0x00 41#define E1000_KMRNCTRLSTA_OFFSET_FIFO_CTRL 0x00
42#define E1000_KMRNCTRLSTA_OFFSET_INB_CTRL 0x02 42#define E1000_KMRNCTRLSTA_OFFSET_INB_CTRL 0x02
43#define E1000_KMRNCTRLSTA_OFFSET_HD_CTRL 0x10 43#define E1000_KMRNCTRLSTA_OFFSET_HD_CTRL 0x10
44#define E1000_KMRNCTRLSTA_OFFSET_MAC2PHY_OPMODE 0x1F
44 45
45#define E1000_KMRNCTRLSTA_FIFO_CTRL_RX_BYPASS 0x0008 46#define E1000_KMRNCTRLSTA_FIFO_CTRL_RX_BYPASS 0x0008
46#define E1000_KMRNCTRLSTA_FIFO_CTRL_TX_BYPASS 0x0800 47#define E1000_KMRNCTRLSTA_FIFO_CTRL_TX_BYPASS 0x0800
@@ -48,6 +49,7 @@
48 49
49#define E1000_KMRNCTRLSTA_HD_CTRL_10_100_DEFAULT 0x0004 50#define E1000_KMRNCTRLSTA_HD_CTRL_10_100_DEFAULT 0x0004
50#define E1000_KMRNCTRLSTA_HD_CTRL_1000_DEFAULT 0x0000 51#define E1000_KMRNCTRLSTA_HD_CTRL_1000_DEFAULT 0x0000
52#define E1000_KMRNCTRLSTA_OPMODE_E_IDLE 0x2000
51 53
52#define E1000_TCTL_EXT_GCEX_MASK 0x000FFC00 /* Gigabit Carry Extend Padding */ 54#define E1000_TCTL_EXT_GCEX_MASK 0x000FFC00 /* Gigabit Carry Extend Padding */
53#define DEFAULT_TCTL_EXT_GCEX_80003ES2LAN 0x00010000 55#define DEFAULT_TCTL_EXT_GCEX_80003ES2LAN 0x00010000
@@ -85,6 +87,9 @@
85/* Kumeran Mode Control Register (Page 193, Register 16) */ 87/* Kumeran Mode Control Register (Page 193, Register 16) */
86#define GG82563_KMCR_PASS_FALSE_CARRIER 0x0800 88#define GG82563_KMCR_PASS_FALSE_CARRIER 0x0800
87 89
90/* Max number of times Kumeran read/write should be validated */
91#define GG82563_MAX_KMRN_RETRY 0x5
92
88/* Power Management Control Register (Page 193, Register 20) */ 93/* Power Management Control Register (Page 193, Register 20) */
89#define GG82563_PMCR_ENABLE_ELECTRICAL_IDLE 0x0001 94#define GG82563_PMCR_ENABLE_ELECTRICAL_IDLE 0x0001
90 /* 1=Enable SERDES Electrical Idle */ 95 /* 1=Enable SERDES Electrical Idle */
@@ -270,6 +275,7 @@ static s32 e1000_acquire_phy_80003es2lan(struct e1000_hw *hw)
270 u16 mask; 275 u16 mask;
271 276
272 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM; 277 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
278 mask |= E1000_SWFW_CSR_SM;
273 279
274 return e1000_acquire_swfw_sync_80003es2lan(hw, mask); 280 return e1000_acquire_swfw_sync_80003es2lan(hw, mask);
275} 281}
@@ -286,6 +292,8 @@ static void e1000_release_phy_80003es2lan(struct e1000_hw *hw)
286 u16 mask; 292 u16 mask;
287 293
288 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM; 294 mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
295 mask |= E1000_SWFW_CSR_SM;
296
289 e1000_release_swfw_sync_80003es2lan(hw, mask); 297 e1000_release_swfw_sync_80003es2lan(hw, mask);
290} 298}
291 299
@@ -410,20 +418,27 @@ static s32 e1000_read_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
410 u32 page_select; 418 u32 page_select;
411 u16 temp; 419 u16 temp;
412 420
421 ret_val = e1000_acquire_phy_80003es2lan(hw);
422 if (ret_val)
423 return ret_val;
424
413 /* Select Configuration Page */ 425 /* Select Configuration Page */
414 if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) 426 if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
415 page_select = GG82563_PHY_PAGE_SELECT; 427 page_select = GG82563_PHY_PAGE_SELECT;
416 else 428 } else {
417 /* 429 /*
418 * Use Alternative Page Select register to access 430 * Use Alternative Page Select register to access
419 * registers 30 and 31 431 * registers 30 and 31
420 */ 432 */
421 page_select = GG82563_PHY_PAGE_SELECT_ALT; 433 page_select = GG82563_PHY_PAGE_SELECT_ALT;
434 }
422 435
423 temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT); 436 temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT);
424 ret_val = e1000e_write_phy_reg_m88(hw, page_select, temp); 437 ret_val = e1000e_write_phy_reg_mdic(hw, page_select, temp);
425 if (ret_val) 438 if (ret_val) {
439 e1000_release_phy_80003es2lan(hw);
426 return ret_val; 440 return ret_val;
441 }
427 442
428 /* 443 /*
429 * The "ready" bit in the MDIC register may be incorrectly set 444 * The "ready" bit in the MDIC register may be incorrectly set
@@ -433,20 +448,21 @@ static s32 e1000_read_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
433 udelay(200); 448 udelay(200);
434 449
435 /* ...and verify the command was successful. */ 450 /* ...and verify the command was successful. */
436 ret_val = e1000e_read_phy_reg_m88(hw, page_select, &temp); 451 ret_val = e1000e_read_phy_reg_mdic(hw, page_select, &temp);
437 452
438 if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) { 453 if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) {
439 ret_val = -E1000_ERR_PHY; 454 ret_val = -E1000_ERR_PHY;
455 e1000_release_phy_80003es2lan(hw);
440 return ret_val; 456 return ret_val;
441 } 457 }
442 458
443 udelay(200); 459 udelay(200);
444 460
445 ret_val = e1000e_read_phy_reg_m88(hw, 461 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
446 MAX_PHY_REG_ADDRESS & offset, 462 data);
447 data);
448 463
449 udelay(200); 464 udelay(200);
465 e1000_release_phy_80003es2lan(hw);
450 466
451 return ret_val; 467 return ret_val;
452} 468}
@@ -467,20 +483,27 @@ static s32 e1000_write_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
467 u32 page_select; 483 u32 page_select;
468 u16 temp; 484 u16 temp;
469 485
486 ret_val = e1000_acquire_phy_80003es2lan(hw);
487 if (ret_val)
488 return ret_val;
489
470 /* Select Configuration Page */ 490 /* Select Configuration Page */
471 if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) 491 if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
472 page_select = GG82563_PHY_PAGE_SELECT; 492 page_select = GG82563_PHY_PAGE_SELECT;
473 else 493 } else {
474 /* 494 /*
475 * Use Alternative Page Select register to access 495 * Use Alternative Page Select register to access
476 * registers 30 and 31 496 * registers 30 and 31
477 */ 497 */
478 page_select = GG82563_PHY_PAGE_SELECT_ALT; 498 page_select = GG82563_PHY_PAGE_SELECT_ALT;
499 }
479 500
480 temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT); 501 temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT);
481 ret_val = e1000e_write_phy_reg_m88(hw, page_select, temp); 502 ret_val = e1000e_write_phy_reg_mdic(hw, page_select, temp);
482 if (ret_val) 503 if (ret_val) {
504 e1000_release_phy_80003es2lan(hw);
483 return ret_val; 505 return ret_val;
506 }
484 507
485 508
486 /* 509 /*
@@ -491,18 +514,20 @@ static s32 e1000_write_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
491 udelay(200); 514 udelay(200);
492 515
493 /* ...and verify the command was successful. */ 516 /* ...and verify the command was successful. */
494 ret_val = e1000e_read_phy_reg_m88(hw, page_select, &temp); 517 ret_val = e1000e_read_phy_reg_mdic(hw, page_select, &temp);
495 518
496 if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) 519 if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) {
520 e1000_release_phy_80003es2lan(hw);
497 return -E1000_ERR_PHY; 521 return -E1000_ERR_PHY;
522 }
498 523
499 udelay(200); 524 udelay(200);
500 525
501 ret_val = e1000e_write_phy_reg_m88(hw, 526 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
502 MAX_PHY_REG_ADDRESS & offset, 527 data);
503 data);
504 528
505 udelay(200); 529 udelay(200);
530 e1000_release_phy_80003es2lan(hw);
506 531
507 return ret_val; 532 return ret_val;
508} 533}
@@ -882,10 +907,10 @@ static s32 e1000_copper_link_setup_gg82563_80003es2lan(struct e1000_hw *hw)
882 struct e1000_phy_info *phy = &hw->phy; 907 struct e1000_phy_info *phy = &hw->phy;
883 s32 ret_val; 908 s32 ret_val;
884 u32 ctrl_ext; 909 u32 ctrl_ext;
885 u16 data; 910 u32 i = 0;
911 u16 data, data2;
886 912
887 ret_val = e1e_rphy(hw, GG82563_PHY_MAC_SPEC_CTRL, 913 ret_val = e1e_rphy(hw, GG82563_PHY_MAC_SPEC_CTRL, &data);
888 &data);
889 if (ret_val) 914 if (ret_val)
890 return ret_val; 915 return ret_val;
891 916
@@ -893,8 +918,7 @@ static s32 e1000_copper_link_setup_gg82563_80003es2lan(struct e1000_hw *hw)
893 /* Use 25MHz for both link down and 1000Base-T for Tx clock. */ 918 /* Use 25MHz for both link down and 1000Base-T for Tx clock. */
894 data |= GG82563_MSCR_TX_CLK_1000MBPS_25; 919 data |= GG82563_MSCR_TX_CLK_1000MBPS_25;
895 920
896 ret_val = e1e_wphy(hw, GG82563_PHY_MAC_SPEC_CTRL, 921 ret_val = e1e_wphy(hw, GG82563_PHY_MAC_SPEC_CTRL, data);
897 data);
898 if (ret_val) 922 if (ret_val)
899 return ret_val; 923 return ret_val;
900 924
@@ -954,6 +978,18 @@ static s32 e1000_copper_link_setup_gg82563_80003es2lan(struct e1000_hw *hw)
954 if (ret_val) 978 if (ret_val)
955 return ret_val; 979 return ret_val;
956 980
981 ret_val = e1000e_read_kmrn_reg(hw,
982 E1000_KMRNCTRLSTA_OFFSET_MAC2PHY_OPMODE,
983 &data);
984 if (ret_val)
985 return ret_val;
986 data |= E1000_KMRNCTRLSTA_OPMODE_E_IDLE;
987 ret_val = e1000e_write_kmrn_reg(hw,
988 E1000_KMRNCTRLSTA_OFFSET_MAC2PHY_OPMODE,
989 data);
990 if (ret_val)
991 return ret_val;
992
957 ret_val = e1e_rphy(hw, GG82563_PHY_SPEC_CTRL_2, &data); 993 ret_val = e1e_rphy(hw, GG82563_PHY_SPEC_CTRL_2, &data);
958 if (ret_val) 994 if (ret_val)
959 return ret_val; 995 return ret_val;
@@ -983,9 +1019,18 @@ static s32 e1000_copper_link_setup_gg82563_80003es2lan(struct e1000_hw *hw)
983 if (ret_val) 1019 if (ret_val)
984 return ret_val; 1020 return ret_val;
985 1021
986 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &data); 1022 do {
987 if (ret_val) 1023 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL,
988 return ret_val; 1024 &data);
1025 if (ret_val)
1026 return ret_val;
1027
1028 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL,
1029 &data2);
1030 if (ret_val)
1031 return ret_val;
1032 i++;
1033 } while ((data != data2) && (i < GG82563_MAX_KMRN_RETRY));
989 1034
990 data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; 1035 data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
991 ret_val = e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, data); 1036 ret_val = e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, data);
@@ -1074,7 +1119,8 @@ static s32 e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex)
1074{ 1119{
1075 s32 ret_val; 1120 s32 ret_val;
1076 u32 tipg; 1121 u32 tipg;
1077 u16 reg_data; 1122 u32 i = 0;
1123 u16 reg_data, reg_data2;
1078 1124
1079 reg_data = E1000_KMRNCTRLSTA_HD_CTRL_10_100_DEFAULT; 1125 reg_data = E1000_KMRNCTRLSTA_HD_CTRL_10_100_DEFAULT;
1080 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_OFFSET_HD_CTRL, 1126 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
@@ -1088,9 +1134,16 @@ static s32 e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex)
1088 tipg |= DEFAULT_TIPG_IPGT_10_100_80003ES2LAN; 1134 tipg |= DEFAULT_TIPG_IPGT_10_100_80003ES2LAN;
1089 ew32(TIPG, tipg); 1135 ew32(TIPG, tipg);
1090 1136
1091 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data); 1137 do {
1092 if (ret_val) 1138 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
1093 return ret_val; 1139 if (ret_val)
1140 return ret_val;
1141
1142 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data2);
1143 if (ret_val)
1144 return ret_val;
1145 i++;
1146 } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
1094 1147
1095 if (duplex == HALF_DUPLEX) 1148 if (duplex == HALF_DUPLEX)
1096 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER; 1149 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
@@ -1112,8 +1165,9 @@ static s32 e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex)
1112static s32 e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw) 1165static s32 e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw)
1113{ 1166{
1114 s32 ret_val; 1167 s32 ret_val;
1115 u16 reg_data; 1168 u16 reg_data, reg_data2;
1116 u32 tipg; 1169 u32 tipg;
1170 u32 i = 0;
1117 1171
1118 reg_data = E1000_KMRNCTRLSTA_HD_CTRL_1000_DEFAULT; 1172 reg_data = E1000_KMRNCTRLSTA_HD_CTRL_1000_DEFAULT;
1119 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_OFFSET_HD_CTRL, 1173 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
@@ -1127,9 +1181,16 @@ static s32 e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw)
1127 tipg |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN; 1181 tipg |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN;
1128 ew32(TIPG, tipg); 1182 ew32(TIPG, tipg);
1129 1183
1130 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data); 1184 do {
1131 if (ret_val) 1185 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
1132 return ret_val; 1186 if (ret_val)
1187 return ret_val;
1188
1189 ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data2);
1190 if (ret_val)
1191 return ret_val;
1192 i++;
1193 } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
1133 1194
1134 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; 1195 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1135 ret_val = e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); 1196 ret_val = e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
@@ -1231,12 +1292,10 @@ struct e1000_info e1000_es2_info = {
1231 .mac = e1000_80003es2lan, 1292 .mac = e1000_80003es2lan,
1232 .flags = FLAG_HAS_HW_VLAN_FILTER 1293 .flags = FLAG_HAS_HW_VLAN_FILTER
1233 | FLAG_HAS_JUMBO_FRAMES 1294 | FLAG_HAS_JUMBO_FRAMES
1234 | FLAG_HAS_STATS_PTC_PRC
1235 | FLAG_HAS_WOL 1295 | FLAG_HAS_WOL
1236 | FLAG_APME_IN_CTRL3 1296 | FLAG_APME_IN_CTRL3
1237 | FLAG_RX_CSUM_ENABLED 1297 | FLAG_RX_CSUM_ENABLED
1238 | FLAG_HAS_CTRLEXT_ON_LOAD 1298 | FLAG_HAS_CTRLEXT_ON_LOAD
1239 | FLAG_HAS_STATS_ICR_ICT
1240 | FLAG_RX_NEEDS_RESTART /* errata */ 1299 | FLAG_RX_NEEDS_RESTART /* errata */
1241 | FLAG_TARC_SET_BIT_ZERO /* errata */ 1300 | FLAG_TARC_SET_BIT_ZERO /* errata */
1242 | FLAG_APME_CHECK_PORT_B 1301 | FLAG_APME_CHECK_PORT_B
diff --git a/drivers/net/e1000e/ethtool.c b/drivers/net/e1000e/ethtool.c
index 6d1b257bbda6..ce045acce63e 100644
--- a/drivers/net/e1000e/ethtool.c
+++ b/drivers/net/e1000e/ethtool.c
@@ -46,8 +46,8 @@ struct e1000_stats {
46static const struct e1000_stats e1000_gstrings_stats[] = { 46static const struct e1000_stats e1000_gstrings_stats[] = {
47 { "rx_packets", E1000_STAT(stats.gprc) }, 47 { "rx_packets", E1000_STAT(stats.gprc) },
48 { "tx_packets", E1000_STAT(stats.gptc) }, 48 { "tx_packets", E1000_STAT(stats.gptc) },
49 { "rx_bytes", E1000_STAT(stats.gorcl) }, 49 { "rx_bytes", E1000_STAT(stats.gorc) },
50 { "tx_bytes", E1000_STAT(stats.gotcl) }, 50 { "tx_bytes", E1000_STAT(stats.gotc) },
51 { "rx_broadcast", E1000_STAT(stats.bprc) }, 51 { "rx_broadcast", E1000_STAT(stats.bprc) },
52 { "tx_broadcast", E1000_STAT(stats.bptc) }, 52 { "tx_broadcast", E1000_STAT(stats.bptc) },
53 { "rx_multicast", E1000_STAT(stats.mprc) }, 53 { "rx_multicast", E1000_STAT(stats.mprc) },
@@ -83,7 +83,7 @@ static const struct e1000_stats e1000_gstrings_stats[] = {
83 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) }, 83 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
84 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) }, 84 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
85 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) }, 85 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
86 { "rx_long_byte_count", E1000_STAT(stats.gorcl) }, 86 { "rx_long_byte_count", E1000_STAT(stats.gorc) },
87 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) }, 87 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
88 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }, 88 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
89 { "rx_header_split", E1000_STAT(rx_hdr_split) }, 89 { "rx_header_split", E1000_STAT(rx_hdr_split) },
@@ -1770,6 +1770,47 @@ static int e1000_phys_id(struct net_device *netdev, u32 data)
1770 return 0; 1770 return 0;
1771} 1771}
1772 1772
1773static int e1000_get_coalesce(struct net_device *netdev,
1774 struct ethtool_coalesce *ec)
1775{
1776 struct e1000_adapter *adapter = netdev_priv(netdev);
1777
1778 if (adapter->itr_setting <= 3)
1779 ec->rx_coalesce_usecs = adapter->itr_setting;
1780 else
1781 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1782
1783 return 0;
1784}
1785
1786static int e1000_set_coalesce(struct net_device *netdev,
1787 struct ethtool_coalesce *ec)
1788{
1789 struct e1000_adapter *adapter = netdev_priv(netdev);
1790 struct e1000_hw *hw = &adapter->hw;
1791
1792 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1793 ((ec->rx_coalesce_usecs > 3) &&
1794 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1795 (ec->rx_coalesce_usecs == 2))
1796 return -EINVAL;
1797
1798 if (ec->rx_coalesce_usecs <= 3) {
1799 adapter->itr = 20000;
1800 adapter->itr_setting = ec->rx_coalesce_usecs;
1801 } else {
1802 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1803 adapter->itr_setting = adapter->itr & ~3;
1804 }
1805
1806 if (adapter->itr_setting != 0)
1807 ew32(ITR, 1000000000 / (adapter->itr * 256));
1808 else
1809 ew32(ITR, 0);
1810
1811 return 0;
1812}
1813
1773static int e1000_nway_reset(struct net_device *netdev) 1814static int e1000_nway_reset(struct net_device *netdev)
1774{ 1815{
1775 struct e1000_adapter *adapter = netdev_priv(netdev); 1816 struct e1000_adapter *adapter = netdev_priv(netdev);
@@ -1845,6 +1886,8 @@ static const struct ethtool_ops e1000_ethtool_ops = {
1845 .phys_id = e1000_phys_id, 1886 .phys_id = e1000_phys_id,
1846 .get_ethtool_stats = e1000_get_ethtool_stats, 1887 .get_ethtool_stats = e1000_get_ethtool_stats,
1847 .get_sset_count = e1000e_get_sset_count, 1888 .get_sset_count = e1000e_get_sset_count,
1889 .get_coalesce = e1000_get_coalesce,
1890 .set_coalesce = e1000_set_coalesce,
1848}; 1891};
1849 1892
1850void e1000e_set_ethtool_ops(struct net_device *netdev) 1893void e1000e_set_ethtool_ops(struct net_device *netdev)
diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
index 53f1ac6327fa..a930e6d9cf02 100644
--- a/drivers/net/e1000e/hw.h
+++ b/drivers/net/e1000e/hw.h
@@ -592,10 +592,8 @@ struct e1000_hw_stats {
592 u64 bprc; 592 u64 bprc;
593 u64 mprc; 593 u64 mprc;
594 u64 gptc; 594 u64 gptc;
595 u64 gorcl; 595 u64 gorc;
596 u64 gorch; 596 u64 gotc;
597 u64 gotcl;
598 u64 gotch;
599 u64 rnbc; 597 u64 rnbc;
600 u64 ruc; 598 u64 ruc;
601 u64 rfc; 599 u64 rfc;
@@ -604,10 +602,8 @@ struct e1000_hw_stats {
604 u64 mgprc; 602 u64 mgprc;
605 u64 mgpdc; 603 u64 mgpdc;
606 u64 mgptc; 604 u64 mgptc;
607 u64 torl; 605 u64 tor;
608 u64 torh; 606 u64 tot;
609 u64 totl;
610 u64 toth;
611 u64 tpr; 607 u64 tpr;
612 u64 tpt; 608 u64 tpt;
613 u64 ptc64; 609 u64 ptc64;
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index c8dc47fd132a..8991ab8911e2 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -46,7 +46,7 @@
46 46
47#include "e1000.h" 47#include "e1000.h"
48 48
49#define DRV_VERSION "0.2.0" 49#define DRV_VERSION "0.2.1"
50char e1000e_driver_name[] = "e1000e"; 50char e1000e_driver_name[] = "e1000e";
51const char e1000e_driver_version[] = DRV_VERSION; 51const char e1000e_driver_version[] = DRV_VERSION;
52 52
@@ -466,10 +466,10 @@ next_desc:
466 if (cleaned_count) 466 if (cleaned_count)
467 adapter->alloc_rx_buf(adapter, cleaned_count); 467 adapter->alloc_rx_buf(adapter, cleaned_count);
468 468
469 adapter->total_rx_packets += total_rx_packets;
470 adapter->total_rx_bytes += total_rx_bytes; 469 adapter->total_rx_bytes += total_rx_bytes;
471 adapter->net_stats.rx_packets += total_rx_packets; 470 adapter->total_rx_packets += total_rx_packets;
472 adapter->net_stats.rx_bytes += total_rx_bytes; 471 adapter->net_stats.rx_bytes += total_rx_bytes;
472 adapter->net_stats.rx_packets += total_rx_packets;
473 return cleaned; 473 return cleaned;
474} 474}
475 475
@@ -606,8 +606,8 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
606 } 606 }
607 adapter->total_tx_bytes += total_tx_bytes; 607 adapter->total_tx_bytes += total_tx_bytes;
608 adapter->total_tx_packets += total_tx_packets; 608 adapter->total_tx_packets += total_tx_packets;
609 adapter->net_stats.tx_packets += total_tx_packets;
610 adapter->net_stats.tx_bytes += total_tx_bytes; 609 adapter->net_stats.tx_bytes += total_tx_bytes;
610 adapter->net_stats.tx_packets += total_tx_packets;
611 return cleaned; 611 return cleaned;
612} 612}
613 613
@@ -775,10 +775,10 @@ next_desc:
775 if (cleaned_count) 775 if (cleaned_count)
776 adapter->alloc_rx_buf(adapter, cleaned_count); 776 adapter->alloc_rx_buf(adapter, cleaned_count);
777 777
778 adapter->total_rx_packets += total_rx_packets;
779 adapter->total_rx_bytes += total_rx_bytes; 778 adapter->total_rx_bytes += total_rx_bytes;
780 adapter->net_stats.rx_packets += total_rx_packets; 779 adapter->total_rx_packets += total_rx_packets;
781 adapter->net_stats.rx_bytes += total_rx_bytes; 780 adapter->net_stats.rx_bytes += total_rx_bytes;
781 adapter->net_stats.rx_packets += total_rx_packets;
782 return cleaned; 782 return cleaned;
783} 783}
784 784
@@ -2506,56 +2506,27 @@ void e1000e_update_stats(struct e1000_adapter *adapter)
2506 2506
2507 adapter->stats.crcerrs += er32(CRCERRS); 2507 adapter->stats.crcerrs += er32(CRCERRS);
2508 adapter->stats.gprc += er32(GPRC); 2508 adapter->stats.gprc += er32(GPRC);
2509 adapter->stats.gorcl += er32(GORCL); 2509 adapter->stats.gorc += er32(GORCL);
2510 adapter->stats.gorch += er32(GORCH); 2510 er32(GORCH); /* Clear gorc */
2511 adapter->stats.bprc += er32(BPRC); 2511 adapter->stats.bprc += er32(BPRC);
2512 adapter->stats.mprc += er32(MPRC); 2512 adapter->stats.mprc += er32(MPRC);
2513 adapter->stats.roc += er32(ROC); 2513 adapter->stats.roc += er32(ROC);
2514 2514
2515 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2516 adapter->stats.prc64 += er32(PRC64);
2517 adapter->stats.prc127 += er32(PRC127);
2518 adapter->stats.prc255 += er32(PRC255);
2519 adapter->stats.prc511 += er32(PRC511);
2520 adapter->stats.prc1023 += er32(PRC1023);
2521 adapter->stats.prc1522 += er32(PRC1522);
2522 adapter->stats.symerrs += er32(SYMERRS);
2523 adapter->stats.sec += er32(SEC);
2524 }
2525
2526 adapter->stats.mpc += er32(MPC); 2515 adapter->stats.mpc += er32(MPC);
2527 adapter->stats.scc += er32(SCC); 2516 adapter->stats.scc += er32(SCC);
2528 adapter->stats.ecol += er32(ECOL); 2517 adapter->stats.ecol += er32(ECOL);
2529 adapter->stats.mcc += er32(MCC); 2518 adapter->stats.mcc += er32(MCC);
2530 adapter->stats.latecol += er32(LATECOL); 2519 adapter->stats.latecol += er32(LATECOL);
2531 adapter->stats.dc += er32(DC); 2520 adapter->stats.dc += er32(DC);
2532 adapter->stats.rlec += er32(RLEC);
2533 adapter->stats.xonrxc += er32(XONRXC); 2521 adapter->stats.xonrxc += er32(XONRXC);
2534 adapter->stats.xontxc += er32(XONTXC); 2522 adapter->stats.xontxc += er32(XONTXC);
2535 adapter->stats.xoffrxc += er32(XOFFRXC); 2523 adapter->stats.xoffrxc += er32(XOFFRXC);
2536 adapter->stats.xofftxc += er32(XOFFTXC); 2524 adapter->stats.xofftxc += er32(XOFFTXC);
2537 adapter->stats.fcruc += er32(FCRUC);
2538 adapter->stats.gptc += er32(GPTC); 2525 adapter->stats.gptc += er32(GPTC);
2539 adapter->stats.gotcl += er32(GOTCL); 2526 adapter->stats.gotc += er32(GOTCL);
2540 adapter->stats.gotch += er32(GOTCH); 2527 er32(GOTCH); /* Clear gotc */
2541 adapter->stats.rnbc += er32(RNBC); 2528 adapter->stats.rnbc += er32(RNBC);
2542 adapter->stats.ruc += er32(RUC); 2529 adapter->stats.ruc += er32(RUC);
2543 adapter->stats.rfc += er32(RFC);
2544 adapter->stats.rjc += er32(RJC);
2545 adapter->stats.torl += er32(TORL);
2546 adapter->stats.torh += er32(TORH);
2547 adapter->stats.totl += er32(TOTL);
2548 adapter->stats.toth += er32(TOTH);
2549 adapter->stats.tpr += er32(TPR);
2550
2551 if (adapter->flags & FLAG_HAS_STATS_PTC_PRC) {
2552 adapter->stats.ptc64 += er32(PTC64);
2553 adapter->stats.ptc127 += er32(PTC127);
2554 adapter->stats.ptc255 += er32(PTC255);
2555 adapter->stats.ptc511 += er32(PTC511);
2556 adapter->stats.ptc1023 += er32(PTC1023);
2557 adapter->stats.ptc1522 += er32(PTC1522);
2558 }
2559 2530
2560 adapter->stats.mptc += er32(MPTC); 2531 adapter->stats.mptc += er32(MPTC);
2561 adapter->stats.bptc += er32(BPTC); 2532 adapter->stats.bptc += er32(BPTC);
@@ -2574,19 +2545,6 @@ void e1000e_update_stats(struct e1000_adapter *adapter)
2574 adapter->stats.tsctc += er32(TSCTC); 2545 adapter->stats.tsctc += er32(TSCTC);
2575 adapter->stats.tsctfc += er32(TSCTFC); 2546 adapter->stats.tsctfc += er32(TSCTFC);
2576 2547
2577 adapter->stats.iac += er32(IAC);
2578
2579 if (adapter->flags & FLAG_HAS_STATS_ICR_ICT) {
2580 adapter->stats.icrxoc += er32(ICRXOC);
2581 adapter->stats.icrxptc += er32(ICRXPTC);
2582 adapter->stats.icrxatc += er32(ICRXATC);
2583 adapter->stats.ictxptc += er32(ICTXPTC);
2584 adapter->stats.ictxatc += er32(ICTXATC);
2585 adapter->stats.ictxqec += er32(ICTXQEC);
2586 adapter->stats.ictxqmtc += er32(ICTXQMTC);
2587 adapter->stats.icrxdmtc += er32(ICRXDMTC);
2588 }
2589
2590 /* Fill out the OS statistics structure */ 2548 /* Fill out the OS statistics structure */
2591 adapter->net_stats.multicast = adapter->stats.mprc; 2549 adapter->net_stats.multicast = adapter->stats.mprc;
2592 adapter->net_stats.collisions = adapter->stats.colc; 2550 adapter->net_stats.collisions = adapter->stats.colc;
@@ -2633,6 +2591,54 @@ void e1000e_update_stats(struct e1000_adapter *adapter)
2633 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); 2591 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
2634} 2592}
2635 2593
2594/**
2595 * e1000_phy_read_status - Update the PHY register status snapshot
2596 * @adapter: board private structure
2597 **/
2598static void e1000_phy_read_status(struct e1000_adapter *adapter)
2599{
2600 struct e1000_hw *hw = &adapter->hw;
2601 struct e1000_phy_regs *phy = &adapter->phy_regs;
2602 int ret_val;
2603 unsigned long irq_flags;
2604
2605
2606 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
2607
2608 if ((er32(STATUS) & E1000_STATUS_LU) &&
2609 (adapter->hw.phy.media_type == e1000_media_type_copper)) {
2610 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy->bmcr);
2611 ret_val |= e1e_rphy(hw, PHY_STATUS, &phy->bmsr);
2612 ret_val |= e1e_rphy(hw, PHY_AUTONEG_ADV, &phy->advertise);
2613 ret_val |= e1e_rphy(hw, PHY_LP_ABILITY, &phy->lpa);
2614 ret_val |= e1e_rphy(hw, PHY_AUTONEG_EXP, &phy->expansion);
2615 ret_val |= e1e_rphy(hw, PHY_1000T_CTRL, &phy->ctrl1000);
2616 ret_val |= e1e_rphy(hw, PHY_1000T_STATUS, &phy->stat1000);
2617 ret_val |= e1e_rphy(hw, PHY_EXT_STATUS, &phy->estatus);
2618 if (ret_val)
2619 ndev_warn(adapter->netdev,
2620 "Error reading PHY register\n");
2621 } else {
2622 /*
2623 * Do not read PHY registers if link is not up
2624 * Set values to typical power-on defaults
2625 */
2626 phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
2627 phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
2628 BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
2629 BMSR_ERCAP);
2630 phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
2631 ADVERTISE_ALL | ADVERTISE_CSMA);
2632 phy->lpa = 0;
2633 phy->expansion = EXPANSION_ENABLENPAGE;
2634 phy->ctrl1000 = ADVERTISE_1000FULL;
2635 phy->stat1000 = 0;
2636 phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
2637 }
2638
2639 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
2640}
2641
2636static void e1000_print_link_info(struct e1000_adapter *adapter) 2642static void e1000_print_link_info(struct e1000_adapter *adapter)
2637{ 2643{
2638 struct e1000_hw *hw = &adapter->hw; 2644 struct e1000_hw *hw = &adapter->hw;
@@ -2745,6 +2751,7 @@ static void e1000_watchdog_task(struct work_struct *work)
2745 if (!netif_carrier_ok(netdev)) { 2751 if (!netif_carrier_ok(netdev)) {
2746 bool txb2b = 1; 2752 bool txb2b = 1;
2747 /* update snapshot of PHY registers on LSC */ 2753 /* update snapshot of PHY registers on LSC */
2754 e1000_phy_read_status(adapter);
2748 mac->ops.get_link_up_info(&adapter->hw, 2755 mac->ops.get_link_up_info(&adapter->hw,
2749 &adapter->link_speed, 2756 &adapter->link_speed,
2750 &adapter->link_duplex); 2757 &adapter->link_duplex);
@@ -2842,10 +2849,10 @@ link_up:
2842 mac->collision_delta = adapter->stats.colc - adapter->colc_old; 2849 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
2843 adapter->colc_old = adapter->stats.colc; 2850 adapter->colc_old = adapter->stats.colc;
2844 2851
2845 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; 2852 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
2846 adapter->gorcl_old = adapter->stats.gorcl; 2853 adapter->gorc_old = adapter->stats.gorc;
2847 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; 2854 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
2848 adapter->gotcl_old = adapter->stats.gotcl; 2855 adapter->gotc_old = adapter->stats.gotc;
2849 2856
2850 e1000e_update_adaptive(&adapter->hw); 2857 e1000e_update_adaptive(&adapter->hw);
2851 2858
@@ -3500,7 +3507,6 @@ static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
3500{ 3507{
3501 struct e1000_adapter *adapter = netdev_priv(netdev); 3508 struct e1000_adapter *adapter = netdev_priv(netdev);
3502 struct mii_ioctl_data *data = if_mii(ifr); 3509 struct mii_ioctl_data *data = if_mii(ifr);
3503 unsigned long irq_flags;
3504 3510
3505 if (adapter->hw.phy.media_type != e1000_media_type_copper) 3511 if (adapter->hw.phy.media_type != e1000_media_type_copper)
3506 return -EOPNOTSUPP; 3512 return -EOPNOTSUPP;
@@ -3512,13 +3518,40 @@ static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
3512 case SIOCGMIIREG: 3518 case SIOCGMIIREG:
3513 if (!capable(CAP_NET_ADMIN)) 3519 if (!capable(CAP_NET_ADMIN))
3514 return -EPERM; 3520 return -EPERM;
3515 spin_lock_irqsave(&adapter->stats_lock, irq_flags); 3521 switch (data->reg_num & 0x1F) {
3516 if (e1e_rphy(&adapter->hw, data->reg_num & 0x1F, 3522 case MII_BMCR:
3517 &data->val_out)) { 3523 data->val_out = adapter->phy_regs.bmcr;
3518 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags); 3524 break;
3525 case MII_BMSR:
3526 data->val_out = adapter->phy_regs.bmsr;
3527 break;
3528 case MII_PHYSID1:
3529 data->val_out = (adapter->hw.phy.id >> 16);
3530 break;
3531 case MII_PHYSID2:
3532 data->val_out = (adapter->hw.phy.id & 0xFFFF);
3533 break;
3534 case MII_ADVERTISE:
3535 data->val_out = adapter->phy_regs.advertise;
3536 break;
3537 case MII_LPA:
3538 data->val_out = adapter->phy_regs.lpa;
3539 break;
3540 case MII_EXPANSION:
3541 data->val_out = adapter->phy_regs.expansion;
3542 break;
3543 case MII_CTRL1000:
3544 data->val_out = adapter->phy_regs.ctrl1000;
3545 break;
3546 case MII_STAT1000:
3547 data->val_out = adapter->phy_regs.stat1000;
3548 break;
3549 case MII_ESTATUS:
3550 data->val_out = adapter->phy_regs.estatus;
3551 break;
3552 default:
3519 return -EIO; 3553 return -EIO;
3520 } 3554 }
3521 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
3522 break; 3555 break;
3523 case SIOCSMIIREG: 3556 case SIOCSMIIREG:
3524 default: 3557 default:
@@ -3774,6 +3807,7 @@ static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
3774 return PCI_ERS_RESULT_DISCONNECT; 3807 return PCI_ERS_RESULT_DISCONNECT;
3775 } 3808 }
3776 pci_set_master(pdev); 3809 pci_set_master(pdev);
3810 pci_restore_state(pdev);
3777 3811
3778 pci_enable_wake(pdev, PCI_D3hot, 0); 3812 pci_enable_wake(pdev, PCI_D3hot, 0);
3779 pci_enable_wake(pdev, PCI_D3cold, 0); 3813 pci_enable_wake(pdev, PCI_D3cold, 0);
@@ -3900,6 +3934,7 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
3900 goto err_pci_reg; 3934 goto err_pci_reg;
3901 3935
3902 pci_set_master(pdev); 3936 pci_set_master(pdev);
3937 pci_save_state(pdev);
3903 3938
3904 err = -ENOMEM; 3939 err = -ENOMEM;
3905 netdev = alloc_etherdev(sizeof(struct e1000_adapter)); 3940 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
diff --git a/drivers/net/e1000e/phy.c b/drivers/net/e1000e/phy.c
index 3a4574caa75b..e102332a6bee 100644
--- a/drivers/net/e1000e/phy.c
+++ b/drivers/net/e1000e/phy.c
@@ -116,7 +116,7 @@ s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
116} 116}
117 117
118/** 118/**
119 * e1000_read_phy_reg_mdic - Read MDI control register 119 * e1000e_read_phy_reg_mdic - Read MDI control register
120 * @hw: pointer to the HW structure 120 * @hw: pointer to the HW structure
121 * @offset: register offset to be read 121 * @offset: register offset to be read
122 * @data: pointer to the read data 122 * @data: pointer to the read data
@@ -124,7 +124,7 @@ s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
124 * Reads the MDI control register in the PHY at offset and stores the 124 * Reads the MDI control register in the PHY at offset and stores the
125 * information read to data. 125 * information read to data.
126 **/ 126 **/
127static s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data) 127s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
128{ 128{
129 struct e1000_phy_info *phy = &hw->phy; 129 struct e1000_phy_info *phy = &hw->phy;
130 u32 i, mdic = 0; 130 u32 i, mdic = 0;
@@ -150,7 +150,7 @@ static s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
150 * Increasing the time out as testing showed failures with 150 * Increasing the time out as testing showed failures with
151 * the lower time out 151 * the lower time out
152 */ 152 */
153 for (i = 0; i < 64; i++) { 153 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
154 udelay(50); 154 udelay(50);
155 mdic = er32(MDIC); 155 mdic = er32(MDIC);
156 if (mdic & E1000_MDIC_READY) 156 if (mdic & E1000_MDIC_READY)
@@ -170,14 +170,14 @@ static s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
170} 170}
171 171
172/** 172/**
173 * e1000_write_phy_reg_mdic - Write MDI control register 173 * e1000e_write_phy_reg_mdic - Write MDI control register
174 * @hw: pointer to the HW structure 174 * @hw: pointer to the HW structure
175 * @offset: register offset to write to 175 * @offset: register offset to write to
176 * @data: data to write to register at offset 176 * @data: data to write to register at offset
177 * 177 *
178 * Writes data to MDI control register in the PHY at offset. 178 * Writes data to MDI control register in the PHY at offset.
179 **/ 179 **/
180static s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data) 180s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
181{ 181{
182 struct e1000_phy_info *phy = &hw->phy; 182 struct e1000_phy_info *phy = &hw->phy;
183 u32 i, mdic = 0; 183 u32 i, mdic = 0;
@@ -199,9 +199,13 @@ static s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
199 199
200 ew32(MDIC, mdic); 200 ew32(MDIC, mdic);
201 201
202 /* Poll the ready bit to see if the MDI read completed */ 202 /*
203 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) { 203 * Poll the ready bit to see if the MDI read completed
204 udelay(5); 204 * Increasing the time out as testing showed failures with
205 * the lower time out
206 */
207 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
208 udelay(50);
205 mdic = er32(MDIC); 209 mdic = er32(MDIC);
206 if (mdic & E1000_MDIC_READY) 210 if (mdic & E1000_MDIC_READY)
207 break; 211 break;
@@ -210,6 +214,10 @@ static s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
210 hw_dbg(hw, "MDI Write did not complete\n"); 214 hw_dbg(hw, "MDI Write did not complete\n");
211 return -E1000_ERR_PHY; 215 return -E1000_ERR_PHY;
212 } 216 }
217 if (mdic & E1000_MDIC_ERROR) {
218 hw_dbg(hw, "MDI Error\n");
219 return -E1000_ERR_PHY;
220 }
213 221
214 return 0; 222 return 0;
215} 223}
@@ -232,9 +240,8 @@ s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
232 if (ret_val) 240 if (ret_val)
233 return ret_val; 241 return ret_val;
234 242
235 ret_val = e1000_read_phy_reg_mdic(hw, 243 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
236 MAX_PHY_REG_ADDRESS & offset, 244 data);
237 data);
238 245
239 hw->phy.ops.release_phy(hw); 246 hw->phy.ops.release_phy(hw);
240 247
@@ -258,9 +265,8 @@ s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
258 if (ret_val) 265 if (ret_val)
259 return ret_val; 266 return ret_val;
260 267
261 ret_val = e1000_write_phy_reg_mdic(hw, 268 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
262 MAX_PHY_REG_ADDRESS & offset, 269 data);
263 data);
264 270
265 hw->phy.ops.release_phy(hw); 271 hw->phy.ops.release_phy(hw);
266 272
@@ -286,18 +292,17 @@ s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
286 return ret_val; 292 return ret_val;
287 293
288 if (offset > MAX_PHY_MULTI_PAGE_REG) { 294 if (offset > MAX_PHY_MULTI_PAGE_REG) {
289 ret_val = e1000_write_phy_reg_mdic(hw, 295 ret_val = e1000e_write_phy_reg_mdic(hw,
290 IGP01E1000_PHY_PAGE_SELECT, 296 IGP01E1000_PHY_PAGE_SELECT,
291 (u16)offset); 297 (u16)offset);
292 if (ret_val) { 298 if (ret_val) {
293 hw->phy.ops.release_phy(hw); 299 hw->phy.ops.release_phy(hw);
294 return ret_val; 300 return ret_val;
295 } 301 }
296 } 302 }
297 303
298 ret_val = e1000_read_phy_reg_mdic(hw, 304 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
299 MAX_PHY_REG_ADDRESS & offset, 305 data);
300 data);
301 306
302 hw->phy.ops.release_phy(hw); 307 hw->phy.ops.release_phy(hw);
303 308
@@ -322,18 +327,17 @@ s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
322 return ret_val; 327 return ret_val;
323 328
324 if (offset > MAX_PHY_MULTI_PAGE_REG) { 329 if (offset > MAX_PHY_MULTI_PAGE_REG) {
325 ret_val = e1000_write_phy_reg_mdic(hw, 330 ret_val = e1000e_write_phy_reg_mdic(hw,
326 IGP01E1000_PHY_PAGE_SELECT, 331 IGP01E1000_PHY_PAGE_SELECT,
327 (u16)offset); 332 (u16)offset);
328 if (ret_val) { 333 if (ret_val) {
329 hw->phy.ops.release_phy(hw); 334 hw->phy.ops.release_phy(hw);
330 return ret_val; 335 return ret_val;
331 } 336 }
332 } 337 }
333 338
334 ret_val = e1000_write_phy_reg_mdic(hw, 339 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
335 MAX_PHY_REG_ADDRESS & offset, 340 data);
336 data);
337 341
338 hw->phy.ops.release_phy(hw); 342 hw->phy.ops.release_phy(hw);
339 343
@@ -420,7 +424,9 @@ s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
420 if (ret_val) 424 if (ret_val)
421 return ret_val; 425 return ret_val;
422 426
423 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; 427 /* For newer PHYs this bit is downshift enable */
428 if (phy->type == e1000_phy_m88)
429 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
424 430
425 /* 431 /*
426 * Options: 432 * Options:
@@ -463,7 +469,7 @@ s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
463 if (ret_val) 469 if (ret_val)
464 return ret_val; 470 return ret_val;
465 471
466 if (phy->revision < 4) { 472 if ((phy->type == e1000_phy_m88) && (phy->revision < 4)) {
467 /* 473 /*
468 * Force TX_CLK in the Extended PHY Specific Control Register 474 * Force TX_CLK in the Extended PHY Specific Control Register
469 * to 25MHz clock. 475 * to 25MHz clock.
@@ -518,8 +524,11 @@ s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
518 return ret_val; 524 return ret_val;
519 } 525 }
520 526
521 /* Wait 15ms for MAC to configure PHY from NVM settings. */ 527 /*
522 msleep(15); 528 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
529 * timeout issues when LFS is enabled.
530 */
531 msleep(100);
523 532
524 /* disable lplu d0 during driver init */ 533 /* disable lplu d0 during driver init */
525 ret_val = e1000_set_d0_lplu_state(hw, 0); 534 ret_val = e1000_set_d0_lplu_state(hw, 0);
@@ -1152,9 +1161,7 @@ s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1152 1161
1153 if (!active) { 1162 if (!active) {
1154 data &= ~IGP02E1000_PM_D3_LPLU; 1163 data &= ~IGP02E1000_PM_D3_LPLU;
1155 ret_val = e1e_wphy(hw, 1164 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1156 IGP02E1000_PHY_POWER_MGMT,
1157 data);
1158 if (ret_val) 1165 if (ret_val)
1159 return ret_val; 1166 return ret_val;
1160 /* 1167 /*
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 9ff7538b7595..f9bc21c74b59 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -2611,7 +2611,7 @@ static int ehea_stop(struct net_device *dev)
2611 return ret; 2611 return ret;
2612} 2612}
2613 2613
2614void ehea_purge_sq(struct ehea_qp *orig_qp) 2614static void ehea_purge_sq(struct ehea_qp *orig_qp)
2615{ 2615{
2616 struct ehea_qp qp = *orig_qp; 2616 struct ehea_qp qp = *orig_qp;
2617 struct ehea_qp_init_attr *init_attr = &qp.init_attr; 2617 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
@@ -2625,7 +2625,7 @@ void ehea_purge_sq(struct ehea_qp *orig_qp)
2625 } 2625 }
2626} 2626}
2627 2627
2628void ehea_flush_sq(struct ehea_port *port) 2628static void ehea_flush_sq(struct ehea_port *port)
2629{ 2629{
2630 int i; 2630 int i;
2631 2631
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 8c4214b0ee1f..35f66d4a4595 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -96,6 +96,7 @@
96#define DEV_HAS_PAUSEFRAME_TX_V2 0x10000 /* device supports tx pause frames version 2 */ 96#define DEV_HAS_PAUSEFRAME_TX_V2 0x10000 /* device supports tx pause frames version 2 */
97#define DEV_HAS_PAUSEFRAME_TX_V3 0x20000 /* device supports tx pause frames version 3 */ 97#define DEV_HAS_PAUSEFRAME_TX_V3 0x20000 /* device supports tx pause frames version 3 */
98#define DEV_NEED_TX_LIMIT 0x40000 /* device needs to limit tx */ 98#define DEV_NEED_TX_LIMIT 0x40000 /* device needs to limit tx */
99#define DEV_HAS_GEAR_MODE 0x80000 /* device supports gear mode */
99 100
100enum { 101enum {
101 NvRegIrqStatus = 0x000, 102 NvRegIrqStatus = 0x000,
@@ -174,11 +175,13 @@ enum {
174 NvRegReceiverStatus = 0x98, 175 NvRegReceiverStatus = 0x98,
175#define NVREG_RCVSTAT_BUSY 0x01 176#define NVREG_RCVSTAT_BUSY 0x01
176 177
177 NvRegRandomSeed = 0x9c, 178 NvRegSlotTime = 0x9c,
178#define NVREG_RNDSEED_MASK 0x00ff 179#define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000
179#define NVREG_RNDSEED_FORCE 0x7f00 180#define NVREG_SLOTTIME_10_100_FULL 0x00007f00
180#define NVREG_RNDSEED_FORCE2 0x2d00 181#define NVREG_SLOTTIME_1000_FULL 0x0003ff00
181#define NVREG_RNDSEED_FORCE3 0x7400 182#define NVREG_SLOTTIME_HALF 0x0000ff00
183#define NVREG_SLOTTIME_DEFAULT 0x00007f00
184#define NVREG_SLOTTIME_MASK 0x000000ff
182 185
183 NvRegTxDeferral = 0xA0, 186 NvRegTxDeferral = 0xA0,
184#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f 187#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
@@ -201,6 +204,11 @@ enum {
201 204
202 NvRegPhyInterface = 0xC0, 205 NvRegPhyInterface = 0xC0,
203#define PHY_RGMII 0x10000000 206#define PHY_RGMII 0x10000000
207 NvRegBackOffControl = 0xC4,
208#define NVREG_BKOFFCTRL_DEFAULT 0x70000000
209#define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff
210#define NVREG_BKOFFCTRL_SELECT 24
211#define NVREG_BKOFFCTRL_GEAR 12
204 212
205 NvRegTxRingPhysAddr = 0x100, 213 NvRegTxRingPhysAddr = 0x100,
206 NvRegRxRingPhysAddr = 0x104, 214 NvRegRxRingPhysAddr = 0x104,
@@ -352,6 +360,7 @@ union ring_type {
352 360
353#define NV_TX_LASTPACKET (1<<16) 361#define NV_TX_LASTPACKET (1<<16)
354#define NV_TX_RETRYERROR (1<<19) 362#define NV_TX_RETRYERROR (1<<19)
363#define NV_TX_RETRYCOUNT_MASK (0xF<<20)
355#define NV_TX_FORCED_INTERRUPT (1<<24) 364#define NV_TX_FORCED_INTERRUPT (1<<24)
356#define NV_TX_DEFERRED (1<<26) 365#define NV_TX_DEFERRED (1<<26)
357#define NV_TX_CARRIERLOST (1<<27) 366#define NV_TX_CARRIERLOST (1<<27)
@@ -362,6 +371,7 @@ union ring_type {
362 371
363#define NV_TX2_LASTPACKET (1<<29) 372#define NV_TX2_LASTPACKET (1<<29)
364#define NV_TX2_RETRYERROR (1<<18) 373#define NV_TX2_RETRYERROR (1<<18)
374#define NV_TX2_RETRYCOUNT_MASK (0xF<<19)
365#define NV_TX2_FORCED_INTERRUPT (1<<30) 375#define NV_TX2_FORCED_INTERRUPT (1<<30)
366#define NV_TX2_DEFERRED (1<<25) 376#define NV_TX2_DEFERRED (1<<25)
367#define NV_TX2_CARRIERLOST (1<<26) 377#define NV_TX2_CARRIERLOST (1<<26)
@@ -473,16 +483,22 @@ union ring_type {
473#define DESC_VER_3 3 483#define DESC_VER_3 3
474 484
475/* PHY defines */ 485/* PHY defines */
476#define PHY_OUI_MARVELL 0x5043 486#define PHY_OUI_MARVELL 0x5043
477#define PHY_OUI_CICADA 0x03f1 487#define PHY_OUI_CICADA 0x03f1
478#define PHY_OUI_VITESSE 0x01c1 488#define PHY_OUI_VITESSE 0x01c1
479#define PHY_OUI_REALTEK 0x0732 489#define PHY_OUI_REALTEK 0x0732
490#define PHY_OUI_REALTEK2 0x0020
480#define PHYID1_OUI_MASK 0x03ff 491#define PHYID1_OUI_MASK 0x03ff
481#define PHYID1_OUI_SHFT 6 492#define PHYID1_OUI_SHFT 6
482#define PHYID2_OUI_MASK 0xfc00 493#define PHYID2_OUI_MASK 0xfc00
483#define PHYID2_OUI_SHFT 10 494#define PHYID2_OUI_SHFT 10
484#define PHYID2_MODEL_MASK 0x03f0 495#define PHYID2_MODEL_MASK 0x03f0
485#define PHY_MODEL_MARVELL_E3016 0x220 496#define PHY_MODEL_REALTEK_8211 0x0110
497#define PHY_REV_MASK 0x0001
498#define PHY_REV_REALTEK_8211B 0x0000
499#define PHY_REV_REALTEK_8211C 0x0001
500#define PHY_MODEL_REALTEK_8201 0x0200
501#define PHY_MODEL_MARVELL_E3016 0x0220
486#define PHY_MARVELL_E3016_INITMASK 0x0300 502#define PHY_MARVELL_E3016_INITMASK 0x0300
487#define PHY_CICADA_INIT1 0x0f000 503#define PHY_CICADA_INIT1 0x0f000
488#define PHY_CICADA_INIT2 0x0e00 504#define PHY_CICADA_INIT2 0x0e00
@@ -509,10 +525,18 @@ union ring_type {
509#define PHY_REALTEK_INIT_REG1 0x1f 525#define PHY_REALTEK_INIT_REG1 0x1f
510#define PHY_REALTEK_INIT_REG2 0x19 526#define PHY_REALTEK_INIT_REG2 0x19
511#define PHY_REALTEK_INIT_REG3 0x13 527#define PHY_REALTEK_INIT_REG3 0x13
528#define PHY_REALTEK_INIT_REG4 0x14
529#define PHY_REALTEK_INIT_REG5 0x18
530#define PHY_REALTEK_INIT_REG6 0x11
512#define PHY_REALTEK_INIT1 0x0000 531#define PHY_REALTEK_INIT1 0x0000
513#define PHY_REALTEK_INIT2 0x8e00 532#define PHY_REALTEK_INIT2 0x8e00
514#define PHY_REALTEK_INIT3 0x0001 533#define PHY_REALTEK_INIT3 0x0001
515#define PHY_REALTEK_INIT4 0xad17 534#define PHY_REALTEK_INIT4 0xad17
535#define PHY_REALTEK_INIT5 0xfb54
536#define PHY_REALTEK_INIT6 0xf5c7
537#define PHY_REALTEK_INIT7 0x1000
538#define PHY_REALTEK_INIT8 0x0003
539#define PHY_REALTEK_INIT_MSK1 0x0003
516 540
517#define PHY_GIGABIT 0x0100 541#define PHY_GIGABIT 0x0100
518 542
@@ -691,6 +715,7 @@ struct fe_priv {
691 int wolenabled; 715 int wolenabled;
692 unsigned int phy_oui; 716 unsigned int phy_oui;
693 unsigned int phy_model; 717 unsigned int phy_model;
718 unsigned int phy_rev;
694 u16 gigabit; 719 u16 gigabit;
695 int intr_test; 720 int intr_test;
696 int recover_error; 721 int recover_error;
@@ -704,6 +729,7 @@ struct fe_priv {
704 u32 txrxctl_bits; 729 u32 txrxctl_bits;
705 u32 vlanctl_bits; 730 u32 vlanctl_bits;
706 u32 driver_data; 731 u32 driver_data;
732 u32 device_id;
707 u32 register_size; 733 u32 register_size;
708 int rx_csum; 734 int rx_csum;
709 u32 mac_in_use; 735 u32 mac_in_use;
@@ -814,6 +840,16 @@ enum {
814}; 840};
815static int dma_64bit = NV_DMA_64BIT_ENABLED; 841static int dma_64bit = NV_DMA_64BIT_ENABLED;
816 842
843/*
844 * Crossover Detection
845 * Realtek 8201 phy + some OEM boards do not work properly.
846 */
847enum {
848 NV_CROSSOVER_DETECTION_DISABLED,
849 NV_CROSSOVER_DETECTION_ENABLED
850};
851static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED;
852
817static inline struct fe_priv *get_nvpriv(struct net_device *dev) 853static inline struct fe_priv *get_nvpriv(struct net_device *dev)
818{ 854{
819 return netdev_priv(dev); 855 return netdev_priv(dev);
@@ -1078,25 +1114,53 @@ static int phy_init(struct net_device *dev)
1078 } 1114 }
1079 } 1115 }
1080 if (np->phy_oui == PHY_OUI_REALTEK) { 1116 if (np->phy_oui == PHY_OUI_REALTEK) {
1081 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) { 1117 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1082 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1118 np->phy_rev == PHY_REV_REALTEK_8211B) {
1083 return PHY_ERROR; 1119 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1084 } 1120 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1085 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) { 1121 return PHY_ERROR;
1086 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1122 }
1087 return PHY_ERROR; 1123 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1088 } 1124 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1089 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) { 1125 return PHY_ERROR;
1090 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1126 }
1091 return PHY_ERROR; 1127 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1092 } 1128 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1093 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) { 1129 return PHY_ERROR;
1094 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1130 }
1095 return PHY_ERROR; 1131 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1132 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1133 return PHY_ERROR;
1134 }
1135 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5)) {
1136 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1137 return PHY_ERROR;
1138 }
1139 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6)) {
1140 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1141 return PHY_ERROR;
1142 }
1143 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1144 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1145 return PHY_ERROR;
1146 }
1096 } 1147 }
1097 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) { 1148 if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1098 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1149 if (np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_32 ||
1099 return PHY_ERROR; 1150 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_33 ||
1151 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_34 ||
1152 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_35 ||
1153 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_36 ||
1154 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_37 ||
1155 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_38 ||
1156 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_39) {
1157 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1158 phy_reserved |= PHY_REALTEK_INIT7;
1159 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, phy_reserved)) {
1160 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1161 return PHY_ERROR;
1162 }
1163 }
1100 } 1164 }
1101 } 1165 }
1102 1166
@@ -1236,26 +1300,71 @@ static int phy_init(struct net_device *dev)
1236 } 1300 }
1237 } 1301 }
1238 if (np->phy_oui == PHY_OUI_REALTEK) { 1302 if (np->phy_oui == PHY_OUI_REALTEK) {
1239 /* reset could have cleared these out, set them back */ 1303 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1240 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) { 1304 np->phy_rev == PHY_REV_REALTEK_8211B) {
1241 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1305 /* reset could have cleared these out, set them back */
1242 return PHY_ERROR; 1306 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1243 } 1307 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1244 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) { 1308 return PHY_ERROR;
1245 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1309 }
1246 return PHY_ERROR; 1310 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1247 } 1311 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1248 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) { 1312 return PHY_ERROR;
1249 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1313 }
1250 return PHY_ERROR; 1314 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1251 } 1315 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1252 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) { 1316 return PHY_ERROR;
1253 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1317 }
1254 return PHY_ERROR; 1318 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1319 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1320 return PHY_ERROR;
1321 }
1322 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5)) {
1323 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1324 return PHY_ERROR;
1325 }
1326 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6)) {
1327 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1328 return PHY_ERROR;
1329 }
1330 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1331 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1332 return PHY_ERROR;
1333 }
1255 } 1334 }
1256 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) { 1335 if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1257 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); 1336 if (np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_32 ||
1258 return PHY_ERROR; 1337 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_33 ||
1338 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_34 ||
1339 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_35 ||
1340 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_36 ||
1341 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_37 ||
1342 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_38 ||
1343 np->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_39) {
1344 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1345 phy_reserved |= PHY_REALTEK_INIT7;
1346 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, phy_reserved)) {
1347 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1348 return PHY_ERROR;
1349 }
1350 }
1351 if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
1352 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1353 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1354 return PHY_ERROR;
1355 }
1356 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
1357 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
1358 phy_reserved |= PHY_REALTEK_INIT3;
1359 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved)) {
1360 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1361 return PHY_ERROR;
1362 }
1363 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1364 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1365 return PHY_ERROR;
1366 }
1367 }
1259 } 1368 }
1260 } 1369 }
1261 1370
@@ -1769,6 +1878,115 @@ static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
1769 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size)); 1878 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
1770} 1879}
1771 1880
1881static void nv_legacybackoff_reseed(struct net_device *dev)
1882{
1883 u8 __iomem *base = get_hwbase(dev);
1884 u32 reg;
1885 u32 low;
1886 int tx_status = 0;
1887
1888 reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
1889 get_random_bytes(&low, sizeof(low));
1890 reg |= low & NVREG_SLOTTIME_MASK;
1891
1892 /* Need to stop tx before change takes effect.
1893 * Caller has already gained np->lock.
1894 */
1895 tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
1896 if (tx_status)
1897 nv_stop_tx(dev);
1898 nv_stop_rx(dev);
1899 writel(reg, base + NvRegSlotTime);
1900 if (tx_status)
1901 nv_start_tx(dev);
1902 nv_start_rx(dev);
1903}
1904
1905/* Gear Backoff Seeds */
1906#define BACKOFF_SEEDSET_ROWS 8
1907#define BACKOFF_SEEDSET_LFSRS 15
1908
1909/* Known Good seed sets */
1910static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
1911 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
1912 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
1913 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
1914 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
1915 {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
1916 {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
1917 {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
1918 {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184}};
1919
1920static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
1921 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
1922 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
1923 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
1924 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
1925 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
1926 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
1927 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
1928 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395}};
1929
1930static void nv_gear_backoff_reseed(struct net_device *dev)
1931{
1932 u8 __iomem *base = get_hwbase(dev);
1933 u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
1934 u32 temp, seedset, combinedSeed;
1935 int i;
1936
1937 /* Setup seed for free running LFSR */
1938 /* We are going to read the time stamp counter 3 times
1939 and swizzle bits around to increase randomness */
1940 get_random_bytes(&miniseed1, sizeof(miniseed1));
1941 miniseed1 &= 0x0fff;
1942 if (miniseed1 == 0)
1943 miniseed1 = 0xabc;
1944
1945 get_random_bytes(&miniseed2, sizeof(miniseed2));
1946 miniseed2 &= 0x0fff;
1947 if (miniseed2 == 0)
1948 miniseed2 = 0xabc;
1949 miniseed2_reversed =
1950 ((miniseed2 & 0xF00) >> 8) |
1951 (miniseed2 & 0x0F0) |
1952 ((miniseed2 & 0x00F) << 8);
1953
1954 get_random_bytes(&miniseed3, sizeof(miniseed3));
1955 miniseed3 &= 0x0fff;
1956 if (miniseed3 == 0)
1957 miniseed3 = 0xabc;
1958 miniseed3_reversed =
1959 ((miniseed3 & 0xF00) >> 8) |
1960 (miniseed3 & 0x0F0) |
1961 ((miniseed3 & 0x00F) << 8);
1962
1963 combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
1964 (miniseed2 ^ miniseed3_reversed);
1965
1966 /* Seeds can not be zero */
1967 if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
1968 combinedSeed |= 0x08;
1969 if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
1970 combinedSeed |= 0x8000;
1971
1972 /* No need to disable tx here */
1973 temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
1974 temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
1975 temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
1976 writel(temp,base + NvRegBackOffControl);
1977
1978 /* Setup seeds for all gear LFSRs. */
1979 get_random_bytes(&seedset, sizeof(seedset));
1980 seedset = seedset % BACKOFF_SEEDSET_ROWS;
1981 for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++)
1982 {
1983 temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
1984 temp |= main_seedset[seedset][i-1] & 0x3ff;
1985 temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
1986 writel(temp, base + NvRegBackOffControl);
1987 }
1988}
1989
1772/* 1990/*
1773 * nv_start_xmit: dev->hard_start_xmit function 1991 * nv_start_xmit: dev->hard_start_xmit function
1774 * Called with netif_tx_lock held. 1992 * Called with netif_tx_lock held.
@@ -2088,6 +2306,8 @@ static void nv_tx_done(struct net_device *dev)
2088 dev->stats.tx_fifo_errors++; 2306 dev->stats.tx_fifo_errors++;
2089 if (flags & NV_TX_CARRIERLOST) 2307 if (flags & NV_TX_CARRIERLOST)
2090 dev->stats.tx_carrier_errors++; 2308 dev->stats.tx_carrier_errors++;
2309 if ((flags & NV_TX_RETRYERROR) && !(flags & NV_TX_RETRYCOUNT_MASK))
2310 nv_legacybackoff_reseed(dev);
2091 dev->stats.tx_errors++; 2311 dev->stats.tx_errors++;
2092 } else { 2312 } else {
2093 dev->stats.tx_packets++; 2313 dev->stats.tx_packets++;
@@ -2103,6 +2323,8 @@ static void nv_tx_done(struct net_device *dev)
2103 dev->stats.tx_fifo_errors++; 2323 dev->stats.tx_fifo_errors++;
2104 if (flags & NV_TX2_CARRIERLOST) 2324 if (flags & NV_TX2_CARRIERLOST)
2105 dev->stats.tx_carrier_errors++; 2325 dev->stats.tx_carrier_errors++;
2326 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK))
2327 nv_legacybackoff_reseed(dev);
2106 dev->stats.tx_errors++; 2328 dev->stats.tx_errors++;
2107 } else { 2329 } else {
2108 dev->stats.tx_packets++; 2330 dev->stats.tx_packets++;
@@ -2144,6 +2366,15 @@ static void nv_tx_done_optimized(struct net_device *dev, int limit)
2144 if (flags & NV_TX2_LASTPACKET) { 2366 if (flags & NV_TX2_LASTPACKET) {
2145 if (!(flags & NV_TX2_ERROR)) 2367 if (!(flags & NV_TX2_ERROR))
2146 dev->stats.tx_packets++; 2368 dev->stats.tx_packets++;
2369 else {
2370 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
2371 if (np->driver_data & DEV_HAS_GEAR_MODE)
2372 nv_gear_backoff_reseed(dev);
2373 else
2374 nv_legacybackoff_reseed(dev);
2375 }
2376 }
2377
2147 dev_kfree_skb_any(np->get_tx_ctx->skb); 2378 dev_kfree_skb_any(np->get_tx_ctx->skb);
2148 np->get_tx_ctx->skb = NULL; 2379 np->get_tx_ctx->skb = NULL;
2149 2380
@@ -2905,15 +3136,14 @@ set_speed:
2905 } 3136 }
2906 3137
2907 if (np->gigabit == PHY_GIGABIT) { 3138 if (np->gigabit == PHY_GIGABIT) {
2908 phyreg = readl(base + NvRegRandomSeed); 3139 phyreg = readl(base + NvRegSlotTime);
2909 phyreg &= ~(0x3FF00); 3140 phyreg &= ~(0x3FF00);
2910 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) 3141 if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
2911 phyreg |= NVREG_RNDSEED_FORCE3; 3142 ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
2912 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100) 3143 phyreg |= NVREG_SLOTTIME_10_100_FULL;
2913 phyreg |= NVREG_RNDSEED_FORCE2;
2914 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000) 3144 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
2915 phyreg |= NVREG_RNDSEED_FORCE; 3145 phyreg |= NVREG_SLOTTIME_1000_FULL;
2916 writel(phyreg, base + NvRegRandomSeed); 3146 writel(phyreg, base + NvRegSlotTime);
2917 } 3147 }
2918 3148
2919 phyreg = readl(base + NvRegPhyInterface); 3149 phyreg = readl(base + NvRegPhyInterface);
@@ -4843,6 +5073,7 @@ static int nv_open(struct net_device *dev)
4843 u8 __iomem *base = get_hwbase(dev); 5073 u8 __iomem *base = get_hwbase(dev);
4844 int ret = 1; 5074 int ret = 1;
4845 int oom, i; 5075 int oom, i;
5076 u32 low;
4846 5077
4847 dprintk(KERN_DEBUG "nv_open: begin\n"); 5078 dprintk(KERN_DEBUG "nv_open: begin\n");
4848 5079
@@ -4902,8 +5133,20 @@ static int nv_open(struct net_device *dev)
4902 writel(np->rx_buf_sz, base + NvRegOffloadConfig); 5133 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4903 5134
4904 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus); 5135 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
4905 get_random_bytes(&i, sizeof(i)); 5136
4906 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed); 5137 get_random_bytes(&low, sizeof(low));
5138 low &= NVREG_SLOTTIME_MASK;
5139 if (np->desc_ver == DESC_VER_1) {
5140 writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
5141 } else {
5142 if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
5143 /* setup legacy backoff */
5144 writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
5145 } else {
5146 writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
5147 nv_gear_backoff_reseed(dev);
5148 }
5149 }
4907 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral); 5150 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
4908 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral); 5151 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
4909 if (poll_interval == -1) { 5152 if (poll_interval == -1) {
@@ -5110,6 +5353,8 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
5110 5353
5111 /* copy of driver data */ 5354 /* copy of driver data */
5112 np->driver_data = id->driver_data; 5355 np->driver_data = id->driver_data;
5356 /* copy of device id */
5357 np->device_id = id->device;
5113 5358
5114 /* handle different descriptor versions */ 5359 /* handle different descriptor versions */
5115 if (id->driver_data & DEV_HAS_HIGH_DMA) { 5360 if (id->driver_data & DEV_HAS_HIGH_DMA) {
@@ -5399,6 +5644,14 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
5399 pci_name(pci_dev), id1, id2, phyaddr); 5644 pci_name(pci_dev), id1, id2, phyaddr);
5400 np->phyaddr = phyaddr; 5645 np->phyaddr = phyaddr;
5401 np->phy_oui = id1 | id2; 5646 np->phy_oui = id1 | id2;
5647
5648 /* Realtek hardcoded phy id1 to all zero's on certain phys */
5649 if (np->phy_oui == PHY_OUI_REALTEK2)
5650 np->phy_oui = PHY_OUI_REALTEK;
5651 /* Setup phy revision for Realtek */
5652 if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
5653 np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
5654
5402 break; 5655 break;
5403 } 5656 }
5404 if (i == 33) { 5657 if (i == 33) {
@@ -5477,6 +5730,28 @@ out:
5477 return err; 5730 return err;
5478} 5731}
5479 5732
5733static void nv_restore_phy(struct net_device *dev)
5734{
5735 struct fe_priv *np = netdev_priv(dev);
5736 u16 phy_reserved, mii_control;
5737
5738 if (np->phy_oui == PHY_OUI_REALTEK &&
5739 np->phy_model == PHY_MODEL_REALTEK_8201 &&
5740 phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
5741 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
5742 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
5743 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
5744 phy_reserved |= PHY_REALTEK_INIT8;
5745 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
5746 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
5747
5748 /* restart auto negotiation */
5749 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
5750 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
5751 mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
5752 }
5753}
5754
5480static void __devexit nv_remove(struct pci_dev *pci_dev) 5755static void __devexit nv_remove(struct pci_dev *pci_dev)
5481{ 5756{
5482 struct net_device *dev = pci_get_drvdata(pci_dev); 5757 struct net_device *dev = pci_get_drvdata(pci_dev);
@@ -5493,6 +5768,9 @@ static void __devexit nv_remove(struct pci_dev *pci_dev)
5493 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV, 5768 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
5494 base + NvRegTransmitPoll); 5769 base + NvRegTransmitPoll);
5495 5770
5771 /* restore any phy related changes */
5772 nv_restore_phy(dev);
5773
5496 /* free all structures */ 5774 /* free all structures */
5497 free_rings(dev); 5775 free_rings(dev);
5498 iounmap(get_hwbase(dev)); 5776 iounmap(get_hwbase(dev));
@@ -5632,83 +5910,83 @@ static struct pci_device_id pci_tbl[] = {
5632 }, 5910 },
5633 { /* MCP65 Ethernet Controller */ 5911 { /* MCP65 Ethernet Controller */
5634 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20), 5912 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
5635 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_NEED_TX_LIMIT, 5913 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5636 }, 5914 },
5637 { /* MCP65 Ethernet Controller */ 5915 { /* MCP65 Ethernet Controller */
5638 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21), 5916 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
5639 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT, 5917 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5640 }, 5918 },
5641 { /* MCP65 Ethernet Controller */ 5919 { /* MCP65 Ethernet Controller */
5642 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22), 5920 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
5643 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT, 5921 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5644 }, 5922 },
5645 { /* MCP65 Ethernet Controller */ 5923 { /* MCP65 Ethernet Controller */
5646 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23), 5924 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
5647 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT, 5925 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5648 }, 5926 },
5649 { /* MCP67 Ethernet Controller */ 5927 { /* MCP67 Ethernet Controller */
5650 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24), 5928 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24),
5651 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR, 5929 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE,
5652 }, 5930 },
5653 { /* MCP67 Ethernet Controller */ 5931 { /* MCP67 Ethernet Controller */
5654 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25), 5932 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25),
5655 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR, 5933 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE,
5656 }, 5934 },
5657 { /* MCP67 Ethernet Controller */ 5935 { /* MCP67 Ethernet Controller */
5658 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26), 5936 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26),
5659 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR, 5937 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE,
5660 }, 5938 },
5661 { /* MCP67 Ethernet Controller */ 5939 { /* MCP67 Ethernet Controller */
5662 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27), 5940 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27),
5663 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR, 5941 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE,
5664 }, 5942 },
5665 { /* MCP73 Ethernet Controller */ 5943 { /* MCP73 Ethernet Controller */
5666 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_28), 5944 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_28),
5667 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX, 5945 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE,
5668 }, 5946 },
5669 { /* MCP73 Ethernet Controller */ 5947 { /* MCP73 Ethernet Controller */
5670 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_29), 5948 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_29),
5671 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX, 5949 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE,
5672 }, 5950 },
5673 { /* MCP73 Ethernet Controller */ 5951 { /* MCP73 Ethernet Controller */
5674 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_30), 5952 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_30),
5675 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX, 5953 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE,
5676 }, 5954 },
5677 { /* MCP73 Ethernet Controller */ 5955 { /* MCP73 Ethernet Controller */
5678 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_31), 5956 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_31),
5679 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX, 5957 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE,
5680 }, 5958 },
5681 { /* MCP77 Ethernet Controller */ 5959 { /* MCP77 Ethernet Controller */
5682 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_32), 5960 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_32),
5683 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5961 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5684 }, 5962 },
5685 { /* MCP77 Ethernet Controller */ 5963 { /* MCP77 Ethernet Controller */
5686 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_33), 5964 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_33),
5687 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5965 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5688 }, 5966 },
5689 { /* MCP77 Ethernet Controller */ 5967 { /* MCP77 Ethernet Controller */
5690 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_34), 5968 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_34),
5691 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5969 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5692 }, 5970 },
5693 { /* MCP77 Ethernet Controller */ 5971 { /* MCP77 Ethernet Controller */
5694 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_35), 5972 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_35),
5695 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5973 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5696 }, 5974 },
5697 { /* MCP79 Ethernet Controller */ 5975 { /* MCP79 Ethernet Controller */
5698 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_36), 5976 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_36),
5699 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5977 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5700 }, 5978 },
5701 { /* MCP79 Ethernet Controller */ 5979 { /* MCP79 Ethernet Controller */
5702 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_37), 5980 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_37),
5703 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5981 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5704 }, 5982 },
5705 { /* MCP79 Ethernet Controller */ 5983 { /* MCP79 Ethernet Controller */
5706 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_38), 5984 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_38),
5707 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5985 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5708 }, 5986 },
5709 { /* MCP79 Ethernet Controller */ 5987 { /* MCP79 Ethernet Controller */
5710 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_39), 5988 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_39),
5711 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT, 5989 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE,
5712 }, 5990 },
5713 {0,}, 5991 {0,},
5714}; 5992};
@@ -5744,6 +6022,8 @@ module_param(msix, int, 0);
5744MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0."); 6022MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
5745module_param(dma_64bit, int, 0); 6023module_param(dma_64bit, int, 0);
5746MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0."); 6024MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
6025module_param(phy_cross, int, 0);
6026MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0.");
5747 6027
5748MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>"); 6028MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
5749MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver"); 6029MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index c8c3df737d73..99a4b990939f 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -98,7 +98,6 @@
98#include "gianfar_mii.h" 98#include "gianfar_mii.h"
99 99
100#define TX_TIMEOUT (1*HZ) 100#define TX_TIMEOUT (1*HZ)
101#define SKB_ALLOC_TIMEOUT 1000000
102#undef BRIEF_GFAR_ERRORS 101#undef BRIEF_GFAR_ERRORS
103#undef VERBOSE_GFAR_ERRORS 102#undef VERBOSE_GFAR_ERRORS
104 103
@@ -115,7 +114,9 @@ static int gfar_enet_open(struct net_device *dev);
115static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); 114static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
116static void gfar_timeout(struct net_device *dev); 115static void gfar_timeout(struct net_device *dev);
117static int gfar_close(struct net_device *dev); 116static int gfar_close(struct net_device *dev);
118struct sk_buff *gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp); 117struct sk_buff *gfar_new_skb(struct net_device *dev);
118static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
119 struct sk_buff *skb);
119static int gfar_set_mac_address(struct net_device *dev); 120static int gfar_set_mac_address(struct net_device *dev);
120static int gfar_change_mtu(struct net_device *dev, int new_mtu); 121static int gfar_change_mtu(struct net_device *dev, int new_mtu);
121static irqreturn_t gfar_error(int irq, void *dev_id); 122static irqreturn_t gfar_error(int irq, void *dev_id);
@@ -783,14 +784,21 @@ int startup_gfar(struct net_device *dev)
783 784
784 rxbdp = priv->rx_bd_base; 785 rxbdp = priv->rx_bd_base;
785 for (i = 0; i < priv->rx_ring_size; i++) { 786 for (i = 0; i < priv->rx_ring_size; i++) {
786 struct sk_buff *skb = NULL; 787 struct sk_buff *skb;
787 788
788 rxbdp->status = 0; 789 skb = gfar_new_skb(dev);
789 790
790 skb = gfar_new_skb(dev, rxbdp); 791 if (!skb) {
792 printk(KERN_ERR "%s: Can't allocate RX buffers\n",
793 dev->name);
794
795 goto err_rxalloc_fail;
796 }
791 797
792 priv->rx_skbuff[i] = skb; 798 priv->rx_skbuff[i] = skb;
793 799
800 gfar_new_rxbdp(dev, rxbdp, skb);
801
794 rxbdp++; 802 rxbdp++;
795 } 803 }
796 804
@@ -916,6 +924,7 @@ rx_irq_fail:
916tx_irq_fail: 924tx_irq_fail:
917 free_irq(priv->interruptError, dev); 925 free_irq(priv->interruptError, dev);
918err_irq_fail: 926err_irq_fail:
927err_rxalloc_fail:
919rx_skb_fail: 928rx_skb_fail:
920 free_skb_resources(priv); 929 free_skb_resources(priv);
921tx_skb_fail: 930tx_skb_fail:
@@ -1328,18 +1337,37 @@ static irqreturn_t gfar_transmit(int irq, void *dev_id)
1328 return IRQ_HANDLED; 1337 return IRQ_HANDLED;
1329} 1338}
1330 1339
1331struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp) 1340static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
1341 struct sk_buff *skb)
1342{
1343 struct gfar_private *priv = netdev_priv(dev);
1344 u32 * status_len = (u32 *)bdp;
1345 u16 flags;
1346
1347 bdp->bufPtr = dma_map_single(&dev->dev, skb->data,
1348 priv->rx_buffer_size, DMA_FROM_DEVICE);
1349
1350 flags = RXBD_EMPTY | RXBD_INTERRUPT;
1351
1352 if (bdp == priv->rx_bd_base + priv->rx_ring_size - 1)
1353 flags |= RXBD_WRAP;
1354
1355 eieio();
1356
1357 *status_len = (u32)flags << 16;
1358}
1359
1360
1361struct sk_buff * gfar_new_skb(struct net_device *dev)
1332{ 1362{
1333 unsigned int alignamount; 1363 unsigned int alignamount;
1334 struct gfar_private *priv = netdev_priv(dev); 1364 struct gfar_private *priv = netdev_priv(dev);
1335 struct sk_buff *skb = NULL; 1365 struct sk_buff *skb = NULL;
1336 unsigned int timeout = SKB_ALLOC_TIMEOUT;
1337 1366
1338 /* We have to allocate the skb, so keep trying till we succeed */ 1367 /* We have to allocate the skb, so keep trying till we succeed */
1339 while ((!skb) && timeout--) 1368 skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT);
1340 skb = dev_alloc_skb(priv->rx_buffer_size + RXBUF_ALIGNMENT);
1341 1369
1342 if (NULL == skb) 1370 if (!skb)
1343 return NULL; 1371 return NULL;
1344 1372
1345 alignamount = RXBUF_ALIGNMENT - 1373 alignamount = RXBUF_ALIGNMENT -
@@ -1350,15 +1378,6 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
1350 */ 1378 */
1351 skb_reserve(skb, alignamount); 1379 skb_reserve(skb, alignamount);
1352 1380
1353 bdp->bufPtr = dma_map_single(&dev->dev, skb->data,
1354 priv->rx_buffer_size, DMA_FROM_DEVICE);
1355
1356 bdp->length = 0;
1357
1358 /* Mark the buffer empty */
1359 eieio();
1360 bdp->status |= (RXBD_EMPTY | RXBD_INTERRUPT);
1361
1362 return skb; 1381 return skb;
1363} 1382}
1364 1383
@@ -1544,10 +1563,31 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
1544 bdp = priv->cur_rx; 1563 bdp = priv->cur_rx;
1545 1564
1546 while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) { 1565 while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
1566 struct sk_buff *newskb;
1547 rmb(); 1567 rmb();
1568
1569 /* Add another skb for the future */
1570 newskb = gfar_new_skb(dev);
1571
1548 skb = priv->rx_skbuff[priv->skb_currx]; 1572 skb = priv->rx_skbuff[priv->skb_currx];
1549 1573
1550 if ((bdp->status & RXBD_LAST) && !(bdp->status & RXBD_ERR)) { 1574 /* We drop the frame if we failed to allocate a new buffer */
1575 if (unlikely(!newskb || !(bdp->status & RXBD_LAST) ||
1576 bdp->status & RXBD_ERR)) {
1577 count_errors(bdp->status, dev);
1578
1579 if (unlikely(!newskb))
1580 newskb = skb;
1581
1582 if (skb) {
1583 dma_unmap_single(&priv->dev->dev,
1584 bdp->bufPtr,
1585 priv->rx_buffer_size,
1586 DMA_FROM_DEVICE);
1587
1588 dev_kfree_skb_any(skb);
1589 }
1590 } else {
1551 /* Increment the number of packets */ 1591 /* Increment the number of packets */
1552 dev->stats.rx_packets++; 1592 dev->stats.rx_packets++;
1553 howmany++; 1593 howmany++;
@@ -1558,23 +1598,14 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
1558 gfar_process_frame(dev, skb, pkt_len); 1598 gfar_process_frame(dev, skb, pkt_len);
1559 1599
1560 dev->stats.rx_bytes += pkt_len; 1600 dev->stats.rx_bytes += pkt_len;
1561 } else {
1562 count_errors(bdp->status, dev);
1563
1564 if (skb)
1565 dev_kfree_skb_any(skb);
1566
1567 priv->rx_skbuff[priv->skb_currx] = NULL;
1568 } 1601 }
1569 1602
1570 dev->last_rx = jiffies; 1603 dev->last_rx = jiffies;
1571 1604
1572 /* Clear the status flags for this buffer */ 1605 priv->rx_skbuff[priv->skb_currx] = newskb;
1573 bdp->status &= ~RXBD_STATS;
1574 1606
1575 /* Add another skb for the future */ 1607 /* Setup the new bdp */
1576 skb = gfar_new_skb(dev, bdp); 1608 gfar_new_rxbdp(dev, bdp, newskb);
1577 priv->rx_skbuff[priv->skb_currx] = skb;
1578 1609
1579 /* Update to the next pointer */ 1610 /* Update to the next pointer */
1580 if (bdp->status & RXBD_WRAP) 1611 if (bdp->status & RXBD_WRAP)
@@ -1584,9 +1615,8 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
1584 1615
1585 /* update to point at the next skb */ 1616 /* update to point at the next skb */
1586 priv->skb_currx = 1617 priv->skb_currx =
1587 (priv->skb_currx + 1618 (priv->skb_currx + 1) &
1588 1) & RX_RING_MOD_MASK(priv->rx_ring_size); 1619 RX_RING_MOD_MASK(priv->rx_ring_size);
1589
1590 } 1620 }
1591 1621
1592 /* Update the current rxbd pointer to be the next one */ 1622 /* Update the current rxbd pointer to be the next one */
@@ -2001,12 +2031,16 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
2001 return IRQ_HANDLED; 2031 return IRQ_HANDLED;
2002} 2032}
2003 2033
2034/* work with hotplug and coldplug */
2035MODULE_ALIAS("platform:fsl-gianfar");
2036
2004/* Structure for a device driver */ 2037/* Structure for a device driver */
2005static struct platform_driver gfar_driver = { 2038static struct platform_driver gfar_driver = {
2006 .probe = gfar_probe, 2039 .probe = gfar_probe,
2007 .remove = gfar_remove, 2040 .remove = gfar_remove,
2008 .driver = { 2041 .driver = {
2009 .name = "fsl-gianfar", 2042 .name = "fsl-gianfar",
2043 .owner = THIS_MODULE,
2010 }, 2044 },
2011}; 2045};
2012 2046
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 378a23963495..5d2108c5ac7c 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -43,6 +43,8 @@
43#include <asm/io.h> 43#include <asm/io.h>
44#include <asm/dma.h> 44#include <asm/dma.h>
45#include <asm/uaccess.h> 45#include <asm/uaccess.h>
46#include <asm/dcr.h>
47#include <asm/dcr-regs.h>
46 48
47#include "core.h" 49#include "core.h"
48 50
@@ -127,10 +129,35 @@ static struct device_node *emac_boot_list[EMAC_BOOT_LIST_SIZE];
127static inline void emac_report_timeout_error(struct emac_instance *dev, 129static inline void emac_report_timeout_error(struct emac_instance *dev,
128 const char *error) 130 const char *error)
129{ 131{
130 if (net_ratelimit()) 132 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX |
133 EMAC_FTR_440EP_PHY_CLK_FIX))
134 DBG(dev, "%s" NL, error);
135 else if (net_ratelimit())
131 printk(KERN_ERR "%s: %s\n", dev->ndev->name, error); 136 printk(KERN_ERR "%s: %s\n", dev->ndev->name, error);
132} 137}
133 138
139/* EMAC PHY clock workaround:
140 * 440EP/440GR has more sane SDR0_MFR register implementation than 440GX,
141 * which allows controlling each EMAC clock
142 */
143static inline void emac_rx_clk_tx(struct emac_instance *dev)
144{
145#ifdef CONFIG_PPC_DCR_NATIVE
146 if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX))
147 dcri_clrset(SDR0, SDR0_MFR,
148 0, SDR0_MFR_ECS >> dev->cell_index);
149#endif
150}
151
152static inline void emac_rx_clk_default(struct emac_instance *dev)
153{
154#ifdef CONFIG_PPC_DCR_NATIVE
155 if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX))
156 dcri_clrset(SDR0, SDR0_MFR,
157 SDR0_MFR_ECS >> dev->cell_index, 0);
158#endif
159}
160
134/* PHY polling intervals */ 161/* PHY polling intervals */
135#define PHY_POLL_LINK_ON HZ 162#define PHY_POLL_LINK_ON HZ
136#define PHY_POLL_LINK_OFF (HZ / 5) 163#define PHY_POLL_LINK_OFF (HZ / 5)
@@ -524,7 +551,10 @@ static int emac_configure(struct emac_instance *dev)
524 rx_size = dev->rx_fifo_size_gige; 551 rx_size = dev->rx_fifo_size_gige;
525 552
526 if (dev->ndev->mtu > ETH_DATA_LEN) { 553 if (dev->ndev->mtu > ETH_DATA_LEN) {
527 mr1 |= EMAC_MR1_JPSM; 554 if (emac_has_feature(dev, EMAC_FTR_EMAC4))
555 mr1 |= EMAC4_MR1_JPSM;
556 else
557 mr1 |= EMAC_MR1_JPSM;
528 dev->stop_timeout = STOP_TIMEOUT_1000_JUMBO; 558 dev->stop_timeout = STOP_TIMEOUT_1000_JUMBO;
529 } else 559 } else
530 dev->stop_timeout = STOP_TIMEOUT_1000; 560 dev->stop_timeout = STOP_TIMEOUT_1000;
@@ -708,7 +738,7 @@ static int __emac_mdio_read(struct emac_instance *dev, u8 id, u8 reg)
708 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); 738 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port);
709 739
710 /* Wait for management interface to become idle */ 740 /* Wait for management interface to become idle */
711 n = 10; 741 n = 20;
712 while (!emac_phy_done(dev, in_be32(&p->stacr))) { 742 while (!emac_phy_done(dev, in_be32(&p->stacr))) {
713 udelay(1); 743 udelay(1);
714 if (!--n) { 744 if (!--n) {
@@ -733,7 +763,7 @@ static int __emac_mdio_read(struct emac_instance *dev, u8 id, u8 reg)
733 out_be32(&p->stacr, r); 763 out_be32(&p->stacr, r);
734 764
735 /* Wait for read to complete */ 765 /* Wait for read to complete */
736 n = 100; 766 n = 200;
737 while (!emac_phy_done(dev, (r = in_be32(&p->stacr)))) { 767 while (!emac_phy_done(dev, (r = in_be32(&p->stacr)))) {
738 udelay(1); 768 udelay(1);
739 if (!--n) { 769 if (!--n) {
@@ -780,7 +810,7 @@ static void __emac_mdio_write(struct emac_instance *dev, u8 id, u8 reg,
780 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); 810 rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port);
781 811
782 /* Wait for management interface to be idle */ 812 /* Wait for management interface to be idle */
783 n = 10; 813 n = 20;
784 while (!emac_phy_done(dev, in_be32(&p->stacr))) { 814 while (!emac_phy_done(dev, in_be32(&p->stacr))) {
785 udelay(1); 815 udelay(1);
786 if (!--n) { 816 if (!--n) {
@@ -806,7 +836,7 @@ static void __emac_mdio_write(struct emac_instance *dev, u8 id, u8 reg,
806 out_be32(&p->stacr, r); 836 out_be32(&p->stacr, r);
807 837
808 /* Wait for write to complete */ 838 /* Wait for write to complete */
809 n = 100; 839 n = 200;
810 while (!emac_phy_done(dev, in_be32(&p->stacr))) { 840 while (!emac_phy_done(dev, in_be32(&p->stacr))) {
811 udelay(1); 841 udelay(1);
812 if (!--n) { 842 if (!--n) {
@@ -1094,9 +1124,11 @@ static int emac_open(struct net_device *ndev)
1094 int link_poll_interval; 1124 int link_poll_interval;
1095 if (dev->phy.def->ops->poll_link(&dev->phy)) { 1125 if (dev->phy.def->ops->poll_link(&dev->phy)) {
1096 dev->phy.def->ops->read_link(&dev->phy); 1126 dev->phy.def->ops->read_link(&dev->phy);
1127 emac_rx_clk_default(dev);
1097 netif_carrier_on(dev->ndev); 1128 netif_carrier_on(dev->ndev);
1098 link_poll_interval = PHY_POLL_LINK_ON; 1129 link_poll_interval = PHY_POLL_LINK_ON;
1099 } else { 1130 } else {
1131 emac_rx_clk_tx(dev);
1100 netif_carrier_off(dev->ndev); 1132 netif_carrier_off(dev->ndev);
1101 link_poll_interval = PHY_POLL_LINK_OFF; 1133 link_poll_interval = PHY_POLL_LINK_OFF;
1102 } 1134 }
@@ -1174,6 +1206,7 @@ static void emac_link_timer(struct work_struct *work)
1174 1206
1175 if (dev->phy.def->ops->poll_link(&dev->phy)) { 1207 if (dev->phy.def->ops->poll_link(&dev->phy)) {
1176 if (!netif_carrier_ok(dev->ndev)) { 1208 if (!netif_carrier_ok(dev->ndev)) {
1209 emac_rx_clk_default(dev);
1177 /* Get new link parameters */ 1210 /* Get new link parameters */
1178 dev->phy.def->ops->read_link(&dev->phy); 1211 dev->phy.def->ops->read_link(&dev->phy);
1179 1212
@@ -1186,6 +1219,7 @@ static void emac_link_timer(struct work_struct *work)
1186 link_poll_interval = PHY_POLL_LINK_ON; 1219 link_poll_interval = PHY_POLL_LINK_ON;
1187 } else { 1220 } else {
1188 if (netif_carrier_ok(dev->ndev)) { 1221 if (netif_carrier_ok(dev->ndev)) {
1222 emac_rx_clk_tx(dev);
1189 netif_carrier_off(dev->ndev); 1223 netif_carrier_off(dev->ndev);
1190 netif_tx_disable(dev->ndev); 1224 netif_tx_disable(dev->ndev);
1191 emac_reinitialize(dev); 1225 emac_reinitialize(dev);
@@ -2237,7 +2271,7 @@ static int __devinit emac_of_bus_notify(struct notifier_block *nb,
2237 return 0; 2271 return 0;
2238} 2272}
2239 2273
2240static struct notifier_block emac_of_bus_notifier = { 2274static struct notifier_block emac_of_bus_notifier __devinitdata = {
2241 .notifier_call = emac_of_bus_notify 2275 .notifier_call = emac_of_bus_notify
2242}; 2276};
2243 2277
@@ -2330,6 +2364,19 @@ static int __devinit emac_init_phy(struct emac_instance *dev)
2330 dev->phy.mdio_read = emac_mdio_read; 2364 dev->phy.mdio_read = emac_mdio_read;
2331 dev->phy.mdio_write = emac_mdio_write; 2365 dev->phy.mdio_write = emac_mdio_write;
2332 2366
2367 /* Enable internal clock source */
2368#ifdef CONFIG_PPC_DCR_NATIVE
2369 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX))
2370 dcri_clrset(SDR0, SDR0_MFR, 0, SDR0_MFR_ECS);
2371#endif
2372 /* PHY clock workaround */
2373 emac_rx_clk_tx(dev);
2374
2375 /* Enable internal clock source on 440GX*/
2376#ifdef CONFIG_PPC_DCR_NATIVE
2377 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX))
2378 dcri_clrset(SDR0, SDR0_MFR, 0, SDR0_MFR_ECS);
2379#endif
2333 /* Configure EMAC with defaults so we can at least use MDIO 2380 /* Configure EMAC with defaults so we can at least use MDIO
2334 * This is needed mostly for 440GX 2381 * This is needed mostly for 440GX
2335 */ 2382 */
@@ -2362,6 +2409,12 @@ static int __devinit emac_init_phy(struct emac_instance *dev)
2362 if (!emac_mii_phy_probe(&dev->phy, i)) 2409 if (!emac_mii_phy_probe(&dev->phy, i))
2363 break; 2410 break;
2364 } 2411 }
2412
2413 /* Enable external clock source */
2414#ifdef CONFIG_PPC_DCR_NATIVE
2415 if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX))
2416 dcri_clrset(SDR0, SDR0_MFR, SDR0_MFR_ECS, 0);
2417#endif
2365 mutex_unlock(&emac_phy_map_lock); 2418 mutex_unlock(&emac_phy_map_lock);
2366 if (i == 0x20) { 2419 if (i == 0x20) {
2367 printk(KERN_WARNING "%s: can't find PHY!\n", np->full_name); 2420 printk(KERN_WARNING "%s: can't find PHY!\n", np->full_name);
@@ -2487,8 +2540,15 @@ static int __devinit emac_init_config(struct emac_instance *dev)
2487 } 2540 }
2488 2541
2489 /* Check EMAC version */ 2542 /* Check EMAC version */
2490 if (of_device_is_compatible(np, "ibm,emac4")) 2543 if (of_device_is_compatible(np, "ibm,emac4")) {
2491 dev->features |= EMAC_FTR_EMAC4; 2544 dev->features |= EMAC_FTR_EMAC4;
2545 if (of_device_is_compatible(np, "ibm,emac-440gx"))
2546 dev->features |= EMAC_FTR_440GX_PHY_CLK_FIX;
2547 } else {
2548 if (of_device_is_compatible(np, "ibm,emac-440ep") ||
2549 of_device_is_compatible(np, "ibm,emac-440gr"))
2550 dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX;
2551 }
2492 2552
2493 /* Fixup some feature bits based on the device tree */ 2553 /* Fixup some feature bits based on the device tree */
2494 if (of_get_property(np, "has-inverted-stacr-oc", NULL)) 2554 if (of_get_property(np, "has-inverted-stacr-oc", NULL))
@@ -2559,8 +2619,11 @@ static int __devinit emac_probe(struct of_device *ofdev,
2559 struct device_node **blist = NULL; 2619 struct device_node **blist = NULL;
2560 int err, i; 2620 int err, i;
2561 2621
2562 /* Skip unused/unwired EMACS */ 2622 /* Skip unused/unwired EMACS. We leave the check for an unused
2563 if (of_get_property(np, "unused", NULL)) 2623 * property here for now, but new flat device trees should set a
2624 * status property to "disabled" instead.
2625 */
2626 if (of_get_property(np, "unused", NULL) || !of_device_is_available(np))
2564 return -ENODEV; 2627 return -ENODEV;
2565 2628
2566 /* Find ourselves in the bootlist if we are there */ 2629 /* Find ourselves in the bootlist if we are there */
diff --git a/drivers/net/ibm_newemac/core.h b/drivers/net/ibm_newemac/core.h
index 4e74d8287c65..1683db9870a4 100644
--- a/drivers/net/ibm_newemac/core.h
+++ b/drivers/net/ibm_newemac/core.h
@@ -301,6 +301,14 @@ struct emac_instance {
301 * Set if we have new type STACR with STAOPC 301 * Set if we have new type STACR with STAOPC
302 */ 302 */
303#define EMAC_FTR_HAS_NEW_STACR 0x00000040 303#define EMAC_FTR_HAS_NEW_STACR 0x00000040
304/*
305 * Set if we need phy clock workaround for 440gx
306 */
307#define EMAC_FTR_440GX_PHY_CLK_FIX 0x00000080
308/*
309 * Set if we need phy clock workaround for 440ep or 440gr
310 */
311#define EMAC_FTR_440EP_PHY_CLK_FIX 0x00000100
304 312
305 313
306/* Right now, we don't quite handle the always/possible masks on the 314/* Right now, we don't quite handle the always/possible masks on the
@@ -312,8 +320,8 @@ enum {
312 320
313 EMAC_FTRS_POSSIBLE = 321 EMAC_FTRS_POSSIBLE =
314#ifdef CONFIG_IBM_NEW_EMAC_EMAC4 322#ifdef CONFIG_IBM_NEW_EMAC_EMAC4
315 EMAC_FTR_EMAC4 | EMAC_FTR_HAS_NEW_STACR | 323 EMAC_FTR_EMAC4 | EMAC_FTR_HAS_NEW_STACR |
316 EMAC_FTR_STACR_OC_INVERT | 324 EMAC_FTR_STACR_OC_INVERT | EMAC_FTR_440GX_PHY_CLK_FIX |
317#endif 325#endif
318#ifdef CONFIG_IBM_NEW_EMAC_TAH 326#ifdef CONFIG_IBM_NEW_EMAC_TAH
319 EMAC_FTR_HAS_TAH | 327 EMAC_FTR_HAS_TAH |
@@ -324,7 +332,7 @@ enum {
324#ifdef CONFIG_IBM_NEW_EMAC_RGMII 332#ifdef CONFIG_IBM_NEW_EMAC_RGMII
325 EMAC_FTR_HAS_RGMII | 333 EMAC_FTR_HAS_RGMII |
326#endif 334#endif
327 0, 335 EMAC_FTR_440EP_PHY_CLK_FIX,
328}; 336};
329 337
330static inline int emac_has_feature(struct emac_instance *dev, 338static inline int emac_has_feature(struct emac_instance *dev,
diff --git a/drivers/net/ibm_newemac/mal.c b/drivers/net/ibm_newemac/mal.c
index 6869f08c9dcb..10c267b2b961 100644
--- a/drivers/net/ibm_newemac/mal.c
+++ b/drivers/net/ibm_newemac/mal.c
@@ -61,8 +61,8 @@ int __devinit mal_register_commac(struct mal_instance *mal,
61 return 0; 61 return 0;
62} 62}
63 63
64void __devexit mal_unregister_commac(struct mal_instance *mal, 64void mal_unregister_commac(struct mal_instance *mal,
65 struct mal_commac *commac) 65 struct mal_commac *commac)
66{ 66{
67 unsigned long flags; 67 unsigned long flags;
68 68
@@ -136,6 +136,14 @@ void mal_enable_rx_channel(struct mal_instance *mal, int channel)
136{ 136{
137 unsigned long flags; 137 unsigned long flags;
138 138
139 /*
140 * On some 4xx PPC's (e.g. 460EX/GT), the rx channel is a multiple
141 * of 8, but enabling in MAL_RXCASR needs the divided by 8 value
142 * for the bitmask
143 */
144 if (!(channel % 8))
145 channel >>= 3;
146
139 spin_lock_irqsave(&mal->lock, flags); 147 spin_lock_irqsave(&mal->lock, flags);
140 148
141 MAL_DBG(mal, "enable_rx(%d)" NL, channel); 149 MAL_DBG(mal, "enable_rx(%d)" NL, channel);
@@ -148,6 +156,14 @@ void mal_enable_rx_channel(struct mal_instance *mal, int channel)
148 156
149void mal_disable_rx_channel(struct mal_instance *mal, int channel) 157void mal_disable_rx_channel(struct mal_instance *mal, int channel)
150{ 158{
159 /*
160 * On some 4xx PPC's (e.g. 460EX/GT), the rx channel is a multiple
161 * of 8, but enabling in MAL_RXCASR needs the divided by 8 value
162 * for the bitmask
163 */
164 if (!(channel % 8))
165 channel >>= 3;
166
151 set_mal_dcrn(mal, MAL_RXCARR, MAL_CHAN_MASK(channel)); 167 set_mal_dcrn(mal, MAL_RXCARR, MAL_CHAN_MASK(channel));
152 168
153 MAL_DBG(mal, "disable_rx(%d)" NL, channel); 169 MAL_DBG(mal, "disable_rx(%d)" NL, channel);
diff --git a/drivers/net/ibm_newemac/rgmii.c b/drivers/net/ibm_newemac/rgmii.c
index 5757788227be..e32da3de2695 100644
--- a/drivers/net/ibm_newemac/rgmii.c
+++ b/drivers/net/ibm_newemac/rgmii.c
@@ -179,7 +179,7 @@ void rgmii_put_mdio(struct of_device *ofdev, int input)
179 mutex_unlock(&dev->lock); 179 mutex_unlock(&dev->lock);
180} 180}
181 181
182void __devexit rgmii_detach(struct of_device *ofdev, int input) 182void rgmii_detach(struct of_device *ofdev, int input)
183{ 183{
184 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 184 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
185 struct rgmii_regs __iomem *p = dev->base; 185 struct rgmii_regs __iomem *p = dev->base;
diff --git a/drivers/net/ibm_newemac/tah.c b/drivers/net/ibm_newemac/tah.c
index b023d10d7e1c..30173a9fb557 100644
--- a/drivers/net/ibm_newemac/tah.c
+++ b/drivers/net/ibm_newemac/tah.c
@@ -35,7 +35,7 @@ int __devinit tah_attach(struct of_device *ofdev, int channel)
35 return 0; 35 return 0;
36} 36}
37 37
38void __devexit tah_detach(struct of_device *ofdev, int channel) 38void tah_detach(struct of_device *ofdev, int channel)
39{ 39{
40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
41 41
diff --git a/drivers/net/ibm_newemac/zmii.c b/drivers/net/ibm_newemac/zmii.c
index 2ea472aeab06..17b154124943 100644
--- a/drivers/net/ibm_newemac/zmii.c
+++ b/drivers/net/ibm_newemac/zmii.c
@@ -189,7 +189,7 @@ void zmii_set_speed(struct of_device *ofdev, int input, int speed)
189 mutex_unlock(&dev->lock); 189 mutex_unlock(&dev->lock);
190} 190}
191 191
192void __devexit zmii_detach(struct of_device *ofdev, int input) 192void zmii_detach(struct of_device *ofdev, int input)
193{ 193{
194 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 194 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
195 195
diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
index aaee02e9e3f0..ae398f04c7b4 100644
--- a/drivers/net/igb/igb_main.c
+++ b/drivers/net/igb/igb_main.c
@@ -871,6 +871,7 @@ static int __devinit igb_probe(struct pci_dev *pdev,
871 goto err_pci_reg; 871 goto err_pci_reg;
872 872
873 pci_set_master(pdev); 873 pci_set_master(pdev);
874 pci_save_state(pdev);
874 875
875 err = -ENOMEM; 876 err = -ENOMEM;
876 netdev = alloc_etherdev(sizeof(struct igb_adapter)); 877 netdev = alloc_etherdev(sizeof(struct igb_adapter));
@@ -4079,6 +4080,7 @@ static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
4079 return PCI_ERS_RESULT_DISCONNECT; 4080 return PCI_ERS_RESULT_DISCONNECT;
4080 } 4081 }
4081 pci_set_master(pdev); 4082 pci_set_master(pdev);
4083 pci_restore_state(pdev);
4082 4084
4083 pci_enable_wake(pdev, PCI_D3hot, 0); 4085 pci_enable_wake(pdev, PCI_D3hot, 0);
4084 pci_enable_wake(pdev, PCI_D3cold, 0); 4086 pci_enable_wake(pdev, PCI_D3cold, 0);
diff --git a/drivers/net/irda/ali-ircc.c b/drivers/net/irda/ali-ircc.c
index 9f584521304a..083b0dd70fef 100644
--- a/drivers/net/irda/ali-ircc.c
+++ b/drivers/net/irda/ali-ircc.c
@@ -60,6 +60,7 @@ static struct platform_driver ali_ircc_driver = {
60 .resume = ali_ircc_resume, 60 .resume = ali_ircc_resume,
61 .driver = { 61 .driver = {
62 .name = ALI_IRCC_DRIVER_NAME, 62 .name = ALI_IRCC_DRIVER_NAME,
63 .owner = THIS_MODULE,
63 }, 64 },
64}; 65};
65 66
@@ -2256,6 +2257,7 @@ static void FIR2SIR(int iobase)
2256MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>"); 2257MODULE_AUTHOR("Benjamin Kong <benjamin_kong@ali.com.tw>");
2257MODULE_DESCRIPTION("ALi FIR Controller Driver"); 2258MODULE_DESCRIPTION("ALi FIR Controller Driver");
2258MODULE_LICENSE("GPL"); 2259MODULE_LICENSE("GPL");
2260MODULE_ALIAS("platform:" ALI_IRCC_DRIVER_NAME);
2259 2261
2260 2262
2261module_param_array(io, int, NULL, 0); 2263module_param_array(io, int, NULL, 0);
diff --git a/drivers/net/irda/pxaficp_ir.c b/drivers/net/irda/pxaficp_ir.c
index 8db71ab20456..d5c2d27f3ea4 100644
--- a/drivers/net/irda/pxaficp_ir.c
+++ b/drivers/net/irda/pxaficp_ir.c
@@ -908,6 +908,7 @@ static int pxa_irda_remove(struct platform_device *_dev)
908static struct platform_driver pxa_ir_driver = { 908static struct platform_driver pxa_ir_driver = {
909 .driver = { 909 .driver = {
910 .name = "pxa2xx-ir", 910 .name = "pxa2xx-ir",
911 .owner = THIS_MODULE,
911 }, 912 },
912 .probe = pxa_irda_probe, 913 .probe = pxa_irda_probe,
913 .remove = pxa_irda_remove, 914 .remove = pxa_irda_remove,
@@ -929,3 +930,4 @@ module_init(pxa_irda_init);
929module_exit(pxa_irda_exit); 930module_exit(pxa_irda_exit);
930 931
931MODULE_LICENSE("GPL"); 932MODULE_LICENSE("GPL");
933MODULE_ALIAS("platform:pxa2xx-ir");
diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c
index 056639f72bec..1bc8518f9197 100644
--- a/drivers/net/irda/sa1100_ir.c
+++ b/drivers/net/irda/sa1100_ir.c
@@ -1008,6 +1008,7 @@ static struct platform_driver sa1100ir_driver = {
1008 .resume = sa1100_irda_resume, 1008 .resume = sa1100_irda_resume,
1009 .driver = { 1009 .driver = {
1010 .name = "sa11x0-ir", 1010 .name = "sa11x0-ir",
1011 .owner = THIS_MODULE,
1011 }, 1012 },
1012}; 1013};
1013 1014
@@ -1041,3 +1042,4 @@ MODULE_LICENSE("GPL");
1041MODULE_PARM_DESC(power_level, "IrDA power level, 1 (low) to 3 (high)"); 1042MODULE_PARM_DESC(power_level, "IrDA power level, 1 (low) to 3 (high)");
1042MODULE_PARM_DESC(tx_lpm, "Enable transmitter low power (1.6us) mode"); 1043MODULE_PARM_DESC(tx_lpm, "Enable transmitter low power (1.6us) mode");
1043MODULE_PARM_DESC(max_rate, "Maximum baud rate (4000000, 115200, 57600, 38400, 19200, 9600)"); 1044MODULE_PARM_DESC(max_rate, "Maximum baud rate (4000000, 115200, 57600, 38400, 19200, 9600)");
1045MODULE_ALIAS("platform:sa11x0-ir");
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c
index cb371a8c24a7..7b859220c255 100644
--- a/drivers/net/ixgbe/ixgbe_main.c
+++ b/drivers/net/ixgbe/ixgbe_main.c
@@ -3431,6 +3431,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
3431 } 3431 }
3432 3432
3433 pci_set_master(pdev); 3433 pci_set_master(pdev);
3434 pci_save_state(pdev);
3434 3435
3435#ifdef CONFIG_NETDEVICES_MULTIQUEUE 3436#ifdef CONFIG_NETDEVICES_MULTIQUEUE
3436 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); 3437 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
@@ -3721,6 +3722,7 @@ static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
3721 return PCI_ERS_RESULT_DISCONNECT; 3722 return PCI_ERS_RESULT_DISCONNECT;
3722 } 3723 }
3723 pci_set_master(pdev); 3724 pci_set_master(pdev);
3725 pci_restore_state(pdev);
3724 3726
3725 pci_enable_wake(pdev, PCI_D3hot, 0); 3727 pci_enable_wake(pdev, PCI_D3hot, 0);
3726 pci_enable_wake(pdev, PCI_D3cold, 0); 3728 pci_enable_wake(pdev, PCI_D3cold, 0);
diff --git a/drivers/net/jazzsonic.c b/drivers/net/jazzsonic.c
index 5c154fe13859..07944820f745 100644
--- a/drivers/net/jazzsonic.c
+++ b/drivers/net/jazzsonic.c
@@ -249,6 +249,7 @@ out:
249MODULE_DESCRIPTION("Jazz SONIC ethernet driver"); 249MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
250module_param(sonic_debug, int, 0); 250module_param(sonic_debug, int, 0);
251MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)"); 251MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
252MODULE_ALIAS("platform:jazzsonic");
252 253
253#include "sonic.c" 254#include "sonic.c"
254 255
@@ -271,6 +272,7 @@ static struct platform_driver jazz_sonic_driver = {
271 .remove = __devexit_p(jazz_sonic_device_remove), 272 .remove = __devexit_p(jazz_sonic_device_remove),
272 .driver = { 273 .driver = {
273 .name = jazz_sonic_string, 274 .name = jazz_sonic_string,
275 .owner = THIS_MODULE,
274 }, 276 },
275}; 277};
276 278
diff --git a/drivers/net/korina.c b/drivers/net/korina.c
index 1d24a73a0e1a..e18576316bda 100644
--- a/drivers/net/korina.c
+++ b/drivers/net/korina.c
@@ -883,7 +883,7 @@ static int korina_init(struct net_device *dev)
883static int korina_restart(struct net_device *dev) 883static int korina_restart(struct net_device *dev)
884{ 884{
885 struct korina_private *lp = netdev_priv(dev); 885 struct korina_private *lp = netdev_priv(dev);
886 int ret = 0; 886 int ret;
887 887
888 /* 888 /*
889 * Disable interrupts 889 * Disable interrupts
@@ -987,7 +987,7 @@ static void korina_poll_controller(struct net_device *dev)
987static int korina_open(struct net_device *dev) 987static int korina_open(struct net_device *dev)
988{ 988{
989 struct korina_private *lp = netdev_priv(dev); 989 struct korina_private *lp = netdev_priv(dev);
990 int ret = 0; 990 int ret;
991 991
992 /* Initialize */ 992 /* Initialize */
993 ret = korina_init(dev); 993 ret = korina_init(dev);
@@ -1031,6 +1031,8 @@ static int korina_open(struct net_device *dev)
1031 dev->name, lp->und_irq); 1031 dev->name, lp->und_irq);
1032 goto err_free_ovr_irq; 1032 goto err_free_ovr_irq;
1033 } 1033 }
1034out:
1035 return ret;
1034 1036
1035err_free_ovr_irq: 1037err_free_ovr_irq:
1036 free_irq(lp->ovr_irq, dev); 1038 free_irq(lp->ovr_irq, dev);
@@ -1041,8 +1043,6 @@ err_free_rx_irq:
1041err_release: 1043err_release:
1042 korina_free_ring(dev); 1044 korina_free_ring(dev);
1043 goto out; 1045 goto out;
1044out:
1045 return ret;
1046} 1046}
1047 1047
1048static int korina_close(struct net_device *dev) 1048static int korina_close(struct net_device *dev)
@@ -1082,7 +1082,7 @@ static int korina_probe(struct platform_device *pdev)
1082 struct korina_private *lp; 1082 struct korina_private *lp;
1083 struct net_device *dev; 1083 struct net_device *dev;
1084 struct resource *r; 1084 struct resource *r;
1085 int retval, err; 1085 int rc;
1086 1086
1087 dev = alloc_etherdev(sizeof(struct korina_private)); 1087 dev = alloc_etherdev(sizeof(struct korina_private));
1088 if (!dev) { 1088 if (!dev) {
@@ -1106,7 +1106,7 @@ static int korina_probe(struct platform_device *pdev)
1106 lp->eth_regs = ioremap_nocache(r->start, r->end - r->start); 1106 lp->eth_regs = ioremap_nocache(r->start, r->end - r->start);
1107 if (!lp->eth_regs) { 1107 if (!lp->eth_regs) {
1108 printk(KERN_ERR DRV_NAME "cannot remap registers\n"); 1108 printk(KERN_ERR DRV_NAME "cannot remap registers\n");
1109 retval = -ENXIO; 1109 rc = -ENXIO;
1110 goto probe_err_out; 1110 goto probe_err_out;
1111 } 1111 }
1112 1112
@@ -1114,7 +1114,7 @@ static int korina_probe(struct platform_device *pdev)
1114 lp->rx_dma_regs = ioremap_nocache(r->start, r->end - r->start); 1114 lp->rx_dma_regs = ioremap_nocache(r->start, r->end - r->start);
1115 if (!lp->rx_dma_regs) { 1115 if (!lp->rx_dma_regs) {
1116 printk(KERN_ERR DRV_NAME "cannot remap Rx DMA registers\n"); 1116 printk(KERN_ERR DRV_NAME "cannot remap Rx DMA registers\n");
1117 retval = -ENXIO; 1117 rc = -ENXIO;
1118 goto probe_err_dma_rx; 1118 goto probe_err_dma_rx;
1119 } 1119 }
1120 1120
@@ -1122,14 +1122,14 @@ static int korina_probe(struct platform_device *pdev)
1122 lp->tx_dma_regs = ioremap_nocache(r->start, r->end - r->start); 1122 lp->tx_dma_regs = ioremap_nocache(r->start, r->end - r->start);
1123 if (!lp->tx_dma_regs) { 1123 if (!lp->tx_dma_regs) {
1124 printk(KERN_ERR DRV_NAME "cannot remap Tx DMA registers\n"); 1124 printk(KERN_ERR DRV_NAME "cannot remap Tx DMA registers\n");
1125 retval = -ENXIO; 1125 rc = -ENXIO;
1126 goto probe_err_dma_tx; 1126 goto probe_err_dma_tx;
1127 } 1127 }
1128 1128
1129 lp->td_ring = kmalloc(TD_RING_SIZE + RD_RING_SIZE, GFP_KERNEL); 1129 lp->td_ring = kmalloc(TD_RING_SIZE + RD_RING_SIZE, GFP_KERNEL);
1130 if (!lp->td_ring) { 1130 if (!lp->td_ring) {
1131 printk(KERN_ERR DRV_NAME "cannot allocate descriptors\n"); 1131 printk(KERN_ERR DRV_NAME "cannot allocate descriptors\n");
1132 retval = -ENOMEM; 1132 rc = -ENXIO;
1133 goto probe_err_td_ring; 1133 goto probe_err_td_ring;
1134 } 1134 }
1135 1135
@@ -1166,14 +1166,14 @@ static int korina_probe(struct platform_device *pdev)
1166 lp->mii_if.phy_id_mask = 0x1f; 1166 lp->mii_if.phy_id_mask = 0x1f;
1167 lp->mii_if.reg_num_mask = 0x1f; 1167 lp->mii_if.reg_num_mask = 0x1f;
1168 1168
1169 err = register_netdev(dev); 1169 rc = register_netdev(dev);
1170 if (err) { 1170 if (rc < 0) {
1171 printk(KERN_ERR DRV_NAME 1171 printk(KERN_ERR DRV_NAME
1172 ": cannot register net device %d\n", err); 1172 ": cannot register net device %d\n", rc);
1173 retval = -EINVAL;
1174 goto probe_err_register; 1173 goto probe_err_register;
1175 } 1174 }
1176 return 0; 1175out:
1176 return rc;
1177 1177
1178probe_err_register: 1178probe_err_register:
1179 kfree(lp->td_ring); 1179 kfree(lp->td_ring);
@@ -1185,7 +1185,7 @@ probe_err_dma_rx:
1185 iounmap(lp->eth_regs); 1185 iounmap(lp->eth_regs);
1186probe_err_out: 1186probe_err_out:
1187 free_netdev(dev); 1187 free_netdev(dev);
1188 return retval; 1188 goto out;
1189} 1189}
1190 1190
1191static int korina_remove(struct platform_device *pdev) 1191static int korina_remove(struct platform_device *pdev)
@@ -1193,12 +1193,9 @@ static int korina_remove(struct platform_device *pdev)
1193 struct korina_device *bif = platform_get_drvdata(pdev); 1193 struct korina_device *bif = platform_get_drvdata(pdev);
1194 struct korina_private *lp = netdev_priv(bif->dev); 1194 struct korina_private *lp = netdev_priv(bif->dev);
1195 1195
1196 if (lp->eth_regs) 1196 iounmap(lp->eth_regs);
1197 iounmap(lp->eth_regs); 1197 iounmap(lp->rx_dma_regs);
1198 if (lp->rx_dma_regs) 1198 iounmap(lp->tx_dma_regs);
1199 iounmap(lp->rx_dma_regs);
1200 if (lp->tx_dma_regs)
1201 iounmap(lp->tx_dma_regs);
1202 1199
1203 platform_set_drvdata(pdev, NULL); 1200 platform_set_drvdata(pdev, NULL);
1204 unregister_netdev(bif->dev); 1201 unregister_netdev(bif->dev);
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index d513bb8a4902..92dccd43bdca 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -1281,6 +1281,7 @@ static struct platform_driver macb_driver = {
1281 .remove = __exit_p(macb_remove), 1281 .remove = __exit_p(macb_remove),
1282 .driver = { 1282 .driver = {
1283 .name = "macb", 1283 .name = "macb",
1284 .owner = THIS_MODULE,
1284 }, 1285 },
1285}; 1286};
1286 1287
@@ -1300,3 +1301,4 @@ module_exit(macb_exit);
1300MODULE_LICENSE("GPL"); 1301MODULE_LICENSE("GPL");
1301MODULE_DESCRIPTION("Atmel MACB Ethernet driver"); 1302MODULE_DESCRIPTION("Atmel MACB Ethernet driver");
1302MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>"); 1303MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
1304MODULE_ALIAS("platform:macb");
diff --git a/drivers/net/meth.c b/drivers/net/meth.c
index cdaa8fc21809..0b32648a2136 100644
--- a/drivers/net/meth.c
+++ b/drivers/net/meth.c
@@ -830,6 +830,7 @@ static struct platform_driver meth_driver = {
830 .remove = __devexit_p(meth_remove), 830 .remove = __devexit_p(meth_remove),
831 .driver = { 831 .driver = {
832 .name = "meth", 832 .name = "meth",
833 .owner = THIS_MODULE,
833 } 834 }
834}; 835};
835 836
@@ -855,3 +856,4 @@ module_exit(meth_exit_module);
855MODULE_AUTHOR("Ilya Volynets <ilya@theIlya.com>"); 856MODULE_AUTHOR("Ilya Volynets <ilya@theIlya.com>");
856MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver"); 857MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver");
857MODULE_LICENSE("GPL"); 858MODULE_LICENSE("GPL");
859MODULE_ALIAS("platform:meth");
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index 601ffd69ebc8..381b36e5f64c 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -2030,6 +2030,7 @@ static struct platform_driver mv643xx_eth_driver = {
2030 .shutdown = mv643xx_eth_shutdown, 2030 .shutdown = mv643xx_eth_shutdown,
2031 .driver = { 2031 .driver = {
2032 .name = MV643XX_ETH_NAME, 2032 .name = MV643XX_ETH_NAME,
2033 .owner = THIS_MODULE,
2033 }, 2034 },
2034}; 2035};
2035 2036
@@ -2038,6 +2039,7 @@ static struct platform_driver mv643xx_eth_shared_driver = {
2038 .remove = mv643xx_eth_shared_remove, 2039 .remove = mv643xx_eth_shared_remove,
2039 .driver = { 2040 .driver = {
2040 .name = MV643XX_ETH_SHARED_NAME, 2041 .name = MV643XX_ETH_SHARED_NAME,
2042 .owner = THIS_MODULE,
2041 }, 2043 },
2042}; 2044};
2043 2045
@@ -2085,7 +2087,8 @@ MODULE_LICENSE("GPL");
2085MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani" 2087MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani"
2086 " and Dale Farnsworth"); 2088 " and Dale Farnsworth");
2087MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX"); 2089MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX");
2088MODULE_ALIAS("platform:mv643xx_eth"); 2090MODULE_ALIAS("platform:" MV643XX_ETH_NAME);
2091MODULE_ALIAS("platform:" MV643XX_ETH_SHARED_NAME);
2089 2092
2090/* 2093/*
2091 * The second part is the low level driver of the gigE ethernet ports. 2094 * The second part is the low level driver of the gigE ethernet ports.
diff --git a/drivers/net/netx-eth.c b/drivers/net/netx-eth.c
index 78d34af13a1c..dc442e370850 100644
--- a/drivers/net/netx-eth.c
+++ b/drivers/net/netx-eth.c
@@ -502,4 +502,4 @@ module_exit(netx_eth_cleanup);
502 502
503MODULE_AUTHOR("Sascha Hauer, Pengutronix"); 503MODULE_AUTHOR("Sascha Hauer, Pengutronix");
504MODULE_LICENSE("GPL"); 504MODULE_LICENSE("GPL");
505 505MODULE_ALIAS("platform:" CARDNAME);
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index 05748ca6f216..af7356468251 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -1132,8 +1132,8 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
1132 u32 fw_minor = 0; 1132 u32 fw_minor = 0;
1133 u32 fw_build = 0; 1133 u32 fw_build = 0;
1134 char brd_name[NETXEN_MAX_SHORT_NAME]; 1134 char brd_name[NETXEN_MAX_SHORT_NAME];
1135 struct netxen_new_user_info user_info; 1135 char serial_num[32];
1136 int i, addr = NETXEN_USER_START; 1136 int i, addr;
1137 __le32 *ptr32; 1137 __le32 *ptr32;
1138 1138
1139 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg); 1139 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
@@ -1150,10 +1150,10 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
1150 valid = 0; 1150 valid = 0;
1151 } 1151 }
1152 if (valid) { 1152 if (valid) {
1153 ptr32 = (u32 *) & user_info; 1153 ptr32 = (u32 *)&serial_num;
1154 for (i = 0; 1154 addr = NETXEN_USER_START +
1155 i < sizeof(struct netxen_new_user_info) / sizeof(u32); 1155 offsetof(struct netxen_new_user_info, serial_num);
1156 i++) { 1156 for (i = 0; i < 8; i++) {
1157 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) { 1157 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
1158 printk("%s: ERROR reading %s board userarea.\n", 1158 printk("%s: ERROR reading %s board userarea.\n",
1159 netxen_nic_driver_name, 1159 netxen_nic_driver_name,
@@ -1163,10 +1163,11 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
1163 ptr32++; 1163 ptr32++;
1164 addr += sizeof(u32); 1164 addr += sizeof(u32);
1165 } 1165 }
1166
1166 get_brd_name_by_type(board_info->board_type, brd_name); 1167 get_brd_name_by_type(board_info->board_type, brd_name);
1167 1168
1168 printk("NetXen %s Board S/N %s Chip id 0x%x\n", 1169 printk("NetXen %s Board S/N %s Chip id 0x%x\n",
1169 brd_name, user_info.serial_num, board_info->chip_id); 1170 brd_name, serial_num, board_info->chip_id);
1170 1171
1171 printk("NetXen %s Board #%d, Chip id 0x%x\n", 1172 printk("NetXen %s Board #%d, Chip id 0x%x\n",
1172 board_info->board_type == 0x0b ? "XGB" : "GBE", 1173 board_info->board_type == 0x0b ? "XGB" : "GBE",
diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index 7565c2d7f30e..4009c4ce96b4 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -33,8 +33,8 @@
33 33
34#define DRV_MODULE_NAME "niu" 34#define DRV_MODULE_NAME "niu"
35#define PFX DRV_MODULE_NAME ": " 35#define PFX DRV_MODULE_NAME ": "
36#define DRV_MODULE_VERSION "0.7" 36#define DRV_MODULE_VERSION "0.8"
37#define DRV_MODULE_RELDATE "February 18, 2008" 37#define DRV_MODULE_RELDATE "April 24, 2008"
38 38
39static char version[] __devinitdata = 39static char version[] __devinitdata =
40 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; 40 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
@@ -673,11 +673,16 @@ static int serdes_init_10g(struct niu *np)
673 } 673 }
674 674
675 if ((sig & mask) != val) { 675 if ((sig & mask) != val) {
676 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) {
677 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT;
678 return 0;
679 }
676 dev_err(np->device, PFX "Port %u signal bits [%08x] are not " 680 dev_err(np->device, PFX "Port %u signal bits [%08x] are not "
677 "[%08x]\n", np->port, (int) (sig & mask), (int) val); 681 "[%08x]\n", np->port, (int) (sig & mask), (int) val);
678 return -ENODEV; 682 return -ENODEV;
679 } 683 }
680 684 if (np->flags & NIU_FLAGS_HOTPLUG_PHY)
685 np->flags |= NIU_FLAGS_HOTPLUG_PHY_PRESENT;
681 return 0; 686 return 0;
682} 687}
683 688
@@ -998,6 +1003,28 @@ static int bcm8704_user_dev3_readback(struct niu *np, int reg)
998 return 0; 1003 return 0;
999} 1004}
1000 1005
1006static int bcm8706_init_user_dev3(struct niu *np)
1007{
1008 int err;
1009
1010
1011 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
1012 BCM8704_USER_OPT_DIGITAL_CTRL);
1013 if (err < 0)
1014 return err;
1015 err &= ~USER_ODIG_CTRL_GPIOS;
1016 err |= (0x3 << USER_ODIG_CTRL_GPIOS_SHIFT);
1017 err |= USER_ODIG_CTRL_RESV2;
1018 err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
1019 BCM8704_USER_OPT_DIGITAL_CTRL, err);
1020 if (err)
1021 return err;
1022
1023 mdelay(1000);
1024
1025 return 0;
1026}
1027
1001static int bcm8704_init_user_dev3(struct niu *np) 1028static int bcm8704_init_user_dev3(struct niu *np)
1002{ 1029{
1003 int err; 1030 int err;
@@ -1127,33 +1154,11 @@ static int xcvr_init_10g_mrvl88x2011(struct niu *np)
1127 MRVL88X2011_10G_PMD_TX_DIS, MRVL88X2011_ENA_PMDTX); 1154 MRVL88X2011_10G_PMD_TX_DIS, MRVL88X2011_ENA_PMDTX);
1128} 1155}
1129 1156
1130static int xcvr_init_10g_bcm8704(struct niu *np) 1157
1158static int xcvr_diag_bcm870x(struct niu *np)
1131{ 1159{
1132 struct niu_link_config *lp = &np->link_config;
1133 u16 analog_stat0, tx_alarm_status; 1160 u16 analog_stat0, tx_alarm_status;
1134 int err; 1161 int err = 0;
1135
1136 err = bcm8704_reset(np);
1137 if (err)
1138 return err;
1139
1140 err = bcm8704_init_user_dev3(np);
1141 if (err)
1142 return err;
1143
1144 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
1145 MII_BMCR);
1146 if (err < 0)
1147 return err;
1148 err &= ~BMCR_LOOPBACK;
1149
1150 if (lp->loopback_mode == LOOPBACK_MAC)
1151 err |= BMCR_LOOPBACK;
1152
1153 err = mdio_write(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
1154 MII_BMCR, err);
1155 if (err)
1156 return err;
1157 1162
1158#if 1 1163#if 1
1159 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR, 1164 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
@@ -1211,6 +1216,89 @@ static int xcvr_init_10g_bcm8704(struct niu *np)
1211 return 0; 1216 return 0;
1212} 1217}
1213 1218
1219static int xcvr_10g_set_lb_bcm870x(struct niu *np)
1220{
1221 struct niu_link_config *lp = &np->link_config;
1222 int err;
1223
1224 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
1225 MII_BMCR);
1226 if (err < 0)
1227 return err;
1228
1229 err &= ~BMCR_LOOPBACK;
1230
1231 if (lp->loopback_mode == LOOPBACK_MAC)
1232 err |= BMCR_LOOPBACK;
1233
1234 err = mdio_write(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
1235 MII_BMCR, err);
1236 if (err)
1237 return err;
1238
1239 return 0;
1240}
1241
1242static int xcvr_init_10g_bcm8706(struct niu *np)
1243{
1244 int err = 0;
1245 u64 val;
1246
1247 if ((np->flags & NIU_FLAGS_HOTPLUG_PHY) &&
1248 (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) == 0)
1249 return err;
1250
1251 val = nr64_mac(XMAC_CONFIG);
1252 val &= ~XMAC_CONFIG_LED_POLARITY;
1253 val |= XMAC_CONFIG_FORCE_LED_ON;
1254 nw64_mac(XMAC_CONFIG, val);
1255
1256 val = nr64(MIF_CONFIG);
1257 val |= MIF_CONFIG_INDIRECT_MODE;
1258 nw64(MIF_CONFIG, val);
1259
1260 err = bcm8704_reset(np);
1261 if (err)
1262 return err;
1263
1264 err = xcvr_10g_set_lb_bcm870x(np);
1265 if (err)
1266 return err;
1267
1268 err = bcm8706_init_user_dev3(np);
1269 if (err)
1270 return err;
1271
1272 err = xcvr_diag_bcm870x(np);
1273 if (err)
1274 return err;
1275
1276 return 0;
1277}
1278
1279static int xcvr_init_10g_bcm8704(struct niu *np)
1280{
1281 int err;
1282
1283 err = bcm8704_reset(np);
1284 if (err)
1285 return err;
1286
1287 err = bcm8704_init_user_dev3(np);
1288 if (err)
1289 return err;
1290
1291 err = xcvr_10g_set_lb_bcm870x(np);
1292 if (err)
1293 return err;
1294
1295 err = xcvr_diag_bcm870x(np);
1296 if (err)
1297 return err;
1298
1299 return 0;
1300}
1301
1214static int xcvr_init_10g(struct niu *np) 1302static int xcvr_init_10g(struct niu *np)
1215{ 1303{
1216 int phy_id, err; 1304 int phy_id, err;
@@ -1548,6 +1636,59 @@ out:
1548 return err; 1636 return err;
1549} 1637}
1550 1638
1639static int link_status_10g_bcm8706(struct niu *np, int *link_up_p)
1640{
1641 int err, link_up;
1642 link_up = 0;
1643
1644 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
1645 BCM8704_PMD_RCV_SIGDET);
1646 if (err < 0)
1647 goto out;
1648 if (!(err & PMD_RCV_SIGDET_GLOBAL)) {
1649 err = 0;
1650 goto out;
1651 }
1652
1653 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
1654 BCM8704_PCS_10G_R_STATUS);
1655 if (err < 0)
1656 goto out;
1657
1658 if (!(err & PCS_10G_R_STATUS_BLK_LOCK)) {
1659 err = 0;
1660 goto out;
1661 }
1662
1663 err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
1664 BCM8704_PHYXS_XGXS_LANE_STAT);
1665 if (err < 0)
1666 goto out;
1667 if (err != (PHYXS_XGXS_LANE_STAT_ALINGED |
1668 PHYXS_XGXS_LANE_STAT_MAGIC |
1669 PHYXS_XGXS_LANE_STAT_PATTEST |
1670 PHYXS_XGXS_LANE_STAT_LANE3 |
1671 PHYXS_XGXS_LANE_STAT_LANE2 |
1672 PHYXS_XGXS_LANE_STAT_LANE1 |
1673 PHYXS_XGXS_LANE_STAT_LANE0)) {
1674 err = 0;
1675 np->link_config.active_speed = SPEED_INVALID;
1676 np->link_config.active_duplex = DUPLEX_INVALID;
1677 goto out;
1678 }
1679
1680 link_up = 1;
1681 np->link_config.active_speed = SPEED_10000;
1682 np->link_config.active_duplex = DUPLEX_FULL;
1683 err = 0;
1684
1685out:
1686 *link_up_p = link_up;
1687 if (np->flags & NIU_FLAGS_HOTPLUG_PHY)
1688 err = 0;
1689 return err;
1690}
1691
1551static int link_status_10g_bcom(struct niu *np, int *link_up_p) 1692static int link_status_10g_bcom(struct niu *np, int *link_up_p)
1552{ 1693{
1553 int err, link_up; 1694 int err, link_up;
@@ -1627,6 +1768,82 @@ static int link_status_10g(struct niu *np, int *link_up_p)
1627 return err; 1768 return err;
1628} 1769}
1629 1770
1771static int niu_10g_phy_present(struct niu *np)
1772{
1773 u64 sig, mask, val;
1774
1775 sig = nr64(ESR_INT_SIGNALS);
1776 switch (np->port) {
1777 case 0:
1778 mask = ESR_INT_SIGNALS_P0_BITS;
1779 val = (ESR_INT_SRDY0_P0 |
1780 ESR_INT_DET0_P0 |
1781 ESR_INT_XSRDY_P0 |
1782 ESR_INT_XDP_P0_CH3 |
1783 ESR_INT_XDP_P0_CH2 |
1784 ESR_INT_XDP_P0_CH1 |
1785 ESR_INT_XDP_P0_CH0);
1786 break;
1787
1788 case 1:
1789 mask = ESR_INT_SIGNALS_P1_BITS;
1790 val = (ESR_INT_SRDY0_P1 |
1791 ESR_INT_DET0_P1 |
1792 ESR_INT_XSRDY_P1 |
1793 ESR_INT_XDP_P1_CH3 |
1794 ESR_INT_XDP_P1_CH2 |
1795 ESR_INT_XDP_P1_CH1 |
1796 ESR_INT_XDP_P1_CH0);
1797 break;
1798
1799 default:
1800 return 0;
1801 }
1802
1803 if ((sig & mask) != val)
1804 return 0;
1805 return 1;
1806}
1807
1808static int link_status_10g_hotplug(struct niu *np, int *link_up_p)
1809{
1810 unsigned long flags;
1811 int err = 0;
1812 int phy_present;
1813 int phy_present_prev;
1814
1815 spin_lock_irqsave(&np->lock, flags);
1816
1817 if (np->link_config.loopback_mode == LOOPBACK_DISABLED) {
1818 phy_present_prev = (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) ?
1819 1 : 0;
1820 phy_present = niu_10g_phy_present(np);
1821 if (phy_present != phy_present_prev) {
1822 /* state change */
1823 if (phy_present) {
1824 np->flags |= NIU_FLAGS_HOTPLUG_PHY_PRESENT;
1825 if (np->phy_ops->xcvr_init)
1826 err = np->phy_ops->xcvr_init(np);
1827 if (err) {
1828 /* debounce */
1829 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT;
1830 }
1831 } else {
1832 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT;
1833 *link_up_p = 0;
1834 niuwarn(LINK, "%s: Hotplug PHY Removed\n",
1835 np->dev->name);
1836 }
1837 }
1838 if (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT)
1839 err = link_status_10g_bcm8706(np, link_up_p);
1840 }
1841
1842 spin_unlock_irqrestore(&np->lock, flags);
1843
1844 return err;
1845}
1846
1630static int link_status_1g(struct niu *np, int *link_up_p) 1847static int link_status_1g(struct niu *np, int *link_up_p)
1631{ 1848{
1632 struct niu_link_config *lp = &np->link_config; 1849 struct niu_link_config *lp = &np->link_config;
@@ -1761,6 +1978,12 @@ static const struct niu_phy_ops phy_ops_10g_fiber = {
1761 .link_status = link_status_10g, 1978 .link_status = link_status_10g,
1762}; 1979};
1763 1980
1981static const struct niu_phy_ops phy_ops_10g_fiber_hotplug = {
1982 .serdes_init = serdes_init_10g,
1983 .xcvr_init = xcvr_init_10g_bcm8706,
1984 .link_status = link_status_10g_hotplug,
1985};
1986
1764static const struct niu_phy_ops phy_ops_10g_copper = { 1987static const struct niu_phy_ops phy_ops_10g_copper = {
1765 .serdes_init = serdes_init_10g, 1988 .serdes_init = serdes_init_10g,
1766 .link_status = link_status_10g, /* XXX */ 1989 .link_status = link_status_10g, /* XXX */
@@ -1792,6 +2015,11 @@ static const struct niu_phy_template phy_template_10g_fiber = {
1792 .phy_addr_base = 8, 2015 .phy_addr_base = 8,
1793}; 2016};
1794 2017
2018static const struct niu_phy_template phy_template_10g_fiber_hotplug = {
2019 .ops = &phy_ops_10g_fiber_hotplug,
2020 .phy_addr_base = 8,
2021};
2022
1795static const struct niu_phy_template phy_template_10g_copper = { 2023static const struct niu_phy_template phy_template_10g_copper = {
1796 .ops = &phy_ops_10g_copper, 2024 .ops = &phy_ops_10g_copper,
1797 .phy_addr_base = 10, 2025 .phy_addr_base = 10,
@@ -1996,6 +2224,13 @@ static int niu_determine_phy_disposition(struct niu *np)
1996 plat_type == PLAT_TYPE_VF_P1) 2224 plat_type == PLAT_TYPE_VF_P1)
1997 phy_addr_off = 8; 2225 phy_addr_off = 8;
1998 phy_addr_off += np->port; 2226 phy_addr_off += np->port;
2227 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) {
2228 tp = &phy_template_10g_fiber_hotplug;
2229 if (np->port == 0)
2230 phy_addr_off = 8;
2231 if (np->port == 1)
2232 phy_addr_off = 12;
2233 }
1999 break; 2234 break;
2000 2235
2001 case NIU_FLAGS_10G | NIU_FLAGS_XCVR_SERDES: 2236 case NIU_FLAGS_10G | NIU_FLAGS_XCVR_SERDES:
@@ -6773,6 +7008,37 @@ static int __devinit niu_phy_type_prop_decode(struct niu *np,
6773 return 0; 7008 return 0;
6774} 7009}
6775 7010
7011/* niu board models have a trailing dash version incremented
7012 * with HW rev change. Need to ingnore the dash version while
7013 * checking for match
7014 *
7015 * for example, for the 10G card the current vpd.board_model
7016 * is 501-5283-04, of which -04 is the dash version and have
7017 * to be ignored
7018 */
7019static int niu_board_model_match(struct niu *np, const char *model)
7020{
7021 return !strncmp(np->vpd.board_model, model, strlen(model));
7022}
7023
7024static int niu_pci_vpd_get_nports(struct niu *np)
7025{
7026 int ports = 0;
7027
7028 if ((niu_board_model_match(np, NIU_QGC_LP_BM_STR)) ||
7029 (niu_board_model_match(np, NIU_QGC_PEM_BM_STR)) ||
7030 (niu_board_model_match(np, NIU_ALONSO_BM_STR))) {
7031 ports = 4;
7032 } else if ((niu_board_model_match(np, NIU_2XGF_LP_BM_STR)) ||
7033 (niu_board_model_match(np, NIU_2XGF_PEM_BM_STR)) ||
7034 (niu_board_model_match(np, NIU_FOXXY_BM_STR)) ||
7035 (niu_board_model_match(np, NIU_2XGF_MRVL_BM_STR))) {
7036 ports = 2;
7037 }
7038
7039 return ports;
7040}
7041
6776static void __devinit niu_pci_vpd_validate(struct niu *np) 7042static void __devinit niu_pci_vpd_validate(struct niu *np)
6777{ 7043{
6778 struct net_device *dev = np->dev; 7044 struct net_device *dev = np->dev;
@@ -6799,6 +7065,9 @@ static void __devinit niu_pci_vpd_validate(struct niu *np)
6799 } 7065 }
6800 if (np->flags & NIU_FLAGS_10G) 7066 if (np->flags & NIU_FLAGS_10G)
6801 np->mac_xcvr = MAC_XCVR_XPCS; 7067 np->mac_xcvr = MAC_XCVR_XPCS;
7068 } else if (niu_board_model_match(np, NIU_FOXXY_BM_STR)) {
7069 np->flags |= (NIU_FLAGS_10G | NIU_FLAGS_FIBER |
7070 NIU_FLAGS_HOTPLUG_PHY);
6802 } else if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) { 7071 } else if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) {
6803 dev_err(np->device, PFX "Illegal phy string [%s].\n", 7072 dev_err(np->device, PFX "Illegal phy string [%s].\n",
6804 np->vpd.phy_type); 7073 np->vpd.phy_type);
@@ -6987,11 +7256,17 @@ static int __devinit niu_get_and_validate_port(struct niu *np)
6987 if (parent->plat_type == PLAT_TYPE_NIU) { 7256 if (parent->plat_type == PLAT_TYPE_NIU) {
6988 parent->num_ports = 2; 7257 parent->num_ports = 2;
6989 } else { 7258 } else {
6990 parent->num_ports = nr64(ESPC_NUM_PORTS_MACS) & 7259 parent->num_ports = niu_pci_vpd_get_nports(np);
6991 ESPC_NUM_PORTS_MACS_VAL; 7260 if (!parent->num_ports) {
6992 7261 /* Fall back to SPROM as last resort.
6993 if (!parent->num_ports) 7262 * This will fail on most cards.
6994 parent->num_ports = 4; 7263 */
7264 parent->num_ports = nr64(ESPC_NUM_PORTS_MACS) &
7265 ESPC_NUM_PORTS_MACS_VAL;
7266
7267 if (!parent->num_ports)
7268 return -ENODEV;
7269 }
6995 } 7270 }
6996 } 7271 }
6997 7272
@@ -7015,7 +7290,8 @@ static int __devinit phy_record(struct niu_parent *parent,
7015 return 0; 7290 return 0;
7016 if (type == PHY_TYPE_PMA_PMD || type == PHY_TYPE_PCS) { 7291 if (type == PHY_TYPE_PMA_PMD || type == PHY_TYPE_PCS) {
7017 if (((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM8704) && 7292 if (((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM8704) &&
7018 ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_MRVL88X2011)) 7293 ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_MRVL88X2011) &&
7294 ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM8706))
7019 return 0; 7295 return 0;
7020 } else { 7296 } else {
7021 if ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM5464R) 7297 if ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM5464R)
@@ -7262,7 +7538,6 @@ static int __devinit walk_phys(struct niu *np, struct niu_parent *parent)
7262 u32 val; 7538 u32 val;
7263 int err; 7539 int err;
7264 7540
7265
7266 if (!strcmp(np->vpd.model, "SUNW,CP3220") || 7541 if (!strcmp(np->vpd.model, "SUNW,CP3220") ||
7267 !strcmp(np->vpd.model, "SUNW,CP3260")) { 7542 !strcmp(np->vpd.model, "SUNW,CP3260")) {
7268 num_10g = 0; 7543 num_10g = 0;
@@ -7273,6 +7548,12 @@ static int __devinit walk_phys(struct niu *np, struct niu_parent *parent)
7273 phy_encode(PORT_TYPE_1G, 1) | 7548 phy_encode(PORT_TYPE_1G, 1) |
7274 phy_encode(PORT_TYPE_1G, 2) | 7549 phy_encode(PORT_TYPE_1G, 2) |
7275 phy_encode(PORT_TYPE_1G, 3)); 7550 phy_encode(PORT_TYPE_1G, 3));
7551 } else if (niu_board_model_match(np, NIU_FOXXY_BM_STR)) {
7552 num_10g = 2;
7553 num_1g = 0;
7554 parent->num_ports = 2;
7555 val = (phy_encode(PORT_TYPE_10G, 0) |
7556 phy_encode(PORT_TYPE_10G, 1));
7276 } else { 7557 } else {
7277 err = fill_phy_probe_info(np, parent, info); 7558 err = fill_phy_probe_info(np, parent, info);
7278 if (err) 7559 if (err)
@@ -7733,15 +8014,16 @@ static int __devinit niu_get_invariants(struct niu *np)
7733 8014
7734 have_props = !err; 8015 have_props = !err;
7735 8016
7736 err = niu_get_and_validate_port(np);
7737 if (err)
7738 return err;
7739
7740 err = niu_init_mac_ipp_pcs_base(np); 8017 err = niu_init_mac_ipp_pcs_base(np);
7741 if (err) 8018 if (err)
7742 return err; 8019 return err;
7743 8020
7744 if (!have_props) { 8021 if (have_props) {
8022 err = niu_get_and_validate_port(np);
8023 if (err)
8024 return err;
8025
8026 } else {
7745 if (np->parent->plat_type == PLAT_TYPE_NIU) 8027 if (np->parent->plat_type == PLAT_TYPE_NIU)
7746 return -EINVAL; 8028 return -EINVAL;
7747 8029
@@ -7753,10 +8035,17 @@ static int __devinit niu_get_invariants(struct niu *np)
7753 niu_pci_vpd_fetch(np, offset); 8035 niu_pci_vpd_fetch(np, offset);
7754 nw64(ESPC_PIO_EN, 0); 8036 nw64(ESPC_PIO_EN, 0);
7755 8037
7756 if (np->flags & NIU_FLAGS_VPD_VALID) 8038 if (np->flags & NIU_FLAGS_VPD_VALID) {
7757 niu_pci_vpd_validate(np); 8039 niu_pci_vpd_validate(np);
8040 err = niu_get_and_validate_port(np);
8041 if (err)
8042 return err;
8043 }
7758 8044
7759 if (!(np->flags & NIU_FLAGS_VPD_VALID)) { 8045 if (!(np->flags & NIU_FLAGS_VPD_VALID)) {
8046 err = niu_get_and_validate_port(np);
8047 if (err)
8048 return err;
7760 err = niu_pci_probe_sprom(np); 8049 err = niu_pci_probe_sprom(np);
7761 if (err) 8050 if (err)
7762 return err; 8051 return err;
diff --git a/drivers/net/niu.h b/drivers/net/niu.h
index 336aed08b275..97ffbe137bcb 100644
--- a/drivers/net/niu.h
+++ b/drivers/net/niu.h
@@ -2537,6 +2537,7 @@ struct fcram_hash_ipv6 {
2537 2537
2538#define NIU_PHY_ID_MASK 0xfffff0f0 2538#define NIU_PHY_ID_MASK 0xfffff0f0
2539#define NIU_PHY_ID_BCM8704 0x00206030 2539#define NIU_PHY_ID_BCM8704 0x00206030
2540#define NIU_PHY_ID_BCM8706 0x00206035
2540#define NIU_PHY_ID_BCM5464R 0x002060b0 2541#define NIU_PHY_ID_BCM5464R 0x002060b0
2541#define NIU_PHY_ID_MRVL88X2011 0x01410020 2542#define NIU_PHY_ID_MRVL88X2011 0x01410020
2542 2543
@@ -2937,6 +2938,15 @@ struct rx_ring_info {
2937 2938
2938#define NIU_MAX_MTU 9216 2939#define NIU_MAX_MTU 9216
2939 2940
2941/* VPD strings */
2942#define NIU_QGC_LP_BM_STR "501-7606"
2943#define NIU_2XGF_LP_BM_STR "501-7283"
2944#define NIU_QGC_PEM_BM_STR "501-7765"
2945#define NIU_2XGF_PEM_BM_STR "501-7626"
2946#define NIU_ALONSO_BM_STR "373-0202"
2947#define NIU_FOXXY_BM_STR "501-7961"
2948#define NIU_2XGF_MRVL_BM_STR "SK-6E82"
2949
2940#define NIU_VPD_MIN_MAJOR 3 2950#define NIU_VPD_MIN_MAJOR 3
2941#define NIU_VPD_MIN_MINOR 4 2951#define NIU_VPD_MIN_MINOR 4
2942 2952
@@ -3199,6 +3209,8 @@ struct niu {
3199 struct niu_parent *parent; 3209 struct niu_parent *parent;
3200 3210
3201 u32 flags; 3211 u32 flags;
3212#define NIU_FLAGS_HOTPLUG_PHY_PRESENT 0x02000000 /* Removebale PHY detected*/
3213#define NIU_FLAGS_HOTPLUG_PHY 0x01000000 /* Removebale PHY */
3202#define NIU_FLAGS_VPD_VALID 0x00800000 /* VPD has valid version */ 3214#define NIU_FLAGS_VPD_VALID 0x00800000 /* VPD has valid version */
3203#define NIU_FLAGS_MSIX 0x00400000 /* MSI-X in use */ 3215#define NIU_FLAGS_MSIX 0x00400000 /* MSI-X in use */
3204#define NIU_FLAGS_MCAST 0x00200000 /* multicast filter enabled */ 3216#define NIU_FLAGS_MCAST 0x00200000 /* multicast filter enabled */
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 963630c65ca9..94e0b7ed76f1 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -89,6 +89,9 @@ int mdiobus_register(struct mii_bus *bus)
89 89
90 phydev->bus = bus; 90 phydev->bus = bus;
91 91
92 /* Run all of the fixups for this PHY */
93 phy_scan_fixups(phydev);
94
92 err = device_register(&phydev->dev); 95 err = device_register(&phydev->dev);
93 96
94 if (err) { 97 if (err) {
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 12fccb1c76dc..3c18bb594957 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -406,8 +406,10 @@ int phy_mii_ioctl(struct phy_device *phydev,
406 406
407 if (mii_data->reg_num == MII_BMCR 407 if (mii_data->reg_num == MII_BMCR
408 && val & BMCR_RESET 408 && val & BMCR_RESET
409 && phydev->drv->config_init) 409 && phydev->drv->config_init) {
410 phy_scan_fixups(phydev);
410 phydev->drv->config_init(phydev); 411 phydev->drv->config_init(phydev);
412 }
411 break; 413 break;
412 414
413 default: 415 default:
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 8b1121b02f98..ddf8d51832a6 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -53,6 +53,96 @@ static void phy_device_release(struct device *dev)
53 phy_device_free(to_phy_device(dev)); 53 phy_device_free(to_phy_device(dev));
54} 54}
55 55
56static LIST_HEAD(phy_fixup_list);
57static DEFINE_MUTEX(phy_fixup_lock);
58
59/*
60 * Creates a new phy_fixup and adds it to the list
61 * @bus_id: A string which matches phydev->dev.bus_id (or PHY_ANY_ID)
62 * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY)
63 * It can also be PHY_ANY_UID
64 * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before
65 * comparison
66 * @run: The actual code to be run when a matching PHY is found
67 */
68int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
69 int (*run)(struct phy_device *))
70{
71 struct phy_fixup *fixup;
72
73 fixup = kzalloc(sizeof(struct phy_fixup), GFP_KERNEL);
74 if (!fixup)
75 return -ENOMEM;
76
77 strncpy(fixup->bus_id, bus_id, BUS_ID_SIZE);
78 fixup->phy_uid = phy_uid;
79 fixup->phy_uid_mask = phy_uid_mask;
80 fixup->run = run;
81
82 mutex_lock(&phy_fixup_lock);
83 list_add_tail(&fixup->list, &phy_fixup_list);
84 mutex_unlock(&phy_fixup_lock);
85
86 return 0;
87}
88EXPORT_SYMBOL(phy_register_fixup);
89
90/* Registers a fixup to be run on any PHY with the UID in phy_uid */
91int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
92 int (*run)(struct phy_device *))
93{
94 return phy_register_fixup(PHY_ANY_ID, phy_uid, phy_uid_mask, run);
95}
96EXPORT_SYMBOL(phy_register_fixup_for_uid);
97
98/* Registers a fixup to be run on the PHY with id string bus_id */
99int phy_register_fixup_for_id(const char *bus_id,
100 int (*run)(struct phy_device *))
101{
102 return phy_register_fixup(bus_id, PHY_ANY_UID, 0xffffffff, run);
103}
104EXPORT_SYMBOL(phy_register_fixup_for_id);
105
106/*
107 * Returns 1 if fixup matches phydev in bus_id and phy_uid.
108 * Fixups can be set to match any in one or more fields.
109 */
110static int phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup)
111{
112 if (strcmp(fixup->bus_id, phydev->dev.bus_id) != 0)
113 if (strcmp(fixup->bus_id, PHY_ANY_ID) != 0)
114 return 0;
115
116 if ((fixup->phy_uid & fixup->phy_uid_mask) !=
117 (phydev->phy_id & fixup->phy_uid_mask))
118 if (fixup->phy_uid != PHY_ANY_UID)
119 return 0;
120
121 return 1;
122}
123
124/* Runs any matching fixups for this phydev */
125int phy_scan_fixups(struct phy_device *phydev)
126{
127 struct phy_fixup *fixup;
128
129 mutex_lock(&phy_fixup_lock);
130 list_for_each_entry(fixup, &phy_fixup_list, list) {
131 if (phy_needs_fixup(phydev, fixup)) {
132 int err;
133
134 err = fixup->run(phydev);
135
136 if (err < 0)
137 return err;
138 }
139 }
140 mutex_unlock(&phy_fixup_lock);
141
142 return 0;
143}
144EXPORT_SYMBOL(phy_scan_fixups);
145
56struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id) 146struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
57{ 147{
58 struct phy_device *dev; 148 struct phy_device *dev;
@@ -179,13 +269,13 @@ void phy_prepare_link(struct phy_device *phydev,
179 * choose to call only the subset of functions which provide 269 * choose to call only the subset of functions which provide
180 * the desired functionality. 270 * the desired functionality.
181 */ 271 */
182struct phy_device * phy_connect(struct net_device *dev, const char *phy_id, 272struct phy_device * phy_connect(struct net_device *dev, const char *bus_id,
183 void (*handler)(struct net_device *), u32 flags, 273 void (*handler)(struct net_device *), u32 flags,
184 phy_interface_t interface) 274 phy_interface_t interface)
185{ 275{
186 struct phy_device *phydev; 276 struct phy_device *phydev;
187 277
188 phydev = phy_attach(dev, phy_id, flags, interface); 278 phydev = phy_attach(dev, bus_id, flags, interface);
189 279
190 if (IS_ERR(phydev)) 280 if (IS_ERR(phydev))
191 return phydev; 281 return phydev;
@@ -226,7 +316,7 @@ static int phy_compare_id(struct device *dev, void *data)
226/** 316/**
227 * phy_attach - attach a network device to a particular PHY device 317 * phy_attach - attach a network device to a particular PHY device
228 * @dev: network device to attach 318 * @dev: network device to attach
229 * @phy_id: PHY device to attach 319 * @bus_id: PHY device to attach
230 * @flags: PHY device's dev_flags 320 * @flags: PHY device's dev_flags
231 * @interface: PHY device's interface 321 * @interface: PHY device's interface
232 * 322 *
@@ -238,7 +328,7 @@ static int phy_compare_id(struct device *dev, void *data)
238 * change. The phy_device is returned to the attaching driver. 328 * change. The phy_device is returned to the attaching driver.
239 */ 329 */
240struct phy_device *phy_attach(struct net_device *dev, 330struct phy_device *phy_attach(struct net_device *dev,
241 const char *phy_id, u32 flags, phy_interface_t interface) 331 const char *bus_id, u32 flags, phy_interface_t interface)
242{ 332{
243 struct bus_type *bus = &mdio_bus_type; 333 struct bus_type *bus = &mdio_bus_type;
244 struct phy_device *phydev; 334 struct phy_device *phydev;
@@ -246,12 +336,12 @@ struct phy_device *phy_attach(struct net_device *dev,
246 336
247 /* Search the list of PHY devices on the mdio bus for the 337 /* Search the list of PHY devices on the mdio bus for the
248 * PHY with the requested name */ 338 * PHY with the requested name */
249 d = bus_find_device(bus, NULL, (void *)phy_id, phy_compare_id); 339 d = bus_find_device(bus, NULL, (void *)bus_id, phy_compare_id);
250 340
251 if (d) { 341 if (d) {
252 phydev = to_phy_device(d); 342 phydev = to_phy_device(d);
253 } else { 343 } else {
254 printk(KERN_ERR "%s not found\n", phy_id); 344 printk(KERN_ERR "%s not found\n", bus_id);
255 return ERR_PTR(-ENODEV); 345 return ERR_PTR(-ENODEV);
256 } 346 }
257 347
@@ -271,7 +361,7 @@ struct phy_device *phy_attach(struct net_device *dev,
271 361
272 if (phydev->attached_dev) { 362 if (phydev->attached_dev) {
273 printk(KERN_ERR "%s: %s already attached\n", 363 printk(KERN_ERR "%s: %s already attached\n",
274 dev->name, phy_id); 364 dev->name, bus_id);
275 return ERR_PTR(-EBUSY); 365 return ERR_PTR(-EBUSY);
276 } 366 }
277 367
@@ -287,6 +377,11 @@ struct phy_device *phy_attach(struct net_device *dev,
287 if (phydev->drv->config_init) { 377 if (phydev->drv->config_init) {
288 int err; 378 int err;
289 379
380 err = phy_scan_fixups(phydev);
381
382 if (err < 0)
383 return ERR_PTR(err);
384
290 err = phydev->drv->config_init(phydev); 385 err = phydev->drv->config_init(phydev);
291 386
292 if (err < 0) 387 if (err < 0)
@@ -395,6 +490,7 @@ EXPORT_SYMBOL(genphy_config_advert);
395 */ 490 */
396int genphy_setup_forced(struct phy_device *phydev) 491int genphy_setup_forced(struct phy_device *phydev)
397{ 492{
493 int err;
398 int ctl = 0; 494 int ctl = 0;
399 495
400 phydev->pause = phydev->asym_pause = 0; 496 phydev->pause = phydev->asym_pause = 0;
@@ -407,17 +503,26 @@ int genphy_setup_forced(struct phy_device *phydev)
407 if (DUPLEX_FULL == phydev->duplex) 503 if (DUPLEX_FULL == phydev->duplex)
408 ctl |= BMCR_FULLDPLX; 504 ctl |= BMCR_FULLDPLX;
409 505
410 ctl = phy_write(phydev, MII_BMCR, ctl); 506 err = phy_write(phydev, MII_BMCR, ctl);
411 507
412 if (ctl < 0) 508 if (err < 0)
413 return ctl; 509 return err;
510
511 /*
512 * Run the fixups on this PHY, just in case the
513 * board code needs to change something after a reset
514 */
515 err = phy_scan_fixups(phydev);
516
517 if (err < 0)
518 return err;
414 519
415 /* We just reset the device, so we'd better configure any 520 /* We just reset the device, so we'd better configure any
416 * settings the PHY requires to operate */ 521 * settings the PHY requires to operate */
417 if (phydev->drv->config_init) 522 if (phydev->drv->config_init)
418 ctl = phydev->drv->config_init(phydev); 523 err = phydev->drv->config_init(phydev);
419 524
420 return ctl; 525 return err;
421} 526}
422 527
423 528
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index dcbe01b0ca0d..157fd932e951 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -86,7 +86,7 @@
86#include "s2io.h" 86#include "s2io.h"
87#include "s2io-regs.h" 87#include "s2io-regs.h"
88 88
89#define DRV_VERSION "2.0.26.20" 89#define DRV_VERSION "2.0.26.22"
90 90
91/* S2io Driver name & version. */ 91/* S2io Driver name & version. */
92static char s2io_driver_name[] = "Neterion"; 92static char s2io_driver_name[] = "Neterion";
@@ -117,20 +117,6 @@ static inline int RXD_IS_UP2DT(struct RxD_t *rxdp)
117 117
118#define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \ 118#define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
119 ADAPTER_STATUS_RMAC_LOCAL_FAULT))) 119 ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
120#define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
121#define PANIC 1
122#define LOW 2
123static inline int rx_buffer_level(struct s2io_nic * sp, int rxb_size, int ring)
124{
125 struct mac_info *mac_control;
126
127 mac_control = &sp->mac_control;
128 if (rxb_size <= rxd_count[sp->rxd_mode])
129 return PANIC;
130 else if ((mac_control->rings[ring].pkt_cnt - rxb_size) > 16)
131 return LOW;
132 return 0;
133}
134 120
135static inline int is_s2io_card_up(const struct s2io_nic * sp) 121static inline int is_s2io_card_up(const struct s2io_nic * sp)
136{ 122{
@@ -2458,7 +2444,7 @@ static void free_tx_buffers(struct s2io_nic *nic)
2458 for (i = 0; i < config->tx_fifo_num; i++) { 2444 for (i = 0; i < config->tx_fifo_num; i++) {
2459 unsigned long flags; 2445 unsigned long flags;
2460 spin_lock_irqsave(&mac_control->fifos[i].tx_lock, flags); 2446 spin_lock_irqsave(&mac_control->fifos[i].tx_lock, flags);
2461 for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) { 2447 for (j = 0; j < config->tx_cfg[i].fifo_len; j++) {
2462 txdp = (struct TxD *) \ 2448 txdp = (struct TxD *) \
2463 mac_control->fifos[i].list_info[j].list_virt_addr; 2449 mac_control->fifos[i].list_info[j].list_virt_addr;
2464 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j); 2450 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
@@ -2544,7 +2530,6 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2544 struct config_param *config; 2530 struct config_param *config;
2545 u64 tmp; 2531 u64 tmp;
2546 struct buffAdd *ba; 2532 struct buffAdd *ba;
2547 unsigned long flags;
2548 struct RxD_t *first_rxdp = NULL; 2533 struct RxD_t *first_rxdp = NULL;
2549 u64 Buffer0_ptr = 0, Buffer1_ptr = 0; 2534 u64 Buffer0_ptr = 0, Buffer1_ptr = 0;
2550 struct RxD1 *rxdp1; 2535 struct RxD1 *rxdp1;
@@ -2592,15 +2577,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2592 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n", 2577 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
2593 dev->name, rxdp); 2578 dev->name, rxdp);
2594 } 2579 }
2595 if(!napi) { 2580
2596 spin_lock_irqsave(&nic->put_lock, flags);
2597 mac_control->rings[ring_no].put_pos =
2598 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
2599 spin_unlock_irqrestore(&nic->put_lock, flags);
2600 } else {
2601 mac_control->rings[ring_no].put_pos =
2602 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
2603 }
2604 if ((rxdp->Control_1 & RXD_OWN_XENA) && 2581 if ((rxdp->Control_1 & RXD_OWN_XENA) &&
2605 ((nic->rxd_mode == RXD_MODE_3B) && 2582 ((nic->rxd_mode == RXD_MODE_3B) &&
2606 (rxdp->Control_2 & s2BIT(0)))) { 2583 (rxdp->Control_2 & s2BIT(0)))) {
@@ -2978,7 +2955,7 @@ static void rx_intr_handler(struct ring_info *ring_data)
2978{ 2955{
2979 struct s2io_nic *nic = ring_data->nic; 2956 struct s2io_nic *nic = ring_data->nic;
2980 struct net_device *dev = (struct net_device *) nic->dev; 2957 struct net_device *dev = (struct net_device *) nic->dev;
2981 int get_block, put_block, put_offset; 2958 int get_block, put_block;
2982 struct rx_curr_get_info get_info, put_info; 2959 struct rx_curr_get_info get_info, put_info;
2983 struct RxD_t *rxdp; 2960 struct RxD_t *rxdp;
2984 struct sk_buff *skb; 2961 struct sk_buff *skb;
@@ -2987,19 +2964,11 @@ static void rx_intr_handler(struct ring_info *ring_data)
2987 struct RxD1* rxdp1; 2964 struct RxD1* rxdp1;
2988 struct RxD3* rxdp3; 2965 struct RxD3* rxdp3;
2989 2966
2990 spin_lock(&nic->rx_lock);
2991
2992 get_info = ring_data->rx_curr_get_info; 2967 get_info = ring_data->rx_curr_get_info;
2993 get_block = get_info.block_index; 2968 get_block = get_info.block_index;
2994 memcpy(&put_info, &ring_data->rx_curr_put_info, sizeof(put_info)); 2969 memcpy(&put_info, &ring_data->rx_curr_put_info, sizeof(put_info));
2995 put_block = put_info.block_index; 2970 put_block = put_info.block_index;
2996 rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr; 2971 rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
2997 if (!napi) {
2998 spin_lock(&nic->put_lock);
2999 put_offset = ring_data->put_pos;
3000 spin_unlock(&nic->put_lock);
3001 } else
3002 put_offset = ring_data->put_pos;
3003 2972
3004 while (RXD_IS_UP2DT(rxdp)) { 2973 while (RXD_IS_UP2DT(rxdp)) {
3005 /* 2974 /*
@@ -3016,7 +2985,6 @@ static void rx_intr_handler(struct ring_info *ring_data)
3016 DBG_PRINT(ERR_DBG, "%s: The skb is ", 2985 DBG_PRINT(ERR_DBG, "%s: The skb is ",
3017 dev->name); 2986 dev->name);
3018 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n"); 2987 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
3019 spin_unlock(&nic->rx_lock);
3020 return; 2988 return;
3021 } 2989 }
3022 if (nic->rxd_mode == RXD_MODE_1) { 2990 if (nic->rxd_mode == RXD_MODE_1) {
@@ -3072,8 +3040,6 @@ static void rx_intr_handler(struct ring_info *ring_data)
3072 } 3040 }
3073 } 3041 }
3074 } 3042 }
3075
3076 spin_unlock(&nic->rx_lock);
3077} 3043}
3078 3044
3079/** 3045/**
@@ -4105,7 +4071,6 @@ static int s2io_close(struct net_device *dev)
4105 do_s2io_delete_unicast_mc(sp, tmp64); 4071 do_s2io_delete_unicast_mc(sp, tmp64);
4106 } 4072 }
4107 4073
4108 /* Reset card, kill tasklet and free Tx and Rx buffers. */
4109 s2io_card_down(sp); 4074 s2io_card_down(sp);
4110 4075
4111 return 0; 4076 return 0;
@@ -4370,29 +4335,9 @@ s2io_alarm_handle(unsigned long data)
4370 4335
4371static int s2io_chk_rx_buffers(struct s2io_nic *sp, int rng_n) 4336static int s2io_chk_rx_buffers(struct s2io_nic *sp, int rng_n)
4372{ 4337{
4373 int rxb_size, level; 4338 if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
4374 4339 DBG_PRINT(INFO_DBG, "%s:Out of memory", sp->dev->name);
4375 if (!sp->lro) { 4340 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n");
4376 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
4377 level = rx_buffer_level(sp, rxb_size, rng_n);
4378
4379 if ((level == PANIC) && (!TASKLET_IN_USE)) {
4380 int ret;
4381 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
4382 DBG_PRINT(INTR_DBG, "PANIC levels\n");
4383 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
4384 DBG_PRINT(INFO_DBG, "Out of memory in %s",
4385 __FUNCTION__);
4386 clear_bit(0, (&sp->tasklet_status));
4387 return -1;
4388 }
4389 clear_bit(0, (&sp->tasklet_status));
4390 } else if (level == LOW)
4391 tasklet_schedule(&sp->task);
4392
4393 } else if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
4394 DBG_PRINT(INFO_DBG, "%s:Out of memory", sp->dev->name);
4395 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n");
4396 } 4341 }
4397 return 0; 4342 return 0;
4398} 4343}
@@ -6770,49 +6715,6 @@ static int s2io_change_mtu(struct net_device *dev, int new_mtu)
6770} 6715}
6771 6716
6772/** 6717/**
6773 * s2io_tasklet - Bottom half of the ISR.
6774 * @dev_adr : address of the device structure in dma_addr_t format.
6775 * Description:
6776 * This is the tasklet or the bottom half of the ISR. This is
6777 * an extension of the ISR which is scheduled by the scheduler to be run
6778 * when the load on the CPU is low. All low priority tasks of the ISR can
6779 * be pushed into the tasklet. For now the tasklet is used only to
6780 * replenish the Rx buffers in the Rx buffer descriptors.
6781 * Return value:
6782 * void.
6783 */
6784
6785static void s2io_tasklet(unsigned long dev_addr)
6786{
6787 struct net_device *dev = (struct net_device *) dev_addr;
6788 struct s2io_nic *sp = dev->priv;
6789 int i, ret;
6790 struct mac_info *mac_control;
6791 struct config_param *config;
6792
6793 mac_control = &sp->mac_control;
6794 config = &sp->config;
6795
6796 if (!TASKLET_IN_USE) {
6797 for (i = 0; i < config->rx_ring_num; i++) {
6798 ret = fill_rx_buffers(sp, i);
6799 if (ret == -ENOMEM) {
6800 DBG_PRINT(INFO_DBG, "%s: Out of ",
6801 dev->name);
6802 DBG_PRINT(INFO_DBG, "memory in tasklet\n");
6803 break;
6804 } else if (ret == -EFILL) {
6805 DBG_PRINT(INFO_DBG,
6806 "%s: Rx Ring %d is full\n",
6807 dev->name, i);
6808 break;
6809 }
6810 }
6811 clear_bit(0, (&sp->tasklet_status));
6812 }
6813}
6814
6815/**
6816 * s2io_set_link - Set the LInk status 6718 * s2io_set_link - Set the LInk status
6817 * @data: long pointer to device private structue 6719 * @data: long pointer to device private structue
6818 * Description: Sets the link status for the adapter 6720 * Description: Sets the link status for the adapter
@@ -7161,7 +7063,6 @@ static void do_s2io_card_down(struct s2io_nic * sp, int do_io)
7161{ 7063{
7162 int cnt = 0; 7064 int cnt = 0;
7163 struct XENA_dev_config __iomem *bar0 = sp->bar0; 7065 struct XENA_dev_config __iomem *bar0 = sp->bar0;
7164 unsigned long flags;
7165 register u64 val64 = 0; 7066 register u64 val64 = 0;
7166 struct config_param *config; 7067 struct config_param *config;
7167 config = &sp->config; 7068 config = &sp->config;
@@ -7186,9 +7087,6 @@ static void do_s2io_card_down(struct s2io_nic * sp, int do_io)
7186 7087
7187 s2io_rem_isr(sp); 7088 s2io_rem_isr(sp);
7188 7089
7189 /* Kill tasklet. */
7190 tasklet_kill(&sp->task);
7191
7192 /* Check if the device is Quiescent and then Reset the NIC */ 7090 /* Check if the device is Quiescent and then Reset the NIC */
7193 while(do_io) { 7091 while(do_io) {
7194 /* As per the HW requirement we need to replenish the 7092 /* As per the HW requirement we need to replenish the
@@ -7223,9 +7121,7 @@ static void do_s2io_card_down(struct s2io_nic * sp, int do_io)
7223 free_tx_buffers(sp); 7121 free_tx_buffers(sp);
7224 7122
7225 /* Free all Rx buffers */ 7123 /* Free all Rx buffers */
7226 spin_lock_irqsave(&sp->rx_lock, flags);
7227 free_rx_buffers(sp); 7124 free_rx_buffers(sp);
7228 spin_unlock_irqrestore(&sp->rx_lock, flags);
7229 7125
7230 clear_bit(__S2IO_STATE_LINK_TASK, &(sp->state)); 7126 clear_bit(__S2IO_STATE_LINK_TASK, &(sp->state));
7231} 7127}
@@ -7314,9 +7210,6 @@ static int s2io_card_up(struct s2io_nic * sp)
7314 7210
7315 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2)); 7211 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
7316 7212
7317 /* Enable tasklet for the device */
7318 tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
7319
7320 /* Enable select interrupts */ 7213 /* Enable select interrupts */
7321 en_dis_err_alarms(sp, ENA_ALL_INTRS, ENABLE_INTRS); 7214 en_dis_err_alarms(sp, ENA_ALL_INTRS, ENABLE_INTRS);
7322 if (sp->config.intr_type != INTA) 7215 if (sp->config.intr_type != INTA)
@@ -8119,20 +8012,15 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
8119 s2io_reset(sp); 8012 s2io_reset(sp);
8120 8013
8121 /* 8014 /*
8122 * Initialize the tasklet status and link state flags 8015 * Initialize link state flags
8123 * and the card state parameter 8016 * and the card state parameter
8124 */ 8017 */
8125 sp->tasklet_status = 0;
8126 sp->state = 0; 8018 sp->state = 0;
8127 8019
8128 /* Initialize spinlocks */ 8020 /* Initialize spinlocks */
8129 for (i = 0; i < sp->config.tx_fifo_num; i++) 8021 for (i = 0; i < sp->config.tx_fifo_num; i++)
8130 spin_lock_init(&mac_control->fifos[i].tx_lock); 8022 spin_lock_init(&mac_control->fifos[i].tx_lock);
8131 8023
8132 if (!napi)
8133 spin_lock_init(&sp->put_lock);
8134 spin_lock_init(&sp->rx_lock);
8135
8136 /* 8024 /*
8137 * SXE-002: Configure link and activity LED to init state 8025 * SXE-002: Configure link and activity LED to init state
8138 * on driver load. 8026 * on driver load.
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index e68fdf7e4260..ce53a02105f2 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -703,9 +703,6 @@ struct ring_info {
703 */ 703 */
704 struct rx_curr_get_info rx_curr_get_info; 704 struct rx_curr_get_info rx_curr_get_info;
705 705
706 /* Index to the absolute position of the put pointer of Rx ring */
707 int put_pos;
708
709 /* Buffer Address store. */ 706 /* Buffer Address store. */
710 struct buffAdd **ba; 707 struct buffAdd **ba;
711 struct s2io_nic *nic; 708 struct s2io_nic *nic;
@@ -868,8 +865,6 @@ struct s2io_nic {
868 int device_enabled_once; 865 int device_enabled_once;
869 866
870 char name[60]; 867 char name[60];
871 struct tasklet_struct task;
872 volatile unsigned long tasklet_status;
873 868
874 /* Timer that handles I/O errors/exceptions */ 869 /* Timer that handles I/O errors/exceptions */
875 struct timer_list alarm_timer; 870 struct timer_list alarm_timer;
@@ -879,8 +874,6 @@ struct s2io_nic {
879 874
880 atomic_t rx_bufs_left[MAX_RX_RINGS]; 875 atomic_t rx_bufs_left[MAX_RX_RINGS];
881 876
882 spinlock_t put_lock;
883
884#define PROMISC 1 877#define PROMISC 1
885#define ALL_MULTI 2 878#define ALL_MULTI 2
886 879
@@ -964,7 +957,6 @@ struct s2io_nic {
964 u8 lro; 957 u8 lro;
965 u16 lro_max_aggr_per_sess; 958 u16 lro_max_aggr_per_sess;
966 volatile unsigned long state; 959 volatile unsigned long state;
967 spinlock_t rx_lock;
968 u64 general_int_mask; 960 u64 general_int_mask;
969#define VPD_STRING_LEN 80 961#define VPD_STRING_LEN 80
970 u8 product_name[VPD_STRING_LEN]; 962 u8 product_name[VPD_STRING_LEN];
@@ -1094,7 +1086,6 @@ static void s2io_handle_errors(void * dev_id);
1094static int s2io_starter(void); 1086static int s2io_starter(void);
1095static void s2io_closer(void); 1087static void s2io_closer(void);
1096static void s2io_tx_watchdog(struct net_device *dev); 1088static void s2io_tx_watchdog(struct net_device *dev);
1097static void s2io_tasklet(unsigned long dev_addr);
1098static void s2io_set_multicast(struct net_device *dev); 1089static void s2io_set_multicast(struct net_device *dev);
1099static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp); 1090static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp);
1100static void s2io_link(struct s2io_nic * sp, int link); 1091static void s2io_link(struct s2io_nic * sp, int link);
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index 78994ede0cb0..6261201403cd 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -825,7 +825,8 @@ static struct platform_driver sgiseeq_driver = {
825 .probe = sgiseeq_probe, 825 .probe = sgiseeq_probe,
826 .remove = __devexit_p(sgiseeq_remove), 826 .remove = __devexit_p(sgiseeq_remove),
827 .driver = { 827 .driver = {
828 .name = "sgiseeq" 828 .name = "sgiseeq",
829 .owner = THIS_MODULE,
829 } 830 }
830}; 831};
831 832
@@ -850,3 +851,4 @@ module_exit(sgiseeq_module_exit);
850MODULE_DESCRIPTION("SGI Seeq 8003 driver"); 851MODULE_DESCRIPTION("SGI Seeq 8003 driver");
851MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>"); 852MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
852MODULE_LICENSE("GPL"); 853MODULE_LICENSE("GPL");
854MODULE_ALIAS("platform:sgiseeq");
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 76cc1d3adf71..4e2800205189 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -92,6 +92,7 @@ module_param(tx_fifo_kb, int, 0400);
92MODULE_PARM_DESC(tx_fifo_kb,"transmit FIFO size in KB (1<x<15)(default=8)"); 92MODULE_PARM_DESC(tx_fifo_kb,"transmit FIFO size in KB (1<x<15)(default=8)");
93 93
94MODULE_LICENSE("GPL"); 94MODULE_LICENSE("GPL");
95MODULE_ALIAS("platform:smc911x");
95 96
96/* 97/*
97 * The internal workings of the driver. If you are changing anything 98 * The internal workings of the driver. If you are changing anything
@@ -243,7 +244,7 @@ static void smc911x_reset(struct net_device *dev)
243 do { 244 do {
244 udelay(10); 245 udelay(10);
245 reg = SMC_GET_PMT_CTRL() & PMT_CTRL_READY_; 246 reg = SMC_GET_PMT_CTRL() & PMT_CTRL_READY_;
246 } while ( timeout-- && !reg); 247 } while (--timeout && !reg);
247 if (timeout == 0) { 248 if (timeout == 0) {
248 PRINTK("%s: smc911x_reset timeout waiting for PM restore\n", dev->name); 249 PRINTK("%s: smc911x_reset timeout waiting for PM restore\n", dev->name);
249 return; 250 return;
@@ -267,7 +268,7 @@ static void smc911x_reset(struct net_device *dev)
267 resets++; 268 resets++;
268 break; 269 break;
269 } 270 }
270 } while ( timeout-- && (reg & HW_CFG_SRST_)); 271 } while (--timeout && (reg & HW_CFG_SRST_));
271 } 272 }
272 if (timeout == 0) { 273 if (timeout == 0) {
273 PRINTK("%s: smc911x_reset timeout waiting for reset\n", dev->name); 274 PRINTK("%s: smc911x_reset timeout waiting for reset\n", dev->name);
@@ -413,7 +414,7 @@ static inline void smc911x_drop_pkt(struct net_device *dev)
413 do { 414 do {
414 udelay(10); 415 udelay(10);
415 reg = SMC_GET_RX_DP_CTRL() & RX_DP_CTRL_FFWD_BUSY_; 416 reg = SMC_GET_RX_DP_CTRL() & RX_DP_CTRL_FFWD_BUSY_;
416 } while ( timeout-- && reg); 417 } while (--timeout && reg);
417 if (timeout == 0) { 418 if (timeout == 0) {
418 PRINTK("%s: timeout waiting for RX fast forward\n", dev->name); 419 PRINTK("%s: timeout waiting for RX fast forward\n", dev->name);
419 } 420 }
@@ -2262,6 +2263,7 @@ static struct platform_driver smc911x_driver = {
2262 .resume = smc911x_drv_resume, 2263 .resume = smc911x_drv_resume,
2263 .driver = { 2264 .driver = {
2264 .name = CARDNAME, 2265 .name = CARDNAME,
2266 .owner = THIS_MODULE,
2265 }, 2267 },
2266}; 2268};
2267 2269
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index 600b92af3334..a188e33484e6 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -132,6 +132,7 @@ module_param(watchdog, int, 0400);
132MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); 132MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
133 133
134MODULE_LICENSE("GPL"); 134MODULE_LICENSE("GPL");
135MODULE_ALIAS("platform:smc91x");
135 136
136/* 137/*
137 * The internal workings of the driver. If you are changing anything 138 * The internal workings of the driver. If you are changing anything
@@ -2308,6 +2309,7 @@ static struct platform_driver smc_driver = {
2308 .resume = smc_drv_resume, 2309 .resume = smc_drv_resume,
2309 .driver = { 2310 .driver = {
2310 .name = CARDNAME, 2311 .name = CARDNAME,
2312 .owner = THIS_MODULE,
2311 }, 2313 },
2312}; 2314};
2313 2315
diff --git a/drivers/net/sni_82596.c b/drivers/net/sni_82596.c
index 2cf6794acb4f..854ccf2b4105 100644
--- a/drivers/net/sni_82596.c
+++ b/drivers/net/sni_82596.c
@@ -44,6 +44,7 @@ static const char sni_82596_string[] = "snirm_82596";
44MODULE_AUTHOR("Thomas Bogendoerfer"); 44MODULE_AUTHOR("Thomas Bogendoerfer");
45MODULE_DESCRIPTION("i82596 driver"); 45MODULE_DESCRIPTION("i82596 driver");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_ALIAS("platform:snirm_82596");
47module_param(i596_debug, int, 0); 48module_param(i596_debug, int, 0);
48MODULE_PARM_DESC(i596_debug, "82596 debug mask"); 49MODULE_PARM_DESC(i596_debug, "82596 debug mask");
49 50
@@ -166,6 +167,7 @@ static struct platform_driver sni_82596_driver = {
166 .remove = __devexit_p(sni_82596_driver_remove), 167 .remove = __devexit_p(sni_82596_driver_remove),
167 .driver = { 168 .driver = {
168 .name = sni_82596_string, 169 .name = sni_82596_string,
170 .owner = THIS_MODULE,
169 }, 171 },
170}; 172};
171 173
diff --git a/drivers/net/tehuti.c b/drivers/net/tehuti.c
index 17585e5eed53..e83b166aa6b9 100644
--- a/drivers/net/tehuti.c
+++ b/drivers/net/tehuti.c
@@ -625,6 +625,12 @@ static void __init bdx_firmware_endianess(void)
625 s_firmLoad[i] = CPU_CHIP_SWAP32(s_firmLoad[i]); 625 s_firmLoad[i] = CPU_CHIP_SWAP32(s_firmLoad[i]);
626} 626}
627 627
628static int bdx_range_check(struct bdx_priv *priv, u32 offset)
629{
630 return (offset > (u32) (BDX_REGS_SIZE / priv->nic->port_num)) ?
631 -EINVAL : 0;
632}
633
628static int bdx_ioctl_priv(struct net_device *ndev, struct ifreq *ifr, int cmd) 634static int bdx_ioctl_priv(struct net_device *ndev, struct ifreq *ifr, int cmd)
629{ 635{
630 struct bdx_priv *priv = ndev->priv; 636 struct bdx_priv *priv = ndev->priv;
@@ -643,9 +649,15 @@ static int bdx_ioctl_priv(struct net_device *ndev, struct ifreq *ifr, int cmd)
643 DBG("%d 0x%x 0x%x\n", data[0], data[1], data[2]); 649 DBG("%d 0x%x 0x%x\n", data[0], data[1], data[2]);
644 } 650 }
645 651
652 if (!capable(CAP_NET_ADMIN))
653 return -EPERM;
654
646 switch (data[0]) { 655 switch (data[0]) {
647 656
648 case BDX_OP_READ: 657 case BDX_OP_READ:
658 error = bdx_range_check(priv, data[1]);
659 if (error < 0)
660 return error;
649 data[2] = READ_REG(priv, data[1]); 661 data[2] = READ_REG(priv, data[1]);
650 DBG("read_reg(0x%x)=0x%x (dec %d)\n", data[1], data[2], 662 DBG("read_reg(0x%x)=0x%x (dec %d)\n", data[1], data[2],
651 data[2]); 663 data[2]);
@@ -655,6 +667,9 @@ static int bdx_ioctl_priv(struct net_device *ndev, struct ifreq *ifr, int cmd)
655 break; 667 break;
656 668
657 case BDX_OP_WRITE: 669 case BDX_OP_WRITE:
670 error = bdx_range_check(priv, data[1]);
671 if (error < 0)
672 return error;
658 WRITE_REG(priv, data[1], data[2]); 673 WRITE_REG(priv, data[1], data[2]);
659 DBG("write_reg(0x%x, 0x%x)\n", data[1], data[2]); 674 DBG("write_reg(0x%x, 0x%x)\n", data[1], data[2]);
660 break; 675 break;
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index bc4c62b8e81a..e3f74c9f78bd 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -4017,6 +4017,8 @@ static int tg3_halt(struct tg3 *, int, int);
4017 * Invoked with tp->lock held. 4017 * Invoked with tp->lock held.
4018 */ 4018 */
4019static int tg3_restart_hw(struct tg3 *tp, int reset_phy) 4019static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
4020 __releases(tp->lock)
4021 __acquires(tp->lock)
4020{ 4022{
4021 int err; 4023 int err;
4022 4024
diff --git a/drivers/net/tsi108_eth.c b/drivers/net/tsi108_eth.c
index 6f33f84d37b0..6017d5267d08 100644
--- a/drivers/net/tsi108_eth.c
+++ b/drivers/net/tsi108_eth.c
@@ -162,6 +162,7 @@ static struct platform_driver tsi_eth_driver = {
162 .remove = tsi108_ether_remove, 162 .remove = tsi108_ether_remove,
163 .driver = { 163 .driver = {
164 .name = "tsi-ethernet", 164 .name = "tsi-ethernet",
165 .owner = THIS_MODULE,
165 }, 166 },
166}; 167};
167 168
@@ -1729,3 +1730,4 @@ module_exit(tsi108_ether_exit);
1729MODULE_AUTHOR("Tundra Semiconductor Corporation"); 1730MODULE_AUTHOR("Tundra Semiconductor Corporation");
1730MODULE_DESCRIPTION("Tsi108 Gigabit Ethernet driver"); 1731MODULE_DESCRIPTION("Tsi108 Gigabit Ethernet driver");
1731MODULE_LICENSE("GPL"); 1732MODULE_LICENSE("GPL");
1733MODULE_ALIAS("platform:tsi-ethernet");
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 333961bb7873..c0dd25ba7a18 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -2183,7 +2183,6 @@ typhoon_resume(struct pci_dev *pdev)
2183 } 2183 }
2184 2184
2185 netif_device_attach(dev); 2185 netif_device_attach(dev);
2186 netif_start_queue(dev);
2187 return 0; 2186 return 0;
2188 2187
2189reset: 2188reset:
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 2f11254bcc07..281ce3d39532 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -3932,7 +3932,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3932 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0); 3932 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
3933 fixed_link = of_get_property(np, "fixed-link", NULL); 3933 fixed_link = of_get_property(np, "fixed-link", NULL);
3934 if (fixed_link) { 3934 if (fixed_link) {
3935 ug_info->mdio_bus = 0; 3935 snprintf(ug_info->mdio_bus, MII_BUS_ID_SIZE, "0");
3936 ug_info->phy_address = fixed_link[0]; 3936 ug_info->phy_address = fixed_link[0];
3937 phy = NULL; 3937 phy = NULL;
3938 } else { 3938 } else {
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index ed1afaf683a4..6b8d882d197b 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -605,7 +605,6 @@ static void __devinit velocity_get_options(struct velocity_opt *opts, int index,
605static void velocity_init_cam_filter(struct velocity_info *vptr) 605static void velocity_init_cam_filter(struct velocity_info *vptr)
606{ 606{
607 struct mac_regs __iomem * regs = vptr->mac_regs; 607 struct mac_regs __iomem * regs = vptr->mac_regs;
608 unsigned short vid;
609 608
610 /* Turn on MCFG_PQEN, turn off MCFG_RTGOPT */ 609 /* Turn on MCFG_PQEN, turn off MCFG_RTGOPT */
611 WORD_REG_BITS_SET(MCFG_PQEN, MCFG_RTGOPT, &regs->MCFG); 610 WORD_REG_BITS_SET(MCFG_PQEN, MCFG_RTGOPT, &regs->MCFG);
@@ -617,29 +616,33 @@ static void velocity_init_cam_filter(struct velocity_info *vptr)
617 mac_set_vlan_cam_mask(regs, vptr->vCAMmask); 616 mac_set_vlan_cam_mask(regs, vptr->vCAMmask);
618 mac_set_cam_mask(regs, vptr->mCAMmask); 617 mac_set_cam_mask(regs, vptr->mCAMmask);
619 618
620 /* Enable first VCAM */ 619 /* Enable VCAMs */
621 if (vptr->vlgrp) { 620 if (vptr->vlgrp) {
622 for (vid = 0; vid < VLAN_VID_MASK; vid++) { 621 unsigned int vid, i = 0;
623 if (vlan_group_get_device(vptr->vlgrp, vid)) { 622
624 /* If Tagging option is enabled and 623 if (!vlan_group_get_device(vptr->vlgrp, 0))
625 VLAN ID is not zero, then 624 WORD_REG_BITS_ON(MCFG_RTGOPT, &regs->MCFG);
626 turn on MCFG_RTGOPT also */
627 if (vid != 0)
628 WORD_REG_BITS_ON(MCFG_RTGOPT, &regs->MCFG);
629 625
630 mac_set_vlan_cam(regs, 0, (u8 *) &vid); 626 for (vid = 1; (vid < VLAN_VID_MASK); vid++) {
627 if (vlan_group_get_device(vptr->vlgrp, vid)) {
628 mac_set_vlan_cam(regs, i, (u8 *) &vid);
629 vptr->vCAMmask[i / 8] |= 0x1 << (i % 8);
630 if (++i >= VCAM_SIZE)
631 break;
631 } 632 }
632 } 633 }
633 vptr->vCAMmask[0] |= 1;
634 mac_set_vlan_cam_mask(regs, vptr->vCAMmask); 634 mac_set_vlan_cam_mask(regs, vptr->vCAMmask);
635 } else {
636 u16 temp = 0;
637 mac_set_vlan_cam(regs, 0, (u8 *) &temp);
638 temp = 1;
639 mac_set_vlan_cam_mask(regs, (u8 *) &temp);
640 } 635 }
641} 636}
642 637
638static void velocity_vlan_rx_register(struct net_device *dev,
639 struct vlan_group *grp)
640{
641 struct velocity_info *vptr = netdev_priv(dev);
642
643 vptr->vlgrp = grp;
644}
645
643static void velocity_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) 646static void velocity_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
644{ 647{
645 struct velocity_info *vptr = netdev_priv(dev); 648 struct velocity_info *vptr = netdev_priv(dev);
@@ -959,11 +962,13 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
959 962
960 dev->vlan_rx_add_vid = velocity_vlan_rx_add_vid; 963 dev->vlan_rx_add_vid = velocity_vlan_rx_add_vid;
961 dev->vlan_rx_kill_vid = velocity_vlan_rx_kill_vid; 964 dev->vlan_rx_kill_vid = velocity_vlan_rx_kill_vid;
965 dev->vlan_rx_register = velocity_vlan_rx_register;
962 966
963#ifdef VELOCITY_ZERO_COPY_SUPPORT 967#ifdef VELOCITY_ZERO_COPY_SUPPORT
964 dev->features |= NETIF_F_SG; 968 dev->features |= NETIF_F_SG;
965#endif 969#endif
966 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_FILTER; 970 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_FILTER |
971 NETIF_F_HW_VLAN_RX;
967 972
968 if (vptr->flags & VELOCITY_FLAGS_TX_CSUM) 973 if (vptr->flags & VELOCITY_FLAGS_TX_CSUM)
969 dev->features |= NETIF_F_IP_CSUM; 974 dev->features |= NETIF_F_IP_CSUM;
@@ -1597,8 +1602,13 @@ static int velocity_receive_frame(struct velocity_info *vptr, int idx)
1597 skb_put(skb, pkt_len - 4); 1602 skb_put(skb, pkt_len - 4);
1598 skb->protocol = eth_type_trans(skb, vptr->dev); 1603 skb->protocol = eth_type_trans(skb, vptr->dev);
1599 1604
1605 if (vptr->vlgrp && (rd->rdesc0.RSR & RSR_DETAG)) {
1606 vlan_hwaccel_rx(skb, vptr->vlgrp,
1607 swab16(le16_to_cpu(rd->rdesc1.PQTAG)));
1608 } else
1609 netif_rx(skb);
1610
1600 stats->rx_bytes += pkt_len; 1611 stats->rx_bytes += pkt_len;
1601 netif_rx(skb);
1602 1612
1603 return 0; 1613 return 0;
1604} 1614}
diff --git a/drivers/net/wan/c101.c b/drivers/net/wan/c101.c
index c4c8eab8574f..c2cc42f723d5 100644
--- a/drivers/net/wan/c101.c
+++ b/drivers/net/wan/c101.c
@@ -402,7 +402,7 @@ static int __init c101_init(void)
402#ifdef MODULE 402#ifdef MODULE
403 printk(KERN_INFO "c101: no card initialized\n"); 403 printk(KERN_INFO "c101: no card initialized\n");
404#endif 404#endif
405 return -ENOSYS; /* no parameters specified, abort */ 405 return -EINVAL; /* no parameters specified, abort */
406 } 406 }
407 407
408 printk(KERN_INFO "%s\n", version); 408 printk(KERN_INFO "%s\n", version);
@@ -420,11 +420,11 @@ static int __init c101_init(void)
420 c101_run(irq, ram); 420 c101_run(irq, ram);
421 421
422 if (*hw == '\x0') 422 if (*hw == '\x0')
423 return first_card ? 0 : -ENOSYS; 423 return first_card ? 0 : -EINVAL;
424 }while(*hw++ == ':'); 424 }while(*hw++ == ':');
425 425
426 printk(KERN_ERR "c101: invalid hardware parameters\n"); 426 printk(KERN_ERR "c101: invalid hardware parameters\n");
427 return first_card ? 0 : -ENOSYS; 427 return first_card ? 0 : -EINVAL;
428} 428}
429 429
430 430
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index c4ab0326f911..520bb0b1a9a2 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -1090,10 +1090,6 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
1090 pvc_device *pvc = NULL; 1090 pvc_device *pvc = NULL;
1091 struct net_device *dev; 1091 struct net_device *dev;
1092 int result, used; 1092 int result, used;
1093 char * prefix = "pvc%d";
1094
1095 if (type == ARPHRD_ETHER)
1096 prefix = "pvceth%d";
1097 1093
1098 if ((pvc = add_pvc(frad, dlci)) == NULL) { 1094 if ((pvc = add_pvc(frad, dlci)) == NULL) {
1099 printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n", 1095 printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n",
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 7483d45bc5bc..e62018a36133 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -1809,3 +1809,5 @@ module_exit(netif_exit);
1809 1809
1810MODULE_DESCRIPTION("Xen virtual network device frontend"); 1810MODULE_DESCRIPTION("Xen virtual network device frontend");
1811MODULE_LICENSE("GPL"); 1811MODULE_LICENSE("GPL");
1812MODULE_ALIAS("xen:vif");
1813MODULE_ALIAS("xennet");
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index 631689171159..715a44471617 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/module.h>
16 17
17struct i2c_driver_device { 18struct i2c_driver_device {
18 char *of_device; 19 char *of_device;
@@ -113,3 +114,5 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
113 } 114 }
114} 115}
115EXPORT_SYMBOL(of_register_i2c_devices); 116EXPORT_SYMBOL(of_register_i2c_devices);
117
118MODULE_LICENSE("GPL");
diff --git a/drivers/serial/of_serial.c b/drivers/serial/of_serial.c
index 8aacfb78deab..25029c7570b6 100644
--- a/drivers/serial/of_serial.c
+++ b/drivers/serial/of_serial.c
@@ -31,7 +31,8 @@ static int __devinit of_platform_serial_setup(struct of_device *ofdev,
31 struct resource resource; 31 struct resource resource;
32 struct device_node *np = ofdev->node; 32 struct device_node *np = ofdev->node;
33 const unsigned int *clk, *spd; 33 const unsigned int *clk, *spd;
34 int ret; 34 const u32 *prop;
35 int ret, prop_size;
35 36
36 memset(port, 0, sizeof *port); 37 memset(port, 0, sizeof *port);
37 spd = of_get_property(np, "current-speed", NULL); 38 spd = of_get_property(np, "current-speed", NULL);
@@ -49,6 +50,17 @@ static int __devinit of_platform_serial_setup(struct of_device *ofdev,
49 50
50 spin_lock_init(&port->lock); 51 spin_lock_init(&port->lock);
51 port->mapbase = resource.start; 52 port->mapbase = resource.start;
53
54 /* Check for shifted address mapping */
55 prop = of_get_property(np, "reg-offset", &prop_size);
56 if (prop && (prop_size == sizeof(u32)))
57 port->mapbase += *prop;
58
59 /* Check for registers offset within the devices address range */
60 prop = of_get_property(np, "reg-shift", &prop_size);
61 if (prop && (prop_size == sizeof(u32)))
62 port->regshift = *prop;
63
52 port->irq = irq_of_parse_and_map(np, 0); 64 port->irq = irq_of_parse_and_map(np, 0);
53 port->iotype = UPIO_MEM; 65 port->iotype = UPIO_MEM;
54 port->type = type; 66 port->type = type;
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index a51eeedc18d4..d470c72b737e 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -444,7 +444,7 @@ CXACRU_ALL_FILES(INIT);
444/* the following three functions are stolen from drivers/usb/core/message.c */ 444/* the following three functions are stolen from drivers/usb/core/message.c */
445static void cxacru_blocking_completion(struct urb *urb) 445static void cxacru_blocking_completion(struct urb *urb)
446{ 446{
447 complete((struct completion *)urb->context); 447 complete(urb->context);
448} 448}
449 449
450static void cxacru_timeout_kill(unsigned long data) 450static void cxacru_timeout_kill(unsigned long data)
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index c5ec1a55eee3..abb7d7410e63 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -83,7 +83,7 @@
83 if (debug >= 1) \ 83 if (debug >= 1) \
84 dev_dbg(&(usb_dev)->dev, \ 84 dev_dbg(&(usb_dev)->dev, \
85 "[ueagle-atm dbg] %s: " format, \ 85 "[ueagle-atm dbg] %s: " format, \
86 __FUNCTION__, ##args); \ 86 __func__, ##args); \
87 } while (0) 87 } while (0)
88 88
89#define uea_vdbg(usb_dev, format, args...) \ 89#define uea_vdbg(usb_dev, format, args...) \
@@ -94,10 +94,10 @@
94 } while (0) 94 } while (0)
95 95
96#define uea_enters(usb_dev) \ 96#define uea_enters(usb_dev) \
97 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__) 97 uea_vdbg(usb_dev, "entering %s\n", __func__)
98 98
99#define uea_leaves(usb_dev) \ 99#define uea_leaves(usb_dev) \
100 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__) 100 uea_vdbg(usb_dev, "leaving %s\n", __func__)
101 101
102#define uea_err(usb_dev, format,args...) \ 102#define uea_err(usb_dev, format,args...) \
103 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args) 103 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index e717f5b1caee..07228721cafe 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -80,6 +80,7 @@
80#include <linux/stat.h> 80#include <linux/stat.h>
81#include <linux/timer.h> 81#include <linux/timer.h>
82#include <linux/wait.h> 82#include <linux/wait.h>
83#include <linux/kthread.h>
83 84
84#ifdef VERBOSE_DEBUG 85#ifdef VERBOSE_DEBUG
85static int usbatm_print_packet(const unsigned char *data, int len); 86static int usbatm_print_packet(const unsigned char *data, int len);
@@ -1014,10 +1015,7 @@ static int usbatm_do_heavy_init(void *arg)
1014 struct usbatm_data *instance = arg; 1015 struct usbatm_data *instance = arg;
1015 int ret; 1016 int ret;
1016 1017
1017 daemonize(instance->driver->driver_name);
1018 allow_signal(SIGTERM); 1018 allow_signal(SIGTERM);
1019 instance->thread_pid = current->pid;
1020
1021 complete(&instance->thread_started); 1019 complete(&instance->thread_started);
1022 1020
1023 ret = instance->driver->heavy_init(instance, instance->usb_intf); 1021 ret = instance->driver->heavy_init(instance, instance->usb_intf);
@@ -1026,7 +1024,7 @@ static int usbatm_do_heavy_init(void *arg)
1026 ret = usbatm_atm_init(instance); 1024 ret = usbatm_atm_init(instance);
1027 1025
1028 mutex_lock(&instance->serialize); 1026 mutex_lock(&instance->serialize);
1029 instance->thread_pid = -1; 1027 instance->thread = NULL;
1030 mutex_unlock(&instance->serialize); 1028 mutex_unlock(&instance->serialize);
1031 1029
1032 complete_and_exit(&instance->thread_exited, ret); 1030 complete_and_exit(&instance->thread_exited, ret);
@@ -1034,13 +1032,18 @@ static int usbatm_do_heavy_init(void *arg)
1034 1032
1035static int usbatm_heavy_init(struct usbatm_data *instance) 1033static int usbatm_heavy_init(struct usbatm_data *instance)
1036{ 1034{
1037 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_FS | CLONE_FILES); 1035 struct task_struct *t;
1038 1036
1039 if (ret < 0) { 1037 t = kthread_create(usbatm_do_heavy_init, instance,
1040 usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret); 1038 instance->driver->driver_name);
1041 return ret; 1039 if (IS_ERR(t)) {
1040 usb_err(instance, "%s: failed to create kernel_thread (%ld)!\n",
1041 __func__, PTR_ERR(t));
1042 return PTR_ERR(t);
1042 } 1043 }
1043 1044
1045 instance->thread = t;
1046 wake_up_process(t);
1044 wait_for_completion(&instance->thread_started); 1047 wait_for_completion(&instance->thread_started);
1045 1048
1046 return 0; 1049 return 0;
@@ -1124,7 +1127,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1124 kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */ 1127 kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
1125 mutex_init(&instance->serialize); 1128 mutex_init(&instance->serialize);
1126 1129
1127 instance->thread_pid = -1; 1130 instance->thread = NULL;
1128 init_completion(&instance->thread_started); 1131 init_completion(&instance->thread_started);
1129 init_completion(&instance->thread_exited); 1132 init_completion(&instance->thread_exited);
1130 1133
@@ -1287,8 +1290,8 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1287 1290
1288 mutex_lock(&instance->serialize); 1291 mutex_lock(&instance->serialize);
1289 instance->disconnected = 1; 1292 instance->disconnected = 1;
1290 if (instance->thread_pid >= 0) 1293 if (instance->thread != NULL)
1291 kill_proc(instance->thread_pid, SIGTERM, 1); 1294 send_sig(SIGTERM, instance->thread, 1);
1292 mutex_unlock(&instance->serialize); 1295 mutex_unlock(&instance->serialize);
1293 1296
1294 wait_for_completion(&instance->thread_exited); 1297 wait_for_completion(&instance->thread_exited);
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
index fc6c2be5999c..e6887c6cf3cf 100644
--- a/drivers/usb/atm/usbatm.h
+++ b/drivers/usb/atm/usbatm.h
@@ -175,7 +175,7 @@ struct usbatm_data {
175 int disconnected; 175 int disconnected;
176 176
177 /* heavy init */ 177 /* heavy init */
178 int thread_pid; 178 struct task_struct *thread;
179 struct completion thread_started; 179 struct completion thread_started;
180 struct completion thread_exited; 180 struct completion thread_exited;
181 181
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 0147ea39340e..7b572e75e73c 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -31,6 +31,7 @@
31 * v0.23 - use softirq for rx processing, as needed by tty layer 31 * v0.23 - use softirq for rx processing, as needed by tty layer
32 * v0.24 - change probe method to evaluate CDC union descriptor 32 * v0.24 - change probe method to evaluate CDC union descriptor
33 * v0.25 - downstream tasks paralelized to maximize throughput 33 * v0.25 - downstream tasks paralelized to maximize throughput
34 * v0.26 - multiple write urbs, writesize increased
34 */ 35 */
35 36
36/* 37/*
@@ -72,7 +73,7 @@
72/* 73/*
73 * Version Information 74 * Version Information
74 */ 75 */
75#define DRIVER_VERSION "v0.25" 76#define DRIVER_VERSION "v0.26"
76#define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek" 77#define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek"
77#define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters" 78#define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters"
78 79
@@ -118,7 +119,7 @@ static int acm_wb_alloc(struct acm *acm)
118 int i, wbn; 119 int i, wbn;
119 struct acm_wb *wb; 120 struct acm_wb *wb;
120 121
121 wbn = acm->write_current; 122 wbn = 0;
122 i = 0; 123 i = 0;
123 for (;;) { 124 for (;;) {
124 wb = &acm->wb[wbn]; 125 wb = &acm->wb[wbn];
@@ -132,11 +133,6 @@ static int acm_wb_alloc(struct acm *acm)
132 } 133 }
133} 134}
134 135
135static void acm_wb_free(struct acm *acm, int wbn)
136{
137 acm->wb[wbn].use = 0;
138}
139
140static int acm_wb_is_avail(struct acm *acm) 136static int acm_wb_is_avail(struct acm *acm)
141{ 137{
142 int i, n; 138 int i, n;
@@ -156,26 +152,22 @@ static inline int acm_wb_is_used(struct acm *acm, int wbn)
156/* 152/*
157 * Finish write. 153 * Finish write.
158 */ 154 */
159static void acm_write_done(struct acm *acm) 155static void acm_write_done(struct acm *acm, struct acm_wb *wb)
160{ 156{
161 unsigned long flags; 157 unsigned long flags;
162 int wbn;
163 158
164 spin_lock_irqsave(&acm->write_lock, flags); 159 spin_lock_irqsave(&acm->write_lock, flags);
165 acm->write_ready = 1; 160 acm->write_ready = 1;
166 wbn = acm->write_current; 161 wb->use = 0;
167 acm_wb_free(acm, wbn);
168 acm->write_current = (wbn + 1) % ACM_NW;
169 spin_unlock_irqrestore(&acm->write_lock, flags); 162 spin_unlock_irqrestore(&acm->write_lock, flags);
170} 163}
171 164
172/* 165/*
173 * Poke write. 166 * Poke write.
174 */ 167 */
175static int acm_write_start(struct acm *acm) 168static int acm_write_start(struct acm *acm, int wbn)
176{ 169{
177 unsigned long flags; 170 unsigned long flags;
178 int wbn;
179 struct acm_wb *wb; 171 struct acm_wb *wb;
180 int rc; 172 int rc;
181 173
@@ -190,24 +182,24 @@ static int acm_write_start(struct acm *acm)
190 return 0; /* A white lie */ 182 return 0; /* A white lie */
191 } 183 }
192 184
193 wbn = acm->write_current;
194 if (!acm_wb_is_used(acm, wbn)) { 185 if (!acm_wb_is_used(acm, wbn)) {
195 spin_unlock_irqrestore(&acm->write_lock, flags); 186 spin_unlock_irqrestore(&acm->write_lock, flags);
196 return 0; 187 return 0;
197 } 188 }
198 wb = &acm->wb[wbn]; 189 wb = &acm->wb[wbn];
199 190
200 acm->write_ready = 0; 191 if(acm_wb_is_avail(acm) <= 1)
192 acm->write_ready = 0;
201 spin_unlock_irqrestore(&acm->write_lock, flags); 193 spin_unlock_irqrestore(&acm->write_lock, flags);
202 194
203 acm->writeurb->transfer_buffer = wb->buf; 195 wb->urb->transfer_buffer = wb->buf;
204 acm->writeurb->transfer_dma = wb->dmah; 196 wb->urb->transfer_dma = wb->dmah;
205 acm->writeurb->transfer_buffer_length = wb->len; 197 wb->urb->transfer_buffer_length = wb->len;
206 acm->writeurb->dev = acm->dev; 198 wb->urb->dev = acm->dev;
207 199
208 if ((rc = usb_submit_urb(acm->writeurb, GFP_ATOMIC)) < 0) { 200 if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) {
209 dbg("usb_submit_urb(write bulk) failed: %d", rc); 201 dbg("usb_submit_urb(write bulk) failed: %d", rc);
210 acm_write_done(acm); 202 acm_write_done(acm, wb);
211 } 203 }
212 return rc; 204 return rc;
213} 205}
@@ -268,10 +260,10 @@ static void acm_ctrl_irq(struct urb *urb)
268 case -ENOENT: 260 case -ENOENT:
269 case -ESHUTDOWN: 261 case -ESHUTDOWN:
270 /* this urb is terminated, clean up */ 262 /* this urb is terminated, clean up */
271 dbg("%s - urb shutting down with status: %d", __FUNCTION__, status); 263 dbg("%s - urb shutting down with status: %d", __func__, status);
272 return; 264 return;
273 default: 265 default:
274 dbg("%s - nonzero urb status received: %d", __FUNCTION__, status); 266 dbg("%s - nonzero urb status received: %d", __func__, status);
275 goto exit; 267 goto exit;
276 } 268 }
277 269
@@ -315,7 +307,7 @@ exit:
315 retval = usb_submit_urb (urb, GFP_ATOMIC); 307 retval = usb_submit_urb (urb, GFP_ATOMIC);
316 if (retval) 308 if (retval)
317 err ("%s - usb_submit_urb failed with result %d", 309 err ("%s - usb_submit_urb failed with result %d",
318 __FUNCTION__, retval); 310 __func__, retval);
319} 311}
320 312
321/* data interface returns incoming bytes, or we got unthrottled */ 313/* data interface returns incoming bytes, or we got unthrottled */
@@ -450,12 +442,13 @@ urbs:
450/* data interface wrote those outgoing bytes */ 442/* data interface wrote those outgoing bytes */
451static void acm_write_bulk(struct urb *urb) 443static void acm_write_bulk(struct urb *urb)
452{ 444{
453 struct acm *acm = (struct acm *)urb->context; 445 struct acm *acm;
446 struct acm_wb *wb = urb->context;
454 447
455 dbg("Entering acm_write_bulk with status %d", urb->status); 448 dbg("Entering acm_write_bulk with status %d", urb->status);
456 449
457 acm_write_done(acm); 450 acm = wb->instance;
458 acm_write_start(acm); 451 acm_write_done(acm, wb);
459 if (ACM_READY(acm)) 452 if (ACM_READY(acm))
460 schedule_work(&acm->work); 453 schedule_work(&acm->work);
461} 454}
@@ -489,6 +482,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
489 else 482 else
490 rv = 0; 483 rv = 0;
491 484
485 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
492 tty->driver_data = acm; 486 tty->driver_data = acm;
493 acm->tty = tty; 487 acm->tty = tty;
494 488
@@ -556,7 +550,8 @@ static void acm_tty_unregister(struct acm *acm)
556 usb_put_intf(acm->control); 550 usb_put_intf(acm->control);
557 acm_table[acm->minor] = NULL; 551 acm_table[acm->minor] = NULL;
558 usb_free_urb(acm->ctrlurb); 552 usb_free_urb(acm->ctrlurb);
559 usb_free_urb(acm->writeurb); 553 for (i = 0; i < ACM_NW; i++)
554 usb_free_urb(acm->wb[i].urb);
560 for (i = 0; i < nr; i++) 555 for (i = 0; i < nr; i++)
561 usb_free_urb(acm->ru[i].urb); 556 usb_free_urb(acm->ru[i].urb);
562 kfree(acm->country_codes); 557 kfree(acm->country_codes);
@@ -577,7 +572,8 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
577 if (acm->dev) { 572 if (acm->dev) {
578 acm_set_control(acm, acm->ctrlout = 0); 573 acm_set_control(acm, acm->ctrlout = 0);
579 usb_kill_urb(acm->ctrlurb); 574 usb_kill_urb(acm->ctrlurb);
580 usb_kill_urb(acm->writeurb); 575 for (i = 0; i < ACM_NW; i++)
576 usb_kill_urb(acm->wb[i].urb);
581 for (i = 0; i < nr; i++) 577 for (i = 0; i < nr; i++)
582 usb_kill_urb(acm->ru[i].urb); 578 usb_kill_urb(acm->ru[i].urb);
583 usb_autopm_put_interface(acm->control); 579 usb_autopm_put_interface(acm->control);
@@ -605,7 +601,6 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
605 spin_lock_irqsave(&acm->write_lock, flags); 601 spin_lock_irqsave(&acm->write_lock, flags);
606 if ((wbn = acm_wb_alloc(acm)) < 0) { 602 if ((wbn = acm_wb_alloc(acm)) < 0) {
607 spin_unlock_irqrestore(&acm->write_lock, flags); 603 spin_unlock_irqrestore(&acm->write_lock, flags);
608 acm_write_start(acm);
609 return 0; 604 return 0;
610 } 605 }
611 wb = &acm->wb[wbn]; 606 wb = &acm->wb[wbn];
@@ -616,7 +611,7 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
616 wb->len = count; 611 wb->len = count;
617 spin_unlock_irqrestore(&acm->write_lock, flags); 612 spin_unlock_irqrestore(&acm->write_lock, flags);
618 613
619 if ((stat = acm_write_start(acm)) < 0) 614 if ((stat = acm_write_start(acm, wbn)) < 0)
620 return stat; 615 return stat;
621 return count; 616 return count;
622} 617}
@@ -809,7 +804,7 @@ static int acm_probe (struct usb_interface *intf,
809{ 804{
810 struct usb_cdc_union_desc *union_header = NULL; 805 struct usb_cdc_union_desc *union_header = NULL;
811 struct usb_cdc_country_functional_desc *cfd = NULL; 806 struct usb_cdc_country_functional_desc *cfd = NULL;
812 char *buffer = intf->altsetting->extra; 807 unsigned char *buffer = intf->altsetting->extra;
813 int buflen = intf->altsetting->extralen; 808 int buflen = intf->altsetting->extralen;
814 struct usb_interface *control_interface; 809 struct usb_interface *control_interface;
815 struct usb_interface *data_interface; 810 struct usb_interface *data_interface;
@@ -886,9 +881,13 @@ static int acm_probe (struct usb_interface *intf,
886 if ((call_management_function & 3) != 3) 881 if ((call_management_function & 3) != 3)
887 err("This device cannot do calls on its own. It is no modem."); 882 err("This device cannot do calls on its own. It is no modem.");
888 break; 883 break;
889
890 default: 884 default:
891 err("Ignoring extra header, type %d, length %d", buffer[2], buffer[0]); 885 /* there are LOTS more CDC descriptors that
886 * could legitimately be found here.
887 */
888 dev_dbg(&intf->dev, "Ignoring descriptor: "
889 "type %02x, length %d\n",
890 buffer[2], buffer[0]);
892 break; 891 break;
893 } 892 }
894next_desc: 893next_desc:
@@ -976,7 +975,7 @@ skip_normal_probe:
976 975
977 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); 976 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize);
978 readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); 977 readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2);
979 acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize); 978 acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20;
980 acm->control = control_interface; 979 acm->control = control_interface;
981 acm->data = data_interface; 980 acm->data = data_interface;
982 acm->minor = minor; 981 acm->minor = minor;
@@ -1031,10 +1030,19 @@ skip_normal_probe:
1031 goto alloc_fail7; 1030 goto alloc_fail7;
1032 } 1031 }
1033 } 1032 }
1034 acm->writeurb = usb_alloc_urb(0, GFP_KERNEL); 1033 for(i = 0; i < ACM_NW; i++)
1035 if (!acm->writeurb) { 1034 {
1036 dev_dbg(&intf->dev, "out of memory (writeurb kmalloc)\n"); 1035 struct acm_wb *snd = &(acm->wb[i]);
1037 goto alloc_fail7; 1036
1037 if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) {
1038 dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)");
1039 goto alloc_fail7;
1040 }
1041
1042 usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
1043 NULL, acm->writesize, acm_write_bulk, snd);
1044 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1045 snd->instance = acm;
1038 } 1046 }
1039 1047
1040 usb_set_intfdata (intf, acm); 1048 usb_set_intfdata (intf, acm);
@@ -1070,10 +1078,6 @@ skip_countries:
1070 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1078 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1071 acm->ctrlurb->transfer_dma = acm->ctrl_dma; 1079 acm->ctrlurb->transfer_dma = acm->ctrl_dma;
1072 1080
1073 usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
1074 NULL, acm->writesize, acm_write_bulk, acm);
1075 acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP;
1076
1077 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); 1081 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
1078 1082
1079 acm_set_control(acm, acm->ctrlout); 1083 acm_set_control(acm, acm->ctrlout);
@@ -1091,7 +1095,8 @@ skip_countries:
1091 1095
1092 return 0; 1096 return 0;
1093alloc_fail8: 1097alloc_fail8:
1094 usb_free_urb(acm->writeurb); 1098 for (i = 0; i < ACM_NW; i++)
1099 usb_free_urb(acm->wb[i].urb);
1095alloc_fail7: 1100alloc_fail7:
1096 for (i = 0; i < num_rx_buf; i++) 1101 for (i = 0; i < num_rx_buf; i++)
1097 usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); 1102 usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
@@ -1115,7 +1120,8 @@ static void stop_data_traffic(struct acm *acm)
1115 tasklet_disable(&acm->urb_task); 1120 tasklet_disable(&acm->urb_task);
1116 1121
1117 usb_kill_urb(acm->ctrlurb); 1122 usb_kill_urb(acm->ctrlurb);
1118 usb_kill_urb(acm->writeurb); 1123 for(i = 0; i < ACM_NW; i++)
1124 usb_kill_urb(acm->wb[i].urb);
1119 for (i = 0; i < acm->rx_buflimit; i++) 1125 for (i = 0; i < acm->rx_buflimit; i++)
1120 usb_kill_urb(acm->ru[i].urb); 1126 usb_kill_urb(acm->ru[i].urb);
1121 1127
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 8df6a57dcf9e..046e064b033a 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -59,7 +59,7 @@
59 * when processing onlcr, so we only need 2 buffers. These values must be 59 * when processing onlcr, so we only need 2 buffers. These values must be
60 * powers of 2. 60 * powers of 2.
61 */ 61 */
62#define ACM_NW 2 62#define ACM_NW 16
63#define ACM_NR 16 63#define ACM_NR 16
64 64
65struct acm_wb { 65struct acm_wb {
@@ -67,6 +67,8 @@ struct acm_wb {
67 dma_addr_t dmah; 67 dma_addr_t dmah;
68 int len; 68 int len;
69 int use; 69 int use;
70 struct urb *urb;
71 struct acm *instance;
70}; 72};
71 73
72struct acm_rb { 74struct acm_rb {
@@ -88,7 +90,7 @@ struct acm {
88 struct usb_interface *control; /* control interface */ 90 struct usb_interface *control; /* control interface */
89 struct usb_interface *data; /* data interface */ 91 struct usb_interface *data; /* data interface */
90 struct tty_struct *tty; /* the corresponding tty */ 92 struct tty_struct *tty; /* the corresponding tty */
91 struct urb *ctrlurb, *writeurb; /* urbs */ 93 struct urb *ctrlurb; /* urbs */
92 u8 *ctrl_buffer; /* buffers of urbs */ 94 u8 *ctrl_buffer; /* buffers of urbs */
93 dma_addr_t ctrl_dma; /* dma handles of buffers */ 95 dma_addr_t ctrl_dma; /* dma handles of buffers */
94 u8 *country_codes; /* country codes from device */ 96 u8 *country_codes; /* country codes from device */
@@ -103,7 +105,6 @@ struct acm {
103 struct list_head spare_read_urbs; 105 struct list_head spare_read_urbs;
104 struct list_head spare_read_bufs; 106 struct list_head spare_read_bufs;
105 struct list_head filled_read_bufs; 107 struct list_head filled_read_bufs;
106 int write_current; /* current write buffer */
107 int write_used; /* number of non-empty write buffers */ 108 int write_used; /* number of non-empty write buffers */
108 int write_ready; /* write urb is not running */ 109 int write_ready; /* write urb is not running */
109 spinlock_t write_lock; 110 spinlock_t write_lock;
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index a2b0aa48b8ea..cc9f397e8398 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -76,8 +76,8 @@ config USB_DEVICE_CLASS
76 NAME="bus/usb/$env{BUSNUM}/$env{DEVNUM}", MODE="0644" 76 NAME="bus/usb/$env{BUSNUM}/$env{DEVNUM}", MODE="0644"
77 77
78config USB_DYNAMIC_MINORS 78config USB_DYNAMIC_MINORS
79 bool "Dynamic USB minor allocation (EXPERIMENTAL)" 79 bool "Dynamic USB minor allocation"
80 depends on USB && EXPERIMENTAL 80 depends on USB
81 help 81 help
82 If you say Y here, the USB subsystem will use dynamic minor 82 If you say Y here, the USB subsystem will use dynamic minor
83 allocation for any device that uses the USB major number. 83 allocation for any device that uses the USB major number.
@@ -102,31 +102,6 @@ config USB_SUSPEND
102 102
103 If you are unsure about this, say N here. 103 If you are unsure about this, say N here.
104 104
105config USB_PERSIST
106 bool "USB device persistence during system suspend (DANGEROUS)"
107 depends on USB && PM && EXPERIMENTAL
108 default n
109 help
110
111 If you say Y here and enable the "power/persist" attribute
112 for a USB device, the device's data structures will remain
113 persistent across system suspend, even if the USB bus loses
114 power. (This includes hibernation, also known as swsusp or
115 suspend-to-disk.) The devices will reappear as if by magic
116 when the system wakes up, with no need to unmount USB
117 filesystems, rmmod host-controller drivers, or do anything
118 else.
119
120 WARNING: This option can be dangerous!
121
122 If a USB device is replaced by another of the same type while
123 the system is asleep, there's a good chance the kernel won't
124 detect the change. Likewise if the media in a USB storage
125 device is replaced. When this happens it's almost certain to
126 cause data corruption and maybe even crash your system.
127
128 If you are unsure, say N here.
129
130config USB_OTG 105config USB_OTG
131 bool 106 bool
132 depends on USB && EXPERIMENTAL 107 depends on USB && EXPERIMENTAL
@@ -136,14 +111,16 @@ config USB_OTG
136 111
137config USB_OTG_WHITELIST 112config USB_OTG_WHITELIST
138 bool "Rely on OTG Targeted Peripherals List" 113 bool "Rely on OTG Targeted Peripherals List"
139 depends on USB_OTG 114 depends on USB_OTG || EMBEDDED
140 default y 115 default y if USB_OTG
116 default n if EMBEDDED
141 help 117 help
142 If you say Y here, the "otg_whitelist.h" file will be used as a 118 If you say Y here, the "otg_whitelist.h" file will be used as a
143 product whitelist, so USB peripherals not listed there will be 119 product whitelist, so USB peripherals not listed there will be
144 rejected during enumeration. This behavior is required by the 120 rejected during enumeration. This behavior is required by the
145 USB OTG specification for all devices not on your product's 121 USB OTG specification for all devices not on your product's
146 "Targeted Peripherals List". 122 "Targeted Peripherals List". "Embedded Hosts" are likewise
123 allowed to support only a limited number of peripherals.
147 124
148 Otherwise, peripherals not listed there will only generate a 125 Otherwise, peripherals not listed there will only generate a
149 warning and enumeration will continue. That's more like what 126 warning and enumeration will continue. That's more like what
@@ -152,9 +129,10 @@ config USB_OTG_WHITELIST
152 129
153config USB_OTG_BLACKLIST_HUB 130config USB_OTG_BLACKLIST_HUB
154 bool "Disable external hubs" 131 bool "Disable external hubs"
155 depends on USB_OTG 132 depends on USB_OTG || EMBEDDED
156 help 133 help
157 If you say Y here, then Linux will refuse to enumerate 134 If you say Y here, then Linux will refuse to enumerate
158 external hubs. OTG hosts are allowed to reduce hardware 135 external hubs. OTG hosts are allowed to reduce hardware
159 and software costs by not supporting external hubs. 136 and software costs by not supporting external hubs. So
137 are "Emedded Hosts" that don't offer OTG support.
160 138
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index a92122a216bc..568244c99bdc 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -145,6 +145,23 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
145 endpoint->desc.wMaxPacketSize = cpu_to_le16(8); 145 endpoint->desc.wMaxPacketSize = cpu_to_le16(8);
146 } 146 }
147 147
148 /*
149 * Some buggy high speed devices have bulk endpoints using
150 * maxpacket sizes other than 512. High speed HCDs may not
151 * be able to handle that particular bug, so let's warn...
152 */
153 if (to_usb_device(ddev)->speed == USB_SPEED_HIGH
154 && usb_endpoint_xfer_bulk(d)) {
155 unsigned maxp;
156
157 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize) & 0x07ff;
158 if (maxp != 512)
159 dev_warn(ddev, "config %d interface %d altsetting %d "
160 "bulk endpoint 0x%X has invalid maxpacket %d\n",
161 cfgno, inum, asnum, d->bEndpointAddress,
162 maxp);
163 }
164
148 /* Skip over any Class Specific or Vendor Specific descriptors; 165 /* Skip over any Class Specific or Vendor Specific descriptors;
149 * find the next endpoint or interface descriptor */ 166 * find the next endpoint or interface descriptor */
150 endpoint->extra = buffer; 167 endpoint->extra = buffer;
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index ae94176c64e4..de17738f3acb 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -647,6 +647,7 @@ static int proc_control(struct dev_state *ps, void __user *arg)
647 struct usbdevfs_ctrltransfer ctrl; 647 struct usbdevfs_ctrltransfer ctrl;
648 unsigned int tmo; 648 unsigned int tmo;
649 unsigned char *tbuf; 649 unsigned char *tbuf;
650 unsigned wLength;
650 int i, j, ret; 651 int i, j, ret;
651 652
652 if (copy_from_user(&ctrl, arg, sizeof(ctrl))) 653 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
@@ -654,7 +655,8 @@ static int proc_control(struct dev_state *ps, void __user *arg)
654 ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex); 655 ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex);
655 if (ret) 656 if (ret)
656 return ret; 657 return ret;
657 if (ctrl.wLength > PAGE_SIZE) 658 wLength = ctrl.wLength; /* To suppress 64k PAGE_SIZE warning */
659 if (wLength > PAGE_SIZE)
658 return -EINVAL; 660 return -EINVAL;
659 tbuf = (unsigned char *)__get_free_page(GFP_KERNEL); 661 tbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
660 if (!tbuf) 662 if (!tbuf)
@@ -946,8 +948,11 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
946 int ret, ifnum = -1; 948 int ret, ifnum = -1;
947 int is_in; 949 int is_in;
948 950
949 if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP|USBDEVFS_URB_SHORT_NOT_OK| 951 if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP |
950 URB_NO_FSBR|URB_ZERO_PACKET)) 952 USBDEVFS_URB_SHORT_NOT_OK |
953 USBDEVFS_URB_NO_FSBR |
954 USBDEVFS_URB_ZERO_PACKET |
955 USBDEVFS_URB_NO_INTERRUPT))
951 return -EINVAL; 956 return -EINVAL;
952 if (!uurb->buffer) 957 if (!uurb->buffer)
953 return -EINVAL; 958 return -EINVAL;
@@ -1102,8 +1107,24 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1102 as->urb->pipe = (uurb->type << 30) | 1107 as->urb->pipe = (uurb->type << 30) |
1103 __create_pipe(ps->dev, uurb->endpoint & 0xf) | 1108 __create_pipe(ps->dev, uurb->endpoint & 0xf) |
1104 (uurb->endpoint & USB_DIR_IN); 1109 (uurb->endpoint & USB_DIR_IN);
1105 as->urb->transfer_flags = uurb->flags | 1110
1106 (is_in ? URB_DIR_IN : URB_DIR_OUT); 1111 /* This tedious sequence is necessary because the URB_* flags
1112 * are internal to the kernel and subject to change, whereas
1113 * the USBDEVFS_URB_* flags are a user API and must not be changed.
1114 */
1115 u = (is_in ? URB_DIR_IN : URB_DIR_OUT);
1116 if (uurb->flags & USBDEVFS_URB_ISO_ASAP)
1117 u |= URB_ISO_ASAP;
1118 if (uurb->flags & USBDEVFS_URB_SHORT_NOT_OK)
1119 u |= URB_SHORT_NOT_OK;
1120 if (uurb->flags & USBDEVFS_URB_NO_FSBR)
1121 u |= URB_NO_FSBR;
1122 if (uurb->flags & USBDEVFS_URB_ZERO_PACKET)
1123 u |= URB_ZERO_PACKET;
1124 if (uurb->flags & USBDEVFS_URB_NO_INTERRUPT)
1125 u |= URB_NO_INTERRUPT;
1126 as->urb->transfer_flags = u;
1127
1107 as->urb->transfer_buffer_length = uurb->buffer_length; 1128 as->urb->transfer_buffer_length = uurb->buffer_length;
1108 as->urb->setup_packet = (unsigned char *)dr; 1129 as->urb->setup_packet = (unsigned char *)dr;
1109 as->urb->start_frame = uurb->start_frame; 1130 as->urb->start_frame = uurb->start_frame;
@@ -1509,60 +1530,60 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1509 1530
1510 switch (cmd) { 1531 switch (cmd) {
1511 case USBDEVFS_CONTROL: 1532 case USBDEVFS_CONTROL:
1512 snoop(&dev->dev, "%s: CONTROL\n", __FUNCTION__); 1533 snoop(&dev->dev, "%s: CONTROL\n", __func__);
1513 ret = proc_control(ps, p); 1534 ret = proc_control(ps, p);
1514 if (ret >= 0) 1535 if (ret >= 0)
1515 inode->i_mtime = CURRENT_TIME; 1536 inode->i_mtime = CURRENT_TIME;
1516 break; 1537 break;
1517 1538
1518 case USBDEVFS_BULK: 1539 case USBDEVFS_BULK:
1519 snoop(&dev->dev, "%s: BULK\n", __FUNCTION__); 1540 snoop(&dev->dev, "%s: BULK\n", __func__);
1520 ret = proc_bulk(ps, p); 1541 ret = proc_bulk(ps, p);
1521 if (ret >= 0) 1542 if (ret >= 0)
1522 inode->i_mtime = CURRENT_TIME; 1543 inode->i_mtime = CURRENT_TIME;
1523 break; 1544 break;
1524 1545
1525 case USBDEVFS_RESETEP: 1546 case USBDEVFS_RESETEP:
1526 snoop(&dev->dev, "%s: RESETEP\n", __FUNCTION__); 1547 snoop(&dev->dev, "%s: RESETEP\n", __func__);
1527 ret = proc_resetep(ps, p); 1548 ret = proc_resetep(ps, p);
1528 if (ret >= 0) 1549 if (ret >= 0)
1529 inode->i_mtime = CURRENT_TIME; 1550 inode->i_mtime = CURRENT_TIME;
1530 break; 1551 break;
1531 1552
1532 case USBDEVFS_RESET: 1553 case USBDEVFS_RESET:
1533 snoop(&dev->dev, "%s: RESET\n", __FUNCTION__); 1554 snoop(&dev->dev, "%s: RESET\n", __func__);
1534 ret = proc_resetdevice(ps); 1555 ret = proc_resetdevice(ps);
1535 break; 1556 break;
1536 1557
1537 case USBDEVFS_CLEAR_HALT: 1558 case USBDEVFS_CLEAR_HALT:
1538 snoop(&dev->dev, "%s: CLEAR_HALT\n", __FUNCTION__); 1559 snoop(&dev->dev, "%s: CLEAR_HALT\n", __func__);
1539 ret = proc_clearhalt(ps, p); 1560 ret = proc_clearhalt(ps, p);
1540 if (ret >= 0) 1561 if (ret >= 0)
1541 inode->i_mtime = CURRENT_TIME; 1562 inode->i_mtime = CURRENT_TIME;
1542 break; 1563 break;
1543 1564
1544 case USBDEVFS_GETDRIVER: 1565 case USBDEVFS_GETDRIVER:
1545 snoop(&dev->dev, "%s: GETDRIVER\n", __FUNCTION__); 1566 snoop(&dev->dev, "%s: GETDRIVER\n", __func__);
1546 ret = proc_getdriver(ps, p); 1567 ret = proc_getdriver(ps, p);
1547 break; 1568 break;
1548 1569
1549 case USBDEVFS_CONNECTINFO: 1570 case USBDEVFS_CONNECTINFO:
1550 snoop(&dev->dev, "%s: CONNECTINFO\n", __FUNCTION__); 1571 snoop(&dev->dev, "%s: CONNECTINFO\n", __func__);
1551 ret = proc_connectinfo(ps, p); 1572 ret = proc_connectinfo(ps, p);
1552 break; 1573 break;
1553 1574
1554 case USBDEVFS_SETINTERFACE: 1575 case USBDEVFS_SETINTERFACE:
1555 snoop(&dev->dev, "%s: SETINTERFACE\n", __FUNCTION__); 1576 snoop(&dev->dev, "%s: SETINTERFACE\n", __func__);
1556 ret = proc_setintf(ps, p); 1577 ret = proc_setintf(ps, p);
1557 break; 1578 break;
1558 1579
1559 case USBDEVFS_SETCONFIGURATION: 1580 case USBDEVFS_SETCONFIGURATION:
1560 snoop(&dev->dev, "%s: SETCONFIGURATION\n", __FUNCTION__); 1581 snoop(&dev->dev, "%s: SETCONFIGURATION\n", __func__);
1561 ret = proc_setconfig(ps, p); 1582 ret = proc_setconfig(ps, p);
1562 break; 1583 break;
1563 1584
1564 case USBDEVFS_SUBMITURB: 1585 case USBDEVFS_SUBMITURB:
1565 snoop(&dev->dev, "%s: SUBMITURB\n", __FUNCTION__); 1586 snoop(&dev->dev, "%s: SUBMITURB\n", __func__);
1566 ret = proc_submiturb(ps, p); 1587 ret = proc_submiturb(ps, p);
1567 if (ret >= 0) 1588 if (ret >= 0)
1568 inode->i_mtime = CURRENT_TIME; 1589 inode->i_mtime = CURRENT_TIME;
@@ -1571,60 +1592,60 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1571#ifdef CONFIG_COMPAT 1592#ifdef CONFIG_COMPAT
1572 1593
1573 case USBDEVFS_SUBMITURB32: 1594 case USBDEVFS_SUBMITURB32:
1574 snoop(&dev->dev, "%s: SUBMITURB32\n", __FUNCTION__); 1595 snoop(&dev->dev, "%s: SUBMITURB32\n", __func__);
1575 ret = proc_submiturb_compat(ps, p); 1596 ret = proc_submiturb_compat(ps, p);
1576 if (ret >= 0) 1597 if (ret >= 0)
1577 inode->i_mtime = CURRENT_TIME; 1598 inode->i_mtime = CURRENT_TIME;
1578 break; 1599 break;
1579 1600
1580 case USBDEVFS_REAPURB32: 1601 case USBDEVFS_REAPURB32:
1581 snoop(&dev->dev, "%s: REAPURB32\n", __FUNCTION__); 1602 snoop(&dev->dev, "%s: REAPURB32\n", __func__);
1582 ret = proc_reapurb_compat(ps, p); 1603 ret = proc_reapurb_compat(ps, p);
1583 break; 1604 break;
1584 1605
1585 case USBDEVFS_REAPURBNDELAY32: 1606 case USBDEVFS_REAPURBNDELAY32:
1586 snoop(&dev->dev, "%s: REAPURBDELAY32\n", __FUNCTION__); 1607 snoop(&dev->dev, "%s: REAPURBDELAY32\n", __func__);
1587 ret = proc_reapurbnonblock_compat(ps, p); 1608 ret = proc_reapurbnonblock_compat(ps, p);
1588 break; 1609 break;
1589 1610
1590 case USBDEVFS_IOCTL32: 1611 case USBDEVFS_IOCTL32:
1591 snoop(&dev->dev, "%s: IOCTL\n", __FUNCTION__); 1612 snoop(&dev->dev, "%s: IOCTL\n", __func__);
1592 ret = proc_ioctl_compat(ps, ptr_to_compat(p)); 1613 ret = proc_ioctl_compat(ps, ptr_to_compat(p));
1593 break; 1614 break;
1594#endif 1615#endif
1595 1616
1596 case USBDEVFS_DISCARDURB: 1617 case USBDEVFS_DISCARDURB:
1597 snoop(&dev->dev, "%s: DISCARDURB\n", __FUNCTION__); 1618 snoop(&dev->dev, "%s: DISCARDURB\n", __func__);
1598 ret = proc_unlinkurb(ps, p); 1619 ret = proc_unlinkurb(ps, p);
1599 break; 1620 break;
1600 1621
1601 case USBDEVFS_REAPURB: 1622 case USBDEVFS_REAPURB:
1602 snoop(&dev->dev, "%s: REAPURB\n", __FUNCTION__); 1623 snoop(&dev->dev, "%s: REAPURB\n", __func__);
1603 ret = proc_reapurb(ps, p); 1624 ret = proc_reapurb(ps, p);
1604 break; 1625 break;
1605 1626
1606 case USBDEVFS_REAPURBNDELAY: 1627 case USBDEVFS_REAPURBNDELAY:
1607 snoop(&dev->dev, "%s: REAPURBDELAY\n", __FUNCTION__); 1628 snoop(&dev->dev, "%s: REAPURBDELAY\n", __func__);
1608 ret = proc_reapurbnonblock(ps, p); 1629 ret = proc_reapurbnonblock(ps, p);
1609 break; 1630 break;
1610 1631
1611 case USBDEVFS_DISCSIGNAL: 1632 case USBDEVFS_DISCSIGNAL:
1612 snoop(&dev->dev, "%s: DISCSIGNAL\n", __FUNCTION__); 1633 snoop(&dev->dev, "%s: DISCSIGNAL\n", __func__);
1613 ret = proc_disconnectsignal(ps, p); 1634 ret = proc_disconnectsignal(ps, p);
1614 break; 1635 break;
1615 1636
1616 case USBDEVFS_CLAIMINTERFACE: 1637 case USBDEVFS_CLAIMINTERFACE:
1617 snoop(&dev->dev, "%s: CLAIMINTERFACE\n", __FUNCTION__); 1638 snoop(&dev->dev, "%s: CLAIMINTERFACE\n", __func__);
1618 ret = proc_claiminterface(ps, p); 1639 ret = proc_claiminterface(ps, p);
1619 break; 1640 break;
1620 1641
1621 case USBDEVFS_RELEASEINTERFACE: 1642 case USBDEVFS_RELEASEINTERFACE:
1622 snoop(&dev->dev, "%s: RELEASEINTERFACE\n", __FUNCTION__); 1643 snoop(&dev->dev, "%s: RELEASEINTERFACE\n", __func__);
1623 ret = proc_releaseinterface(ps, p); 1644 ret = proc_releaseinterface(ps, p);
1624 break; 1645 break;
1625 1646
1626 case USBDEVFS_IOCTL: 1647 case USBDEVFS_IOCTL:
1627 snoop(&dev->dev, "%s: IOCTL\n", __FUNCTION__); 1648 snoop(&dev->dev, "%s: IOCTL\n", __func__);
1628 ret = proc_ioctl_default(ps, p); 1649 ret = proc_ioctl_default(ps, p);
1629 break; 1650 break;
1630 } 1651 }
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 801b6f142fa7..1e56f1cfa6dc 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -157,7 +157,7 @@ static int usb_probe_device(struct device *dev)
157 struct usb_device *udev; 157 struct usb_device *udev;
158 int error = -ENODEV; 158 int error = -ENODEV;
159 159
160 dev_dbg(dev, "%s\n", __FUNCTION__); 160 dev_dbg(dev, "%s\n", __func__);
161 161
162 if (!is_usb_device(dev)) /* Sanity check */ 162 if (!is_usb_device(dev)) /* Sanity check */
163 return error; 163 return error;
@@ -194,7 +194,7 @@ static int usb_probe_interface(struct device *dev)
194 const struct usb_device_id *id; 194 const struct usb_device_id *id;
195 int error = -ENODEV; 195 int error = -ENODEV;
196 196
197 dev_dbg(dev, "%s\n", __FUNCTION__); 197 dev_dbg(dev, "%s\n", __func__);
198 198
199 if (is_usb_device(dev)) /* Sanity check */ 199 if (is_usb_device(dev)) /* Sanity check */
200 return error; 200 return error;
@@ -211,7 +211,7 @@ static int usb_probe_interface(struct device *dev)
211 if (!id) 211 if (!id)
212 id = usb_match_dynamic_id(intf, driver); 212 id = usb_match_dynamic_id(intf, driver);
213 if (id) { 213 if (id) {
214 dev_dbg(dev, "%s - got id\n", __FUNCTION__); 214 dev_dbg(dev, "%s - got id\n", __func__);
215 215
216 error = usb_autoresume_device(udev); 216 error = usb_autoresume_device(udev);
217 if (error) 217 if (error)
@@ -793,9 +793,7 @@ static int usb_suspend_device(struct usb_device *udev, pm_message_t msg)
793 status = udriver->suspend(udev, msg); 793 status = udriver->suspend(udev, msg);
794 794
795 done: 795 done:
796 dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); 796 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);
797 if (status == 0)
798 udev->dev.power.power_state.event = msg.event;
799 return status; 797 return status;
800} 798}
801 799
@@ -823,11 +821,9 @@ static int usb_resume_device(struct usb_device *udev)
823 status = udriver->resume(udev); 821 status = udriver->resume(udev);
824 822
825 done: 823 done:
826 dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); 824 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);
827 if (status == 0) { 825 if (status == 0)
828 udev->autoresume_disabled = 0; 826 udev->autoresume_disabled = 0;
829 udev->dev.power.power_state.event = PM_EVENT_ON;
830 }
831 return status; 827 return status;
832} 828}
833 829
@@ -864,7 +860,7 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg)
864 } 860 }
865 861
866 done: 862 done:
867 dev_vdbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status); 863 dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status);
868 return status; 864 return status;
869} 865}
870 866
@@ -914,7 +910,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
914 } 910 }
915 911
916done: 912done:
917 dev_vdbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status); 913 dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status);
918 if (status == 0) 914 if (status == 0)
919 mark_active(intf); 915 mark_active(intf);
920 916
@@ -936,7 +932,6 @@ static int autosuspend_check(struct usb_device *udev, int reschedule)
936 * is disabled. Also fail if any interfaces require remote wakeup 932 * is disabled. Also fail if any interfaces require remote wakeup
937 * but it isn't available. 933 * but it isn't available.
938 */ 934 */
939 udev->do_remote_wakeup = device_may_wakeup(&udev->dev);
940 if (udev->pm_usage_cnt > 0) 935 if (udev->pm_usage_cnt > 0)
941 return -EBUSY; 936 return -EBUSY;
942 if (udev->autosuspend_delay < 0 || udev->autosuspend_disabled) 937 if (udev->autosuspend_delay < 0 || udev->autosuspend_disabled)
@@ -1098,7 +1093,7 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1098 } 1093 }
1099 1094
1100 done: 1095 done:
1101 dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); 1096 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);
1102 return status; 1097 return status;
1103} 1098}
1104 1099
@@ -1180,8 +1175,7 @@ static int usb_resume_both(struct usb_device *udev)
1180 } 1175 }
1181 } else { 1176 } else {
1182 1177
1183 /* Needed for setting udev->dev.power.power_state.event, 1178 /* Needed for reset-resume */
1184 * for possible debugging message, and for reset_resume. */
1185 status = usb_resume_device(udev); 1179 status = usb_resume_device(udev);
1186 } 1180 }
1187 1181
@@ -1193,8 +1187,9 @@ static int usb_resume_both(struct usb_device *udev)
1193 } 1187 }
1194 1188
1195 done: 1189 done:
1196 dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); 1190 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);
1197 udev->reset_resume = 0; 1191 if (!status)
1192 udev->reset_resume = 0;
1198 return status; 1193 return status;
1199} 1194}
1200 1195
@@ -1262,7 +1257,7 @@ void usb_autosuspend_device(struct usb_device *udev)
1262 1257
1263 status = usb_autopm_do_device(udev, -1); 1258 status = usb_autopm_do_device(udev, -1);
1264 dev_vdbg(&udev->dev, "%s: cnt %d\n", 1259 dev_vdbg(&udev->dev, "%s: cnt %d\n",
1265 __FUNCTION__, udev->pm_usage_cnt); 1260 __func__, udev->pm_usage_cnt);
1266} 1261}
1267 1262
1268/** 1263/**
@@ -1282,7 +1277,7 @@ void usb_try_autosuspend_device(struct usb_device *udev)
1282{ 1277{
1283 usb_autopm_do_device(udev, 0); 1278 usb_autopm_do_device(udev, 0);
1284 dev_vdbg(&udev->dev, "%s: cnt %d\n", 1279 dev_vdbg(&udev->dev, "%s: cnt %d\n",
1285 __FUNCTION__, udev->pm_usage_cnt); 1280 __func__, udev->pm_usage_cnt);
1286} 1281}
1287 1282
1288/** 1283/**
@@ -1310,7 +1305,7 @@ int usb_autoresume_device(struct usb_device *udev)
1310 1305
1311 status = usb_autopm_do_device(udev, 1); 1306 status = usb_autopm_do_device(udev, 1);
1312 dev_vdbg(&udev->dev, "%s: status %d cnt %d\n", 1307 dev_vdbg(&udev->dev, "%s: status %d cnt %d\n",
1313 __FUNCTION__, status, udev->pm_usage_cnt); 1308 __func__, status, udev->pm_usage_cnt);
1314 return status; 1309 return status;
1315} 1310}
1316 1311
@@ -1382,7 +1377,7 @@ void usb_autopm_put_interface(struct usb_interface *intf)
1382 1377
1383 status = usb_autopm_do_interface(intf, -1); 1378 status = usb_autopm_do_interface(intf, -1);
1384 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1379 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1385 __FUNCTION__, status, intf->pm_usage_cnt); 1380 __func__, status, intf->pm_usage_cnt);
1386} 1381}
1387EXPORT_SYMBOL_GPL(usb_autopm_put_interface); 1382EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1388 1383
@@ -1426,7 +1421,7 @@ int usb_autopm_get_interface(struct usb_interface *intf)
1426 1421
1427 status = usb_autopm_do_interface(intf, 1); 1422 status = usb_autopm_do_interface(intf, 1);
1428 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1423 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1429 __FUNCTION__, status, intf->pm_usage_cnt); 1424 __func__, status, intf->pm_usage_cnt);
1430 return status; 1425 return status;
1431} 1426}
1432EXPORT_SYMBOL_GPL(usb_autopm_get_interface); 1427EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
@@ -1448,7 +1443,7 @@ int usb_autopm_set_interface(struct usb_interface *intf)
1448 1443
1449 status = usb_autopm_do_interface(intf, 0); 1444 status = usb_autopm_do_interface(intf, 0);
1450 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1445 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1451 __FUNCTION__, status, intf->pm_usage_cnt); 1446 __func__, status, intf->pm_usage_cnt);
1452 return status; 1447 return status;
1453} 1448}
1454EXPORT_SYMBOL_GPL(usb_autopm_set_interface); 1449EXPORT_SYMBOL_GPL(usb_autopm_set_interface);
@@ -1523,9 +1518,14 @@ static int usb_suspend(struct device *dev, pm_message_t message)
1523 udev = to_usb_device(dev); 1518 udev = to_usb_device(dev);
1524 1519
1525 /* If udev is already suspended, we can skip this suspend and 1520 /* If udev is already suspended, we can skip this suspend and
1526 * we should also skip the upcoming system resume. */ 1521 * we should also skip the upcoming system resume. High-speed
1522 * root hubs are an exception; they need to resume whenever the
1523 * system wakes up in order for USB-PERSIST port handover to work
1524 * properly.
1525 */
1527 if (udev->state == USB_STATE_SUSPENDED) { 1526 if (udev->state == USB_STATE_SUSPENDED) {
1528 udev->skip_sys_resume = 1; 1527 if (udev->parent || udev->speed != USB_SPEED_HIGH)
1528 udev->skip_sys_resume = 1;
1529 return 0; 1529 return 0;
1530 } 1530 }
1531 1531
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 84760ddbc332..5b87ae7f0a6a 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -73,7 +73,6 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
73 if (pci_enable_device(dev) < 0) 73 if (pci_enable_device(dev) < 0)
74 return -ENODEV; 74 return -ENODEV;
75 dev->current_state = PCI_D0; 75 dev->current_state = PCI_D0;
76 dev->dev.power.power_state = PMSG_ON;
77 76
78 if (!dev->irq) { 77 if (!dev->irq) {
79 dev_err(&dev->dev, 78 dev_err(&dev->dev,
@@ -216,9 +215,9 @@ int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message)
216 hcd->state == HC_STATE_HALT)) 215 hcd->state == HC_STATE_HALT))
217 return -EBUSY; 216 return -EBUSY;
218 217
219 if (hcd->driver->suspend) { 218 if (hcd->driver->pci_suspend) {
220 retval = hcd->driver->suspend(hcd, message); 219 retval = hcd->driver->pci_suspend(hcd, message);
221 suspend_report_result(hcd->driver->suspend, retval); 220 suspend_report_result(hcd->driver->pci_suspend, retval);
222 if (retval) 221 if (retval)
223 goto done; 222 goto done;
224 } 223 }
@@ -302,8 +301,6 @@ int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message)
302 301
303done: 302done:
304 if (retval == 0) { 303 if (retval == 0) {
305 dev->dev.power.power_state = PMSG_SUSPEND;
306
307#ifdef CONFIG_PPC_PMAC 304#ifdef CONFIG_PPC_PMAC
308 /* Disable ASIC clocks for USB */ 305 /* Disable ASIC clocks for USB */
309 if (machine_is(powermac)) { 306 if (machine_is(powermac)) {
@@ -406,12 +403,10 @@ int usb_hcd_pci_resume(struct pci_dev *dev)
406 pci_set_master(dev); 403 pci_set_master(dev);
407 pci_restore_state(dev); 404 pci_restore_state(dev);
408 405
409 dev->dev.power.power_state = PMSG_ON;
410
411 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 406 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
412 407
413 if (hcd->driver->resume) { 408 if (hcd->driver->pci_resume) {
414 retval = hcd->driver->resume(hcd); 409 retval = hcd->driver->pci_resume(hcd);
415 if (retval) { 410 if (retval) {
416 dev_err(hcd->self.controller, 411 dev_err(hcd->self.controller,
417 "PCI post-resume error %d!\n", retval); 412 "PCI post-resume error %d!\n", retval);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index e52ed1663b3c..bf10e9c4195e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -129,7 +129,7 @@ static const u8 usb2_rh_dev_descriptor [18] = {
129 129
130 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ 130 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
131 0x00, /* __u8 bDeviceSubClass; */ 131 0x00, /* __u8 bDeviceSubClass; */
132 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/ 132 0x00, /* __u8 bDeviceProtocol; [ usb 2.0 no TT ] */
133 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */ 133 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */
134 134
135 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */ 135 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */
@@ -291,7 +291,6 @@ static int ascii2utf (char *s, u8 *utf, int utfmax)
291 * rh_string - provides manufacturer, product and serial strings for root hub 291 * rh_string - provides manufacturer, product and serial strings for root hub
292 * @id: the string ID number (1: serial number, 2: product, 3: vendor) 292 * @id: the string ID number (1: serial number, 2: product, 3: vendor)
293 * @hcd: the host controller for this root hub 293 * @hcd: the host controller for this root hub
294 * @type: string describing our driver
295 * @data: return packet in UTF-16 LE 294 * @data: return packet in UTF-16 LE
296 * @len: length of the return packet 295 * @len: length of the return packet
297 * 296 *
@@ -355,9 +354,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
355 __attribute__((aligned(4))); 354 __attribute__((aligned(4)));
356 const u8 *bufp = tbuf; 355 const u8 *bufp = tbuf;
357 int len = 0; 356 int len = 0;
358 int patch_wakeup = 0;
359 int status; 357 int status;
360 int n; 358 int n;
359 u8 patch_wakeup = 0;
360 u8 patch_protocol = 0;
361 361
362 might_sleep(); 362 might_sleep();
363 363
@@ -434,6 +434,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
434 else 434 else
435 goto error; 435 goto error;
436 len = 18; 436 len = 18;
437 if (hcd->has_tt)
438 patch_protocol = 1;
437 break; 439 break;
438 case USB_DT_CONFIG << 8: 440 case USB_DT_CONFIG << 8:
439 if (hcd->driver->flags & HCD_USB2) { 441 if (hcd->driver->flags & HCD_USB2) {
@@ -528,6 +530,13 @@ error:
528 bmAttributes)) 530 bmAttributes))
529 ((struct usb_config_descriptor *)ubuf)->bmAttributes 531 ((struct usb_config_descriptor *)ubuf)->bmAttributes
530 |= USB_CONFIG_ATT_WAKEUP; 532 |= USB_CONFIG_ATT_WAKEUP;
533
534 /* report whether RH hardware has an integrated TT */
535 if (patch_protocol &&
536 len > offsetof(struct usb_device_descriptor,
537 bDeviceProtocol))
538 ((struct usb_device_descriptor *) ubuf)->
539 bDeviceProtocol = 1;
531 } 540 }
532 541
533 /* any errors get returned through the urb completion */ 542 /* any errors get returned through the urb completion */
@@ -915,15 +924,6 @@ static int register_root_hub(struct usb_hcd *hcd)
915 return retval; 924 return retval;
916} 925}
917 926
918void usb_enable_root_hub_irq (struct usb_bus *bus)
919{
920 struct usb_hcd *hcd;
921
922 hcd = container_of (bus, struct usb_hcd, self);
923 if (hcd->driver->hub_irq_enable && hcd->state != HC_STATE_HALT)
924 hcd->driver->hub_irq_enable (hcd);
925}
926
927 927
928/*-------------------------------------------------------------------------*/ 928/*-------------------------------------------------------------------------*/
929 929
@@ -1677,7 +1677,6 @@ EXPORT_SYMBOL_GPL(usb_bus_start_enum);
1677 * usb_hcd_irq - hook IRQs to HCD framework (bus glue) 1677 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
1678 * @irq: the IRQ being raised 1678 * @irq: the IRQ being raised
1679 * @__hcd: pointer to the HCD whose IRQ is being signaled 1679 * @__hcd: pointer to the HCD whose IRQ is being signaled
1680 * @r: saved hardware registers
1681 * 1680 *
1682 * If the controller isn't HALTed, calls the driver's irq handler. 1681 * If the controller isn't HALTed, calls the driver's irq handler.
1683 * Checks whether the controller is now dead. 1682 * Checks whether the controller is now dead.
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 2d1c3d5e47b8..1e4b81e9eb50 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -28,7 +28,7 @@
28/* 28/*
29 * USB Packet IDs (PIDs) 29 * USB Packet IDs (PIDs)
30 */ 30 */
31#define USB_PID_UNDEF_0 0xf0 31#define USB_PID_EXT 0xf0 /* USB 2.0 LPM ECN */
32#define USB_PID_OUT 0xe1 32#define USB_PID_OUT 0xe1
33#define USB_PID_ACK 0xd2 33#define USB_PID_ACK 0xd2
34#define USB_PID_DATA0 0xc3 34#define USB_PID_DATA0 0xc3
@@ -99,6 +99,7 @@ struct usb_hcd {
99 unsigned poll_pending:1; /* status has changed? */ 99 unsigned poll_pending:1; /* status has changed? */
100 unsigned wireless:1; /* Wireless USB HCD */ 100 unsigned wireless:1; /* Wireless USB HCD */
101 unsigned authorized_default:1; 101 unsigned authorized_default:1;
102 unsigned has_tt:1; /* Integrated TT in root hub */
102 103
103 int irq; /* irq allocated */ 104 int irq; /* irq allocated */
104 void __iomem *regs; /* device memory/io */ 105 void __iomem *regs; /* device memory/io */
@@ -177,10 +178,10 @@ struct hc_driver {
177 * a whole, not just the root hub; they're for PCI bus glue. 178 * a whole, not just the root hub; they're for PCI bus glue.
178 */ 179 */
179 /* called after suspending the hub, before entering D3 etc */ 180 /* called after suspending the hub, before entering D3 etc */
180 int (*suspend) (struct usb_hcd *hcd, pm_message_t message); 181 int (*pci_suspend) (struct usb_hcd *hcd, pm_message_t message);
181 182
182 /* called after entering D0 (etc), before resuming the hub */ 183 /* called after entering D0 (etc), before resuming the hub */
183 int (*resume) (struct usb_hcd *hcd); 184 int (*pci_resume) (struct usb_hcd *hcd);
184 185
185 /* cleanly make HCD stop writing memory and doing I/O */ 186 /* cleanly make HCD stop writing memory and doing I/O */
186 void (*stop) (struct usb_hcd *hcd); 187 void (*stop) (struct usb_hcd *hcd);
@@ -209,8 +210,6 @@ struct hc_driver {
209 int (*bus_suspend)(struct usb_hcd *); 210 int (*bus_suspend)(struct usb_hcd *);
210 int (*bus_resume)(struct usb_hcd *); 211 int (*bus_resume)(struct usb_hcd *);
211 int (*start_port_reset)(struct usb_hcd *, unsigned port_num); 212 int (*start_port_reset)(struct usb_hcd *, unsigned port_num);
212 void (*hub_irq_enable)(struct usb_hcd *);
213 /* Needed only if port-change IRQs are level-triggered */
214 213
215 /* force handover of high-speed port to full-speed companion */ 214 /* force handover of high-speed port to full-speed companion */
216 void (*relinquish_port)(struct usb_hcd *, int); 215 void (*relinquish_port)(struct usb_hcd *, int);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 57aeca160f38..eb57fcc701d7 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -30,12 +30,6 @@
30#include "hcd.h" 30#include "hcd.h"
31#include "hub.h" 31#include "hub.h"
32 32
33#ifdef CONFIG_USB_PERSIST
34#define USB_PERSIST 1
35#else
36#define USB_PERSIST 0
37#endif
38
39/* if we are in debug mode, always announce new devices */ 33/* if we are in debug mode, always announce new devices */
40#ifdef DEBUG 34#ifdef DEBUG
41#ifndef CONFIG_USB_ANNOUNCE_NEW_DEVICES 35#ifndef CONFIG_USB_ANNOUNCE_NEW_DEVICES
@@ -333,6 +327,27 @@ static int get_port_status(struct usb_device *hdev, int port1,
333 return status; 327 return status;
334} 328}
335 329
330static int hub_port_status(struct usb_hub *hub, int port1,
331 u16 *status, u16 *change)
332{
333 int ret;
334
335 mutex_lock(&hub->status_mutex);
336 ret = get_port_status(hub->hdev, port1, &hub->status->port);
337 if (ret < 4) {
338 dev_err(hub->intfdev,
339 "%s failed (err = %d)\n", __func__, ret);
340 if (ret >= 0)
341 ret = -EIO;
342 } else {
343 *status = le16_to_cpu(hub->status->port.wPortStatus);
344 *change = le16_to_cpu(hub->status->port.wPortChange);
345 ret = 0;
346 }
347 mutex_unlock(&hub->status_mutex);
348 return ret;
349}
350
336static void kick_khubd(struct usb_hub *hub) 351static void kick_khubd(struct usb_hub *hub)
337{ 352{
338 unsigned long flags; 353 unsigned long flags;
@@ -560,7 +575,7 @@ static int hub_hub_status(struct usb_hub *hub,
560 ret = get_hub_status(hub->hdev, &hub->status->hub); 575 ret = get_hub_status(hub->hdev, &hub->status->hub);
561 if (ret < 0) 576 if (ret < 0)
562 dev_err (hub->intfdev, 577 dev_err (hub->intfdev,
563 "%s failed (err = %d)\n", __FUNCTION__, ret); 578 "%s failed (err = %d)\n", __func__, ret);
564 else { 579 else {
565 *status = le16_to_cpu(hub->status->hub.wHubStatus); 580 *status = le16_to_cpu(hub->status->hub.wHubStatus);
566 *change = le16_to_cpu(hub->status->hub.wHubChange); 581 *change = le16_to_cpu(hub->status->hub.wHubChange);
@@ -610,9 +625,8 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
610} 625}
611 626
612/* caller has locked the hub device */ 627/* caller has locked the hub device */
613static int hub_pre_reset(struct usb_interface *intf) 628static void hub_stop(struct usb_hub *hub)
614{ 629{
615 struct usb_hub *hub = usb_get_intfdata(intf);
616 struct usb_device *hdev = hub->hdev; 630 struct usb_device *hdev = hub->hdev;
617 int i; 631 int i;
618 632
@@ -622,6 +636,89 @@ static int hub_pre_reset(struct usb_interface *intf)
622 usb_disconnect(&hdev->children[i]); 636 usb_disconnect(&hdev->children[i]);
623 } 637 }
624 hub_quiesce(hub); 638 hub_quiesce(hub);
639}
640
641#define HUB_RESET 1
642#define HUB_RESUME 2
643#define HUB_RESET_RESUME 3
644
645#ifdef CONFIG_PM
646
647static void hub_restart(struct usb_hub *hub, int type)
648{
649 struct usb_device *hdev = hub->hdev;
650 int port1;
651
652 /* Check each of the children to see if they require
653 * USB-PERSIST handling or disconnection. Also check
654 * each unoccupied port to make sure it is still disabled.
655 */
656 for (port1 = 1; port1 <= hdev->maxchild; ++port1) {
657 struct usb_device *udev = hdev->children[port1-1];
658 int status = 0;
659 u16 portstatus, portchange;
660
661 if (!udev || udev->state == USB_STATE_NOTATTACHED) {
662 if (type != HUB_RESET) {
663 status = hub_port_status(hub, port1,
664 &portstatus, &portchange);
665 if (status == 0 && (portstatus &
666 USB_PORT_STAT_ENABLE))
667 clear_port_feature(hdev, port1,
668 USB_PORT_FEAT_ENABLE);
669 }
670 continue;
671 }
672
673 /* Was the power session lost while we were suspended? */
674 switch (type) {
675 case HUB_RESET_RESUME:
676 portstatus = 0;
677 portchange = USB_PORT_STAT_C_CONNECTION;
678 break;
679
680 case HUB_RESET:
681 case HUB_RESUME:
682 status = hub_port_status(hub, port1,
683 &portstatus, &portchange);
684 break;
685 }
686
687 /* For "USB_PERSIST"-enabled children we must
688 * mark the child device for reset-resume and
689 * turn off the various status changes to prevent
690 * khubd from disconnecting it later.
691 */
692 if (udev->persist_enabled && status == 0 &&
693 !(portstatus & USB_PORT_STAT_ENABLE)) {
694 if (portchange & USB_PORT_STAT_C_ENABLE)
695 clear_port_feature(hub->hdev, port1,
696 USB_PORT_FEAT_C_ENABLE);
697 if (portchange & USB_PORT_STAT_C_CONNECTION)
698 clear_port_feature(hub->hdev, port1,
699 USB_PORT_FEAT_C_CONNECTION);
700 udev->reset_resume = 1;
701 }
702
703 /* Otherwise for a reset_resume we must disconnect the child,
704 * but as we may not lock the child device here
705 * we have to do a "logical" disconnect.
706 */
707 else if (type == HUB_RESET_RESUME)
708 hub_port_logical_disconnect(hub, port1);
709 }
710
711 hub_activate(hub);
712}
713
714#endif /* CONFIG_PM */
715
716/* caller has locked the hub device */
717static int hub_pre_reset(struct usb_interface *intf)
718{
719 struct usb_hub *hub = usb_get_intfdata(intf);
720
721 hub_stop(hub);
625 return 0; 722 return 0;
626} 723}
627 724
@@ -910,7 +1007,7 @@ static void hub_disconnect(struct usb_interface *intf)
910 1007
911 /* Disconnect all children and quiesce the hub */ 1008 /* Disconnect all children and quiesce the hub */
912 hub->error = 0; 1009 hub->error = 0;
913 hub_pre_reset(intf); 1010 hub_stop(hub);
914 1011
915 usb_set_intfdata (intf, NULL); 1012 usb_set_intfdata (intf, NULL);
916 1013
@@ -1098,21 +1195,42 @@ void usb_set_device_state(struct usb_device *udev,
1098 spin_unlock_irqrestore(&device_state_lock, flags); 1195 spin_unlock_irqrestore(&device_state_lock, flags);
1099} 1196}
1100 1197
1198/*
1199 * WUSB devices are simple: they have no hubs behind, so the mapping
1200 * device <-> virtual port number becomes 1:1. Why? to simplify the
1201 * life of the device connection logic in
1202 * drivers/usb/wusbcore/devconnect.c. When we do the initial secret
1203 * handshake we need to assign a temporary address in the unauthorized
1204 * space. For simplicity we use the first virtual port number found to
1205 * be free [drivers/usb/wusbcore/devconnect.c:wusbhc_devconnect_ack()]
1206 * and that becomes it's address [X < 128] or its unauthorized address
1207 * [X | 0x80].
1208 *
1209 * We add 1 as an offset to the one-based USB-stack port number
1210 * (zero-based wusb virtual port index) for two reasons: (a) dev addr
1211 * 0 is reserved by USB for default address; (b) Linux's USB stack
1212 * uses always #1 for the root hub of the controller. So USB stack's
1213 * port #1, which is wusb virtual-port #0 has address #2.
1214 */
1101static void choose_address(struct usb_device *udev) 1215static void choose_address(struct usb_device *udev)
1102{ 1216{
1103 int devnum; 1217 int devnum;
1104 struct usb_bus *bus = udev->bus; 1218 struct usb_bus *bus = udev->bus;
1105 1219
1106 /* If khubd ever becomes multithreaded, this will need a lock */ 1220 /* If khubd ever becomes multithreaded, this will need a lock */
1107 1221 if (udev->wusb) {
1108 /* Try to allocate the next devnum beginning at bus->devnum_next. */ 1222 devnum = udev->portnum + 1;
1109 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1223 BUG_ON(test_bit(devnum, bus->devmap.devicemap));
1110 bus->devnum_next); 1224 } else {
1111 if (devnum >= 128) 1225 /* Try to allocate the next devnum beginning at
1112 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1); 1226 * bus->devnum_next. */
1113 1227 devnum = find_next_zero_bit(bus->devmap.devicemap, 128,
1114 bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1); 1228 bus->devnum_next);
1115 1229 if (devnum >= 128)
1230 devnum = find_next_zero_bit(bus->devmap.devicemap,
1231 128, 1);
1232 bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1);
1233 }
1116 if (devnum < 128) { 1234 if (devnum < 128) {
1117 set_bit(devnum, bus->devmap.devicemap); 1235 set_bit(devnum, bus->devmap.devicemap);
1118 udev->devnum = devnum; 1236 udev->devnum = devnum;
@@ -1127,6 +1245,13 @@ static void release_address(struct usb_device *udev)
1127 } 1245 }
1128} 1246}
1129 1247
1248static void update_address(struct usb_device *udev, int devnum)
1249{
1250 /* The address for a WUSB device is managed by wusbcore. */
1251 if (!udev->wusb)
1252 udev->devnum = devnum;
1253}
1254
1130#ifdef CONFIG_USB_SUSPEND 1255#ifdef CONFIG_USB_SUSPEND
1131 1256
1132static void usb_stop_pm(struct usb_device *udev) 1257static void usb_stop_pm(struct usb_device *udev)
@@ -1173,7 +1298,7 @@ void usb_disconnect(struct usb_device **pdev)
1173 int i; 1298 int i;
1174 1299
1175 if (!udev) { 1300 if (!udev) {
1176 pr_debug ("%s nodev\n", __FUNCTION__); 1301 pr_debug ("%s nodev\n", __func__);
1177 return; 1302 return;
1178 } 1303 }
1179 1304
@@ -1510,28 +1635,6 @@ out_authorized:
1510} 1635}
1511 1636
1512 1637
1513static int hub_port_status(struct usb_hub *hub, int port1,
1514 u16 *status, u16 *change)
1515{
1516 int ret;
1517
1518 mutex_lock(&hub->status_mutex);
1519 ret = get_port_status(hub->hdev, port1, &hub->status->port);
1520 if (ret < 4) {
1521 dev_err (hub->intfdev,
1522 "%s failed (err = %d)\n", __FUNCTION__, ret);
1523 if (ret >= 0)
1524 ret = -EIO;
1525 } else {
1526 *status = le16_to_cpu(hub->status->port.wPortStatus);
1527 *change = le16_to_cpu(hub->status->port.wPortChange);
1528 ret = 0;
1529 }
1530 mutex_unlock(&hub->status_mutex);
1531 return ret;
1532}
1533
1534
1535/* Returns 1 if @hub is a WUSB root hub, 0 otherwise */ 1638/* Returns 1 if @hub is a WUSB root hub, 0 otherwise */
1536static unsigned hub_is_wusb(struct usb_hub *hub) 1639static unsigned hub_is_wusb(struct usb_hub *hub)
1537{ 1640{
@@ -1637,7 +1740,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
1637 case 0: 1740 case 0:
1638 /* TRSTRCY = 10 ms; plus some extra */ 1741 /* TRSTRCY = 10 ms; plus some extra */
1639 msleep(10 + 40); 1742 msleep(10 + 40);
1640 udev->devnum = 0; /* Device now at address 0 */ 1743 update_address(udev, 0);
1641 /* FALL THROUGH */ 1744 /* FALL THROUGH */
1642 case -ENOTCONN: 1745 case -ENOTCONN:
1643 case -ENODEV: 1746 case -ENODEV:
@@ -1842,9 +1945,8 @@ static int finish_port_resume(struct usb_device *udev)
1842 * the host and the device is the same as it was when the device 1945 * the host and the device is the same as it was when the device
1843 * suspended. 1946 * suspended.
1844 * 1947 *
1845 * If CONFIG_USB_PERSIST and @udev->reset_resume are both set then this 1948 * If @udev->reset_resume is set then this routine won't check that the
1846 * routine won't check that the port is still enabled. Furthermore, 1949 * port is still enabled. Furthermore, finish_port_resume() above will
1847 * if @udev->reset_resume is set then finish_port_resume() above will
1848 * reset @udev. The end result is that a broken power session can be 1950 * reset @udev. The end result is that a broken power session can be
1849 * recovered and @udev will appear to persist across a loss of VBUS power. 1951 * recovered and @udev will appear to persist across a loss of VBUS power.
1850 * 1952 *
@@ -1856,8 +1958,8 @@ static int finish_port_resume(struct usb_device *udev)
1856 * to it will be lost. Using the USB_PERSIST facility, the device can be 1958 * to it will be lost. Using the USB_PERSIST facility, the device can be
1857 * made to appear as if it had not disconnected. 1959 * made to appear as if it had not disconnected.
1858 * 1960 *
1859 * This facility is inherently dangerous. Although usb_reset_device() 1961 * This facility can be dangerous. Although usb_reset_device() makes
1860 * makes every effort to insure that the same device is present after the 1962 * every effort to insure that the same device is present after the
1861 * reset as before, it cannot provide a 100% guarantee. Furthermore it's 1963 * reset as before, it cannot provide a 100% guarantee. Furthermore it's
1862 * quite possible for a device to remain unaltered but its media to be 1964 * quite possible for a device to remain unaltered but its media to be
1863 * changed. If the user replaces a flash memory card while the system is 1965 * changed. If the user replaces a flash memory card while the system is
@@ -1902,7 +2004,7 @@ int usb_port_resume(struct usb_device *udev)
1902 status = hub_port_status(hub, port1, &portstatus, &portchange); 2004 status = hub_port_status(hub, port1, &portstatus, &portchange);
1903 2005
1904 SuspendCleared: 2006 SuspendCleared:
1905 if (USB_PERSIST && udev->reset_resume) 2007 if (udev->reset_resume)
1906 want_flags = USB_PORT_STAT_POWER 2008 want_flags = USB_PORT_STAT_POWER
1907 | USB_PORT_STAT_CONNECTION; 2009 | USB_PORT_STAT_CONNECTION;
1908 else 2010 else
@@ -1927,8 +2029,6 @@ int usb_port_resume(struct usb_device *udev)
1927 } 2029 }
1928 2030
1929 clear_bit(port1, hub->busy_bits); 2031 clear_bit(port1, hub->busy_bits);
1930 if (!hub->hdev->parent && !hub->busy_bits[0])
1931 usb_enable_root_hub_irq(hub->hdev->bus);
1932 2032
1933 if (status == 0) 2033 if (status == 0)
1934 status = finish_port_resume(udev); 2034 status = finish_port_resume(udev);
@@ -2000,7 +2100,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
2000 } 2100 }
2001 } 2101 }
2002 2102
2003 dev_dbg(&intf->dev, "%s\n", __FUNCTION__); 2103 dev_dbg(&intf->dev, "%s\n", __func__);
2004 2104
2005 /* stop khubd and related activity */ 2105 /* stop khubd and related activity */
2006 hub_quiesce(hub); 2106 hub_quiesce(hub);
@@ -2009,49 +2109,20 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
2009 2109
2010static int hub_resume(struct usb_interface *intf) 2110static int hub_resume(struct usb_interface *intf)
2011{ 2111{
2012 struct usb_hub *hub = usb_get_intfdata (intf); 2112 struct usb_hub *hub = usb_get_intfdata(intf);
2013
2014 dev_dbg(&intf->dev, "%s\n", __FUNCTION__);
2015 2113
2016 /* tell khubd to look for changes on this hub */ 2114 dev_dbg(&intf->dev, "%s\n", __func__);
2017 hub_activate(hub); 2115 hub_restart(hub, HUB_RESUME);
2018 return 0; 2116 return 0;
2019} 2117}
2020 2118
2021static int hub_reset_resume(struct usb_interface *intf) 2119static int hub_reset_resume(struct usb_interface *intf)
2022{ 2120{
2023 struct usb_hub *hub = usb_get_intfdata(intf); 2121 struct usb_hub *hub = usb_get_intfdata(intf);
2024 struct usb_device *hdev = hub->hdev;
2025 int port1;
2026 2122
2123 dev_dbg(&intf->dev, "%s\n", __func__);
2027 hub_power_on(hub); 2124 hub_power_on(hub);
2028 2125 hub_restart(hub, HUB_RESET_RESUME);
2029 for (port1 = 1; port1 <= hdev->maxchild; ++port1) {
2030 struct usb_device *child = hdev->children[port1-1];
2031
2032 if (child) {
2033
2034 /* For "USB_PERSIST"-enabled children we must
2035 * mark the child device for reset-resume and
2036 * turn off the connect-change status to prevent
2037 * khubd from disconnecting it later.
2038 */
2039 if (USB_PERSIST && child->persist_enabled) {
2040 child->reset_resume = 1;
2041 clear_port_feature(hdev, port1,
2042 USB_PORT_FEAT_C_CONNECTION);
2043
2044 /* Otherwise we must disconnect the child,
2045 * but as we may not lock the child device here
2046 * we have to do a "logical" disconnect.
2047 */
2048 } else {
2049 hub_port_logical_disconnect(hub, port1);
2050 }
2051 }
2052 }
2053
2054 hub_activate(hub);
2055 return 0; 2126 return 0;
2056} 2127}
2057 2128
@@ -2061,10 +2132,10 @@ static int hub_reset_resume(struct usb_interface *intf)
2061 * 2132 *
2062 * The USB host controller driver calls this function when its root hub 2133 * The USB host controller driver calls this function when its root hub
2063 * is resumed and Vbus power has been interrupted or the controller 2134 * is resumed and Vbus power has been interrupted or the controller
2064 * has been reset. The routine marks @rhdev as having lost power. When 2135 * has been reset. The routine marks @rhdev as having lost power.
2065 * the hub driver is resumed it will take notice; if CONFIG_USB_PERSIST 2136 * When the hub driver is resumed it will take notice and carry out
2066 * is enabled then it will carry out power-session recovery, otherwise 2137 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
2067 * it will disconnect all the child devices. 2138 * the others will be disconnected.
2068 */ 2139 */
2069void usb_root_hub_lost_power(struct usb_device *rhdev) 2140void usb_root_hub_lost_power(struct usb_device *rhdev)
2070{ 2141{
@@ -2147,12 +2218,13 @@ static int hub_port_debounce(struct usb_hub *hub, int port1)
2147 return portstatus; 2218 return portstatus;
2148} 2219}
2149 2220
2150static void ep0_reinit(struct usb_device *udev) 2221void usb_ep0_reinit(struct usb_device *udev)
2151{ 2222{
2152 usb_disable_endpoint(udev, 0 + USB_DIR_IN); 2223 usb_disable_endpoint(udev, 0 + USB_DIR_IN);
2153 usb_disable_endpoint(udev, 0 + USB_DIR_OUT); 2224 usb_disable_endpoint(udev, 0 + USB_DIR_OUT);
2154 usb_enable_endpoint(udev, &udev->ep0); 2225 usb_enable_endpoint(udev, &udev->ep0);
2155} 2226}
2227EXPORT_SYMBOL_GPL(usb_ep0_reinit);
2156 2228
2157#define usb_sndaddr0pipe() (PIPE_CONTROL << 30) 2229#define usb_sndaddr0pipe() (PIPE_CONTROL << 30)
2158#define usb_rcvaddr0pipe() ((PIPE_CONTROL << 30) | USB_DIR_IN) 2230#define usb_rcvaddr0pipe() ((PIPE_CONTROL << 30) | USB_DIR_IN)
@@ -2171,9 +2243,10 @@ static int hub_set_address(struct usb_device *udev, int devnum)
2171 USB_REQ_SET_ADDRESS, 0, devnum, 0, 2243 USB_REQ_SET_ADDRESS, 0, devnum, 0,
2172 NULL, 0, USB_CTRL_SET_TIMEOUT); 2244 NULL, 0, USB_CTRL_SET_TIMEOUT);
2173 if (retval == 0) { 2245 if (retval == 0) {
2174 udev->devnum = devnum; /* Device now using proper address */ 2246 /* Device now using proper address. */
2247 update_address(udev, devnum);
2175 usb_set_device_state(udev, USB_STATE_ADDRESS); 2248 usb_set_device_state(udev, USB_STATE_ADDRESS);
2176 ep0_reinit(udev); 2249 usb_ep0_reinit(udev);
2177 } 2250 }
2178 return retval; 2251 return retval;
2179} 2252}
@@ -2355,26 +2428,33 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2355#undef GET_DESCRIPTOR_BUFSIZE 2428#undef GET_DESCRIPTOR_BUFSIZE
2356 } 2429 }
2357 2430
2358 for (j = 0; j < SET_ADDRESS_TRIES; ++j) { 2431 /*
2359 retval = hub_set_address(udev, devnum); 2432 * If device is WUSB, we already assigned an
2360 if (retval >= 0) 2433 * unauthorized address in the Connect Ack sequence;
2434 * authorization will assign the final address.
2435 */
2436 if (udev->wusb == 0) {
2437 for (j = 0; j < SET_ADDRESS_TRIES; ++j) {
2438 retval = hub_set_address(udev, devnum);
2439 if (retval >= 0)
2440 break;
2441 msleep(200);
2442 }
2443 if (retval < 0) {
2444 dev_err(&udev->dev,
2445 "device not accepting address %d, error %d\n",
2446 devnum, retval);
2447 goto fail;
2448 }
2449
2450 /* cope with hardware quirkiness:
2451 * - let SET_ADDRESS settle, some device hardware wants it
2452 * - read ep0 maxpacket even for high and low speed,
2453 */
2454 msleep(10);
2455 if (USE_NEW_SCHEME(retry_counter))
2361 break; 2456 break;
2362 msleep(200); 2457 }
2363 }
2364 if (retval < 0) {
2365 dev_err(&udev->dev,
2366 "device not accepting address %d, error %d\n",
2367 devnum, retval);
2368 goto fail;
2369 }
2370
2371 /* cope with hardware quirkiness:
2372 * - let SET_ADDRESS settle, some device hardware wants it
2373 * - read ep0 maxpacket even for high and low speed,
2374 */
2375 msleep(10);
2376 if (USE_NEW_SCHEME(retry_counter))
2377 break;
2378 2458
2379 retval = usb_get_device_descriptor(udev, 8); 2459 retval = usb_get_device_descriptor(udev, 8);
2380 if (retval < 8) { 2460 if (retval < 8) {
@@ -2391,7 +2471,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2391 if (retval) 2471 if (retval)
2392 goto fail; 2472 goto fail;
2393 2473
2394 i = udev->descriptor.bMaxPacketSize0 == 0xff? 2474 i = udev->descriptor.bMaxPacketSize0 == 0xff? /* wusb device? */
2395 512 : udev->descriptor.bMaxPacketSize0; 2475 512 : udev->descriptor.bMaxPacketSize0;
2396 if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { 2476 if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) {
2397 if (udev->speed != USB_SPEED_FULL || 2477 if (udev->speed != USB_SPEED_FULL ||
@@ -2402,7 +2482,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2402 } 2482 }
2403 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); 2483 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i);
2404 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); 2484 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i);
2405 ep0_reinit(udev); 2485 usb_ep0_reinit(udev);
2406 } 2486 }
2407 2487
2408 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); 2488 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE);
@@ -2419,7 +2499,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2419fail: 2499fail:
2420 if (retval) { 2500 if (retval) {
2421 hub_port_disable(hub, port1, 0); 2501 hub_port_disable(hub, port1, 0);
2422 udev->devnum = devnum; /* for disconnect processing */ 2502 update_address(udev, devnum); /* for disconnect processing */
2423 } 2503 }
2424 mutex_unlock(&usb_address0_mutex); 2504 mutex_unlock(&usb_address0_mutex);
2425 return retval; 2505 return retval;
@@ -2568,6 +2648,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2568 udev->speed = USB_SPEED_UNKNOWN; 2648 udev->speed = USB_SPEED_UNKNOWN;
2569 udev->bus_mA = hub->mA_per_port; 2649 udev->bus_mA = hub->mA_per_port;
2570 udev->level = hdev->level + 1; 2650 udev->level = hdev->level + 1;
2651 udev->wusb = hub_is_wusb(hub);
2571 2652
2572 /* set the address */ 2653 /* set the address */
2573 choose_address(udev); 2654 choose_address(udev);
@@ -2657,12 +2738,13 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2657loop_disable: 2738loop_disable:
2658 hub_port_disable(hub, port1, 1); 2739 hub_port_disable(hub, port1, 1);
2659loop: 2740loop:
2660 ep0_reinit(udev); 2741 usb_ep0_reinit(udev);
2661 release_address(udev); 2742 release_address(udev);
2662 usb_put_dev(udev); 2743 usb_put_dev(udev);
2663 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) 2744 if ((status == -ENOTCONN) || (status == -ENOTSUPP))
2664 break; 2745 break;
2665 } 2746 }
2747 dev_err(hub_dev, "unable to enumerate USB device on port %d\n", port1);
2666 2748
2667done: 2749done:
2668 hub_port_disable(hub, port1, 1); 2750 hub_port_disable(hub, port1, 1);
@@ -2726,7 +2808,7 @@ static void hub_events(void)
2726 /* If the hub has died, clean up after it */ 2808 /* If the hub has died, clean up after it */
2727 if (hdev->state == USB_STATE_NOTATTACHED) { 2809 if (hdev->state == USB_STATE_NOTATTACHED) {
2728 hub->error = -ENODEV; 2810 hub->error = -ENODEV;
2729 hub_pre_reset(intf); 2811 hub_stop(hub);
2730 goto loop; 2812 goto loop;
2731 } 2813 }
2732 2814
@@ -2872,11 +2954,6 @@ static void hub_events(void)
2872 2954
2873 hub->activating = 0; 2955 hub->activating = 0;
2874 2956
2875 /* If this is a root hub, tell the HCD it's okay to
2876 * re-enable port-change interrupts now. */
2877 if (!hdev->parent && !hub->busy_bits[0])
2878 usb_enable_root_hub_irq(hdev->bus);
2879
2880loop_autopm: 2957loop_autopm:
2881 /* Allow autosuspend if we're not going to run again */ 2958 /* Allow autosuspend if we're not going to run again */
2882 if (list_empty(&hub->event_list)) 2959 if (list_empty(&hub->event_list))
@@ -2890,7 +2967,13 @@ loop:
2890 2967
2891static int hub_thread(void *__unused) 2968static int hub_thread(void *__unused)
2892{ 2969{
2970 /* khubd needs to be freezable to avoid intefering with USB-PERSIST
2971 * port handover. Otherwise it might see that a full-speed device
2972 * was gone before the EHCI controller had handed its port over to
2973 * the companion full-speed controller.
2974 */
2893 set_freezable(); 2975 set_freezable();
2976
2894 do { 2977 do {
2895 hub_events(); 2978 hub_events();
2896 wait_event_freezable(khubd_wait, 2979 wait_event_freezable(khubd_wait,
@@ -2959,16 +3042,36 @@ void usb_hub_cleanup(void)
2959 usb_deregister(&hub_driver); 3042 usb_deregister(&hub_driver);
2960} /* usb_hub_cleanup() */ 3043} /* usb_hub_cleanup() */
2961 3044
2962static int config_descriptors_changed(struct usb_device *udev) 3045static int descriptors_changed(struct usb_device *udev,
3046 struct usb_device_descriptor *old_device_descriptor)
2963{ 3047{
2964 unsigned index; 3048 int changed = 0;
2965 unsigned len = 0; 3049 unsigned index;
2966 struct usb_config_descriptor *buf; 3050 unsigned serial_len = 0;
3051 unsigned len;
3052 unsigned old_length;
3053 int length;
3054 char *buf;
3055
3056 if (memcmp(&udev->descriptor, old_device_descriptor,
3057 sizeof(*old_device_descriptor)) != 0)
3058 return 1;
2967 3059
3060 /* Since the idVendor, idProduct, and bcdDevice values in the
3061 * device descriptor haven't changed, we will assume the
3062 * Manufacturer and Product strings haven't changed either.
3063 * But the SerialNumber string could be different (e.g., a
3064 * different flash card of the same brand).
3065 */
3066 if (udev->serial)
3067 serial_len = strlen(udev->serial) + 1;
3068
3069 len = serial_len;
2968 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { 3070 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
2969 if (len < le16_to_cpu(udev->config[index].desc.wTotalLength)) 3071 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
2970 len = le16_to_cpu(udev->config[index].desc.wTotalLength); 3072 len = max(len, old_length);
2971 } 3073 }
3074
2972 buf = kmalloc(len, GFP_NOIO); 3075 buf = kmalloc(len, GFP_NOIO);
2973 if (buf == NULL) { 3076 if (buf == NULL) {
2974 dev_err(&udev->dev, "no mem to re-read configs after reset\n"); 3077 dev_err(&udev->dev, "no mem to re-read configs after reset\n");
@@ -2976,25 +3079,41 @@ static int config_descriptors_changed(struct usb_device *udev)
2976 return 1; 3079 return 1;
2977 } 3080 }
2978 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { 3081 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
2979 int length; 3082 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
2980 int old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
2981
2982 length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf, 3083 length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf,
2983 old_length); 3084 old_length);
2984 if (length < old_length) { 3085 if (length != old_length) {
2985 dev_dbg(&udev->dev, "config index %d, error %d\n", 3086 dev_dbg(&udev->dev, "config index %d, error %d\n",
2986 index, length); 3087 index, length);
3088 changed = 1;
2987 break; 3089 break;
2988 } 3090 }
2989 if (memcmp (buf, udev->rawdescriptors[index], old_length) 3091 if (memcmp (buf, udev->rawdescriptors[index], old_length)
2990 != 0) { 3092 != 0) {
2991 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", 3093 dev_dbg(&udev->dev, "config index %d changed (#%d)\n",
2992 index, buf->bConfigurationValue); 3094 index,
3095 ((struct usb_config_descriptor *) buf)->
3096 bConfigurationValue);
3097 changed = 1;
2993 break; 3098 break;
2994 } 3099 }
2995 } 3100 }
3101
3102 if (!changed && serial_len) {
3103 length = usb_string(udev, udev->descriptor.iSerialNumber,
3104 buf, serial_len);
3105 if (length + 1 != serial_len) {
3106 dev_dbg(&udev->dev, "serial string error %d\n",
3107 length);
3108 changed = 1;
3109 } else if (memcmp(buf, udev->serial, length) != 0) {
3110 dev_dbg(&udev->dev, "serial string changed\n");
3111 changed = 1;
3112 }
3113 }
3114
2996 kfree(buf); 3115 kfree(buf);
2997 return index != udev->descriptor.bNumConfigurations; 3116 return changed;
2998} 3117}
2999 3118
3000/** 3119/**
@@ -3044,7 +3163,7 @@ int usb_reset_device(struct usb_device *udev)
3044 3163
3045 if (!parent_hdev) { 3164 if (!parent_hdev) {
3046 /* this requires hcd-specific logic; see OHCI hc_restart() */ 3165 /* this requires hcd-specific logic; see OHCI hc_restart() */
3047 dev_dbg(&udev->dev, "%s for root hub!\n", __FUNCTION__); 3166 dev_dbg(&udev->dev, "%s for root hub!\n", __func__);
3048 return -EISDIR; 3167 return -EISDIR;
3049 } 3168 }
3050 parent_hub = hdev_to_hub(parent_hdev); 3169 parent_hub = hdev_to_hub(parent_hdev);
@@ -3054,21 +3173,18 @@ int usb_reset_device(struct usb_device *udev)
3054 3173
3055 /* ep0 maxpacket size may change; let the HCD know about it. 3174 /* ep0 maxpacket size may change; let the HCD know about it.
3056 * Other endpoints will be handled by re-enumeration. */ 3175 * Other endpoints will be handled by re-enumeration. */
3057 ep0_reinit(udev); 3176 usb_ep0_reinit(udev);
3058 ret = hub_port_init(parent_hub, udev, port1, i); 3177 ret = hub_port_init(parent_hub, udev, port1, i);
3059 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) 3178 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV)
3060 break; 3179 break;
3061 } 3180 }
3062 clear_bit(port1, parent_hub->busy_bits); 3181 clear_bit(port1, parent_hub->busy_bits);
3063 if (!parent_hdev->parent && !parent_hub->busy_bits[0])
3064 usb_enable_root_hub_irq(parent_hdev->bus);
3065 3182
3066 if (ret < 0) 3183 if (ret < 0)
3067 goto re_enumerate; 3184 goto re_enumerate;
3068 3185
3069 /* Device might have changed firmware (DFU or similar) */ 3186 /* Device might have changed firmware (DFU or similar) */
3070 if (memcmp(&udev->descriptor, &descriptor, sizeof descriptor) 3187 if (descriptors_changed(udev, &descriptor)) {
3071 || config_descriptors_changed (udev)) {
3072 dev_info(&udev->dev, "device firmware changed\n"); 3188 dev_info(&udev->dev, "device firmware changed\n");
3073 udev->descriptor = descriptor; /* for disconnect() calls */ 3189 udev->descriptor = descriptor; /* for disconnect() calls */
3074 goto re_enumerate; 3190 goto re_enumerate;
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index 1551aed65e05..2a116ce53c9b 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -41,9 +41,10 @@
41 */ 41 */
42#define USB_PORT_FEAT_CONNECTION 0 42#define USB_PORT_FEAT_CONNECTION 0
43#define USB_PORT_FEAT_ENABLE 1 43#define USB_PORT_FEAT_ENABLE 1
44#define USB_PORT_FEAT_SUSPEND 2 44#define USB_PORT_FEAT_SUSPEND 2 /* L2 suspend */
45#define USB_PORT_FEAT_OVER_CURRENT 3 45#define USB_PORT_FEAT_OVER_CURRENT 3
46#define USB_PORT_FEAT_RESET 4 46#define USB_PORT_FEAT_RESET 4
47#define USB_PORT_FEAT_L1 5 /* L1 suspend */
47#define USB_PORT_FEAT_POWER 8 48#define USB_PORT_FEAT_POWER 8
48#define USB_PORT_FEAT_LOWSPEED 9 49#define USB_PORT_FEAT_LOWSPEED 9
49#define USB_PORT_FEAT_HIGHSPEED 10 50#define USB_PORT_FEAT_HIGHSPEED 10
@@ -54,6 +55,7 @@
54#define USB_PORT_FEAT_C_RESET 20 55#define USB_PORT_FEAT_C_RESET 20
55#define USB_PORT_FEAT_TEST 21 56#define USB_PORT_FEAT_TEST 21
56#define USB_PORT_FEAT_INDICATOR 22 57#define USB_PORT_FEAT_INDICATOR 22
58#define USB_PORT_FEAT_C_PORT_L1 23
57 59
58/* 60/*
59 * Hub Status and Hub Change results 61 * Hub Status and Hub Change results
@@ -73,7 +75,8 @@ struct usb_port_status {
73#define USB_PORT_STAT_SUSPEND 0x0004 75#define USB_PORT_STAT_SUSPEND 0x0004
74#define USB_PORT_STAT_OVERCURRENT 0x0008 76#define USB_PORT_STAT_OVERCURRENT 0x0008
75#define USB_PORT_STAT_RESET 0x0010 77#define USB_PORT_STAT_RESET 0x0010
76/* bits 5 to 7 are reserved */ 78#define USB_PORT_STAT_L1 0x0020
79/* bits 6 to 7 are reserved */
77#define USB_PORT_STAT_POWER 0x0100 80#define USB_PORT_STAT_POWER 0x0100
78#define USB_PORT_STAT_LOW_SPEED 0x0200 81#define USB_PORT_STAT_LOW_SPEED 0x0200
79#define USB_PORT_STAT_HIGH_SPEED 0x0400 82#define USB_PORT_STAT_HIGH_SPEED 0x0400
@@ -91,6 +94,7 @@ struct usb_port_status {
91#define USB_PORT_STAT_C_SUSPEND 0x0004 94#define USB_PORT_STAT_C_SUSPEND 0x0004
92#define USB_PORT_STAT_C_OVERCURRENT 0x0008 95#define USB_PORT_STAT_C_OVERCURRENT 0x0008
93#define USB_PORT_STAT_C_RESET 0x0010 96#define USB_PORT_STAT_C_RESET 0x0010
97#define USB_PORT_STAT_C_L1 0x0020
94 98
95/* 99/*
96 * wHubCharacteristics (masks) 100 * wHubCharacteristics (masks)
@@ -191,5 +195,6 @@ struct usb_tt_clear {
191}; 195};
192 196
193extern void usb_hub_tt_clear_buffer(struct usb_device *dev, int pipe); 197extern void usb_hub_tt_clear_buffer(struct usb_device *dev, int pipe);
198extern void usb_ep0_reinit(struct usb_device *);
194 199
195#endif /* __LINUX_HUB_H */ 200#endif /* __LINUX_HUB_H */
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 83a373e9cc36..8607846e3c3f 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -463,13 +463,13 @@ static int usbfs_fill_super(struct super_block *sb, void *data, int silent)
463 inode = usbfs_get_inode(sb, S_IFDIR | 0755, 0); 463 inode = usbfs_get_inode(sb, S_IFDIR | 0755, 0);
464 464
465 if (!inode) { 465 if (!inode) {
466 dbg("%s: could not get inode!",__FUNCTION__); 466 dbg("%s: could not get inode!",__func__);
467 return -ENOMEM; 467 return -ENOMEM;
468 } 468 }
469 469
470 root = d_alloc_root(inode); 470 root = d_alloc_root(inode);
471 if (!root) { 471 if (!root) {
472 dbg("%s: could not get root dentry!",__FUNCTION__); 472 dbg("%s: could not get root dentry!",__func__);
473 iput(inode); 473 iput(inode);
474 return -ENOMEM; 474 return -ENOMEM;
475 } 475 }
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index c311f67b7f08..e819e5359d57 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -312,7 +312,7 @@ static void sg_complete(struct urb *urb)
312 retval != -EBUSY) 312 retval != -EBUSY)
313 dev_err(&io->dev->dev, 313 dev_err(&io->dev->dev,
314 "%s, unlink --> %d\n", 314 "%s, unlink --> %d\n",
315 __FUNCTION__, retval); 315 __func__, retval);
316 } else if (urb == io->urbs [i]) 316 } else if (urb == io->urbs [i])
317 found = 1; 317 found = 1;
318 } 318 }
@@ -550,7 +550,7 @@ void usb_sg_wait(struct usb_sg_request *io)
550 io->urbs[i]->dev = NULL; 550 io->urbs[i]->dev = NULL;
551 io->urbs[i]->status = retval; 551 io->urbs[i]->status = retval;
552 dev_dbg(&io->dev->dev, "%s, submit --> %d\n", 552 dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
553 __FUNCTION__, retval); 553 __func__, retval);
554 usb_sg_cancel(io); 554 usb_sg_cancel(io);
555 } 555 }
556 spin_lock_irq(&io->lock); 556 spin_lock_irq(&io->lock);
@@ -600,7 +600,7 @@ void usb_sg_cancel(struct usb_sg_request *io)
600 retval = usb_unlink_urb(io->urbs [i]); 600 retval = usb_unlink_urb(io->urbs [i]);
601 if (retval != -EINPROGRESS && retval != -EBUSY) 601 if (retval != -EINPROGRESS && retval != -EBUSY)
602 dev_warn(&io->dev->dev, "%s, unlink --> %d\n", 602 dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
603 __FUNCTION__, retval); 603 __func__, retval);
604 } 604 }
605 spin_lock(&io->lock); 605 spin_lock(&io->lock);
606 } 606 }
@@ -784,7 +784,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
784 if (size <= 0 || !buf || !index) 784 if (size <= 0 || !buf || !index)
785 return -EINVAL; 785 return -EINVAL;
786 buf[0] = 0; 786 buf[0] = 0;
787 tbuf = kmalloc(256, GFP_KERNEL); 787 tbuf = kmalloc(256, GFP_NOIO);
788 if (!tbuf) 788 if (!tbuf)
789 return -ENOMEM; 789 return -ENOMEM;
790 790
@@ -1068,7 +1068,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1068{ 1068{
1069 int i; 1069 int i;
1070 1070
1071 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __FUNCTION__, 1071 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__,
1072 skip_ep0 ? "non-ep0" : "all"); 1072 skip_ep0 ? "non-ep0" : "all");
1073 for (i = skip_ep0; i < 16; ++i) { 1073 for (i = skip_ep0; i < 16; ++i) {
1074 usb_disable_endpoint(dev, i); 1074 usb_disable_endpoint(dev, i);
@@ -1089,8 +1089,8 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1089 continue; 1089 continue;
1090 dev_dbg(&dev->dev, "unregistering interface %s\n", 1090 dev_dbg(&dev->dev, "unregistering interface %s\n",
1091 interface->dev.bus_id); 1091 interface->dev.bus_id);
1092 usb_remove_sysfs_intf_files(interface);
1093 device_del(&interface->dev); 1092 device_del(&interface->dev);
1093 usb_remove_sysfs_intf_files(interface);
1094 } 1094 }
1095 1095
1096 /* Now that the interfaces are unbound, nobody should 1096 /* Now that the interfaces are unbound, nobody should
@@ -1231,7 +1231,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1231 */ 1231 */
1232 1232
1233 /* prevent submissions using previous endpoint settings */ 1233 /* prevent submissions using previous endpoint settings */
1234 if (iface->cur_altsetting != alt && device_is_registered(&iface->dev)) 1234 if (iface->cur_altsetting != alt)
1235 usb_remove_sysfs_intf_files(iface); 1235 usb_remove_sysfs_intf_files(iface);
1236 usb_disable_interface(dev, iface); 1236 usb_disable_interface(dev, iface);
1237 1237
@@ -1330,8 +1330,7 @@ int usb_reset_configuration(struct usb_device *dev)
1330 struct usb_interface *intf = config->interface[i]; 1330 struct usb_interface *intf = config->interface[i];
1331 struct usb_host_interface *alt; 1331 struct usb_host_interface *alt;
1332 1332
1333 if (device_is_registered(&intf->dev)) 1333 usb_remove_sysfs_intf_files(intf);
1334 usb_remove_sysfs_intf_files(intf);
1335 alt = usb_altnum_to_altsetting(intf, 0); 1334 alt = usb_altnum_to_altsetting(intf, 0);
1336 1335
1337 /* No altsetting 0? We'll assume the first altsetting. 1336 /* No altsetting 0? We'll assume the first altsetting.
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index dfc5418ea10c..2e2019390290 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -97,4 +97,18 @@ void usb_detect_quirks(struct usb_device *udev)
97 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) 97 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB)
98 udev->autosuspend_disabled = 1; 98 udev->autosuspend_disabled = 1;
99#endif 99#endif
100
101 /* For the present, all devices default to USB-PERSIST enabled */
102#if 0 /* was: #ifdef CONFIG_PM */
103 /* Hubs are automatically enabled for USB-PERSIST */
104 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
105 udev->persist_enabled = 1;
106
107#else
108 /* In the absence of PM, we can safely enable USB-PERSIST
109 * for all devices. It will affect things like hub resets
110 * and EMF-related port disables.
111 */
112 udev->persist_enabled = 1;
113#endif /* CONFIG_PM */
100} 114}
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index a37ccbd1e007..5b20a60de8ba 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -180,11 +180,9 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
180static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL); 180static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
181 181
182 182
183#if defined(CONFIG_USB_PERSIST) || defined(CONFIG_USB_SUSPEND) 183#ifdef CONFIG_PM
184static const char power_group[] = "power";
185#endif
186 184
187#ifdef CONFIG_USB_PERSIST 185static const char power_group[] = "power";
188 186
189static ssize_t 187static ssize_t
190show_persist(struct device *dev, struct device_attribute *attr, char *buf) 188show_persist(struct device *dev, struct device_attribute *attr, char *buf)
@@ -222,12 +220,13 @@ static int add_persist_attributes(struct device *dev)
222 if (is_usb_device(dev)) { 220 if (is_usb_device(dev)) {
223 struct usb_device *udev = to_usb_device(dev); 221 struct usb_device *udev = to_usb_device(dev);
224 222
225 /* Hubs are automatically enabled for USB_PERSIST */ 223 /* Hubs are automatically enabled for USB_PERSIST,
226 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) 224 * no point in creating the attribute file.
227 udev->persist_enabled = 1; 225 */
228 rc = sysfs_add_file_to_group(&dev->kobj, 226 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB)
229 &dev_attr_persist.attr, 227 rc = sysfs_add_file_to_group(&dev->kobj,
230 power_group); 228 &dev_attr_persist.attr,
229 power_group);
231 } 230 }
232 return rc; 231 return rc;
233} 232}
@@ -238,13 +237,12 @@ static void remove_persist_attributes(struct device *dev)
238 &dev_attr_persist.attr, 237 &dev_attr_persist.attr,
239 power_group); 238 power_group);
240} 239}
241
242#else 240#else
243 241
244#define add_persist_attributes(dev) 0 242#define add_persist_attributes(dev) 0
245#define remove_persist_attributes(dev) do {} while (0) 243#define remove_persist_attributes(dev) do {} while (0)
246 244
247#endif /* CONFIG_USB_PERSIST */ 245#endif /* CONFIG_PM */
248 246
249#ifdef CONFIG_USB_SUSPEND 247#ifdef CONFIG_USB_SUSPEND
250 248
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 9d7e63292c01..c0b1ae25ae2a 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -334,7 +334,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
334 dev_dbg(&dev->dev, 334 dev_dbg(&dev->dev,
335 "bogus endpoint ep%d%s in %s (bad maxpacket %d)\n", 335 "bogus endpoint ep%d%s in %s (bad maxpacket %d)\n",
336 usb_endpoint_num(&ep->desc), is_out ? "out" : "in", 336 usb_endpoint_num(&ep->desc), is_out ? "out" : "in",
337 __FUNCTION__, max); 337 __func__, max);
338 return -EMSGSIZE; 338 return -EMSGSIZE;
339 } 339 }
340 340
@@ -590,6 +590,30 @@ void usb_kill_anchored_urbs(struct usb_anchor *anchor)
590EXPORT_SYMBOL_GPL(usb_kill_anchored_urbs); 590EXPORT_SYMBOL_GPL(usb_kill_anchored_urbs);
591 591
592/** 592/**
593 * usb_unlink_anchored_urbs - asynchronously cancel transfer requests en masse
594 * @anchor: anchor the requests are bound to
595 *
596 * this allows all outstanding URBs to be unlinked starting
597 * from the back of the queue. This function is asynchronous.
598 * The unlinking is just tiggered. It may happen after this
599 * function has returned.
600 */
601void usb_unlink_anchored_urbs(struct usb_anchor *anchor)
602{
603 struct urb *victim;
604
605 spin_lock_irq(&anchor->lock);
606 while (!list_empty(&anchor->urb_list)) {
607 victim = list_entry(anchor->urb_list.prev, struct urb,
608 anchor_list);
609 /* this will unanchor the URB */
610 usb_unlink_urb(victim);
611 }
612 spin_unlock_irq(&anchor->lock);
613}
614EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs);
615
616/**
593 * usb_wait_anchor_empty_timeout - wait for an anchor to be unused 617 * usb_wait_anchor_empty_timeout - wait for an anchor to be unused
594 * @anchor: the anchor you want to become unused 618 * @anchor: the anchor you want to become unused
595 * @timeout: how long you are willing to wait in milliseconds 619 * @timeout: how long you are willing to wait in milliseconds
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 2375194a9d43..1bf8ccb9c58d 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -114,13 +114,11 @@ static inline int is_usb_device_driver(struct device_driver *drv)
114static inline void mark_active(struct usb_interface *f) 114static inline void mark_active(struct usb_interface *f)
115{ 115{
116 f->is_active = 1; 116 f->is_active = 1;
117 f->dev.power.power_state.event = PM_EVENT_ON;
118} 117}
119 118
120static inline void mark_quiesced(struct usb_interface *f) 119static inline void mark_quiesced(struct usb_interface *f)
121{ 120{
122 f->is_active = 0; 121 f->is_active = 0;
123 f->dev.power.power_state.event = PM_EVENT_SUSPEND;
124} 122}
125 123
126static inline int is_active(const struct usb_interface *f) 124static inline int is_active(const struct usb_interface *f)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index d681bb27fa58..f7b54651dd42 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -44,8 +44,8 @@ menuconfig USB_GADGET
44if USB_GADGET 44if USB_GADGET
45 45
46config USB_GADGET_DEBUG 46config USB_GADGET_DEBUG
47 boolean "Debugging messages" 47 boolean "Debugging messages (DEVELOPMENT)"
48 depends on USB_GADGET && DEBUG_KERNEL && EXPERIMENTAL 48 depends on USB_GADGET && DEBUG_KERNEL
49 help 49 help
50 Many controller and gadget drivers will print some debugging 50 Many controller and gadget drivers will print some debugging
51 messages if you use this option to ask for those messages. 51 messages if you use this option to ask for those messages.
@@ -58,7 +58,7 @@ config USB_GADGET_DEBUG
58 production build. 58 production build.
59 59
60config USB_GADGET_DEBUG_FILES 60config USB_GADGET_DEBUG_FILES
61 boolean "Debugging information files" 61 boolean "Debugging information files (DEVELOPMENT)"
62 depends on USB_GADGET && PROC_FS 62 depends on USB_GADGET && PROC_FS
63 help 63 help
64 Some of the drivers in the "gadget" framework can expose 64 Some of the drivers in the "gadget" framework can expose
@@ -69,7 +69,7 @@ config USB_GADGET_DEBUG_FILES
69 here. If in doubt, or to conserve kernel memory, say "N". 69 here. If in doubt, or to conserve kernel memory, say "N".
70 70
71config USB_GADGET_DEBUG_FS 71config USB_GADGET_DEBUG_FS
72 boolean "Debugging information files in debugfs" 72 boolean "Debugging information files in debugfs (DEVELOPMENT)"
73 depends on USB_GADGET && DEBUG_FS 73 depends on USB_GADGET && DEBUG_FS
74 help 74 help
75 Some of the drivers in the "gadget" framework can expose 75 Some of the drivers in the "gadget" framework can expose
@@ -337,7 +337,7 @@ config USB_AT91
337 337
338config USB_GADGET_DUMMY_HCD 338config USB_GADGET_DUMMY_HCD
339 boolean "Dummy HCD (DEVELOPMENT)" 339 boolean "Dummy HCD (DEVELOPMENT)"
340 depends on (USB=y || (USB=m && USB_GADGET=m)) && EXPERIMENTAL 340 depends on USB=y || (USB=m && USB_GADGET=m)
341 select USB_GADGET_DUALSPEED 341 select USB_GADGET_DUALSPEED
342 help 342 help
343 This host controller driver emulates USB, looping all data transfer 343 This host controller driver emulates USB, looping all data transfer
@@ -404,7 +404,6 @@ choice
404 404
405config USB_ZERO 405config USB_ZERO
406 tristate "Gadget Zero (DEVELOPMENT)" 406 tristate "Gadget Zero (DEVELOPMENT)"
407 depends on EXPERIMENTAL
408 help 407 help
409 Gadget Zero is a two-configuration device. It either sinks and 408 Gadget Zero is a two-configuration device. It either sinks and
410 sources bulk data; or it loops back a configurable number of 409 sources bulk data; or it loops back a configurable number of
@@ -468,8 +467,8 @@ config USB_ETH
468 dynamically linked module called "g_ether". 467 dynamically linked module called "g_ether".
469 468
470config USB_ETH_RNDIS 469config USB_ETH_RNDIS
471 bool "RNDIS support (EXPERIMENTAL)" 470 bool "RNDIS support"
472 depends on USB_ETH && EXPERIMENTAL 471 depends on USB_ETH
473 default y 472 default y
474 help 473 help
475 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, 474 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
@@ -495,6 +494,9 @@ config USB_GADGETFS
495 All endpoints, transfer speeds, and transfer types supported by 494 All endpoints, transfer speeds, and transfer types supported by
496 the hardware are available, through read() and write() calls. 495 the hardware are available, through read() and write() calls.
497 496
497 Currently, this option is still labelled as EXPERIMENTAL because
498 of existing race conditions in the underlying in-kernel AIO core.
499
498 Say "y" to link the driver statically, or "m" to build a 500 Say "y" to link the driver statically, or "m" to build a
499 dynamically linked module called "gadgetfs". 501 dynamically linked module called "gadgetfs".
500 502
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index b663f23f2642..fc6f3483be44 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -3248,6 +3248,8 @@ static int udc_pci_probe(
3248 3248
3249 /* pci setup */ 3249 /* pci setup */
3250 if (pci_enable_device(pdev) < 0) { 3250 if (pci_enable_device(pdev) < 0) {
3251 kfree(dev);
3252 dev = 0;
3251 retval = -ENODEV; 3253 retval = -ENODEV;
3252 goto finished; 3254 goto finished;
3253 } 3255 }
@@ -3259,6 +3261,8 @@ static int udc_pci_probe(
3259 3261
3260 if (!request_mem_region(resource, len, name)) { 3262 if (!request_mem_region(resource, len, name)) {
3261 dev_dbg(&pdev->dev, "pci device used already\n"); 3263 dev_dbg(&pdev->dev, "pci device used already\n");
3264 kfree(dev);
3265 dev = 0;
3262 retval = -EBUSY; 3266 retval = -EBUSY;
3263 goto finished; 3267 goto finished;
3264 } 3268 }
@@ -3267,18 +3271,24 @@ static int udc_pci_probe(
3267 dev->virt_addr = ioremap_nocache(resource, len); 3271 dev->virt_addr = ioremap_nocache(resource, len);
3268 if (dev->virt_addr == NULL) { 3272 if (dev->virt_addr == NULL) {
3269 dev_dbg(&pdev->dev, "start address cannot be mapped\n"); 3273 dev_dbg(&pdev->dev, "start address cannot be mapped\n");
3274 kfree(dev);
3275 dev = 0;
3270 retval = -EFAULT; 3276 retval = -EFAULT;
3271 goto finished; 3277 goto finished;
3272 } 3278 }
3273 3279
3274 if (!pdev->irq) { 3280 if (!pdev->irq) {
3275 dev_err(&dev->pdev->dev, "irq not set\n"); 3281 dev_err(&dev->pdev->dev, "irq not set\n");
3282 kfree(dev);
3283 dev = 0;
3276 retval = -ENODEV; 3284 retval = -ENODEV;
3277 goto finished; 3285 goto finished;
3278 } 3286 }
3279 3287
3280 if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) { 3288 if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) {
3281 dev_dbg(&dev->pdev->dev, "request_irq(%d) fail\n", pdev->irq); 3289 dev_dbg(&dev->pdev->dev, "request_irq(%d) fail\n", pdev->irq);
3290 kfree(dev);
3291 dev = 0;
3282 retval = -EBUSY; 3292 retval = -EBUSY;
3283 goto finished; 3293 goto finished;
3284 } 3294 }
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index fd15ced899d8..9b913afb2e6d 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -389,6 +389,7 @@ static int write_fifo(struct at91_ep *ep, struct at91_request *req)
389 u32 csr = __raw_readl(creg); 389 u32 csr = __raw_readl(creg);
390 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); 390 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0));
391 unsigned total, count, is_last; 391 unsigned total, count, is_last;
392 u8 *buf;
392 393
393 /* 394 /*
394 * TODO: allow for writing two packets to the fifo ... that'll 395 * TODO: allow for writing two packets to the fifo ... that'll
@@ -413,6 +414,8 @@ static int write_fifo(struct at91_ep *ep, struct at91_request *req)
413 return 0; 414 return 0;
414 } 415 }
415 416
417 buf = req->req.buf + req->req.actual;
418 prefetch(buf);
416 total = req->req.length - req->req.actual; 419 total = req->req.length - req->req.actual;
417 if (ep->ep.maxpacket < total) { 420 if (ep->ep.maxpacket < total) {
418 count = ep->ep.maxpacket; 421 count = ep->ep.maxpacket;
@@ -435,7 +438,7 @@ static int write_fifo(struct at91_ep *ep, struct at91_request *req)
435 * recover when the actual bytecount matters (e.g. for USB Test 438 * recover when the actual bytecount matters (e.g. for USB Test
436 * and Measurement Class devices). 439 * and Measurement Class devices).
437 */ 440 */
438 __raw_writesb(dreg, req->req.buf + req->req.actual, count); 441 __raw_writesb(dreg, buf, count);
439 csr &= ~SET_FX; 442 csr &= ~SET_FX;
440 csr |= CLR_FX | AT91_UDP_TXPKTRDY; 443 csr |= CLR_FX | AT91_UDP_TXPKTRDY;
441 __raw_writel(csr, creg); 444 __raw_writel(csr, creg);
@@ -457,7 +460,7 @@ static void nuke(struct at91_ep *ep, int status)
457 if (list_empty(&ep->queue)) 460 if (list_empty(&ep->queue))
458 return; 461 return;
459 462
460 VDBG("%s %s\n", __FUNCTION__, ep->ep.name); 463 VDBG("%s %s\n", __func__, ep->ep.name);
461 while (!list_empty(&ep->queue)) { 464 while (!list_empty(&ep->queue)) {
462 req = list_entry(ep->queue.next, struct at91_request, queue); 465 req = list_entry(ep->queue.next, struct at91_request, queue);
463 done(ep, req, status); 466 done(ep, req, status);
@@ -792,7 +795,7 @@ static int at91_wakeup(struct usb_gadget *gadget)
792 int status = -EINVAL; 795 int status = -EINVAL;
793 unsigned long flags; 796 unsigned long flags;
794 797
795 DBG("%s\n", __FUNCTION__ ); 798 DBG("%s\n", __func__ );
796 local_irq_save(flags); 799 local_irq_save(flags);
797 800
798 if (!udc->clocked || !udc->suspended) 801 if (!udc->clocked || !udc->suspended)
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index cbe44535c0f0..66293105d136 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -365,16 +365,14 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
365 case USB_SPEED_HIGH: 365 case USB_SPEED_HIGH:
366 if (max == 512) 366 if (max == 512)
367 break; 367 break;
368 /* conserve return statements */ 368 goto done;
369 default: 369 case USB_SPEED_FULL:
370 switch (max) { 370 if (max == 8 || max == 16 || max == 32 || max == 64)
371 case 8: case 16: case 32: case 64:
372 /* we'll fake any legal size */ 371 /* we'll fake any legal size */
373 break; 372 break;
374 default: 373 /* save a return statement */
375 case USB_SPEED_LOW: 374 default:
376 goto done; 375 goto done;
377 }
378 } 376 }
379 break; 377 break;
380 case USB_ENDPOINT_XFER_INT: 378 case USB_ENDPOINT_XFER_INT:
@@ -894,13 +892,12 @@ static int dummy_udc_suspend (struct platform_device *pdev, pm_message_t state)
894{ 892{
895 struct dummy *dum = platform_get_drvdata(pdev); 893 struct dummy *dum = platform_get_drvdata(pdev);
896 894
897 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 895 dev_dbg (&pdev->dev, "%s\n", __func__);
898 spin_lock_irq (&dum->lock); 896 spin_lock_irq (&dum->lock);
899 dum->udc_suspended = 1; 897 dum->udc_suspended = 1;
900 set_link_state (dum); 898 set_link_state (dum);
901 spin_unlock_irq (&dum->lock); 899 spin_unlock_irq (&dum->lock);
902 900
903 pdev->dev.power.power_state = state;
904 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 901 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
905 return 0; 902 return 0;
906} 903}
@@ -909,13 +906,12 @@ static int dummy_udc_resume (struct platform_device *pdev)
909{ 906{
910 struct dummy *dum = platform_get_drvdata(pdev); 907 struct dummy *dum = platform_get_drvdata(pdev);
911 908
912 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 909 dev_dbg (&pdev->dev, "%s\n", __func__);
913 spin_lock_irq (&dum->lock); 910 spin_lock_irq (&dum->lock);
914 dum->udc_suspended = 0; 911 dum->udc_suspended = 0;
915 set_link_state (dum); 912 set_link_state (dum);
916 spin_unlock_irq (&dum->lock); 913 spin_unlock_irq (&dum->lock);
917 914
918 pdev->dev.power.power_state = PMSG_ON;
919 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 915 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
920 return 0; 916 return 0;
921} 917}
@@ -1711,7 +1707,7 @@ static int dummy_bus_suspend (struct usb_hcd *hcd)
1711{ 1707{
1712 struct dummy *dum = hcd_to_dummy (hcd); 1708 struct dummy *dum = hcd_to_dummy (hcd);
1713 1709
1714 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __FUNCTION__); 1710 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
1715 1711
1716 spin_lock_irq (&dum->lock); 1712 spin_lock_irq (&dum->lock);
1717 dum->rh_state = DUMMY_RH_SUSPENDED; 1713 dum->rh_state = DUMMY_RH_SUSPENDED;
@@ -1726,7 +1722,7 @@ static int dummy_bus_resume (struct usb_hcd *hcd)
1726 struct dummy *dum = hcd_to_dummy (hcd); 1722 struct dummy *dum = hcd_to_dummy (hcd);
1727 int rc = 0; 1723 int rc = 0;
1728 1724
1729 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __FUNCTION__); 1725 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
1730 1726
1731 spin_lock_irq (&dum->lock); 1727 spin_lock_irq (&dum->lock);
1732 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 1728 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
@@ -1900,7 +1896,7 @@ static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state)
1900 struct dummy *dum; 1896 struct dummy *dum;
1901 int rc = 0; 1897 int rc = 0;
1902 1898
1903 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 1899 dev_dbg (&pdev->dev, "%s\n", __func__);
1904 1900
1905 hcd = platform_get_drvdata (pdev); 1901 hcd = platform_get_drvdata (pdev);
1906 dum = hcd_to_dummy (hcd); 1902 dum = hcd_to_dummy (hcd);
@@ -1916,7 +1912,7 @@ static int dummy_hcd_resume (struct platform_device *pdev)
1916{ 1912{
1917 struct usb_hcd *hcd; 1913 struct usb_hcd *hcd;
1918 1914
1919 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 1915 dev_dbg (&pdev->dev, "%s\n", __func__);
1920 1916
1921 hcd = platform_get_drvdata (pdev); 1917 hcd = platform_get_drvdata (pdev);
1922 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 1918 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
@@ -1937,69 +1933,57 @@ static struct platform_driver dummy_hcd_driver = {
1937 1933
1938/*-------------------------------------------------------------------------*/ 1934/*-------------------------------------------------------------------------*/
1939 1935
1940/* These don't need to do anything because the pdev structures are 1936static struct platform_device *the_udc_pdev;
1941 * statically allocated. */ 1937static struct platform_device *the_hcd_pdev;
1942static void
1943dummy_udc_release (struct device *dev) {}
1944
1945static void
1946dummy_hcd_release (struct device *dev) {}
1947
1948static struct platform_device the_udc_pdev = {
1949 .name = (char *) gadget_name,
1950 .id = -1,
1951 .dev = {
1952 .release = dummy_udc_release,
1953 },
1954};
1955
1956static struct platform_device the_hcd_pdev = {
1957 .name = (char *) driver_name,
1958 .id = -1,
1959 .dev = {
1960 .release = dummy_hcd_release,
1961 },
1962};
1963 1938
1964static int __init init (void) 1939static int __init init (void)
1965{ 1940{
1966 int retval; 1941 int retval = -ENOMEM;
1967 1942
1968 if (usb_disabled ()) 1943 if (usb_disabled ())
1969 return -ENODEV; 1944 return -ENODEV;
1970 1945
1971 retval = platform_driver_register (&dummy_hcd_driver); 1946 the_hcd_pdev = platform_device_alloc(driver_name, -1);
1972 if (retval < 0) 1947 if (!the_hcd_pdev)
1973 return retval; 1948 return retval;
1949 the_udc_pdev = platform_device_alloc(gadget_name, -1);
1950 if (!the_udc_pdev)
1951 goto err_alloc_udc;
1974 1952
1975 retval = platform_driver_register (&dummy_udc_driver); 1953 retval = platform_driver_register(&dummy_hcd_driver);
1954 if (retval < 0)
1955 goto err_register_hcd_driver;
1956 retval = platform_driver_register(&dummy_udc_driver);
1976 if (retval < 0) 1957 if (retval < 0)
1977 goto err_register_udc_driver; 1958 goto err_register_udc_driver;
1978 1959
1979 retval = platform_device_register (&the_hcd_pdev); 1960 retval = platform_device_add(the_hcd_pdev);
1980 if (retval < 0) 1961 if (retval < 0)
1981 goto err_register_hcd; 1962 goto err_add_hcd;
1982 1963 retval = platform_device_add(the_udc_pdev);
1983 retval = platform_device_register (&the_udc_pdev);
1984 if (retval < 0) 1964 if (retval < 0)
1985 goto err_register_udc; 1965 goto err_add_udc;
1986 return retval; 1966 return retval;
1987 1967
1988err_register_udc: 1968err_add_udc:
1989 platform_device_unregister (&the_hcd_pdev); 1969 platform_device_del(the_hcd_pdev);
1990err_register_hcd: 1970err_add_hcd:
1991 platform_driver_unregister (&dummy_udc_driver); 1971 platform_driver_unregister(&dummy_udc_driver);
1992err_register_udc_driver: 1972err_register_udc_driver:
1993 platform_driver_unregister (&dummy_hcd_driver); 1973 platform_driver_unregister(&dummy_hcd_driver);
1974err_register_hcd_driver:
1975 platform_device_put(the_udc_pdev);
1976err_alloc_udc:
1977 platform_device_put(the_hcd_pdev);
1994 return retval; 1978 return retval;
1995} 1979}
1996module_init (init); 1980module_init (init);
1997 1981
1998static void __exit cleanup (void) 1982static void __exit cleanup (void)
1999{ 1983{
2000 platform_device_unregister (&the_udc_pdev); 1984 platform_device_unregister(the_udc_pdev);
2001 platform_device_unregister (&the_hcd_pdev); 1985 platform_device_unregister(the_hcd_pdev);
2002 platform_driver_unregister (&dummy_udc_driver); 1986 platform_driver_unregister(&dummy_udc_driver);
2003 platform_driver_unregister (&dummy_hcd_driver); 1987 platform_driver_unregister(&dummy_hcd_driver);
2004} 1988}
2005module_exit (cleanup); 1989module_exit (cleanup);
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index f9d07108bc30..8bdad221fa91 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -34,12 +34,12 @@
34 34
35 35
36/* we must assign addresses for configurable endpoints (like net2280) */ 36/* we must assign addresses for configurable endpoints (like net2280) */
37static __devinitdata unsigned epnum; 37static __initdata unsigned epnum;
38 38
39// #define MANY_ENDPOINTS 39// #define MANY_ENDPOINTS
40#ifdef MANY_ENDPOINTS 40#ifdef MANY_ENDPOINTS
41/* more than 15 configurable endpoints */ 41/* more than 15 configurable endpoints */
42static __devinitdata unsigned in_epnum; 42static __initdata unsigned in_epnum;
43#endif 43#endif
44 44
45 45
@@ -59,7 +59,7 @@ static __devinitdata unsigned in_epnum;
59 * NOTE: each endpoint is unidirectional, as specified by its USB 59 * NOTE: each endpoint is unidirectional, as specified by its USB
60 * descriptor; and isn't specific to a configuration or altsetting. 60 * descriptor; and isn't specific to a configuration or altsetting.
61 */ 61 */
62static int __devinit 62static int __init
63ep_matches ( 63ep_matches (
64 struct usb_gadget *gadget, 64 struct usb_gadget *gadget,
65 struct usb_ep *ep, 65 struct usb_ep *ep,
@@ -186,7 +186,7 @@ ep_matches (
186 return 1; 186 return 1;
187} 187}
188 188
189static struct usb_ep * __devinit 189static struct usb_ep * __init
190find_ep (struct usb_gadget *gadget, const char *name) 190find_ep (struct usb_gadget *gadget, const char *name)
191{ 191{
192 struct usb_ep *ep; 192 struct usb_ep *ep;
@@ -228,7 +228,7 @@ find_ep (struct usb_gadget *gadget, const char *name)
228 * 228 *
229 * On failure, this returns a null endpoint descriptor. 229 * On failure, this returns a null endpoint descriptor.
230 */ 230 */
231struct usb_ep * __devinit usb_ep_autoconfig ( 231struct usb_ep * __init usb_ep_autoconfig (
232 struct usb_gadget *gadget, 232 struct usb_gadget *gadget,
233 struct usb_endpoint_descriptor *desc 233 struct usb_endpoint_descriptor *desc
234) 234)
@@ -295,7 +295,7 @@ struct usb_ep * __devinit usb_ep_autoconfig (
295 * state such as ep->driver_data and the record of assigned endpoints 295 * state such as ep->driver_data and the record of assigned endpoints
296 * used by usb_ep_autoconfig(). 296 * used by usb_ep_autoconfig().
297 */ 297 */
298void __devinit usb_ep_autoconfig_reset (struct usb_gadget *gadget) 298void __init usb_ep_autoconfig_reset (struct usb_gadget *gadget)
299{ 299{
300 struct usb_ep *ep; 300 struct usb_ep *ep;
301 301
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index e99872308144..bb93bdd76593 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1102,7 +1102,7 @@ static void eth_reset_config (struct eth_dev *dev)
1102 if (dev->config == 0) 1102 if (dev->config == 0)
1103 return; 1103 return;
1104 1104
1105 DEBUG (dev, "%s\n", __FUNCTION__); 1105 DEBUG (dev, "%s\n", __func__);
1106 1106
1107 netif_stop_queue (dev->net); 1107 netif_stop_queue (dev->net);
1108 netif_carrier_off (dev->net); 1108 netif_carrier_off (dev->net);
@@ -1263,7 +1263,7 @@ static void issue_start_status (struct eth_dev *dev)
1263 struct usb_cdc_notification *event; 1263 struct usb_cdc_notification *event;
1264 int value; 1264 int value;
1265 1265
1266 DEBUG (dev, "%s, flush old status first\n", __FUNCTION__); 1266 DEBUG (dev, "%s, flush old status first\n", __func__);
1267 1267
1268 /* flush old status 1268 /* flush old status
1269 * 1269 *
@@ -1329,7 +1329,7 @@ static void rndis_command_complete (struct usb_ep *ep, struct usb_request *req)
1329 spin_lock(&dev->lock); 1329 spin_lock(&dev->lock);
1330 status = rndis_msg_parser (dev->rndis_config, (u8 *) req->buf); 1330 status = rndis_msg_parser (dev->rndis_config, (u8 *) req->buf);
1331 if (status < 0) 1331 if (status < 0)
1332 ERROR(dev, "%s: rndis parse error %d\n", __FUNCTION__, status); 1332 ERROR(dev, "%s: rndis parse error %d\n", __func__, status);
1333 spin_unlock(&dev->lock); 1333 spin_unlock(&dev->lock);
1334} 1334}
1335 1335
@@ -2113,7 +2113,7 @@ static int rndis_control_ack (struct net_device *net)
2113 2113
2114static void eth_start (struct eth_dev *dev, gfp_t gfp_flags) 2114static void eth_start (struct eth_dev *dev, gfp_t gfp_flags)
2115{ 2115{
2116 DEBUG (dev, "%s\n", __FUNCTION__); 2116 DEBUG (dev, "%s\n", __func__);
2117 2117
2118 /* fill the rx queue */ 2118 /* fill the rx queue */
2119 rx_fill (dev, gfp_flags); 2119 rx_fill (dev, gfp_flags);
@@ -2133,7 +2133,7 @@ static int eth_open (struct net_device *net)
2133{ 2133{
2134 struct eth_dev *dev = netdev_priv(net); 2134 struct eth_dev *dev = netdev_priv(net);
2135 2135
2136 DEBUG (dev, "%s\n", __FUNCTION__); 2136 DEBUG (dev, "%s\n", __func__);
2137 if (netif_carrier_ok (dev->net)) 2137 if (netif_carrier_ok (dev->net))
2138 eth_start (dev, GFP_KERNEL); 2138 eth_start (dev, GFP_KERNEL);
2139 return 0; 2139 return 0;
@@ -2143,7 +2143,7 @@ static int eth_stop (struct net_device *net)
2143{ 2143{
2144 struct eth_dev *dev = netdev_priv(net); 2144 struct eth_dev *dev = netdev_priv(net);
2145 2145
2146 VDEBUG (dev, "%s\n", __FUNCTION__); 2146 VDEBUG (dev, "%s\n", __func__);
2147 netif_stop_queue (net); 2147 netif_stop_queue (net);
2148 2148
2149 DEBUG (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n", 2149 DEBUG (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n",
@@ -2229,7 +2229,7 @@ eth_unbind (struct usb_gadget *gadget)
2229 set_gadget_data (gadget, NULL); 2229 set_gadget_data (gadget, NULL);
2230} 2230}
2231 2231
2232static u8 __devinit nibble (unsigned char c) 2232static u8 __init nibble (unsigned char c)
2233{ 2233{
2234 if (likely (isdigit (c))) 2234 if (likely (isdigit (c)))
2235 return c - '0'; 2235 return c - '0';
@@ -2239,7 +2239,7 @@ static u8 __devinit nibble (unsigned char c)
2239 return 0; 2239 return 0;
2240} 2240}
2241 2241
2242static int __devinit get_ether_addr(const char *str, u8 *dev_addr) 2242static int __init get_ether_addr(const char *str, u8 *dev_addr)
2243{ 2243{
2244 if (str) { 2244 if (str) {
2245 unsigned i; 2245 unsigned i;
@@ -2260,7 +2260,7 @@ static int __devinit get_ether_addr(const char *str, u8 *dev_addr)
2260 return 1; 2260 return 1;
2261} 2261}
2262 2262
2263static int __devinit 2263static int __init
2264eth_bind (struct usb_gadget *gadget) 2264eth_bind (struct usb_gadget *gadget)
2265{ 2265{
2266 struct eth_dev *dev; 2266 struct eth_dev *dev;
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 017a196d041f..bf3f946fd455 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -644,7 +644,7 @@ struct fsg_dev {
644 644
645 unsigned long atomic_bitflags; 645 unsigned long atomic_bitflags;
646#define REGISTERED 0 646#define REGISTERED 0
647#define CLEAR_BULK_HALTS 1 647#define IGNORE_BULK_OUT 1
648#define SUSPENDED 2 648#define SUSPENDED 2
649 649
650 struct usb_ep *bulk_in; 650 struct usb_ep *bulk_in;
@@ -1104,7 +1104,7 @@ static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
1104 if (req->actual > 0) 1104 if (req->actual > 0)
1105 dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual); 1105 dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
1106 if (req->status || req->actual != req->length) 1106 if (req->status || req->actual != req->length)
1107 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1107 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1108 req->status, req->actual, req->length); 1108 req->status, req->actual, req->length);
1109 if (req->status == -ECONNRESET) // Request was cancelled 1109 if (req->status == -ECONNRESET) // Request was cancelled
1110 usb_ep_fifo_flush(ep); 1110 usb_ep_fifo_flush(ep);
@@ -1125,7 +1125,7 @@ static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
1125 struct fsg_buffhd *bh = req->context; 1125 struct fsg_buffhd *bh = req->context;
1126 1126
1127 if (req->status || req->actual != req->length) 1127 if (req->status || req->actual != req->length)
1128 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1128 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1129 req->status, req->actual, req->length); 1129 req->status, req->actual, req->length);
1130 if (req->status == -ECONNRESET) // Request was cancelled 1130 if (req->status == -ECONNRESET) // Request was cancelled
1131 usb_ep_fifo_flush(ep); 1131 usb_ep_fifo_flush(ep);
@@ -1146,7 +1146,7 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
1146 1146
1147 dump_msg(fsg, "bulk-out", req->buf, req->actual); 1147 dump_msg(fsg, "bulk-out", req->buf, req->actual);
1148 if (req->status || req->actual != bh->bulk_out_intended_length) 1148 if (req->status || req->actual != bh->bulk_out_intended_length)
1149 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1149 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1150 req->status, req->actual, 1150 req->status, req->actual,
1151 bh->bulk_out_intended_length); 1151 bh->bulk_out_intended_length);
1152 if (req->status == -ECONNRESET) // Request was cancelled 1152 if (req->status == -ECONNRESET) // Request was cancelled
@@ -1169,7 +1169,7 @@ static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
1169 struct fsg_buffhd *bh = req->context; 1169 struct fsg_buffhd *bh = req->context;
1170 1170
1171 if (req->status || req->actual != req->length) 1171 if (req->status || req->actual != req->length)
1172 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1172 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1173 req->status, req->actual, req->length); 1173 req->status, req->actual, req->length);
1174 if (req->status == -ECONNRESET) // Request was cancelled 1174 if (req->status == -ECONNRESET) // Request was cancelled
1175 usb_ep_fifo_flush(ep); 1175 usb_ep_fifo_flush(ep);
@@ -2936,8 +2936,8 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2936 struct usb_request *req = bh->outreq; 2936 struct usb_request *req = bh->outreq;
2937 struct bulk_cb_wrap *cbw = req->buf; 2937 struct bulk_cb_wrap *cbw = req->buf;
2938 2938
2939 /* Was this a real packet? */ 2939 /* Was this a real packet? Should it be ignored? */
2940 if (req->status) 2940 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
2941 return -EINVAL; 2941 return -EINVAL;
2942 2942
2943 /* Is the CBW valid? */ 2943 /* Is the CBW valid? */
@@ -2948,13 +2948,17 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2948 req->actual, 2948 req->actual,
2949 le32_to_cpu(cbw->Signature)); 2949 le32_to_cpu(cbw->Signature));
2950 2950
2951 /* The Bulk-only spec says we MUST stall the bulk pipes! 2951 /* The Bulk-only spec says we MUST stall the IN endpoint
2952 * If we want to avoid stalls, set a flag so that we will 2952 * (6.6.1), so it's unavoidable. It also says we must
2953 * clear the endpoint halts at the next reset. */ 2953 * retain this state until the next reset, but there's
2954 if (!mod_data.can_stall) 2954 * no way to tell the controller driver it should ignore
2955 set_bit(CLEAR_BULK_HALTS, &fsg->atomic_bitflags); 2955 * Clear-Feature(HALT) requests.
2956 fsg_set_halt(fsg, fsg->bulk_out); 2956 *
2957 * We aren't required to halt the OUT endpoint; instead
2958 * we can simply accept and discard any data received
2959 * until the next reset. */
2957 halt_bulk_in_endpoint(fsg); 2960 halt_bulk_in_endpoint(fsg);
2961 set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2958 return -EINVAL; 2962 return -EINVAL;
2959 } 2963 }
2960 2964
@@ -3140,6 +3144,7 @@ reset:
3140 goto reset; 3144 goto reset;
3141 fsg->bulk_out_enabled = 1; 3145 fsg->bulk_out_enabled = 1;
3142 fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); 3146 fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
3147 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
3143 3148
3144 if (transport_is_cbi()) { 3149 if (transport_is_cbi()) {
3145 d = ep_desc(fsg->gadget, &fs_intr_in_desc, &hs_intr_in_desc); 3150 d = ep_desc(fsg->gadget, &fs_intr_in_desc, &hs_intr_in_desc);
@@ -3321,11 +3326,8 @@ static void handle_exception(struct fsg_dev *fsg)
3321 /* In case we were forced against our will to halt a 3326 /* In case we were forced against our will to halt a
3322 * bulk endpoint, clear the halt now. (The SuperH UDC 3327 * bulk endpoint, clear the halt now. (The SuperH UDC
3323 * requires this.) */ 3328 * requires this.) */
3324 if (test_and_clear_bit(CLEAR_BULK_HALTS, 3329 if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
3325 &fsg->atomic_bitflags)) {
3326 usb_ep_clear_halt(fsg->bulk_in); 3330 usb_ep_clear_halt(fsg->bulk_in);
3327 usb_ep_clear_halt(fsg->bulk_out);
3328 }
3329 3331
3330 if (transport_is_bbb()) { 3332 if (transport_is_bbb()) {
3331 if (fsg->ep0_req_tag == exception_req_tag) 3333 if (fsg->ep0_req_tag == exception_req_tag)
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index 254012ad2b91..651b82701394 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -773,11 +773,11 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
773 /* catch various bogus parameters */ 773 /* catch various bogus parameters */
774 if (!_req || !req->req.complete || !req->req.buf 774 if (!_req || !req->req.complete || !req->req.buf
775 || !list_empty(&req->queue)) { 775 || !list_empty(&req->queue)) {
776 VDBG("%s, bad params\n", __FUNCTION__); 776 VDBG("%s, bad params\n", __func__);
777 return -EINVAL; 777 return -EINVAL;
778 } 778 }
779 if (unlikely(!_ep || !ep->desc)) { 779 if (unlikely(!_ep || !ep->desc)) {
780 VDBG("%s, bad ep\n", __FUNCTION__); 780 VDBG("%s, bad ep\n", __func__);
781 return -EINVAL; 781 return -EINVAL;
782 } 782 }
783 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 783 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 9fb0b1ec8526..98b1483ef6a5 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -512,7 +512,7 @@ struct fsl_udc {
512 512
513#ifdef DEBUG 513#ifdef DEBUG
514#define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt "\n", \ 514#define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt "\n", \
515 __FUNCTION__, ## args) 515 __func__, ## args)
516#else 516#else
517#define DBG(fmt, args...) do{}while(0) 517#define DBG(fmt, args...) do{}while(0)
518#endif 518#endif
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 5b42ccd0035f..ff3a8513e64d 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -1149,7 +1149,7 @@ fail:
1149/* 1149/*
1150 * Creates an output endpoint, and initializes output ports. 1150 * Creates an output endpoint, and initializes output ports.
1151 */ 1151 */
1152static int __devinit gmidi_bind(struct usb_gadget *gadget) 1152static int __init gmidi_bind(struct usb_gadget *gadget)
1153{ 1153{
1154 struct gmidi_device *dev; 1154 struct gmidi_device *dev;
1155 struct usb_ep *in_ep, *out_ep; 1155 struct usb_ep *in_ep, *out_ep;
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index d3e702576de6..64a592cbbe7b 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -692,7 +692,7 @@ static void abort_dma(struct goku_ep *ep, int status)
692 req->req.actual = (curr - req->req.dma) + 1; 692 req->req.actual = (curr - req->req.dma) + 1;
693 req->req.status = status; 693 req->req.status = status;
694 694
695 VDBG(ep->dev, "%s %s %s %d/%d\n", __FUNCTION__, ep->ep.name, 695 VDBG(ep->dev, "%s %s %s %d/%d\n", __func__, ep->ep.name,
696 ep->is_in ? "IN" : "OUT", 696 ep->is_in ? "IN" : "OUT",
697 req->req.actual, req->req.length); 697 req->req.actual, req->req.length);
698 698
@@ -826,7 +826,7 @@ static int goku_dequeue(struct usb_ep *_ep, struct usb_request *_req)
826 if (dev->ep0state == EP0_SUSPEND) 826 if (dev->ep0state == EP0_SUSPEND)
827 return -EBUSY; 827 return -EBUSY;
828 828
829 VDBG(dev, "%s %s %s %s %p\n", __FUNCTION__, _ep->name, 829 VDBG(dev, "%s %s %s %s %p\n", __func__, _ep->name,
830 ep->is_in ? "IN" : "OUT", 830 ep->is_in ? "IN" : "OUT",
831 ep->dma ? "dma" : "pio", 831 ep->dma ? "dma" : "pio",
832 _req); 832 _req);
@@ -898,7 +898,7 @@ static int goku_set_halt(struct usb_ep *_ep, int value)
898 898
899 /* don't change EPxSTATUS_EP_INVALID to READY */ 899 /* don't change EPxSTATUS_EP_INVALID to READY */
900 } else if (!ep->desc) { 900 } else if (!ep->desc) {
901 DBG(ep->dev, "%s %s inactive?\n", __FUNCTION__, ep->ep.name); 901 DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name);
902 return -EINVAL; 902 return -EINVAL;
903 } 903 }
904 904
@@ -940,7 +940,7 @@ static int goku_fifo_status(struct usb_ep *_ep)
940 regs = ep->dev->regs; 940 regs = ep->dev->regs;
941 size = readl(&regs->EPxSizeLA[ep->num]) & DATASIZE; 941 size = readl(&regs->EPxSizeLA[ep->num]) & DATASIZE;
942 size += readl(&regs->EPxSizeLB[ep->num]) & DATASIZE; 942 size += readl(&regs->EPxSizeLB[ep->num]) & DATASIZE;
943 VDBG(ep->dev, "%s %s %u\n", __FUNCTION__, ep->ep.name, size); 943 VDBG(ep->dev, "%s %s %u\n", __func__, ep->ep.name, size);
944 return size; 944 return size;
945} 945}
946 946
@@ -953,11 +953,11 @@ static void goku_fifo_flush(struct usb_ep *_ep)
953 if (!_ep) 953 if (!_ep)
954 return; 954 return;
955 ep = container_of(_ep, struct goku_ep, ep); 955 ep = container_of(_ep, struct goku_ep, ep);
956 VDBG(ep->dev, "%s %s\n", __FUNCTION__, ep->ep.name); 956 VDBG(ep->dev, "%s %s\n", __func__, ep->ep.name);
957 957
958 /* don't change EPxSTATUS_EP_INVALID to READY */ 958 /* don't change EPxSTATUS_EP_INVALID to READY */
959 if (!ep->desc && ep->num != 0) { 959 if (!ep->desc && ep->num != 0) {
960 DBG(ep->dev, "%s %s inactive?\n", __FUNCTION__, ep->ep.name); 960 DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name);
961 return; 961 return;
962 } 962 }
963 963
@@ -1286,7 +1286,7 @@ static void ep0_start(struct goku_udc *dev)
1286 struct goku_udc_regs __iomem *regs = dev->regs; 1286 struct goku_udc_regs __iomem *regs = dev->regs;
1287 unsigned i; 1287 unsigned i;
1288 1288
1289 VDBG(dev, "%s\n", __FUNCTION__); 1289 VDBG(dev, "%s\n", __func__);
1290 1290
1291 udc_reset(dev); 1291 udc_reset(dev);
1292 udc_reinit (dev); 1292 udc_reinit (dev);
@@ -1322,7 +1322,7 @@ static void udc_enable(struct goku_udc *dev)
1322 if (readl(&dev->regs->power_detect) & PW_DETECT) 1322 if (readl(&dev->regs->power_detect) & PW_DETECT)
1323 ep0_start(dev); 1323 ep0_start(dev);
1324 else { 1324 else {
1325 DBG(dev, "%s\n", __FUNCTION__); 1325 DBG(dev, "%s\n", __func__);
1326 dev->int_enable = INT_PWRDETECT; 1326 dev->int_enable = INT_PWRDETECT;
1327 writel(dev->int_enable, &dev->regs->int_enable); 1327 writel(dev->int_enable, &dev->regs->int_enable);
1328 } 1328 }
@@ -1387,7 +1387,7 @@ stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
1387{ 1387{
1388 unsigned i; 1388 unsigned i;
1389 1389
1390 DBG (dev, "%s\n", __FUNCTION__); 1390 DBG (dev, "%s\n", __func__);
1391 1391
1392 if (dev->gadget.speed == USB_SPEED_UNKNOWN) 1392 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1393 driver = NULL; 1393 driver = NULL;
@@ -1726,7 +1726,7 @@ static void goku_remove(struct pci_dev *pdev)
1726{ 1726{
1727 struct goku_udc *dev = pci_get_drvdata(pdev); 1727 struct goku_udc *dev = pci_get_drvdata(pdev);
1728 1728
1729 DBG(dev, "%s\n", __FUNCTION__); 1729 DBG(dev, "%s\n", __func__);
1730 1730
1731 BUG_ON(dev->driver); 1731 BUG_ON(dev->driver);
1732 1732
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 0a6feafc8d28..69b0a2754f2a 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1107,13 +1107,13 @@ scan:
1107 1107
1108 switch (state) { 1108 switch (state) {
1109 default: 1109 default:
1110 DBG (dev, "fail %s, state %d\n", __FUNCTION__, state); 1110 DBG (dev, "fail %s, state %d\n", __func__, state);
1111 retval = -ESRCH; 1111 retval = -ESRCH;
1112 break; 1112 break;
1113 case STATE_DEV_UNCONNECTED: 1113 case STATE_DEV_UNCONNECTED:
1114 case STATE_DEV_CONNECTED: 1114 case STATE_DEV_CONNECTED:
1115 spin_unlock_irq (&dev->lock); 1115 spin_unlock_irq (&dev->lock);
1116 DBG (dev, "%s wait\n", __FUNCTION__); 1116 DBG (dev, "%s wait\n", __func__);
1117 1117
1118 /* wait for events */ 1118 /* wait for events */
1119 retval = wait_event_interruptible (dev->wait, 1119 retval = wait_event_interruptible (dev->wait,
@@ -1222,7 +1222,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1222 DBG(dev, "bogus ep0out stall!\n"); 1222 DBG(dev, "bogus ep0out stall!\n");
1223 } 1223 }
1224 } else 1224 } else
1225 DBG (dev, "fail %s, state %d\n", __FUNCTION__, dev->state); 1225 DBG (dev, "fail %s, state %d\n", __func__, dev->state);
1226 1226
1227 spin_unlock_irq (&dev->lock); 1227 spin_unlock_irq (&dev->lock);
1228 return retval; 1228 return retval;
@@ -1233,7 +1233,7 @@ ep0_fasync (int f, struct file *fd, int on)
1233{ 1233{
1234 struct dev_data *dev = fd->private_data; 1234 struct dev_data *dev = fd->private_data;
1235 // caller must F_SETOWN before signal delivery happens 1235 // caller must F_SETOWN before signal delivery happens
1236 VDEBUG (dev, "%s %s\n", __FUNCTION__, on ? "on" : "off"); 1236 VDEBUG (dev, "%s %s\n", __func__, on ? "on" : "off");
1237 return fasync_helper (f, fd, on, &dev->fasync); 1237 return fasync_helper (f, fd, on, &dev->fasync);
1238} 1238}
1239 1239
@@ -1575,7 +1575,7 @@ static void destroy_ep_files (struct dev_data *dev)
1575{ 1575{
1576 struct list_head *entry, *tmp; 1576 struct list_head *entry, *tmp;
1577 1577
1578 DBG (dev, "%s %d\n", __FUNCTION__, dev->state); 1578 DBG (dev, "%s %d\n", __func__, dev->state);
1579 1579
1580 /* dev->state must prevent interference */ 1580 /* dev->state must prevent interference */
1581restart: 1581restart:
@@ -1662,7 +1662,7 @@ enomem1:
1662 put_dev (dev); 1662 put_dev (dev);
1663 kfree (data); 1663 kfree (data);
1664enomem0: 1664enomem0:
1665 DBG (dev, "%s enomem\n", __FUNCTION__); 1665 DBG (dev, "%s enomem\n", __func__);
1666 destroy_ep_files (dev); 1666 destroy_ep_files (dev);
1667 return -ENOMEM; 1667 return -ENOMEM;
1668} 1668}
@@ -1672,7 +1672,7 @@ gadgetfs_unbind (struct usb_gadget *gadget)
1672{ 1672{
1673 struct dev_data *dev = get_gadget_data (gadget); 1673 struct dev_data *dev = get_gadget_data (gadget);
1674 1674
1675 DBG (dev, "%s\n", __FUNCTION__); 1675 DBG (dev, "%s\n", __func__);
1676 1676
1677 spin_lock_irq (&dev->lock); 1677 spin_lock_irq (&dev->lock);
1678 dev->state = STATE_DEV_UNBOUND; 1678 dev->state = STATE_DEV_UNBOUND;
@@ -1685,7 +1685,7 @@ gadgetfs_unbind (struct usb_gadget *gadget)
1685 /* we've already been disconnected ... no i/o is active */ 1685 /* we've already been disconnected ... no i/o is active */
1686 if (dev->req) 1686 if (dev->req)
1687 usb_ep_free_request (gadget->ep0, dev->req); 1687 usb_ep_free_request (gadget->ep0, dev->req);
1688 DBG (dev, "%s done\n", __FUNCTION__); 1688 DBG (dev, "%s done\n", __func__);
1689 put_dev (dev); 1689 put_dev (dev);
1690} 1690}
1691 1691
@@ -1933,7 +1933,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1933 1933
1934fail: 1934fail:
1935 spin_unlock_irq (&dev->lock); 1935 spin_unlock_irq (&dev->lock);
1936 pr_debug ("%s: %s fail %Zd, %p\n", shortname, __FUNCTION__, value, dev); 1936 pr_debug ("%s: %s fail %Zd, %p\n", shortname, __func__, value, dev);
1937 kfree (dev->buf); 1937 kfree (dev->buf);
1938 dev->buf = NULL; 1938 dev->buf = NULL;
1939 return value; 1939 return value;
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 078f72467671..825abd2621b3 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -253,7 +253,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
253 */ 253 */
254static void udc_disable(struct lh7a40x_udc *dev) 254static void udc_disable(struct lh7a40x_udc *dev)
255{ 255{
256 DEBUG("%s, %p\n", __FUNCTION__, dev); 256 DEBUG("%s, %p\n", __func__, dev);
257 257
258 udc_set_address(dev, 0); 258 udc_set_address(dev, 0);
259 259
@@ -285,7 +285,7 @@ static void udc_reinit(struct lh7a40x_udc *dev)
285{ 285{
286 u32 i; 286 u32 i;
287 287
288 DEBUG("%s, %p\n", __FUNCTION__, dev); 288 DEBUG("%s, %p\n", __func__, dev);
289 289
290 /* device/ep0 records init */ 290 /* device/ep0 records init */
291 INIT_LIST_HEAD(&dev->gadget.ep_list); 291 INIT_LIST_HEAD(&dev->gadget.ep_list);
@@ -318,7 +318,7 @@ static void udc_enable(struct lh7a40x_udc *dev)
318{ 318{
319 int ep; 319 int ep;
320 320
321 DEBUG("%s, %p\n", __FUNCTION__, dev); 321 DEBUG("%s, %p\n", __func__, dev);
322 322
323 dev->gadget.speed = USB_SPEED_UNKNOWN; 323 dev->gadget.speed = USB_SPEED_UNKNOWN;
324 324
@@ -412,7 +412,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
412 struct lh7a40x_udc *dev = the_controller; 412 struct lh7a40x_udc *dev = the_controller;
413 int retval; 413 int retval;
414 414
415 DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name); 415 DEBUG("%s: %s\n", __func__, driver->driver.name);
416 416
417 if (!driver 417 if (!driver
418 || driver->speed != USB_SPEED_FULL 418 || driver->speed != USB_SPEED_FULL
@@ -521,7 +521,7 @@ static int write_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
521 is_short = unlikely(max < ep_maxpacket(ep)); 521 is_short = unlikely(max < ep_maxpacket(ep));
522 } 522 }
523 523
524 DEBUG("%s: wrote %s %d bytes%s%s %d left %p\n", __FUNCTION__, 524 DEBUG("%s: wrote %s %d bytes%s%s %d left %p\n", __func__,
525 ep->ep.name, count, 525 ep->ep.name, count,
526 is_last ? "/L" : "", is_short ? "/S" : "", 526 is_last ? "/L" : "", is_short ? "/S" : "",
527 req->req.length - req->req.actual, req); 527 req->req.length - req->req.actual, req);
@@ -555,7 +555,7 @@ static int read_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
555 /* make sure there's a packet in the FIFO. */ 555 /* make sure there's a packet in the FIFO. */
556 csr = usb_read(ep->csr1); 556 csr = usb_read(ep->csr1);
557 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) { 557 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) {
558 DEBUG("%s: Packet NOT ready!\n", __FUNCTION__); 558 DEBUG("%s: Packet NOT ready!\n", __func__);
559 return -EINVAL; 559 return -EINVAL;
560 } 560 }
561 561
@@ -614,7 +614,7 @@ static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req, int status)
614 unsigned int stopped = ep->stopped; 614 unsigned int stopped = ep->stopped;
615 u32 index; 615 u32 index;
616 616
617 DEBUG("%s, %p\n", __FUNCTION__, ep); 617 DEBUG("%s, %p\n", __func__, ep);
618 list_del_init(&req->queue); 618 list_del_init(&req->queue);
619 619
620 if (likely(req->req.status == -EINPROGRESS)) 620 if (likely(req->req.status == -EINPROGRESS))
@@ -644,7 +644,7 @@ static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req, int status)
644/** Enable EP interrupt */ 644/** Enable EP interrupt */
645static void pio_irq_enable(int ep) 645static void pio_irq_enable(int ep)
646{ 646{
647 DEBUG("%s: %d\n", __FUNCTION__, ep); 647 DEBUG("%s: %d\n", __func__, ep);
648 648
649 switch (ep) { 649 switch (ep) {
650 case 1: 650 case 1:
@@ -665,7 +665,7 @@ static void pio_irq_enable(int ep)
665/** Disable EP interrupt */ 665/** Disable EP interrupt */
666static void pio_irq_disable(int ep) 666static void pio_irq_disable(int ep)
667{ 667{
668 DEBUG("%s: %d\n", __FUNCTION__, ep); 668 DEBUG("%s: %d\n", __func__, ep);
669 669
670 switch (ep) { 670 switch (ep) {
671 case 1: 671 case 1:
@@ -690,7 +690,7 @@ void nuke(struct lh7a40x_ep *ep, int status)
690{ 690{
691 struct lh7a40x_request *req; 691 struct lh7a40x_request *req;
692 692
693 DEBUG("%s, %p\n", __FUNCTION__, ep); 693 DEBUG("%s, %p\n", __func__, ep);
694 694
695 /* Flush FIFO */ 695 /* Flush FIFO */
696 flush(ep); 696 flush(ep);
@@ -734,7 +734,7 @@ static void flush_all(struct lh7a40x_udc *dev)
734 */ 734 */
735static void flush(struct lh7a40x_ep *ep) 735static void flush(struct lh7a40x_ep *ep)
736{ 736{
737 DEBUG("%s, %p\n", __FUNCTION__, ep); 737 DEBUG("%s, %p\n", __func__, ep);
738 738
739 switch (ep->ep_type) { 739 switch (ep->ep_type) {
740 case ep_control: 740 case ep_control:
@@ -766,7 +766,7 @@ static void lh7a40x_in_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
766 usb_set_index(ep_idx); 766 usb_set_index(ep_idx);
767 767
768 csr = usb_read(ep->csr1); 768 csr = usb_read(ep->csr1);
769 DEBUG("%s: %d, csr %x\n", __FUNCTION__, ep_idx, csr); 769 DEBUG("%s: %d, csr %x\n", __func__, ep_idx, csr);
770 770
771 if (csr & USB_IN_CSR1_SENT_STALL) { 771 if (csr & USB_IN_CSR1_SENT_STALL) {
772 DEBUG("USB_IN_CSR1_SENT_STALL\n"); 772 DEBUG("USB_IN_CSR1_SENT_STALL\n");
@@ -776,7 +776,7 @@ static void lh7a40x_in_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
776 } 776 }
777 777
778 if (!ep->desc) { 778 if (!ep->desc) {
779 DEBUG("%s: NO EP DESC\n", __FUNCTION__); 779 DEBUG("%s: NO EP DESC\n", __func__);
780 return; 780 return;
781 } 781 }
782 782
@@ -802,7 +802,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
802 struct lh7a40x_ep *ep = &dev->ep[ep_idx]; 802 struct lh7a40x_ep *ep = &dev->ep[ep_idx];
803 struct lh7a40x_request *req; 803 struct lh7a40x_request *req;
804 804
805 DEBUG("%s: %d\n", __FUNCTION__, ep_idx); 805 DEBUG("%s: %d\n", __func__, ep_idx);
806 806
807 usb_set_index(ep_idx); 807 usb_set_index(ep_idx);
808 808
@@ -814,11 +814,11 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
814 usb_read(ep-> 814 usb_read(ep->
815 csr1)) & (USB_OUT_CSR1_OUT_PKT_RDY | 815 csr1)) & (USB_OUT_CSR1_OUT_PKT_RDY |
816 USB_OUT_CSR1_SENT_STALL)) { 816 USB_OUT_CSR1_SENT_STALL)) {
817 DEBUG("%s: %x\n", __FUNCTION__, csr); 817 DEBUG("%s: %x\n", __func__, csr);
818 818
819 if (csr & USB_OUT_CSR1_SENT_STALL) { 819 if (csr & USB_OUT_CSR1_SENT_STALL) {
820 DEBUG("%s: stall sent, flush fifo\n", 820 DEBUG("%s: stall sent, flush fifo\n",
821 __FUNCTION__); 821 __func__);
822 /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1); */ 822 /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1); */
823 flush(ep); 823 flush(ep);
824 } else if (csr & USB_OUT_CSR1_OUT_PKT_RDY) { 824 } else if (csr & USB_OUT_CSR1_OUT_PKT_RDY) {
@@ -832,7 +832,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
832 832
833 if (!req) { 833 if (!req) {
834 printk("%s: NULL REQ %d\n", 834 printk("%s: NULL REQ %d\n",
835 __FUNCTION__, ep_idx); 835 __func__, ep_idx);
836 flush(ep); 836 flush(ep);
837 break; 837 break;
838 } else { 838 } else {
@@ -844,7 +844,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
844 844
845 } else { 845 } else {
846 /* Throw packet away.. */ 846 /* Throw packet away.. */
847 printk("%s: No descriptor?!?\n", __FUNCTION__); 847 printk("%s: No descriptor?!?\n", __func__);
848 flush(ep); 848 flush(ep);
849 } 849 }
850} 850}
@@ -886,7 +886,7 @@ static void lh7a40x_reset_intr(struct lh7a40x_udc *dev)
886#if 0 /* def CONFIG_ARCH_LH7A404 */ 886#if 0 /* def CONFIG_ARCH_LH7A404 */
887 /* Does not work always... */ 887 /* Does not work always... */
888 888
889 DEBUG("%s: %d\n", __FUNCTION__, dev->usb_address); 889 DEBUG("%s: %d\n", __func__, dev->usb_address);
890 890
891 if (!dev->usb_address) { 891 if (!dev->usb_address) {
892 /*usb_set(USB_RESET_IO, USB_RESET); 892 /*usb_set(USB_RESET_IO, USB_RESET);
@@ -936,7 +936,7 @@ static irqreturn_t lh7a40x_udc_irq(int irq, void *_dev)
936 if (!intr_out && !intr_in && !intr_int) 936 if (!intr_out && !intr_in && !intr_int)
937 break; 937 break;
938 938
939 DEBUG("%s (on state %s)\n", __FUNCTION__, 939 DEBUG("%s (on state %s)\n", __func__,
940 state_names[dev->ep0state]); 940 state_names[dev->ep0state]);
941 DEBUG("intr_out = %x\n", intr_out); 941 DEBUG("intr_out = %x\n", intr_out);
942 DEBUG("intr_in = %x\n", intr_in); 942 DEBUG("intr_in = %x\n", intr_in);
@@ -1016,14 +1016,14 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1016 struct lh7a40x_udc *dev; 1016 struct lh7a40x_udc *dev;
1017 unsigned long flags; 1017 unsigned long flags;
1018 1018
1019 DEBUG("%s, %p\n", __FUNCTION__, _ep); 1019 DEBUG("%s, %p\n", __func__, _ep);
1020 1020
1021 ep = container_of(_ep, struct lh7a40x_ep, ep); 1021 ep = container_of(_ep, struct lh7a40x_ep, ep);
1022 if (!_ep || !desc || ep->desc || _ep->name == ep0name 1022 if (!_ep || !desc || ep->desc || _ep->name == ep0name
1023 || desc->bDescriptorType != USB_DT_ENDPOINT 1023 || desc->bDescriptorType != USB_DT_ENDPOINT
1024 || ep->bEndpointAddress != desc->bEndpointAddress 1024 || ep->bEndpointAddress != desc->bEndpointAddress
1025 || ep_maxpacket(ep) < le16_to_cpu(desc->wMaxPacketSize)) { 1025 || ep_maxpacket(ep) < le16_to_cpu(desc->wMaxPacketSize)) {
1026 DEBUG("%s, bad ep or descriptor\n", __FUNCTION__); 1026 DEBUG("%s, bad ep or descriptor\n", __func__);
1027 return -EINVAL; 1027 return -EINVAL;
1028 } 1028 }
1029 1029
@@ -1031,7 +1031,7 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1031 if (ep->bmAttributes != desc->bmAttributes 1031 if (ep->bmAttributes != desc->bmAttributes
1032 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK 1032 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
1033 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { 1033 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
1034 DEBUG("%s, %s type mismatch\n", __FUNCTION__, _ep->name); 1034 DEBUG("%s, %s type mismatch\n", __func__, _ep->name);
1035 return -EINVAL; 1035 return -EINVAL;
1036 } 1036 }
1037 1037
@@ -1039,13 +1039,13 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1039 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 1039 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
1040 && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(ep)) 1040 && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(ep))
1041 || !desc->wMaxPacketSize) { 1041 || !desc->wMaxPacketSize) {
1042 DEBUG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 1042 DEBUG("%s, bad %s maxpacket\n", __func__, _ep->name);
1043 return -ERANGE; 1043 return -ERANGE;
1044 } 1044 }
1045 1045
1046 dev = ep->dev; 1046 dev = ep->dev;
1047 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { 1047 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
1048 DEBUG("%s, bogus device state\n", __FUNCTION__); 1048 DEBUG("%s, bogus device state\n", __func__);
1049 return -ESHUTDOWN; 1049 return -ESHUTDOWN;
1050 } 1050 }
1051 1051
@@ -1061,7 +1061,7 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1061 /* Reset halt state (does flush) */ 1061 /* Reset halt state (does flush) */
1062 lh7a40x_set_halt(_ep, 0); 1062 lh7a40x_set_halt(_ep, 0);
1063 1063
1064 DEBUG("%s: enabled %s\n", __FUNCTION__, _ep->name); 1064 DEBUG("%s: enabled %s\n", __func__, _ep->name);
1065 return 0; 1065 return 0;
1066} 1066}
1067 1067
@@ -1073,11 +1073,11 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
1073 struct lh7a40x_ep *ep; 1073 struct lh7a40x_ep *ep;
1074 unsigned long flags; 1074 unsigned long flags;
1075 1075
1076 DEBUG("%s, %p\n", __FUNCTION__, _ep); 1076 DEBUG("%s, %p\n", __func__, _ep);
1077 1077
1078 ep = container_of(_ep, struct lh7a40x_ep, ep); 1078 ep = container_of(_ep, struct lh7a40x_ep, ep);
1079 if (!_ep || !ep->desc) { 1079 if (!_ep || !ep->desc) {
1080 DEBUG("%s, %s not enabled\n", __FUNCTION__, 1080 DEBUG("%s, %s not enabled\n", __func__,
1081 _ep ? ep->ep.name : NULL); 1081 _ep ? ep->ep.name : NULL);
1082 return -EINVAL; 1082 return -EINVAL;
1083 } 1083 }
@@ -1097,7 +1097,7 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
1097 1097
1098 spin_unlock_irqrestore(&ep->dev->lock, flags); 1098 spin_unlock_irqrestore(&ep->dev->lock, flags);
1099 1099
1100 DEBUG("%s: disabled %s\n", __FUNCTION__, _ep->name); 1100 DEBUG("%s: disabled %s\n", __func__, _ep->name);
1101 return 0; 1101 return 0;
1102} 1102}
1103 1103
@@ -1106,7 +1106,7 @@ static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
1106{ 1106{
1107 struct lh7a40x_request *req; 1107 struct lh7a40x_request *req;
1108 1108
1109 DEBUG("%s, %p\n", __FUNCTION__, ep); 1109 DEBUG("%s, %p\n", __func__, ep);
1110 1110
1111 req = kzalloc(sizeof(*req), gfp_flags); 1111 req = kzalloc(sizeof(*req), gfp_flags);
1112 if (!req) 1112 if (!req)
@@ -1121,7 +1121,7 @@ static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
1121{ 1121{
1122 struct lh7a40x_request *req; 1122 struct lh7a40x_request *req;
1123 1123
1124 DEBUG("%s, %p\n", __FUNCTION__, ep); 1124 DEBUG("%s, %p\n", __func__, ep);
1125 1125
1126 req = container_of(_req, struct lh7a40x_request, req); 1126 req = container_of(_req, struct lh7a40x_request, req);
1127 WARN_ON(!list_empty(&req->queue)); 1127 WARN_ON(!list_empty(&req->queue));
@@ -1140,25 +1140,25 @@ static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req,
1140 struct lh7a40x_udc *dev; 1140 struct lh7a40x_udc *dev;
1141 unsigned long flags; 1141 unsigned long flags;
1142 1142
1143 DEBUG("\n\n\n%s, %p\n", __FUNCTION__, _ep); 1143 DEBUG("\n\n\n%s, %p\n", __func__, _ep);
1144 1144
1145 req = container_of(_req, struct lh7a40x_request, req); 1145 req = container_of(_req, struct lh7a40x_request, req);
1146 if (unlikely 1146 if (unlikely
1147 (!_req || !_req->complete || !_req->buf 1147 (!_req || !_req->complete || !_req->buf
1148 || !list_empty(&req->queue))) { 1148 || !list_empty(&req->queue))) {
1149 DEBUG("%s, bad params\n", __FUNCTION__); 1149 DEBUG("%s, bad params\n", __func__);
1150 return -EINVAL; 1150 return -EINVAL;
1151 } 1151 }
1152 1152
1153 ep = container_of(_ep, struct lh7a40x_ep, ep); 1153 ep = container_of(_ep, struct lh7a40x_ep, ep);
1154 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) { 1154 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1155 DEBUG("%s, bad ep\n", __FUNCTION__); 1155 DEBUG("%s, bad ep\n", __func__);
1156 return -EINVAL; 1156 return -EINVAL;
1157 } 1157 }
1158 1158
1159 dev = ep->dev; 1159 dev = ep->dev;
1160 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { 1160 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1161 DEBUG("%s, bogus device state %p\n", __FUNCTION__, dev->driver); 1161 DEBUG("%s, bogus device state %p\n", __func__, dev->driver);
1162 return -ESHUTDOWN; 1162 return -ESHUTDOWN;
1163 } 1163 }
1164 1164
@@ -1218,7 +1218,7 @@ static int lh7a40x_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1218 struct lh7a40x_request *req; 1218 struct lh7a40x_request *req;
1219 unsigned long flags; 1219 unsigned long flags;
1220 1220
1221 DEBUG("%s, %p\n", __FUNCTION__, _ep); 1221 DEBUG("%s, %p\n", __func__, _ep);
1222 1222
1223 ep = container_of(_ep, struct lh7a40x_ep, ep); 1223 ep = container_of(_ep, struct lh7a40x_ep, ep);
1224 if (!_ep || ep->ep.name == ep0name) 1224 if (!_ep || ep->ep.name == ep0name)
@@ -1253,13 +1253,13 @@ static int lh7a40x_set_halt(struct usb_ep *_ep, int value)
1253 1253
1254 ep = container_of(_ep, struct lh7a40x_ep, ep); 1254 ep = container_of(_ep, struct lh7a40x_ep, ep);
1255 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) { 1255 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1256 DEBUG("%s, bad ep\n", __FUNCTION__); 1256 DEBUG("%s, bad ep\n", __func__);
1257 return -EINVAL; 1257 return -EINVAL;
1258 } 1258 }
1259 1259
1260 usb_set_index(ep_index(ep)); 1260 usb_set_index(ep_index(ep));
1261 1261
1262 DEBUG("%s, ep %d, val %d\n", __FUNCTION__, ep_index(ep), value); 1262 DEBUG("%s, ep %d, val %d\n", __func__, ep_index(ep), value);
1263 1263
1264 spin_lock_irqsave(&ep->dev->lock, flags); 1264 spin_lock_irqsave(&ep->dev->lock, flags);
1265 1265
@@ -1325,11 +1325,11 @@ static int lh7a40x_fifo_status(struct usb_ep *_ep)
1325 1325
1326 ep = container_of(_ep, struct lh7a40x_ep, ep); 1326 ep = container_of(_ep, struct lh7a40x_ep, ep);
1327 if (!_ep) { 1327 if (!_ep) {
1328 DEBUG("%s, bad ep\n", __FUNCTION__); 1328 DEBUG("%s, bad ep\n", __func__);
1329 return -ENODEV; 1329 return -ENODEV;
1330 } 1330 }
1331 1331
1332 DEBUG("%s, %d\n", __FUNCTION__, ep_index(ep)); 1332 DEBUG("%s, %d\n", __func__, ep_index(ep));
1333 1333
1334 /* LPD can't report unclaimed bytes from IN fifos */ 1334 /* LPD can't report unclaimed bytes from IN fifos */
1335 if (ep_is_in(ep)) 1335 if (ep_is_in(ep))
@@ -1355,7 +1355,7 @@ static void lh7a40x_fifo_flush(struct usb_ep *_ep)
1355 1355
1356 ep = container_of(_ep, struct lh7a40x_ep, ep); 1356 ep = container_of(_ep, struct lh7a40x_ep, ep);
1357 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) { 1357 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1358 DEBUG("%s, bad ep\n", __FUNCTION__); 1358 DEBUG("%s, bad ep\n", __func__);
1359 return; 1359 return;
1360 } 1360 }
1361 1361
@@ -1376,7 +1376,7 @@ static int write_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1376 1376
1377 max = ep_maxpacket(ep); 1377 max = ep_maxpacket(ep);
1378 1378
1379 DEBUG_EP0("%s\n", __FUNCTION__); 1379 DEBUG_EP0("%s\n", __func__);
1380 1380
1381 count = write_packet(ep, req, max); 1381 count = write_packet(ep, req, max);
1382 1382
@@ -1390,7 +1390,7 @@ static int write_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1390 is_last = 1; 1390 is_last = 1;
1391 } 1391 }
1392 1392
1393 DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __FUNCTION__, 1393 DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __func__,
1394 ep->ep.name, count, 1394 ep->ep.name, count,
1395 is_last ? "/L" : "", req->req.length - req->req.actual, req); 1395 is_last ? "/L" : "", req->req.length - req->req.actual, req);
1396 1396
@@ -1434,7 +1434,7 @@ static int read_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1434 unsigned bufferspace, count, is_short; 1434 unsigned bufferspace, count, is_short;
1435 volatile u32 *fifo = (volatile u32 *)ep->fifo; 1435 volatile u32 *fifo = (volatile u32 *)ep->fifo;
1436 1436
1437 DEBUG_EP0("%s\n", __FUNCTION__); 1437 DEBUG_EP0("%s\n", __func__);
1438 1438
1439 csr = usb_read(USB_EP0_CSR); 1439 csr = usb_read(USB_EP0_CSR);
1440 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) 1440 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY))
@@ -1492,7 +1492,7 @@ static int read_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1492 */ 1492 */
1493static void udc_set_address(struct lh7a40x_udc *dev, unsigned char address) 1493static void udc_set_address(struct lh7a40x_udc *dev, unsigned char address)
1494{ 1494{
1495 DEBUG_EP0("%s: %d\n", __FUNCTION__, address); 1495 DEBUG_EP0("%s: %d\n", __func__, address);
1496 /* c.f. 15.1.2.2 Table 15-4 address will be used after DATA_END is set */ 1496 /* c.f. 15.1.2.2 Table 15-4 address will be used after DATA_END is set */
1497 dev->usb_address = address; 1497 dev->usb_address = address;
1498 usb_set((address & USB_FA_FUNCTION_ADDR), USB_FA); 1498 usb_set((address & USB_FA_FUNCTION_ADDR), USB_FA);
@@ -1514,7 +1514,7 @@ static void lh7a40x_ep0_out(struct lh7a40x_udc *dev, u32 csr)
1514 struct lh7a40x_ep *ep = &dev->ep[0]; 1514 struct lh7a40x_ep *ep = &dev->ep[0];
1515 int ret; 1515 int ret;
1516 1516
1517 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1517 DEBUG_EP0("%s: %x\n", __func__, csr);
1518 1518
1519 if (list_empty(&ep->queue)) 1519 if (list_empty(&ep->queue))
1520 req = 0; 1520 req = 0;
@@ -1533,13 +1533,13 @@ static void lh7a40x_ep0_out(struct lh7a40x_udc *dev, u32 csr)
1533 if (ret) { 1533 if (ret) {
1534 /* Done! */ 1534 /* Done! */
1535 DEBUG_EP0("%s: finished, waiting for status\n", 1535 DEBUG_EP0("%s: finished, waiting for status\n",
1536 __FUNCTION__); 1536 __func__);
1537 1537
1538 usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR); 1538 usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR);
1539 dev->ep0state = WAIT_FOR_SETUP; 1539 dev->ep0state = WAIT_FOR_SETUP;
1540 } else { 1540 } else {
1541 /* Not done yet.. */ 1541 /* Not done yet.. */
1542 DEBUG_EP0("%s: not finished\n", __FUNCTION__); 1542 DEBUG_EP0("%s: not finished\n", __func__);
1543 usb_set(EP0_CLR_OUT, USB_EP0_CSR); 1543 usb_set(EP0_CLR_OUT, USB_EP0_CSR);
1544 } 1544 }
1545 } else { 1545 } else {
@@ -1556,7 +1556,7 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
1556 struct lh7a40x_ep *ep = &dev->ep[0]; 1556 struct lh7a40x_ep *ep = &dev->ep[0];
1557 int ret, need_zlp = 0; 1557 int ret, need_zlp = 0;
1558 1558
1559 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1559 DEBUG_EP0("%s: %x\n", __func__, csr);
1560 1560
1561 if (list_empty(&ep->queue)) 1561 if (list_empty(&ep->queue))
1562 req = 0; 1562 req = 0;
@@ -1564,7 +1564,7 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
1564 req = list_entry(ep->queue.next, struct lh7a40x_request, queue); 1564 req = list_entry(ep->queue.next, struct lh7a40x_request, queue);
1565 1565
1566 if (!req) { 1566 if (!req) {
1567 DEBUG_EP0("%s: NULL REQ\n", __FUNCTION__); 1567 DEBUG_EP0("%s: NULL REQ\n", __func__);
1568 return 0; 1568 return 0;
1569 } 1569 }
1570 1570
@@ -1585,17 +1585,17 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
1585 1585
1586 if (ret == 1 && !need_zlp) { 1586 if (ret == 1 && !need_zlp) {
1587 /* Last packet */ 1587 /* Last packet */
1588 DEBUG_EP0("%s: finished, waiting for status\n", __FUNCTION__); 1588 DEBUG_EP0("%s: finished, waiting for status\n", __func__);
1589 1589
1590 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR); 1590 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
1591 dev->ep0state = WAIT_FOR_SETUP; 1591 dev->ep0state = WAIT_FOR_SETUP;
1592 } else { 1592 } else {
1593 DEBUG_EP0("%s: not finished\n", __FUNCTION__); 1593 DEBUG_EP0("%s: not finished\n", __func__);
1594 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR); 1594 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
1595 } 1595 }
1596 1596
1597 if (need_zlp) { 1597 if (need_zlp) {
1598 DEBUG_EP0("%s: Need ZLP!\n", __FUNCTION__); 1598 DEBUG_EP0("%s: Need ZLP!\n", __func__);
1599 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR); 1599 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
1600 dev->ep0state = DATA_STATE_NEED_ZLP; 1600 dev->ep0state = DATA_STATE_NEED_ZLP;
1601 } 1601 }
@@ -1694,7 +1694,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
1694 struct usb_ctrlrequest ctrl; 1694 struct usb_ctrlrequest ctrl;
1695 int i, bytes, is_in; 1695 int i, bytes, is_in;
1696 1696
1697 DEBUG_SETUP("%s: %x\n", __FUNCTION__, csr); 1697 DEBUG_SETUP("%s: %x\n", __func__, csr);
1698 1698
1699 /* Nuke all previous transfers */ 1699 /* Nuke all previous transfers */
1700 nuke(ep, -EPROTO); 1700 nuke(ep, -EPROTO);
@@ -1799,7 +1799,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
1799 */ 1799 */
1800static void lh7a40x_ep0_in_zlp(struct lh7a40x_udc *dev, u32 csr) 1800static void lh7a40x_ep0_in_zlp(struct lh7a40x_udc *dev, u32 csr)
1801{ 1801{
1802 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1802 DEBUG_EP0("%s: %x\n", __func__, csr);
1803 1803
1804 /* c.f. Table 15-14 */ 1804 /* c.f. Table 15-14 */
1805 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR); 1805 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
@@ -1818,7 +1818,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1818 usb_set_index(0); 1818 usb_set_index(0);
1819 csr = usb_read(USB_EP0_CSR); 1819 csr = usb_read(USB_EP0_CSR);
1820 1820
1821 DEBUG_EP0("%s: csr = %x\n", __FUNCTION__, csr); 1821 DEBUG_EP0("%s: csr = %x\n", __func__, csr);
1822 1822
1823 /* 1823 /*
1824 * For overview of what we should be doing see c.f. Chapter 18.1.2.4 1824 * For overview of what we should be doing see c.f. Chapter 18.1.2.4
@@ -1832,7 +1832,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1832 * - clear the SENT_STALL bit 1832 * - clear the SENT_STALL bit
1833 */ 1833 */
1834 if (csr & EP0_SENT_STALL) { 1834 if (csr & EP0_SENT_STALL) {
1835 DEBUG_EP0("%s: EP0_SENT_STALL is set: %x\n", __FUNCTION__, csr); 1835 DEBUG_EP0("%s: EP0_SENT_STALL is set: %x\n", __func__, csr);
1836 usb_clear((EP0_SENT_STALL | EP0_SEND_STALL), USB_EP0_CSR); 1836 usb_clear((EP0_SENT_STALL | EP0_SEND_STALL), USB_EP0_CSR);
1837 nuke(ep, -ECONNABORTED); 1837 nuke(ep, -ECONNABORTED);
1838 dev->ep0state = WAIT_FOR_SETUP; 1838 dev->ep0state = WAIT_FOR_SETUP;
@@ -1849,7 +1849,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1849 */ 1849 */
1850 if (!(csr & (EP0_IN_PKT_RDY | EP0_OUT_PKT_RDY))) { 1850 if (!(csr & (EP0_IN_PKT_RDY | EP0_OUT_PKT_RDY))) {
1851 DEBUG_EP0("%s: IN_PKT_RDY and OUT_PKT_RDY are clear\n", 1851 DEBUG_EP0("%s: IN_PKT_RDY and OUT_PKT_RDY are clear\n",
1852 __FUNCTION__); 1852 __func__);
1853 1853
1854 switch (dev->ep0state) { 1854 switch (dev->ep0state) {
1855 case DATA_STATE_XMIT: 1855 case DATA_STATE_XMIT:
@@ -1877,7 +1877,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1877 * - set SERVICED_SETUP_END_BIT 1877 * - set SERVICED_SETUP_END_BIT
1878 */ 1878 */
1879 if (csr & EP0_SETUP_END) { 1879 if (csr & EP0_SETUP_END) {
1880 DEBUG_EP0("%s: EP0_SETUP_END is set: %x\n", __FUNCTION__, csr); 1880 DEBUG_EP0("%s: EP0_SETUP_END is set: %x\n", __func__, csr);
1881 1881
1882 usb_set(EP0_CLR_SETUP_END, USB_EP0_CSR); 1882 usb_set(EP0_CLR_SETUP_END, USB_EP0_CSR);
1883 1883
@@ -1896,7 +1896,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1896 */ 1896 */
1897 if (csr & EP0_OUT_PKT_RDY) { 1897 if (csr & EP0_OUT_PKT_RDY) {
1898 1898
1899 DEBUG_EP0("%s: EP0_OUT_PKT_RDY is set: %x\n", __FUNCTION__, 1899 DEBUG_EP0("%s: EP0_OUT_PKT_RDY is set: %x\n", __func__,
1900 csr); 1900 csr);
1901 1901
1902 switch (dev->ep0state) { 1902 switch (dev->ep0state) {
@@ -1926,7 +1926,7 @@ static void lh7a40x_ep0_kick(struct lh7a40x_udc *dev, struct lh7a40x_ep *ep)
1926 usb_set_index(0); 1926 usb_set_index(0);
1927 csr = usb_read(USB_EP0_CSR); 1927 csr = usb_read(USB_EP0_CSR);
1928 1928
1929 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1929 DEBUG_EP0("%s: %x\n", __func__, csr);
1930 1930
1931 /* Clear "out packet ready" */ 1931 /* Clear "out packet ready" */
1932 usb_set(EP0_CLR_OUT, USB_EP0_CSR); 1932 usb_set(EP0_CLR_OUT, USB_EP0_CSR);
@@ -1949,7 +1949,7 @@ static int lh7a40x_udc_get_frame(struct usb_gadget *_gadget)
1949{ 1949{
1950 u32 frame1 = usb_read(USB_FRM_NUM1); /* Least significant 8 bits */ 1950 u32 frame1 = usb_read(USB_FRM_NUM1); /* Least significant 8 bits */
1951 u32 frame2 = usb_read(USB_FRM_NUM2); /* Most significant 3 bits */ 1951 u32 frame2 = usb_read(USB_FRM_NUM2); /* Most significant 3 bits */
1952 DEBUG("%s, %p\n", __FUNCTION__, _gadget); 1952 DEBUG("%s, %p\n", __func__, _gadget);
1953 return ((frame2 & 0x07) << 8) | (frame1 & 0xff); 1953 return ((frame2 & 0x07) << 8) | (frame1 & 0xff);
1954} 1954}
1955 1955
@@ -1970,7 +1970,7 @@ static const struct usb_gadget_ops lh7a40x_udc_ops = {
1970 1970
1971static void nop_release(struct device *dev) 1971static void nop_release(struct device *dev)
1972{ 1972{
1973 DEBUG("%s %s\n", __FUNCTION__, dev->bus_id); 1973 DEBUG("%s %s\n", __func__, dev->bus_id);
1974} 1974}
1975 1975
1976static struct lh7a40x_udc memory = { 1976static struct lh7a40x_udc memory = {
@@ -2065,7 +2065,7 @@ static int lh7a40x_udc_probe(struct platform_device *pdev)
2065 struct lh7a40x_udc *dev = &memory; 2065 struct lh7a40x_udc *dev = &memory;
2066 int retval; 2066 int retval;
2067 2067
2068 DEBUG("%s: %p\n", __FUNCTION__, pdev); 2068 DEBUG("%s: %p\n", __func__, pdev);
2069 2069
2070 spin_lock_init(&dev->lock); 2070 spin_lock_init(&dev->lock);
2071 dev->dev = &pdev->dev; 2071 dev->dev = &pdev->dev;
@@ -2098,7 +2098,7 @@ static int lh7a40x_udc_remove(struct platform_device *pdev)
2098{ 2098{
2099 struct lh7a40x_udc *dev = platform_get_drvdata(pdev); 2099 struct lh7a40x_udc *dev = platform_get_drvdata(pdev);
2100 2100
2101 DEBUG("%s: %p\n", __FUNCTION__, pdev); 2101 DEBUG("%s: %p\n", __func__, pdev);
2102 2102
2103 if (dev->driver) 2103 if (dev->driver)
2104 return -EBUSY; 2104 return -EBUSY;
@@ -2131,7 +2131,7 @@ static struct platform_driver udc_driver = {
2131 2131
2132static int __init udc_init(void) 2132static int __init udc_init(void)
2133{ 2133{
2134 DEBUG("%s: %s version %s\n", __FUNCTION__, driver_name, DRIVER_VERSION); 2134 DEBUG("%s: %s version %s\n", __func__, driver_name, DRIVER_VERSION);
2135 return platform_driver_register(&udc_driver); 2135 return platform_driver_register(&udc_driver);
2136} 2136}
2137 2137
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h
index 17b792b7f6bf..be0a4c1f80a2 100644
--- a/drivers/usb/gadget/m66592-udc.h
+++ b/drivers/usb/gadget/m66592-udc.h
@@ -486,10 +486,10 @@ struct m66592 {
486 486
487 struct usb_request *ep0_req; /* for internal request */ 487 struct usb_request *ep0_req; /* for internal request */
488 u16 ep0_data; /* for internal request */ 488 u16 ep0_data; /* for internal request */
489 u16 old_vbus;
489 490
490 struct timer_list timer; 491 struct timer_list timer;
491 492
492 u16 old_vbus;
493 int scount; 493 int scount;
494 494
495 int old_dvsq; 495 int old_dvsq;
diff --git a/drivers/usb/gadget/net2280.h b/drivers/usb/gadget/net2280.h
index 44ca139983d8..1f2af398a9a4 100644
--- a/drivers/usb/gadget/net2280.h
+++ b/drivers/usb/gadget/net2280.h
@@ -299,7 +299,7 @@ static inline void assert_out_naking (struct net2280_ep *ep, const char *where)
299 &ep->regs->ep_rsp); 299 &ep->regs->ep_rsp);
300 } 300 }
301} 301}
302#define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__FUNCTION__) 302#define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__func__)
303#else 303#else
304#define ASSERT_OUT_NAKING(ep) do {} while (0) 304#define ASSERT_OUT_NAKING(ep) do {} while (0)
305#endif 305#endif
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index ee1e9a314cd1..95f7662376f1 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -163,7 +163,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
163 || ep->bEndpointAddress != desc->bEndpointAddress 163 || ep->bEndpointAddress != desc->bEndpointAddress
164 || ep->maxpacket < le16_to_cpu 164 || ep->maxpacket < le16_to_cpu
165 (desc->wMaxPacketSize)) { 165 (desc->wMaxPacketSize)) {
166 DBG("%s, bad ep or descriptor\n", __FUNCTION__); 166 DBG("%s, bad ep or descriptor\n", __func__);
167 return -EINVAL; 167 return -EINVAL;
168 } 168 }
169 maxp = le16_to_cpu (desc->wMaxPacketSize); 169 maxp = le16_to_cpu (desc->wMaxPacketSize);
@@ -171,7 +171,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
171 && maxp != ep->maxpacket) 171 && maxp != ep->maxpacket)
172 || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket 172 || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket
173 || !desc->wMaxPacketSize) { 173 || !desc->wMaxPacketSize) {
174 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 174 DBG("%s, bad %s maxpacket\n", __func__, _ep->name);
175 return -ERANGE; 175 return -ERANGE;
176 } 176 }
177 177
@@ -194,13 +194,13 @@ static int omap_ep_enable(struct usb_ep *_ep,
194 if (ep->bmAttributes != desc->bmAttributes 194 if (ep->bmAttributes != desc->bmAttributes
195 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK 195 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
196 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { 196 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
197 DBG("%s, %s type mismatch\n", __FUNCTION__, _ep->name); 197 DBG("%s, %s type mismatch\n", __func__, _ep->name);
198 return -EINVAL; 198 return -EINVAL;
199 } 199 }
200 200
201 udc = ep->udc; 201 udc = ep->udc;
202 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { 202 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
203 DBG("%s, bogus device state\n", __FUNCTION__); 203 DBG("%s, bogus device state\n", __func__);
204 return -ESHUTDOWN; 204 return -ESHUTDOWN;
205 } 205 }
206 206
@@ -249,7 +249,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
249 unsigned long flags; 249 unsigned long flags;
250 250
251 if (!_ep || !ep->desc) { 251 if (!_ep || !ep->desc) {
252 DBG("%s, %s not enabled\n", __FUNCTION__, 252 DBG("%s, %s not enabled\n", __func__,
253 _ep ? ep->ep.name : NULL); 253 _ep ? ep->ep.name : NULL);
254 return -EINVAL; 254 return -EINVAL;
255 } 255 }
@@ -936,11 +936,11 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
936 /* catch various bogus parameters */ 936 /* catch various bogus parameters */
937 if (!_req || !req->req.complete || !req->req.buf 937 if (!_req || !req->req.complete || !req->req.buf
938 || !list_empty(&req->queue)) { 938 || !list_empty(&req->queue)) {
939 DBG("%s, bad params\n", __FUNCTION__); 939 DBG("%s, bad params\n", __func__);
940 return -EINVAL; 940 return -EINVAL;
941 } 941 }
942 if (!_ep || (!ep->desc && ep->bEndpointAddress)) { 942 if (!_ep || (!ep->desc && ep->bEndpointAddress)) {
943 DBG("%s, bad ep\n", __FUNCTION__); 943 DBG("%s, bad ep\n", __func__);
944 return -EINVAL; 944 return -EINVAL;
945 } 945 }
946 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 946 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
@@ -959,7 +959,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
959 && (ep->bEndpointAddress & USB_DIR_IN) == 0 959 && (ep->bEndpointAddress & USB_DIR_IN) == 0
960 && !cpu_class_is_omap2() 960 && !cpu_class_is_omap2()
961 && (req->req.length % ep->ep.maxpacket) != 0) { 961 && (req->req.length % ep->ep.maxpacket) != 0) {
962 DBG("%s, no partial packet OUT reads\n", __FUNCTION__); 962 DBG("%s, no partial packet OUT reads\n", __func__);
963 return -EMSGSIZE; 963 return -EMSGSIZE;
964 } 964 }
965 965
@@ -1265,8 +1265,6 @@ static int can_pullup(struct omap_udc *udc)
1265 1265
1266static void pullup_enable(struct omap_udc *udc) 1266static void pullup_enable(struct omap_udc *udc)
1267{ 1267{
1268 udc->gadget.dev.parent->power.power_state = PMSG_ON;
1269 udc->gadget.dev.power.power_state = PMSG_ON;
1270 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1268 UDC_SYSCON1_REG |= UDC_PULLUP_EN;
1271 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) 1269 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx())
1272 OTG_CTRL_REG |= OTG_BSESSVLD; 1270 OTG_CTRL_REG |= OTG_BSESSVLD;
@@ -3061,8 +3059,6 @@ static int omap_udc_suspend(struct platform_device *dev, pm_message_t message)
3061 omap_pullup(&udc->gadget, 0); 3059 omap_pullup(&udc->gadget, 0);
3062 } 3060 }
3063 3061
3064 udc->gadget.dev.power.power_state = PMSG_SUSPEND;
3065 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND;
3066 return 0; 3062 return 0;
3067} 3063}
3068 3064
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 2c32bd08ee7d..76be75e3ab8f 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -390,9 +390,12 @@ static void rx_complete(struct usb_ep *ep, struct usb_request *req)
390 390
391 /* normal completion */ 391 /* normal completion */
392 case 0: 392 case 0:
393 list_add_tail(&req->list, &dev->rx_buffers); 393 if (req->actual > 0) {
394 wake_up_interruptible(&dev->rx_wait); 394 list_add_tail(&req->list, &dev->rx_buffers);
395 DBG(dev, "G_Printer : rx length %d\n", req->actual); 395 DBG(dev, "G_Printer : rx length %d\n", req->actual);
396 } else {
397 list_add(&req->list, &dev->rx_reqs);
398 }
396 break; 399 break;
397 400
398 /* software-driven interface shutdown */ 401 /* software-driven interface shutdown */
@@ -417,6 +420,8 @@ static void rx_complete(struct usb_ep *ep, struct usb_request *req)
417 list_add(&req->list, &dev->rx_reqs); 420 list_add(&req->list, &dev->rx_reqs);
418 break; 421 break;
419 } 422 }
423
424 wake_up_interruptible(&dev->rx_wait);
420 spin_unlock_irqrestore(&dev->lock, flags); 425 spin_unlock_irqrestore(&dev->lock, flags);
421} 426}
422 427
@@ -494,6 +499,39 @@ printer_close(struct inode *inode, struct file *fd)
494 return 0; 499 return 0;
495} 500}
496 501
502/* This function must be called with interrupts turned off. */
503static void
504setup_rx_reqs(struct printer_dev *dev)
505{
506 struct usb_request *req;
507
508 while (likely(!list_empty(&dev->rx_reqs))) {
509 int error;
510
511 req = container_of(dev->rx_reqs.next,
512 struct usb_request, list);
513 list_del_init(&req->list);
514
515 /* The USB Host sends us whatever amount of data it wants to
516 * so we always set the length field to the full USB_BUFSIZE.
517 * If the amount of data is more than the read() caller asked
518 * for it will be stored in the request buffer until it is
519 * asked for by read().
520 */
521 req->length = USB_BUFSIZE;
522 req->complete = rx_complete;
523
524 error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
525 if (error) {
526 DBG(dev, "rx submit --> %d\n", error);
527 list_add(&req->list, &dev->rx_reqs);
528 break;
529 } else {
530 list_add(&req->list, &dev->rx_reqs_active);
531 }
532 }
533}
534
497static ssize_t 535static ssize_t
498printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) 536printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
499{ 537{
@@ -522,31 +560,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
522 */ 560 */
523 dev->reset_printer = 0; 561 dev->reset_printer = 0;
524 562
525 while (likely(!list_empty(&dev->rx_reqs))) { 563 setup_rx_reqs(dev);
526 int error;
527
528 req = container_of(dev->rx_reqs.next,
529 struct usb_request, list);
530 list_del_init(&req->list);
531
532 /* The USB Host sends us whatever amount of data it wants to
533 * so we always set the length field to the full USB_BUFSIZE.
534 * If the amount of data is more than the read() caller asked
535 * for it will be stored in the request buffer until it is
536 * asked for by read().
537 */
538 req->length = USB_BUFSIZE;
539 req->complete = rx_complete;
540
541 error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
542 if (error) {
543 DBG(dev, "rx submit --> %d\n", error);
544 list_add(&req->list, &dev->rx_reqs);
545 break;
546 } else {
547 list_add(&req->list, &dev->rx_reqs_active);
548 }
549 }
550 564
551 bytes_copied = 0; 565 bytes_copied = 0;
552 current_rx_req = dev->current_rx_req; 566 current_rx_req = dev->current_rx_req;
@@ -615,9 +629,9 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
615 629
616 spin_lock_irqsave(&dev->lock, flags); 630 spin_lock_irqsave(&dev->lock, flags);
617 631
618 /* We've disconnected or reset free the req and buffer */ 632 /* We've disconnected or reset so return. */
619 if (dev->reset_printer) { 633 if (dev->reset_printer) {
620 printer_req_free(dev->out_ep, current_rx_req); 634 list_add(&current_rx_req->list, &dev->rx_reqs);
621 spin_unlock_irqrestore(&dev->lock, flags); 635 spin_unlock_irqrestore(&dev->lock, flags);
622 spin_unlock(&dev->lock_printer_io); 636 spin_unlock(&dev->lock_printer_io);
623 return -EAGAIN; 637 return -EAGAIN;
@@ -735,7 +749,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
735 749
736 /* We've disconnected or reset so free the req and buffer */ 750 /* We've disconnected or reset so free the req and buffer */
737 if (dev->reset_printer) { 751 if (dev->reset_printer) {
738 printer_req_free(dev->in_ep, req); 752 list_add(&req->list, &dev->tx_reqs);
739 spin_unlock_irqrestore(&dev->lock, flags); 753 spin_unlock_irqrestore(&dev->lock, flags);
740 spin_unlock(&dev->lock_printer_io); 754 spin_unlock(&dev->lock_printer_io);
741 return -EAGAIN; 755 return -EAGAIN;
@@ -791,6 +805,12 @@ printer_poll(struct file *fd, poll_table *wait)
791 unsigned long flags; 805 unsigned long flags;
792 int status = 0; 806 int status = 0;
793 807
808 spin_lock(&dev->lock_printer_io);
809 spin_lock_irqsave(&dev->lock, flags);
810 setup_rx_reqs(dev);
811 spin_unlock_irqrestore(&dev->lock, flags);
812 spin_unlock(&dev->lock_printer_io);
813
794 poll_wait(fd, &dev->rx_wait, wait); 814 poll_wait(fd, &dev->rx_wait, wait);
795 poll_wait(fd, &dev->tx_wait, wait); 815 poll_wait(fd, &dev->tx_wait, wait);
796 816
@@ -798,7 +818,8 @@ printer_poll(struct file *fd, poll_table *wait)
798 if (likely(!list_empty(&dev->tx_reqs))) 818 if (likely(!list_empty(&dev->tx_reqs)))
799 status |= POLLOUT | POLLWRNORM; 819 status |= POLLOUT | POLLWRNORM;
800 820
801 if (likely(!list_empty(&dev->rx_buffers))) 821 if (likely(dev->current_rx_bytes) ||
822 likely(!list_empty(&dev->rx_buffers)))
802 status |= POLLIN | POLLRDNORM; 823 status |= POLLIN | POLLRDNORM;
803 824
804 spin_unlock_irqrestore(&dev->lock, flags); 825 spin_unlock_irqrestore(&dev->lock, flags);
@@ -894,7 +915,7 @@ static void printer_reset_interface(struct printer_dev *dev)
894 if (dev->interface < 0) 915 if (dev->interface < 0)
895 return; 916 return;
896 917
897 DBG(dev, "%s\n", __FUNCTION__); 918 DBG(dev, "%s\n", __func__);
898 919
899 if (dev->in) 920 if (dev->in)
900 usb_ep_disable(dev->in_ep); 921 usb_ep_disable(dev->in_ep);
@@ -1084,6 +1105,7 @@ static void printer_soft_reset(struct printer_dev *dev)
1084 if (usb_ep_enable(dev->out_ep, dev->out)) 1105 if (usb_ep_enable(dev->out_ep, dev->out))
1085 DBG(dev, "Failed to enable USB out_ep\n"); 1106 DBG(dev, "Failed to enable USB out_ep\n");
1086 1107
1108 wake_up_interruptible(&dev->rx_wait);
1087 wake_up_interruptible(&dev->tx_wait); 1109 wake_up_interruptible(&dev->tx_wait);
1088 wake_up_interruptible(&dev->tx_flush_wait); 1110 wake_up_interruptible(&dev->tx_flush_wait);
1089} 1111}
@@ -1262,7 +1284,7 @@ printer_disconnect(struct usb_gadget *gadget)
1262 struct printer_dev *dev = get_gadget_data(gadget); 1284 struct printer_dev *dev = get_gadget_data(gadget);
1263 unsigned long flags; 1285 unsigned long flags;
1264 1286
1265 DBG(dev, "%s\n", __FUNCTION__); 1287 DBG(dev, "%s\n", __func__);
1266 1288
1267 spin_lock_irqsave(&dev->lock, flags); 1289 spin_lock_irqsave(&dev->lock, flags);
1268 1290
@@ -1278,7 +1300,7 @@ printer_unbind(struct usb_gadget *gadget)
1278 struct usb_request *req; 1300 struct usb_request *req;
1279 1301
1280 1302
1281 DBG(dev, "%s\n", __FUNCTION__); 1303 DBG(dev, "%s\n", __func__);
1282 1304
1283 /* Remove sysfs files */ 1305 /* Remove sysfs files */
1284 device_destroy(usb_gadget_class, g_printer_devno); 1306 device_destroy(usb_gadget_class, g_printer_devno);
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index c00cd8b9d3d1..08f699b1fc57 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -235,7 +235,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
235 || ep->bEndpointAddress != desc->bEndpointAddress 235 || ep->bEndpointAddress != desc->bEndpointAddress
236 || ep->fifo_size < le16_to_cpu 236 || ep->fifo_size < le16_to_cpu
237 (desc->wMaxPacketSize)) { 237 (desc->wMaxPacketSize)) {
238 DMSG("%s, bad ep or descriptor\n", __FUNCTION__); 238 DMSG("%s, bad ep or descriptor\n", __func__);
239 return -EINVAL; 239 return -EINVAL;
240 } 240 }
241 241
@@ -243,7 +243,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
243 if (ep->bmAttributes != desc->bmAttributes 243 if (ep->bmAttributes != desc->bmAttributes
244 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK 244 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
245 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { 245 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
246 DMSG("%s, %s type mismatch\n", __FUNCTION__, _ep->name); 246 DMSG("%s, %s type mismatch\n", __func__, _ep->name);
247 return -EINVAL; 247 return -EINVAL;
248 } 248 }
249 249
@@ -252,13 +252,13 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
252 && le16_to_cpu (desc->wMaxPacketSize) 252 && le16_to_cpu (desc->wMaxPacketSize)
253 != BULK_FIFO_SIZE) 253 != BULK_FIFO_SIZE)
254 || !desc->wMaxPacketSize) { 254 || !desc->wMaxPacketSize) {
255 DMSG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 255 DMSG("%s, bad %s maxpacket\n", __func__, _ep->name);
256 return -ERANGE; 256 return -ERANGE;
257 } 257 }
258 258
259 dev = ep->dev; 259 dev = ep->dev;
260 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { 260 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
261 DMSG("%s, bogus device state\n", __FUNCTION__); 261 DMSG("%s, bogus device state\n", __func__);
262 return -ESHUTDOWN; 262 return -ESHUTDOWN;
263 } 263 }
264 264
@@ -283,7 +283,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
283 283
284 ep = container_of (_ep, struct pxa2xx_ep, ep); 284 ep = container_of (_ep, struct pxa2xx_ep, ep);
285 if (!_ep || !ep->desc) { 285 if (!_ep || !ep->desc) {
286 DMSG("%s, %s not enabled\n", __FUNCTION__, 286 DMSG("%s, %s not enabled\n", __func__,
287 _ep ? ep->ep.name : NULL); 287 _ep ? ep->ep.name : NULL);
288 return -EINVAL; 288 return -EINVAL;
289 } 289 }
@@ -461,7 +461,7 @@ void ep0start(struct pxa2xx_udc *dev, u32 flags, const char *tag)
461 USIR0 = USIR0_IR0; 461 USIR0 = USIR0_IR0;
462 dev->req_pending = 0; 462 dev->req_pending = 0;
463 DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n", 463 DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
464 __FUNCTION__, tag, UDCCS0, flags); 464 __func__, tag, UDCCS0, flags);
465} 465}
466 466
467static int 467static int
@@ -651,20 +651,20 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
651 req = container_of(_req, struct pxa2xx_request, req); 651 req = container_of(_req, struct pxa2xx_request, req);
652 if (unlikely (!_req || !_req->complete || !_req->buf 652 if (unlikely (!_req || !_req->complete || !_req->buf
653 || !list_empty(&req->queue))) { 653 || !list_empty(&req->queue))) {
654 DMSG("%s, bad params\n", __FUNCTION__); 654 DMSG("%s, bad params\n", __func__);
655 return -EINVAL; 655 return -EINVAL;
656 } 656 }
657 657
658 ep = container_of(_ep, struct pxa2xx_ep, ep); 658 ep = container_of(_ep, struct pxa2xx_ep, ep);
659 if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) { 659 if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
660 DMSG("%s, bad ep\n", __FUNCTION__); 660 DMSG("%s, bad ep\n", __func__);
661 return -EINVAL; 661 return -EINVAL;
662 } 662 }
663 663
664 dev = ep->dev; 664 dev = ep->dev;
665 if (unlikely (!dev->driver 665 if (unlikely (!dev->driver
666 || dev->gadget.speed == USB_SPEED_UNKNOWN)) { 666 || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
667 DMSG("%s, bogus device state\n", __FUNCTION__); 667 DMSG("%s, bogus device state\n", __func__);
668 return -ESHUTDOWN; 668 return -ESHUTDOWN;
669 } 669 }
670 670
@@ -807,7 +807,7 @@ static int pxa2xx_ep_set_halt(struct usb_ep *_ep, int value)
807 if (unlikely (!_ep 807 if (unlikely (!_ep
808 || (!ep->desc && ep->ep.name != ep0name)) 808 || (!ep->desc && ep->ep.name != ep0name))
809 || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 809 || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
810 DMSG("%s, bad ep\n", __FUNCTION__); 810 DMSG("%s, bad ep\n", __func__);
811 return -EINVAL; 811 return -EINVAL;
812 } 812 }
813 if (value == 0) { 813 if (value == 0) {
@@ -859,7 +859,7 @@ static int pxa2xx_ep_fifo_status(struct usb_ep *_ep)
859 859
860 ep = container_of(_ep, struct pxa2xx_ep, ep); 860 ep = container_of(_ep, struct pxa2xx_ep, ep);
861 if (!_ep) { 861 if (!_ep) {
862 DMSG("%s, bad ep\n", __FUNCTION__); 862 DMSG("%s, bad ep\n", __func__);
863 return -ENODEV; 863 return -ENODEV;
864 } 864 }
865 /* pxa can't report unclaimed bytes from IN fifos */ 865 /* pxa can't report unclaimed bytes from IN fifos */
@@ -878,7 +878,7 @@ static void pxa2xx_ep_fifo_flush(struct usb_ep *_ep)
878 878
879 ep = container_of(_ep, struct pxa2xx_ep, ep); 879 ep = container_of(_ep, struct pxa2xx_ep, ep);
880 if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) { 880 if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
881 DMSG("%s, bad ep\n", __FUNCTION__); 881 DMSG("%s, bad ep\n", __func__);
882 return; 882 return;
883 } 883 }
884 884
@@ -1813,7 +1813,7 @@ pxa2xx_udc_irq(int irq, void *_dev)
1813 1813
1814static void nop_release (struct device *dev) 1814static void nop_release (struct device *dev)
1815{ 1815{
1816 DMSG("%s %s\n", __FUNCTION__, dev->bus_id); 1816 DMSG("%s %s\n", __func__, dev->bus_id);
1817} 1817}
1818 1818
1819/* this uses load-time allocation and initialization (instead of 1819/* this uses load-time allocation and initialization (instead of
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 3d036647431f..bd58dd504f6f 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -204,7 +204,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
204 204
205 /* mandatory */ 205 /* mandatory */
206 case OID_GEN_SUPPORTED_LIST: 206 case OID_GEN_SUPPORTED_LIST:
207 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); 207 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __func__);
208 length = sizeof (oid_supported_list); 208 length = sizeof (oid_supported_list);
209 count = length / sizeof (u32); 209 count = length / sizeof (u32);
210 for (i = 0; i < count; i++) 210 for (i = 0; i < count; i++)
@@ -214,7 +214,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
214 214
215 /* mandatory */ 215 /* mandatory */
216 case OID_GEN_HARDWARE_STATUS: 216 case OID_GEN_HARDWARE_STATUS:
217 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); 217 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __func__);
218 /* Bogus question! 218 /* Bogus question!
219 * Hardware must be ready to receive high level protocols. 219 * Hardware must be ready to receive high level protocols.
220 * BTW: 220 * BTW:
@@ -227,14 +227,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
227 227
228 /* mandatory */ 228 /* mandatory */
229 case OID_GEN_MEDIA_SUPPORTED: 229 case OID_GEN_MEDIA_SUPPORTED:
230 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); 230 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__);
231 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 231 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
232 retval = 0; 232 retval = 0;
233 break; 233 break;
234 234
235 /* mandatory */ 235 /* mandatory */
236 case OID_GEN_MEDIA_IN_USE: 236 case OID_GEN_MEDIA_IN_USE:
237 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); 237 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __func__);
238 /* one medium, one transport... (maybe you do it better) */ 238 /* one medium, one transport... (maybe you do it better) */
239 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 239 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
240 retval = 0; 240 retval = 0;
@@ -242,7 +242,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
242 242
243 /* mandatory */ 243 /* mandatory */
244 case OID_GEN_MAXIMUM_FRAME_SIZE: 244 case OID_GEN_MAXIMUM_FRAME_SIZE:
245 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); 245 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
246 if (rndis_per_dev_params [configNr].dev) { 246 if (rndis_per_dev_params [configNr].dev) {
247 *outbuf = cpu_to_le32 ( 247 *outbuf = cpu_to_le32 (
248 rndis_per_dev_params [configNr].dev->mtu); 248 rndis_per_dev_params [configNr].dev->mtu);
@@ -253,7 +253,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
253 /* mandatory */ 253 /* mandatory */
254 case OID_GEN_LINK_SPEED: 254 case OID_GEN_LINK_SPEED:
255 if (rndis_debug > 1) 255 if (rndis_debug > 1)
256 DBG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 256 DBG("%s: OID_GEN_LINK_SPEED\n", __func__);
257 if (rndis_per_dev_params [configNr].media_state 257 if (rndis_per_dev_params [configNr].media_state
258 == NDIS_MEDIA_STATE_DISCONNECTED) 258 == NDIS_MEDIA_STATE_DISCONNECTED)
259 *outbuf = __constant_cpu_to_le32 (0); 259 *outbuf = __constant_cpu_to_le32 (0);
@@ -265,7 +265,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
265 265
266 /* mandatory */ 266 /* mandatory */
267 case OID_GEN_TRANSMIT_BLOCK_SIZE: 267 case OID_GEN_TRANSMIT_BLOCK_SIZE:
268 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); 268 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
269 if (rndis_per_dev_params [configNr].dev) { 269 if (rndis_per_dev_params [configNr].dev) {
270 *outbuf = cpu_to_le32 ( 270 *outbuf = cpu_to_le32 (
271 rndis_per_dev_params [configNr].dev->mtu); 271 rndis_per_dev_params [configNr].dev->mtu);
@@ -275,7 +275,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
275 275
276 /* mandatory */ 276 /* mandatory */
277 case OID_GEN_RECEIVE_BLOCK_SIZE: 277 case OID_GEN_RECEIVE_BLOCK_SIZE:
278 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); 278 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
279 if (rndis_per_dev_params [configNr].dev) { 279 if (rndis_per_dev_params [configNr].dev) {
280 *outbuf = cpu_to_le32 ( 280 *outbuf = cpu_to_le32 (
281 rndis_per_dev_params [configNr].dev->mtu); 281 rndis_per_dev_params [configNr].dev->mtu);
@@ -285,7 +285,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
285 285
286 /* mandatory */ 286 /* mandatory */
287 case OID_GEN_VENDOR_ID: 287 case OID_GEN_VENDOR_ID:
288 DBG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); 288 DBG("%s: OID_GEN_VENDOR_ID\n", __func__);
289 *outbuf = cpu_to_le32 ( 289 *outbuf = cpu_to_le32 (
290 rndis_per_dev_params [configNr].vendorID); 290 rndis_per_dev_params [configNr].vendorID);
291 retval = 0; 291 retval = 0;
@@ -293,7 +293,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
293 293
294 /* mandatory */ 294 /* mandatory */
295 case OID_GEN_VENDOR_DESCRIPTION: 295 case OID_GEN_VENDOR_DESCRIPTION:
296 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); 296 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__);
297 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 297 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
298 memcpy (outbuf, 298 memcpy (outbuf,
299 rndis_per_dev_params [configNr].vendorDescr, length); 299 rndis_per_dev_params [configNr].vendorDescr, length);
@@ -301,7 +301,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
301 break; 301 break;
302 302
303 case OID_GEN_VENDOR_DRIVER_VERSION: 303 case OID_GEN_VENDOR_DRIVER_VERSION:
304 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); 304 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
305 /* Created as LE */ 305 /* Created as LE */
306 *outbuf = rndis_driver_version; 306 *outbuf = rndis_driver_version;
307 retval = 0; 307 retval = 0;
@@ -309,14 +309,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
309 309
310 /* mandatory */ 310 /* mandatory */
311 case OID_GEN_CURRENT_PACKET_FILTER: 311 case OID_GEN_CURRENT_PACKET_FILTER:
312 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); 312 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
313 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); 313 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
314 retval = 0; 314 retval = 0;
315 break; 315 break;
316 316
317 /* mandatory */ 317 /* mandatory */
318 case OID_GEN_MAXIMUM_TOTAL_SIZE: 318 case OID_GEN_MAXIMUM_TOTAL_SIZE:
319 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); 319 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
320 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); 320 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
321 retval = 0; 321 retval = 0;
322 break; 322 break;
@@ -324,14 +324,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
324 /* mandatory */ 324 /* mandatory */
325 case OID_GEN_MEDIA_CONNECT_STATUS: 325 case OID_GEN_MEDIA_CONNECT_STATUS:
326 if (rndis_debug > 1) 326 if (rndis_debug > 1)
327 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 327 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
328 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 328 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
329 .media_state); 329 .media_state);
330 retval = 0; 330 retval = 0;
331 break; 331 break;
332 332
333 case OID_GEN_PHYSICAL_MEDIUM: 333 case OID_GEN_PHYSICAL_MEDIUM:
334 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); 334 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
335 *outbuf = __constant_cpu_to_le32 (0); 335 *outbuf = __constant_cpu_to_le32 (0);
336 retval = 0; 336 retval = 0;
337 break; 337 break;
@@ -341,7 +341,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
341 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! 341 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
342 */ 342 */
343 case OID_GEN_MAC_OPTIONS: /* from WinME */ 343 case OID_GEN_MAC_OPTIONS: /* from WinME */
344 DBG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); 344 DBG("%s: OID_GEN_MAC_OPTIONS\n", __func__);
345 *outbuf = __constant_cpu_to_le32( 345 *outbuf = __constant_cpu_to_le32(
346 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 346 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
347 | NDIS_MAC_OPTION_FULL_DUPLEX); 347 | NDIS_MAC_OPTION_FULL_DUPLEX);
@@ -353,7 +353,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
353 /* mandatory */ 353 /* mandatory */
354 case OID_GEN_XMIT_OK: 354 case OID_GEN_XMIT_OK:
355 if (rndis_debug > 1) 355 if (rndis_debug > 1)
356 DBG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 356 DBG("%s: OID_GEN_XMIT_OK\n", __func__);
357 if (rndis_per_dev_params [configNr].stats) { 357 if (rndis_per_dev_params [configNr].stats) {
358 *outbuf = cpu_to_le32 ( 358 *outbuf = cpu_to_le32 (
359 rndis_per_dev_params [configNr].stats->tx_packets - 359 rndis_per_dev_params [configNr].stats->tx_packets -
@@ -366,7 +366,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
366 /* mandatory */ 366 /* mandatory */
367 case OID_GEN_RCV_OK: 367 case OID_GEN_RCV_OK:
368 if (rndis_debug > 1) 368 if (rndis_debug > 1)
369 DBG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 369 DBG("%s: OID_GEN_RCV_OK\n", __func__);
370 if (rndis_per_dev_params [configNr].stats) { 370 if (rndis_per_dev_params [configNr].stats) {
371 *outbuf = cpu_to_le32 ( 371 *outbuf = cpu_to_le32 (
372 rndis_per_dev_params [configNr].stats->rx_packets - 372 rndis_per_dev_params [configNr].stats->rx_packets -
@@ -379,7 +379,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
379 /* mandatory */ 379 /* mandatory */
380 case OID_GEN_XMIT_ERROR: 380 case OID_GEN_XMIT_ERROR:
381 if (rndis_debug > 1) 381 if (rndis_debug > 1)
382 DBG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 382 DBG("%s: OID_GEN_XMIT_ERROR\n", __func__);
383 if (rndis_per_dev_params [configNr].stats) { 383 if (rndis_per_dev_params [configNr].stats) {
384 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 384 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
385 .stats->tx_errors); 385 .stats->tx_errors);
@@ -390,7 +390,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
390 /* mandatory */ 390 /* mandatory */
391 case OID_GEN_RCV_ERROR: 391 case OID_GEN_RCV_ERROR:
392 if (rndis_debug > 1) 392 if (rndis_debug > 1)
393 DBG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 393 DBG("%s: OID_GEN_RCV_ERROR\n", __func__);
394 if (rndis_per_dev_params [configNr].stats) { 394 if (rndis_per_dev_params [configNr].stats) {
395 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 395 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
396 .stats->rx_errors); 396 .stats->rx_errors);
@@ -400,7 +400,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
400 400
401 /* mandatory */ 401 /* mandatory */
402 case OID_GEN_RCV_NO_BUFFER: 402 case OID_GEN_RCV_NO_BUFFER:
403 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); 403 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__);
404 if (rndis_per_dev_params [configNr].stats) { 404 if (rndis_per_dev_params [configNr].stats) {
405 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 405 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
406 .stats->rx_dropped); 406 .stats->rx_dropped);
@@ -410,7 +410,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
410 410
411#ifdef RNDIS_OPTIONAL_STATS 411#ifdef RNDIS_OPTIONAL_STATS
412 case OID_GEN_DIRECTED_BYTES_XMIT: 412 case OID_GEN_DIRECTED_BYTES_XMIT:
413 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __FUNCTION__); 413 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __func__);
414 /* 414 /*
415 * Aunt Tilly's size of shoes 415 * Aunt Tilly's size of shoes
416 * minus antarctica count of penguins 416 * minus antarctica count of penguins
@@ -430,7 +430,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
430 break; 430 break;
431 431
432 case OID_GEN_DIRECTED_FRAMES_XMIT: 432 case OID_GEN_DIRECTED_FRAMES_XMIT:
433 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); 433 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __func__);
434 /* dito */ 434 /* dito */
435 if (rndis_per_dev_params [configNr].stats) { 435 if (rndis_per_dev_params [configNr].stats) {
436 *outbuf = cpu_to_le32 ( 436 *outbuf = cpu_to_le32 (
@@ -446,7 +446,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
446 break; 446 break;
447 447
448 case OID_GEN_MULTICAST_BYTES_XMIT: 448 case OID_GEN_MULTICAST_BYTES_XMIT:
449 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); 449 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __func__);
450 if (rndis_per_dev_params [configNr].stats) { 450 if (rndis_per_dev_params [configNr].stats) {
451 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 451 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
452 .stats->multicast*1234); 452 .stats->multicast*1234);
@@ -455,7 +455,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
455 break; 455 break;
456 456
457 case OID_GEN_MULTICAST_FRAMES_XMIT: 457 case OID_GEN_MULTICAST_FRAMES_XMIT:
458 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); 458 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __func__);
459 if (rndis_per_dev_params [configNr].stats) { 459 if (rndis_per_dev_params [configNr].stats) {
460 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 460 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
461 .stats->multicast); 461 .stats->multicast);
@@ -464,7 +464,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
464 break; 464 break;
465 465
466 case OID_GEN_BROADCAST_BYTES_XMIT: 466 case OID_GEN_BROADCAST_BYTES_XMIT:
467 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); 467 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __func__);
468 if (rndis_per_dev_params [configNr].stats) { 468 if (rndis_per_dev_params [configNr].stats) {
469 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 469 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
470 .stats->tx_packets/42*255); 470 .stats->tx_packets/42*255);
@@ -473,7 +473,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
473 break; 473 break;
474 474
475 case OID_GEN_BROADCAST_FRAMES_XMIT: 475 case OID_GEN_BROADCAST_FRAMES_XMIT:
476 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); 476 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __func__);
477 if (rndis_per_dev_params [configNr].stats) { 477 if (rndis_per_dev_params [configNr].stats) {
478 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 478 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
479 .stats->tx_packets/42); 479 .stats->tx_packets/42);
@@ -482,19 +482,19 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
482 break; 482 break;
483 483
484 case OID_GEN_DIRECTED_BYTES_RCV: 484 case OID_GEN_DIRECTED_BYTES_RCV:
485 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); 485 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __func__);
486 *outbuf = __constant_cpu_to_le32 (0); 486 *outbuf = __constant_cpu_to_le32 (0);
487 retval = 0; 487 retval = 0;
488 break; 488 break;
489 489
490 case OID_GEN_DIRECTED_FRAMES_RCV: 490 case OID_GEN_DIRECTED_FRAMES_RCV:
491 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); 491 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __func__);
492 *outbuf = __constant_cpu_to_le32 (0); 492 *outbuf = __constant_cpu_to_le32 (0);
493 retval = 0; 493 retval = 0;
494 break; 494 break;
495 495
496 case OID_GEN_MULTICAST_BYTES_RCV: 496 case OID_GEN_MULTICAST_BYTES_RCV:
497 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); 497 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __func__);
498 if (rndis_per_dev_params [configNr].stats) { 498 if (rndis_per_dev_params [configNr].stats) {
499 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 499 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
500 .stats->multicast * 1111); 500 .stats->multicast * 1111);
@@ -503,7 +503,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
503 break; 503 break;
504 504
505 case OID_GEN_MULTICAST_FRAMES_RCV: 505 case OID_GEN_MULTICAST_FRAMES_RCV:
506 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); 506 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __func__);
507 if (rndis_per_dev_params [configNr].stats) { 507 if (rndis_per_dev_params [configNr].stats) {
508 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 508 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
509 .stats->multicast); 509 .stats->multicast);
@@ -512,7 +512,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
512 break; 512 break;
513 513
514 case OID_GEN_BROADCAST_BYTES_RCV: 514 case OID_GEN_BROADCAST_BYTES_RCV:
515 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); 515 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __func__);
516 if (rndis_per_dev_params [configNr].stats) { 516 if (rndis_per_dev_params [configNr].stats) {
517 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 517 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
518 .stats->rx_packets/42*255); 518 .stats->rx_packets/42*255);
@@ -521,7 +521,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
521 break; 521 break;
522 522
523 case OID_GEN_BROADCAST_FRAMES_RCV: 523 case OID_GEN_BROADCAST_FRAMES_RCV:
524 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); 524 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __func__);
525 if (rndis_per_dev_params [configNr].stats) { 525 if (rndis_per_dev_params [configNr].stats) {
526 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 526 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
527 .stats->rx_packets/42); 527 .stats->rx_packets/42);
@@ -530,7 +530,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
530 break; 530 break;
531 531
532 case OID_GEN_RCV_CRC_ERROR: 532 case OID_GEN_RCV_CRC_ERROR:
533 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); 533 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __func__);
534 if (rndis_per_dev_params [configNr].stats) { 534 if (rndis_per_dev_params [configNr].stats) {
535 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 535 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
536 .stats->rx_crc_errors); 536 .stats->rx_crc_errors);
@@ -539,7 +539,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
539 break; 539 break;
540 540
541 case OID_GEN_TRANSMIT_QUEUE_LENGTH: 541 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
542 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); 542 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __func__);
543 *outbuf = __constant_cpu_to_le32 (0); 543 *outbuf = __constant_cpu_to_le32 (0);
544 retval = 0; 544 retval = 0;
545 break; 545 break;
@@ -549,7 +549,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
549 549
550 /* mandatory */ 550 /* mandatory */
551 case OID_802_3_PERMANENT_ADDRESS: 551 case OID_802_3_PERMANENT_ADDRESS:
552 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); 552 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__);
553 if (rndis_per_dev_params [configNr].dev) { 553 if (rndis_per_dev_params [configNr].dev) {
554 length = ETH_ALEN; 554 length = ETH_ALEN;
555 memcpy (outbuf, 555 memcpy (outbuf,
@@ -561,7 +561,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
561 561
562 /* mandatory */ 562 /* mandatory */
563 case OID_802_3_CURRENT_ADDRESS: 563 case OID_802_3_CURRENT_ADDRESS:
564 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); 564 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __func__);
565 if (rndis_per_dev_params [configNr].dev) { 565 if (rndis_per_dev_params [configNr].dev) {
566 length = ETH_ALEN; 566 length = ETH_ALEN;
567 memcpy (outbuf, 567 memcpy (outbuf,
@@ -573,7 +573,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
573 573
574 /* mandatory */ 574 /* mandatory */
575 case OID_802_3_MULTICAST_LIST: 575 case OID_802_3_MULTICAST_LIST:
576 DBG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 576 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
577 /* Multicast base address only */ 577 /* Multicast base address only */
578 *outbuf = __constant_cpu_to_le32 (0xE0000000); 578 *outbuf = __constant_cpu_to_le32 (0xE0000000);
579 retval = 0; 579 retval = 0;
@@ -581,21 +581,21 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
581 581
582 /* mandatory */ 582 /* mandatory */
583 case OID_802_3_MAXIMUM_LIST_SIZE: 583 case OID_802_3_MAXIMUM_LIST_SIZE:
584 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); 584 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
585 /* Multicast base address only */ 585 /* Multicast base address only */
586 *outbuf = __constant_cpu_to_le32 (1); 586 *outbuf = __constant_cpu_to_le32 (1);
587 retval = 0; 587 retval = 0;
588 break; 588 break;
589 589
590 case OID_802_3_MAC_OPTIONS: 590 case OID_802_3_MAC_OPTIONS:
591 DBG("%s: OID_802_3_MAC_OPTIONS\n", __FUNCTION__); 591 DBG("%s: OID_802_3_MAC_OPTIONS\n", __func__);
592 break; 592 break;
593 593
594 /* ieee802.3 statistics OIDs (table 4-4) */ 594 /* ieee802.3 statistics OIDs (table 4-4) */
595 595
596 /* mandatory */ 596 /* mandatory */
597 case OID_802_3_RCV_ERROR_ALIGNMENT: 597 case OID_802_3_RCV_ERROR_ALIGNMENT:
598 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); 598 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
599 if (rndis_per_dev_params [configNr].stats) { 599 if (rndis_per_dev_params [configNr].stats) {
600 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 600 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
601 .stats->rx_frame_errors); 601 .stats->rx_frame_errors);
@@ -605,51 +605,51 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
605 605
606 /* mandatory */ 606 /* mandatory */
607 case OID_802_3_XMIT_ONE_COLLISION: 607 case OID_802_3_XMIT_ONE_COLLISION:
608 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); 608 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
609 *outbuf = __constant_cpu_to_le32 (0); 609 *outbuf = __constant_cpu_to_le32 (0);
610 retval = 0; 610 retval = 0;
611 break; 611 break;
612 612
613 /* mandatory */ 613 /* mandatory */
614 case OID_802_3_XMIT_MORE_COLLISIONS: 614 case OID_802_3_XMIT_MORE_COLLISIONS:
615 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); 615 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
616 *outbuf = __constant_cpu_to_le32 (0); 616 *outbuf = __constant_cpu_to_le32 (0);
617 retval = 0; 617 retval = 0;
618 break; 618 break;
619 619
620#ifdef RNDIS_OPTIONAL_STATS 620#ifdef RNDIS_OPTIONAL_STATS
621 case OID_802_3_XMIT_DEFERRED: 621 case OID_802_3_XMIT_DEFERRED:
622 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __FUNCTION__); 622 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __func__);
623 /* TODO */ 623 /* TODO */
624 break; 624 break;
625 625
626 case OID_802_3_XMIT_MAX_COLLISIONS: 626 case OID_802_3_XMIT_MAX_COLLISIONS:
627 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __FUNCTION__); 627 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __func__);
628 /* TODO */ 628 /* TODO */
629 break; 629 break;
630 630
631 case OID_802_3_RCV_OVERRUN: 631 case OID_802_3_RCV_OVERRUN:
632 DBG("%s: OID_802_3_RCV_OVERRUN\n", __FUNCTION__); 632 DBG("%s: OID_802_3_RCV_OVERRUN\n", __func__);
633 /* TODO */ 633 /* TODO */
634 break; 634 break;
635 635
636 case OID_802_3_XMIT_UNDERRUN: 636 case OID_802_3_XMIT_UNDERRUN:
637 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __FUNCTION__); 637 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __func__);
638 /* TODO */ 638 /* TODO */
639 break; 639 break;
640 640
641 case OID_802_3_XMIT_HEARTBEAT_FAILURE: 641 case OID_802_3_XMIT_HEARTBEAT_FAILURE:
642 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __FUNCTION__); 642 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __func__);
643 /* TODO */ 643 /* TODO */
644 break; 644 break;
645 645
646 case OID_802_3_XMIT_TIMES_CRS_LOST: 646 case OID_802_3_XMIT_TIMES_CRS_LOST:
647 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __FUNCTION__); 647 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __func__);
648 /* TODO */ 648 /* TODO */
649 break; 649 break;
650 650
651 case OID_802_3_XMIT_LATE_COLLISIONS: 651 case OID_802_3_XMIT_LATE_COLLISIONS:
652 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __FUNCTION__); 652 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __func__);
653 /* TODO */ 653 /* TODO */
654 break; 654 break;
655#endif /* RNDIS_OPTIONAL_STATS */ 655#endif /* RNDIS_OPTIONAL_STATS */
@@ -657,7 +657,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
657#ifdef RNDIS_PM 657#ifdef RNDIS_PM
658 /* power management OIDs (table 4-5) */ 658 /* power management OIDs (table 4-5) */
659 case OID_PNP_CAPABILITIES: 659 case OID_PNP_CAPABILITIES:
660 DBG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); 660 DBG("%s: OID_PNP_CAPABILITIES\n", __func__);
661 661
662 /* for now, no wakeup capabilities */ 662 /* for now, no wakeup capabilities */
663 length = sizeof (struct NDIS_PNP_CAPABILITIES); 663 length = sizeof (struct NDIS_PNP_CAPABILITIES);
@@ -665,7 +665,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
665 retval = 0; 665 retval = 0;
666 break; 666 break;
667 case OID_PNP_QUERY_POWER: 667 case OID_PNP_QUERY_POWER:
668 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__, 668 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __func__,
669 le32_to_cpu(get_unaligned((__le32 *)buf)) - 1); 669 le32_to_cpu(get_unaligned((__le32 *)buf)) - 1);
670 /* only suspend is a real power state, and 670 /* only suspend is a real power state, and
671 * it can't be entered by OID_PNP_SET_POWER... 671 * it can't be entered by OID_PNP_SET_POWER...
@@ -677,7 +677,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
677 677
678 default: 678 default:
679 pr_warning("%s: query unknown OID 0x%08X\n", 679 pr_warning("%s: query unknown OID 0x%08X\n",
680 __FUNCTION__, OID); 680 __func__, OID);
681 } 681 }
682 if (retval < 0) 682 if (retval < 0)
683 length = 0; 683 length = 0;
@@ -729,7 +729,7 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
729 *params->filter = (u16) le32_to_cpu(get_unaligned( 729 *params->filter = (u16) le32_to_cpu(get_unaligned(
730 (__le32 *)buf)); 730 (__le32 *)buf));
731 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 731 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
732 __FUNCTION__, *params->filter); 732 __func__, *params->filter);
733 733
734 /* this call has a significant side effect: it's 734 /* this call has a significant side effect: it's
735 * what makes the packet flow start and stop, like 735 * what makes the packet flow start and stop, like
@@ -753,7 +753,7 @@ update_linkstate:
753 753
754 case OID_802_3_MULTICAST_LIST: 754 case OID_802_3_MULTICAST_LIST:
755 /* I think we can ignore this */ 755 /* I think we can ignore this */
756 DBG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 756 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
757 retval = 0; 757 retval = 0;
758 break; 758 break;
759#if 0 759#if 0
@@ -762,7 +762,7 @@ update_linkstate:
762 struct rndis_config_parameter *param; 762 struct rndis_config_parameter *param;
763 param = (struct rndis_config_parameter *) buf; 763 param = (struct rndis_config_parameter *) buf;
764 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n", 764 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
765 __FUNCTION__, 765 __func__,
766 min(cpu_to_le32(param->ParameterNameLength),80), 766 min(cpu_to_le32(param->ParameterNameLength),80),
767 buf + param->ParameterNameOffset); 767 buf + param->ParameterNameOffset);
768 retval = 0; 768 retval = 0;
@@ -778,7 +778,7 @@ update_linkstate:
778 * FIXME ... then things go batty; Windows wedges itself. 778 * FIXME ... then things go batty; Windows wedges itself.
779 */ 779 */
780 i = le32_to_cpu(get_unaligned((__le32 *)buf)); 780 i = le32_to_cpu(get_unaligned((__le32 *)buf));
781 DBG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1); 781 DBG("%s: OID_PNP_SET_POWER D%d\n", __func__, i - 1);
782 switch (i) { 782 switch (i) {
783 case NdisDeviceStateD0: 783 case NdisDeviceStateD0:
784 *params->filter = params->saved_filter; 784 *params->filter = params->saved_filter;
@@ -802,7 +802,7 @@ update_linkstate:
802 802
803 default: 803 default:
804 pr_warning("%s: set unknown OID 0x%08X, size %d\n", 804 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
805 __FUNCTION__, OID, buf_len); 805 __func__, OID, buf_len);
806 } 806 }
807 807
808 return retval; 808 return retval;
@@ -855,7 +855,7 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
855 rndis_query_cmplt_type *resp; 855 rndis_query_cmplt_type *resp;
856 rndis_resp_t *r; 856 rndis_resp_t *r;
857 857
858 // DBG("%s: OID = %08X\n", __FUNCTION__, cpu_to_le32(buf->OID)); 858 // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID));
859 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 859 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
860 860
861 /* 861 /*
@@ -908,9 +908,9 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
908 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 908 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
909 909
910#ifdef VERBOSE 910#ifdef VERBOSE
911 DBG("%s: Length: %d\n", __FUNCTION__, BufLength); 911 DBG("%s: Length: %d\n", __func__, BufLength);
912 DBG("%s: Offset: %d\n", __FUNCTION__, BufOffset); 912 DBG("%s: Offset: %d\n", __func__, BufOffset);
913 DBG("%s: InfoBuffer: ", __FUNCTION__); 913 DBG("%s: InfoBuffer: ", __func__);
914 914
915 for (i = 0; i < BufLength; i++) { 915 for (i = 0; i < BufLength; i++) {
916 DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); 916 DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
@@ -1080,14 +1080,14 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1080 switch (MsgType) { 1080 switch (MsgType) {
1081 case REMOTE_NDIS_INITIALIZE_MSG: 1081 case REMOTE_NDIS_INITIALIZE_MSG:
1082 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 1082 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
1083 __FUNCTION__ ); 1083 __func__ );
1084 params->state = RNDIS_INITIALIZED; 1084 params->state = RNDIS_INITIALIZED;
1085 return rndis_init_response (configNr, 1085 return rndis_init_response (configNr,
1086 (rndis_init_msg_type *) buf); 1086 (rndis_init_msg_type *) buf);
1087 1087
1088 case REMOTE_NDIS_HALT_MSG: 1088 case REMOTE_NDIS_HALT_MSG:
1089 DBG("%s: REMOTE_NDIS_HALT_MSG\n", 1089 DBG("%s: REMOTE_NDIS_HALT_MSG\n",
1090 __FUNCTION__ ); 1090 __func__ );
1091 params->state = RNDIS_UNINITIALIZED; 1091 params->state = RNDIS_UNINITIALIZED;
1092 if (params->dev) { 1092 if (params->dev) {
1093 netif_carrier_off (params->dev); 1093 netif_carrier_off (params->dev);
@@ -1105,7 +1105,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1105 1105
1106 case REMOTE_NDIS_RESET_MSG: 1106 case REMOTE_NDIS_RESET_MSG:
1107 DBG("%s: REMOTE_NDIS_RESET_MSG\n", 1107 DBG("%s: REMOTE_NDIS_RESET_MSG\n",
1108 __FUNCTION__ ); 1108 __func__ );
1109 return rndis_reset_response (configNr, 1109 return rndis_reset_response (configNr,
1110 (rndis_reset_msg_type *) buf); 1110 (rndis_reset_msg_type *) buf);
1111 1111
@@ -1113,7 +1113,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1113 /* For USB: host does this every 5 seconds */ 1113 /* For USB: host does this every 5 seconds */
1114 if (rndis_debug > 1) 1114 if (rndis_debug > 1)
1115 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1115 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
1116 __FUNCTION__ ); 1116 __func__ );
1117 return rndis_keepalive_response (configNr, 1117 return rndis_keepalive_response (configNr,
1118 (rndis_keepalive_msg_type *) 1118 (rndis_keepalive_msg_type *)
1119 buf); 1119 buf);
@@ -1124,7 +1124,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1124 * suspending itself. 1124 * suspending itself.
1125 */ 1125 */
1126 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", 1126 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
1127 __FUNCTION__ , MsgType, MsgLength); 1127 __func__ , MsgType, MsgLength);
1128 { 1128 {
1129 unsigned i; 1129 unsigned i;
1130 for (i = 0; i < MsgLength; i += 16) { 1130 for (i = 0; i < MsgLength; i += 16) {
@@ -1159,7 +1159,7 @@ int rndis_register (int (* rndis_control_ack) (struct net_device *))
1159 if (!rndis_per_dev_params [i].used) { 1159 if (!rndis_per_dev_params [i].used) {
1160 rndis_per_dev_params [i].used = 1; 1160 rndis_per_dev_params [i].used = 1;
1161 rndis_per_dev_params [i].ack = rndis_control_ack; 1161 rndis_per_dev_params [i].ack = rndis_control_ack;
1162 DBG("%s: configNr = %d\n", __FUNCTION__, i); 1162 DBG("%s: configNr = %d\n", __func__, i);
1163 return i; 1163 return i;
1164 } 1164 }
1165 } 1165 }
@@ -1170,7 +1170,7 @@ int rndis_register (int (* rndis_control_ack) (struct net_device *))
1170 1170
1171void rndis_deregister (int configNr) 1171void rndis_deregister (int configNr)
1172{ 1172{
1173 DBG("%s: \n", __FUNCTION__ ); 1173 DBG("%s: \n", __func__ );
1174 1174
1175 if (configNr >= RNDIS_MAX_CONFIGS) return; 1175 if (configNr >= RNDIS_MAX_CONFIGS) return;
1176 rndis_per_dev_params [configNr].used = 0; 1176 rndis_per_dev_params [configNr].used = 0;
@@ -1182,7 +1182,7 @@ int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1182 struct net_device_stats *stats, 1182 struct net_device_stats *stats,
1183 u16 *cdc_filter) 1183 u16 *cdc_filter)
1184{ 1184{
1185 DBG("%s:\n", __FUNCTION__ ); 1185 DBG("%s:\n", __func__ );
1186 if (!dev || !stats) return -1; 1186 if (!dev || !stats) return -1;
1187 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1187 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1188 1188
@@ -1195,7 +1195,7 @@ int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1195 1195
1196int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) 1196int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1197{ 1197{
1198 DBG("%s:\n", __FUNCTION__ ); 1198 DBG("%s:\n", __func__ );
1199 if (!vendorDescr) return -1; 1199 if (!vendorDescr) return -1;
1200 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1200 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1201 1201
@@ -1207,7 +1207,7 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1207 1207
1208int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 1208int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1209{ 1209{
1210 DBG("%s: %u %u\n", __FUNCTION__, medium, speed); 1210 DBG("%s: %u %u\n", __func__, medium, speed);
1211 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1211 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1212 1212
1213 rndis_per_dev_params [configNr].medium = medium; 1213 rndis_per_dev_params [configNr].medium = medium;
@@ -1403,7 +1403,7 @@ static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1403#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1403#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1404 1404
1405 1405
1406int __devinit rndis_init (void) 1406int __init rndis_init (void)
1407{ 1407{
1408 u8 i; 1408 u8 i;
1409 1409
@@ -1415,7 +1415,7 @@ int __devinit rndis_init (void)
1415 if (!(rndis_connect_state [i] 1415 if (!(rndis_connect_state [i]
1416 = create_proc_entry (name, 0660, NULL))) 1416 = create_proc_entry (name, 0660, NULL)))
1417 { 1417 {
1418 DBG("%s :remove entries", __FUNCTION__); 1418 DBG("%s :remove entries", __func__);
1419 while (i) { 1419 while (i) {
1420 sprintf (name, NAME_TEMPLATE, --i); 1420 sprintf (name, NAME_TEMPLATE, --i);
1421 remove_proc_entry (name, NULL); 1421 remove_proc_entry (name, NULL);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index f5c3896b1d95..433b3f44f42e 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -2163,8 +2163,7 @@ static void gs_free_ports(struct gs_dev *dev)
2163 port->port_dev = NULL; 2163 port->port_dev = NULL;
2164 wake_up_interruptible(&port->port_write_wait); 2164 wake_up_interruptible(&port->port_write_wait);
2165 if (port->port_tty) { 2165 if (port->port_tty) {
2166 wake_up_interruptible(&port->port_tty->read_wait); 2166 tty_hangup(port->port_tty);
2167 wake_up_interruptible(&port->port_tty->write_wait);
2168 } 2167 }
2169 spin_unlock_irqrestore(&port->port_lock, flags); 2168 spin_unlock_irqrestore(&port->port_lock, flags);
2170 } else { 2169 } else {
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index bf8be2a41a4a..0b87480dd713 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -30,8 +30,8 @@ config USB_EHCI_HCD
30 module will be called ehci-hcd. 30 module will be called ehci-hcd.
31 31
32config USB_EHCI_ROOT_HUB_TT 32config USB_EHCI_ROOT_HUB_TT
33 bool "Root Hub Transaction Translators (EXPERIMENTAL)" 33 bool "Root Hub Transaction Translators"
34 depends on USB_EHCI_HCD && EXPERIMENTAL 34 depends on USB_EHCI_HCD
35 ---help--- 35 ---help---
36 Some EHCI chips have vendor-specific extensions to integrate 36 Some EHCI chips have vendor-specific extensions to integrate
37 transaction translators, so that no OHCI or UHCI companion 37 transaction translators, so that no OHCI or UHCI companion
@@ -260,3 +260,9 @@ config USB_R8A66597_HCD
260 To compile this driver as a module, choose M here: the 260 To compile this driver as a module, choose M here: the
261 module will be called r8a66597-hcd. 261 module will be called r8a66597-hcd.
262 262
263config SUPERH_ON_CHIP_R8A66597
264 boolean "Enable SuperH on-chip USB like the R8A66597"
265 depends on USB_R8A66597_HCD && CPU_SUBTYPE_SH7366
266 help
267 Renesas SuperH processor has USB like the R8A66597.
268 This driver supported processor is SH7366.
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index da7532d38bf1..8b5f991e949c 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -237,6 +237,7 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
237 if (usb_disabled()) 237 if (usb_disabled())
238 return -ENODEV; 238 return -ENODEV;
239 239
240 /* FIXME we only want one one probe() not two */
240 ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev); 241 ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
241 return ret; 242 return ret;
242} 243}
@@ -245,6 +246,7 @@ static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
245{ 246{
246 struct usb_hcd *hcd = platform_get_drvdata(pdev); 247 struct usb_hcd *hcd = platform_get_drvdata(pdev);
247 248
249 /* FIXME we only want one one remove() not two */
248 usb_ehci_au1xxx_remove(hcd, pdev); 250 usb_ehci_au1xxx_remove(hcd, pdev);
249 return 0; 251 return 0;
250} 252}
@@ -265,7 +267,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
265 return 0; 267 return 0;
266} 268}
267*/ 269*/
268MODULE_ALIAS("au1xxx-ehci"); 270MODULE_ALIAS("platform:au1xxx-ehci");
269static struct platform_driver ehci_hcd_au1xxx_driver = { 271static struct platform_driver ehci_hcd_au1xxx_driver = {
270 .probe = ehci_hcd_au1xxx_drv_probe, 272 .probe = ehci_hcd_au1xxx_drv_probe,
271 .remove = ehci_hcd_au1xxx_drv_remove, 273 .remove = ehci_hcd_au1xxx_drv_remove,
@@ -274,6 +276,5 @@ static struct platform_driver ehci_hcd_au1xxx_driver = {
274 /*.resume = ehci_hcd_au1xxx_drv_resume, */ 276 /*.resume = ehci_hcd_au1xxx_drv_resume, */
275 .driver = { 277 .driver = {
276 .name = "au1xxx-ehci", 278 .name = "au1xxx-ehci",
277 .bus = &platform_bus_type
278 } 279 }
279}; 280};
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 64ebfc5548a3..4af90df8e7de 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -27,7 +27,7 @@
27#define ehci_warn(ehci, fmt, args...) \ 27#define ehci_warn(ehci, fmt, args...) \
28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args ) 28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
29 29
30#ifdef EHCI_VERBOSE_DEBUG 30#ifdef VERBOSE_DEBUG
31# define vdbg dbg 31# define vdbg dbg
32# define ehci_vdbg ehci_dbg 32# define ehci_vdbg ehci_dbg
33#else 33#else
@@ -670,7 +670,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
670 670
671 spin_lock_irqsave (&ehci->lock, flags); 671 spin_lock_irqsave (&ehci->lock, flags);
672 672
673 if (buf->bus->controller->power.power_state.event) { 673 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
674 size = scnprintf (next, size, 674 size = scnprintf (next, size,
675 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 675 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
676 "%s\n" 676 "%s\n"
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index adb0defa1631..6d9bed6c1f48 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -1,5 +1,4 @@
1/* 1/*
2 * (C) Copyright David Brownell 2000-2002
3 * Copyright (c) 2005 MontaVista Software 2 * Copyright (c) 2005 MontaVista Software
4 * 3 *
5 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
@@ -28,7 +27,6 @@
28/* FIXME: Power Management is un-ported so temporarily disable it */ 27/* FIXME: Power Management is un-ported so temporarily disable it */
29#undef CONFIG_PM 28#undef CONFIG_PM
30 29
31/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
32 30
33/* configure so an HC device and id are always provided */ 31/* configure so an HC device and id are always provided */
34/* always called with process context; sleeping is OK */ 32/* always called with process context; sleeping is OK */
@@ -331,6 +329,7 @@ static int ehci_fsl_drv_probe(struct platform_device *pdev)
331 if (usb_disabled()) 329 if (usb_disabled())
332 return -ENODEV; 330 return -ENODEV;
333 331
332 /* FIXME we only want one one probe() not two */
334 return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev); 333 return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
335} 334}
336 335
@@ -338,12 +337,12 @@ static int ehci_fsl_drv_remove(struct platform_device *pdev)
338{ 337{
339 struct usb_hcd *hcd = platform_get_drvdata(pdev); 338 struct usb_hcd *hcd = platform_get_drvdata(pdev);
340 339
340 /* FIXME we only want one one remove() not two */
341 usb_hcd_fsl_remove(hcd, pdev); 341 usb_hcd_fsl_remove(hcd, pdev);
342
343 return 0; 342 return 0;
344} 343}
345 344
346MODULE_ALIAS("fsl-ehci"); 345MODULE_ALIAS("platform:fsl-ehci");
347 346
348static struct platform_driver ehci_fsl_driver = { 347static struct platform_driver ehci_fsl_driver = {
349 .probe = ehci_fsl_drv_probe, 348 .probe = ehci_fsl_drv_probe,
@@ -351,5 +350,5 @@ static struct platform_driver ehci_fsl_driver = {
351 .shutdown = usb_hcd_platform_shutdown, 350 .shutdown = usb_hcd_platform_shutdown,
352 .driver = { 351 .driver = {
353 .name = "fsl-ehci", 352 .name = "fsl-ehci",
354 }, 353 },
355}; 354};
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 85074cb36f38..369a8a5ea7bb 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -57,35 +57,6 @@
57 * Special thanks to Intel and VIA for providing host controllers to 57 * Special thanks to Intel and VIA for providing host controllers to
58 * test this driver on, and Cypress (including In-System Design) for 58 * test this driver on, and Cypress (including In-System Design) for
59 * providing early devices for those host controllers to talk to! 59 * providing early devices for those host controllers to talk to!
60 *
61 * HISTORY:
62 *
63 * 2004-05-10 Root hub and PCI suspend/resume support; remote wakeup. (db)
64 * 2004-02-24 Replace pci_* with generic dma_* API calls (dsaxena@plexity.net)
65 * 2003-12-29 Rewritten high speed iso transfer support (by Michal Sojka,
66 * <sojkam@centrum.cz>, updates by DB).
67 *
68 * 2002-11-29 Correct handling for hw async_next register.
69 * 2002-08-06 Handling for bulk and interrupt transfers is mostly shared;
70 * only scheduling is different, no arbitrary limitations.
71 * 2002-07-25 Sanity check PCI reads, mostly for better cardbus support,
72 * clean up HC run state handshaking.
73 * 2002-05-24 Preliminary FS/LS interrupts, using scheduling shortcuts
74 * 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other
75 * missing pieces: enabling 64bit dma, handoff from BIOS/SMM.
76 * 2002-05-07 Some error path cleanups to report better errors; wmb();
77 * use non-CVS version id; better iso bandwidth claim.
78 * 2002-04-19 Control/bulk/interrupt submit no longer uses giveback() on
79 * errors in submit path. Bugfixes to interrupt scheduling/processing.
80 * 2002-03-05 Initial high-speed ISO support; reduce ITD memory; shift
81 * more checking to generic hcd framework (db). Make it work with
82 * Philips EHCI; reduce PCI traffic; shorten IRQ path (Rory Bolt).
83 * 2002-01-14 Minor cleanup; version synch.
84 * 2002-01-08 Fix roothub handoff of FS/LS to companion controllers.
85 * 2002-01-04 Control/Bulk queuing behaves.
86 *
87 * 2001-12-12 Initial patch version for Linux 2.5.1 kernel.
88 * 2001-June Works with usb-storage and NEC EHCI on 2.4
89 */ 60 */
90 61
91#define DRIVER_VERSION "10 Dec 2004" 62#define DRIVER_VERSION "10 Dec 2004"
@@ -95,7 +66,7 @@
95static const char hcd_name [] = "ehci_hcd"; 66static const char hcd_name [] = "ehci_hcd";
96 67
97 68
98#undef EHCI_VERBOSE_DEBUG 69#undef VERBOSE_DEBUG
99#undef EHCI_URB_TRACE 70#undef EHCI_URB_TRACE
100 71
101#ifdef DEBUG 72#ifdef DEBUG
@@ -174,6 +145,16 @@ static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
174 return -ETIMEDOUT; 145 return -ETIMEDOUT;
175} 146}
176 147
148static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr,
149 u32 mask, u32 done, int usec)
150{
151 int error = handshake(ehci, ptr, mask, done, usec);
152 if (error)
153 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
154
155 return error;
156}
157
177/* force HC to halt state from unknown (EHCI spec section 2.3) */ 158/* force HC to halt state from unknown (EHCI spec section 2.3) */
178static int ehci_halt (struct ehci_hcd *ehci) 159static int ehci_halt (struct ehci_hcd *ehci)
179{ 160{
@@ -246,11 +227,9 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
246 /* wait for any schedule enables/disables to take effect */ 227 /* wait for any schedule enables/disables to take effect */
247 temp = ehci_readl(ehci, &ehci->regs->command) << 10; 228 temp = ehci_readl(ehci, &ehci->regs->command) << 10;
248 temp &= STS_ASS | STS_PSS; 229 temp &= STS_ASS | STS_PSS;
249 if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS, 230 if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
250 temp, 16 * 125) != 0) { 231 STS_ASS | STS_PSS, temp, 16 * 125))
251 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
252 return; 232 return;
253 }
254 233
255 /* then disable anything that's still active */ 234 /* then disable anything that's still active */
256 temp = ehci_readl(ehci, &ehci->regs->command); 235 temp = ehci_readl(ehci, &ehci->regs->command);
@@ -258,11 +237,8 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
258 ehci_writel(ehci, temp, &ehci->regs->command); 237 ehci_writel(ehci, temp, &ehci->regs->command);
259 238
260 /* hardware can take 16 microframes to turn off ... */ 239 /* hardware can take 16 microframes to turn off ... */
261 if (handshake (ehci, &ehci->regs->status, STS_ASS | STS_PSS, 240 handshake_on_error_set_halt(ehci, &ehci->regs->status,
262 0, 16 * 125) != 0) { 241 STS_ASS | STS_PSS, 0, 16 * 125);
263 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
264 return;
265 }
266} 242}
267 243
268/*-------------------------------------------------------------------------*/ 244/*-------------------------------------------------------------------------*/
@@ -355,17 +331,13 @@ static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
355 &ehci->regs->port_status[port]); 331 &ehci->regs->port_status[port]);
356} 332}
357 333
358/* ehci_shutdown kick in for silicon on any bus (not just pci, etc). 334/*
359 * This forcibly disables dma and IRQs, helping kexec and other cases 335 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
360 * where the next system software may expect clean state. 336 * Should be called with ehci->lock held.
361 */ 337 */
362static void 338static void ehci_silence_controller(struct ehci_hcd *ehci)
363ehci_shutdown (struct usb_hcd *hcd)
364{ 339{
365 struct ehci_hcd *ehci; 340 ehci_halt(ehci);
366
367 ehci = hcd_to_ehci (hcd);
368 (void) ehci_halt (ehci);
369 ehci_turn_off_all_ports(ehci); 341 ehci_turn_off_all_ports(ehci);
370 342
371 /* make BIOS/etc use companion controller during reboot */ 343 /* make BIOS/etc use companion controller during reboot */
@@ -375,6 +347,22 @@ ehci_shutdown (struct usb_hcd *hcd)
375 ehci_readl(ehci, &ehci->regs->configured_flag); 347 ehci_readl(ehci, &ehci->regs->configured_flag);
376} 348}
377 349
350/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
351 * This forcibly disables dma and IRQs, helping kexec and other cases
352 * where the next system software may expect clean state.
353 */
354static void ehci_shutdown(struct usb_hcd *hcd)
355{
356 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
357
358 del_timer_sync(&ehci->watchdog);
359 del_timer_sync(&ehci->iaa_watchdog);
360
361 spin_lock_irq(&ehci->lock);
362 ehci_silence_controller(ehci);
363 spin_unlock_irq(&ehci->lock);
364}
365
378static void ehci_port_power (struct ehci_hcd *ehci, int is_on) 366static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
379{ 367{
380 unsigned port; 368 unsigned port;
@@ -425,15 +413,15 @@ static void ehci_work (struct ehci_hcd *ehci)
425 timer_action (ehci, TIMER_IO_WATCHDOG); 413 timer_action (ehci, TIMER_IO_WATCHDOG);
426} 414}
427 415
416/*
417 * Called when the ehci_hcd module is removed.
418 */
428static void ehci_stop (struct usb_hcd *hcd) 419static void ehci_stop (struct usb_hcd *hcd)
429{ 420{
430 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 421 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
431 422
432 ehci_dbg (ehci, "stop\n"); 423 ehci_dbg (ehci, "stop\n");
433 424
434 /* Turn off port power on all root hub ports. */
435 ehci_port_power (ehci, 0);
436
437 /* no more interrupts ... */ 425 /* no more interrupts ... */
438 del_timer_sync (&ehci->watchdog); 426 del_timer_sync (&ehci->watchdog);
439 del_timer_sync(&ehci->iaa_watchdog); 427 del_timer_sync(&ehci->iaa_watchdog);
@@ -442,13 +430,10 @@ static void ehci_stop (struct usb_hcd *hcd)
442 if (HC_IS_RUNNING (hcd->state)) 430 if (HC_IS_RUNNING (hcd->state))
443 ehci_quiesce (ehci); 431 ehci_quiesce (ehci);
444 432
433 ehci_silence_controller(ehci);
445 ehci_reset (ehci); 434 ehci_reset (ehci);
446 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
447 spin_unlock_irq(&ehci->lock); 435 spin_unlock_irq(&ehci->lock);
448 436
449 /* let companion controllers work when we aren't */
450 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
451
452 remove_companion_file(ehci); 437 remove_companion_file(ehci);
453 remove_debug_files (ehci); 438 remove_debug_files (ehci);
454 439
@@ -676,7 +661,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
676 cmd = ehci_readl(ehci, &ehci->regs->command); 661 cmd = ehci_readl(ehci, &ehci->regs->command);
677 bh = 0; 662 bh = 0;
678 663
679#ifdef EHCI_VERBOSE_DEBUG 664#ifdef VERBOSE_DEBUG
680 /* unrequested/ignored: Frame List Rollover */ 665 /* unrequested/ignored: Frame List Rollover */
681 dbg_status (ehci, "irq", status); 666 dbg_status (ehci, "irq", status);
682#endif 667#endif
@@ -710,6 +695,8 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
710 /* remote wakeup [4.3.1] */ 695 /* remote wakeup [4.3.1] */
711 if (status & STS_PCD) { 696 if (status & STS_PCD) {
712 unsigned i = HCS_N_PORTS (ehci->hcs_params); 697 unsigned i = HCS_N_PORTS (ehci->hcs_params);
698
699 /* kick root hub later */
713 pcd_status = status; 700 pcd_status = status;
714 701
715 /* resume root hub? */ 702 /* resume root hub? */
@@ -738,8 +725,6 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
738 725
739 /* PCI errors [4.15.2.4] */ 726 /* PCI errors [4.15.2.4] */
740 if (unlikely ((status & STS_FATAL) != 0)) { 727 if (unlikely ((status & STS_FATAL) != 0)) {
741 /* bogus "fatal" IRQs appear on some chips... why? */
742 status = ehci_readl(ehci, &ehci->regs->status);
743 dbg_cmd (ehci, "fatal", ehci_readl(ehci, 728 dbg_cmd (ehci, "fatal", ehci_readl(ehci,
744 &ehci->regs->command)); 729 &ehci->regs->command));
745 dbg_status (ehci, "fatal", status); 730 dbg_status (ehci, "fatal", status);
@@ -758,7 +743,7 @@ dead:
758 if (bh) 743 if (bh)
759 ehci_work (ehci); 744 ehci_work (ehci);
760 spin_unlock (&ehci->lock); 745 spin_unlock (&ehci->lock);
761 if (pcd_status & STS_PCD) 746 if (pcd_status)
762 usb_hcd_poll_rh_status(hcd); 747 usb_hcd_poll_rh_status(hcd);
763 return IRQ_HANDLED; 748 return IRQ_HANDLED;
764} 749}
@@ -788,8 +773,14 @@ static int ehci_urb_enqueue (
788 INIT_LIST_HEAD (&qtd_list); 773 INIT_LIST_HEAD (&qtd_list);
789 774
790 switch (usb_pipetype (urb->pipe)) { 775 switch (usb_pipetype (urb->pipe)) {
791 // case PIPE_CONTROL: 776 case PIPE_CONTROL:
792 // case PIPE_BULK: 777 /* qh_completions() code doesn't handle all the fault cases
778 * in multi-TD control transfers. Even 1KB is rare anyway.
779 */
780 if (urb->transfer_buffer_length > (16 * 1024))
781 return -EMSGSIZE;
782 /* FALLTHROUGH */
783 /* case PIPE_BULK: */
793 default: 784 default:
794 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) 785 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
795 return -ENOMEM; 786 return -ENOMEM;
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 4e065e556e4b..efffef64f59d 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -28,7 +28,9 @@
28 28
29/*-------------------------------------------------------------------------*/ 29/*-------------------------------------------------------------------------*/
30 30
31#ifdef CONFIG_USB_PERSIST 31#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
32
33#ifdef CONFIG_PM
32 34
33static int ehci_hub_control( 35static int ehci_hub_control(
34 struct usb_hcd *hcd, 36 struct usb_hcd *hcd,
@@ -104,15 +106,6 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
104 ehci->owned_ports = 0; 106 ehci->owned_ports = 0;
105} 107}
106 108
107#else /* CONFIG_USB_PERSIST */
108
109static inline void ehci_handover_companion_ports(struct ehci_hcd *ehci)
110{ }
111
112#endif
113
114#ifdef CONFIG_PM
115
116static int ehci_bus_suspend (struct usb_hcd *hcd) 109static int ehci_bus_suspend (struct usb_hcd *hcd)
117{ 110{
118 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 111 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
@@ -158,10 +151,10 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
158 } 151 }
159 152
160 /* enable remote wakeup on all ports */ 153 /* enable remote wakeup on all ports */
161 if (device_may_wakeup(&hcd->self.root_hub->dev)) 154 if (hcd->self.root_hub->do_remote_wakeup)
162 t2 |= PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E; 155 t2 |= PORT_WAKE_BITS;
163 else 156 else
164 t2 &= ~(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E); 157 t2 &= ~PORT_WAKE_BITS;
165 158
166 if (t1 != t2) { 159 if (t1 != t2) {
167 ehci_vdbg (ehci, "port %d, %08x -> %08x\n", 160 ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
@@ -183,7 +176,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
183 176
184 /* allow remote wakeup */ 177 /* allow remote wakeup */
185 mask = INTR_MASK; 178 mask = INTR_MASK;
186 if (!device_may_wakeup(&hcd->self.root_hub->dev)) 179 if (!hcd->self.root_hub->do_remote_wakeup)
187 mask &= ~STS_PCD; 180 mask &= ~STS_PCD;
188 ehci_writel(ehci, mask, &ehci->regs->intr_enable); 181 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
189 ehci_readl(ehci, &ehci->regs->intr_enable); 182 ehci_readl(ehci, &ehci->regs->intr_enable);
@@ -241,8 +234,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
241 i = HCS_N_PORTS (ehci->hcs_params); 234 i = HCS_N_PORTS (ehci->hcs_params);
242 while (i--) { 235 while (i--) {
243 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 236 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
244 temp &= ~(PORT_RWC_BITS 237 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
245 | PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E);
246 if (test_bit(i, &ehci->bus_suspended) && 238 if (test_bit(i, &ehci->bus_suspended) &&
247 (temp & PORT_SUSPEND)) { 239 (temp & PORT_SUSPEND)) {
248 ehci->reset_done [i] = jiffies + msecs_to_jiffies (20); 240 ehci->reset_done [i] = jiffies + msecs_to_jiffies (20);
@@ -281,9 +273,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
281 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); 273 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
282 274
283 spin_unlock_irq (&ehci->lock); 275 spin_unlock_irq (&ehci->lock);
284 276 ehci_handover_companion_ports(ehci);
285 if (!power_okay)
286 ehci_handover_companion_ports(ehci);
287 return 0; 277 return 0;
288} 278}
289 279
@@ -545,8 +535,6 @@ ehci_hub_descriptor (
545 535
546/*-------------------------------------------------------------------------*/ 536/*-------------------------------------------------------------------------*/
547 537
548#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
549
550static int ehci_hub_control ( 538static int ehci_hub_control (
551 struct usb_hcd *hcd, 539 struct usb_hcd *hcd,
552 u16 typeReq, 540 u16 typeReq,
@@ -778,7 +766,7 @@ static int ehci_hub_control (
778 if (temp & PORT_POWER) 766 if (temp & PORT_POWER)
779 status |= 1 << USB_PORT_FEAT_POWER; 767 status |= 1 << USB_PORT_FEAT_POWER;
780 768
781#ifndef EHCI_VERBOSE_DEBUG 769#ifndef VERBOSE_DEBUG
782 if (status & ~0xffff) /* only if wPortChange is interesting */ 770 if (status & ~0xffff) /* only if wPortChange is interesting */
783#endif 771#endif
784 dbg_port (ehci, "GetStatus", wIndex + 1, temp); 772 dbg_port (ehci, "GetStatus", wIndex + 1, temp);
@@ -812,8 +800,6 @@ static int ehci_hub_control (
812 if ((temp & PORT_PE) == 0 800 if ((temp & PORT_PE) == 0
813 || (temp & PORT_RESET) != 0) 801 || (temp & PORT_RESET) != 0)
814 goto error; 802 goto error;
815 if (device_may_wakeup(&hcd->self.root_hub->dev))
816 temp |= PORT_WAKE_BITS;
817 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 803 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
818 break; 804 break;
819 case USB_PORT_FEAT_POWER: 805 case USB_PORT_FEAT_POWER:
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
index 3041d8f055f4..601c8795a854 100644
--- a/drivers/usb/host/ehci-ixp4xx.c
+++ b/drivers/usb/host/ehci-ixp4xx.c
@@ -140,13 +140,12 @@ static int ixp4xx_ehci_remove(struct platform_device *pdev)
140 return 0; 140 return 0;
141} 141}
142 142
143MODULE_ALIAS("ixp4xx-ehci"); 143MODULE_ALIAS("platform:ixp4xx-ehci");
144 144
145static struct platform_driver ixp4xx_ehci_driver = { 145static struct platform_driver ixp4xx_ehci_driver = {
146 .probe = ixp4xx_ehci_probe, 146 .probe = ixp4xx_ehci_probe,
147 .remove = ixp4xx_ehci_remove, 147 .remove = ixp4xx_ehci_remove,
148 .driver = { 148 .driver = {
149 .name = "ixp4xx-ehci", 149 .name = "ixp4xx-ehci",
150 .bus = &platform_bus_type
151 }, 150 },
152}; 151};
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 72ccd56e36dd..5bb7f6bb13f3 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -130,6 +130,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
130 case PCI_VENDOR_ID_TDI: 130 case PCI_VENDOR_ID_TDI:
131 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 131 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
132 ehci->is_tdi_rh_tt = 1; 132 ehci->is_tdi_rh_tt = 1;
133 hcd->has_tt = 1;
133 tdi_reset(ehci); 134 tdi_reset(ehci);
134 } 135 }
135 break; 136 break;
@@ -221,6 +222,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
221 ehci_warn(ehci, "selective suspend/wakeup unavailable\n"); 222 ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
222#endif 223#endif
223 224
225 ehci_port_power(ehci, 1);
224 retval = ehci_pci_reinit(ehci, pdev); 226 retval = ehci_pci_reinit(ehci, pdev);
225done: 227done:
226 return retval; 228 return retval;
@@ -299,7 +301,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd)
299 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) { 301 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
300 int mask = INTR_MASK; 302 int mask = INTR_MASK;
301 303
302 if (!device_may_wakeup(&hcd->self.root_hub->dev)) 304 if (!hcd->self.root_hub->do_remote_wakeup)
303 mask &= ~STS_PCD; 305 mask &= ~STS_PCD;
304 ehci_writel(ehci, mask, &ehci->regs->intr_enable); 306 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
305 ehci_readl(ehci, &ehci->regs->intr_enable); 307 ehci_readl(ehci, &ehci->regs->intr_enable);
@@ -329,7 +331,6 @@ static int ehci_pci_resume(struct usb_hcd *hcd)
329 331
330 /* here we "know" root ports should always stay powered */ 332 /* here we "know" root ports should always stay powered */
331 ehci_port_power(ehci, 1); 333 ehci_port_power(ehci, 1);
332 ehci_handover_companion_ports(ehci);
333 334
334 hcd->state = HC_STATE_SUSPENDED; 335 hcd->state = HC_STATE_SUSPENDED;
335 return 0; 336 return 0;
@@ -353,8 +354,8 @@ static const struct hc_driver ehci_pci_hc_driver = {
353 .reset = ehci_pci_setup, 354 .reset = ehci_pci_setup,
354 .start = ehci_run, 355 .start = ehci_run,
355#ifdef CONFIG_PM 356#ifdef CONFIG_PM
356 .suspend = ehci_pci_suspend, 357 .pci_suspend = ehci_pci_suspend,
357 .resume = ehci_pci_resume, 358 .pci_resume = ehci_pci_resume,
358#endif 359#endif
359 .stop = ehci_stop, 360 .stop = ehci_stop,
360 .shutdown = ehci_shutdown, 361 .shutdown = ehci_shutdown,
diff --git a/drivers/usb/host/ehci-ppc-soc.c b/drivers/usb/host/ehci-ppc-soc.c
index a3249078c808..6c76036783a1 100644
--- a/drivers/usb/host/ehci-ppc-soc.c
+++ b/drivers/usb/host/ehci-ppc-soc.c
@@ -175,6 +175,7 @@ static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
175 if (usb_disabled()) 175 if (usb_disabled())
176 return -ENODEV; 176 return -ENODEV;
177 177
178 /* FIXME we only want one one probe() not two */
178 ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev); 179 ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev);
179 return ret; 180 return ret;
180} 181}
@@ -183,17 +184,17 @@ static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
183{ 184{
184 struct usb_hcd *hcd = platform_get_drvdata(pdev); 185 struct usb_hcd *hcd = platform_get_drvdata(pdev);
185 186
187 /* FIXME we only want one one remove() not two */
186 usb_ehci_ppc_soc_remove(hcd, pdev); 188 usb_ehci_ppc_soc_remove(hcd, pdev);
187 return 0; 189 return 0;
188} 190}
189 191
190MODULE_ALIAS("ppc-soc-ehci"); 192MODULE_ALIAS("platform:ppc-soc-ehci");
191static struct platform_driver ehci_ppc_soc_driver = { 193static struct platform_driver ehci_ppc_soc_driver = {
192 .probe = ehci_hcd_ppc_soc_drv_probe, 194 .probe = ehci_hcd_ppc_soc_drv_probe,
193 .remove = ehci_hcd_ppc_soc_drv_remove, 195 .remove = ehci_hcd_ppc_soc_drv_remove,
194 .shutdown = usb_hcd_platform_shutdown, 196 .shutdown = usb_hcd_platform_shutdown,
195 .driver = { 197 .driver = {
196 .name = "ppc-soc-ehci", 198 .name = "ppc-soc-ehci",
197 .bus = &platform_bus_type
198 } 199 }
199}; 200};
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index bbda58eb8813..69782221bcf3 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -125,7 +125,6 @@ static int ps3_ehci_probe(struct ps3_system_bus_device *dev)
125 goto fail_irq; 125 goto fail_irq;
126 } 126 }
127 127
128 dev->core.power.power_state = PMSG_ON;
129 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */ 128 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
130 129
131 hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev->core.bus_id); 130 hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev->core.bus_id);
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 2e49de820b14..5ae689139dd0 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -242,7 +242,8 @@ __acquires(ehci->lock)
242 if (unlikely(urb->unlinked)) { 242 if (unlikely(urb->unlinked)) {
243 COUNT(ehci->stats.unlink); 243 COUNT(ehci->stats.unlink);
244 } else { 244 } else {
245 if (likely(status == -EINPROGRESS)) 245 /* report non-error and short read status as zero */
246 if (status == -EINPROGRESS || status == -EREMOTEIO)
246 status = 0; 247 status = 0;
247 COUNT(ehci->stats.complete); 248 COUNT(ehci->stats.complete);
248 } 249 }
@@ -250,7 +251,7 @@ __acquires(ehci->lock)
250#ifdef EHCI_URB_TRACE 251#ifdef EHCI_URB_TRACE
251 ehci_dbg (ehci, 252 ehci_dbg (ehci,
252 "%s %s urb %p ep%d%s status %d len %d/%d\n", 253 "%s %s urb %p ep%d%s status %d len %d/%d\n",
253 __FUNCTION__, urb->dev->devpath, urb, 254 __func__, urb->dev->devpath, urb,
254 usb_pipeendpoint (urb->pipe), 255 usb_pipeendpoint (urb->pipe),
255 usb_pipein (urb->pipe) ? "in" : "out", 256 usb_pipein (urb->pipe) ? "in" : "out",
256 status, 257 status,
@@ -283,7 +284,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
283 int last_status = -EINPROGRESS; 284 int last_status = -EINPROGRESS;
284 int stopped; 285 int stopped;
285 unsigned count = 0; 286 unsigned count = 0;
286 int do_status = 0;
287 u8 state; 287 u8 state;
288 u32 halt = HALT_BIT(ehci); 288 u32 halt = HALT_BIT(ehci);
289 289
@@ -309,7 +309,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
309 struct ehci_qtd *qtd; 309 struct ehci_qtd *qtd;
310 struct urb *urb; 310 struct urb *urb;
311 u32 token = 0; 311 u32 token = 0;
312 int qtd_status;
313 312
314 qtd = list_entry (entry, struct ehci_qtd, qtd_list); 313 qtd = list_entry (entry, struct ehci_qtd, qtd_list);
315 urb = qtd->urb; 314 urb = qtd->urb;
@@ -336,11 +335,20 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
336 /* always clean up qtds the hc de-activated */ 335 /* always clean up qtds the hc de-activated */
337 if ((token & QTD_STS_ACTIVE) == 0) { 336 if ((token & QTD_STS_ACTIVE) == 0) {
338 337
338 /* on STALL, error, and short reads this urb must
339 * complete and all its qtds must be recycled.
340 */
339 if ((token & QTD_STS_HALT) != 0) { 341 if ((token & QTD_STS_HALT) != 0) {
340 stopped = 1; 342 stopped = 1;
341 343
342 /* magic dummy for some short reads; qh won't advance. 344 /* magic dummy for some short reads; qh won't advance.
343 * that silicon quirk can kick in with this dummy too. 345 * that silicon quirk can kick in with this dummy too.
346 *
347 * other short reads won't stop the queue, including
348 * control transfers (status stage handles that) or
349 * most other single-qtd reads ... the queue stops if
350 * URB_SHORT_NOT_OK was set so the driver submitting
351 * the urbs could clean it up.
344 */ 352 */
345 } else if (IS_SHORT_READ (token) 353 } else if (IS_SHORT_READ (token)
346 && !(qtd->hw_alt_next 354 && !(qtd->hw_alt_next
@@ -354,28 +362,21 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
354 && HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) { 362 && HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) {
355 break; 363 break;
356 364
365 /* scan the whole queue for unlinks whenever it stops */
357 } else { 366 } else {
358 stopped = 1; 367 stopped = 1;
359 368
360 if (unlikely (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) 369 /* cancel everything if we halt, suspend, etc */
370 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state))
361 last_status = -ESHUTDOWN; 371 last_status = -ESHUTDOWN;
362 372
363 /* ignore active urbs unless some previous qtd 373 /* this qtd is active; skip it unless a previous qtd
364 * for the urb faulted (including short read) or 374 * for its urb faulted, or its urb was canceled.
365 * its urb was canceled. we may patch qh or qtds.
366 */ 375 */
367 if (likely(last_status == -EINPROGRESS && 376 else if (last_status == -EINPROGRESS && !urb->unlinked)
368 !urb->unlinked))
369 continue;
370
371 /* issue status after short control reads */
372 if (unlikely (do_status != 0)
373 && QTD_PID (token) == 0 /* OUT */) {
374 do_status = 0;
375 continue; 377 continue;
376 }
377 378
378 /* token in overlay may be most current */ 379 /* qh unlinked; token in overlay may be most current */
379 if (state == QH_STATE_IDLE 380 if (state == QH_STATE_IDLE
380 && cpu_to_hc32(ehci, qtd->qtd_dma) 381 && cpu_to_hc32(ehci, qtd->qtd_dma)
381 == qh->hw_current) 382 == qh->hw_current)
@@ -392,21 +393,32 @@ halt:
392 } 393 }
393 } 394 }
394 395
395 /* remove it from the queue */ 396 /* unless we already know the urb's status, collect qtd status
396 qtd_status = qtd_copy_status(ehci, urb, qtd->length, token); 397 * and update count of bytes transferred. in common short read
397 if (unlikely(qtd_status == -EREMOTEIO)) { 398 * cases with only one data qtd (including control transfers),
398 do_status = (!urb->unlinked && 399 * queue processing won't halt. but with two or more qtds (for
399 usb_pipecontrol(urb->pipe)); 400 * example, with a 32 KB transfer), when the first qtd gets a
400 qtd_status = 0; 401 * short read the second must be removed by hand.
402 */
403 if (last_status == -EINPROGRESS) {
404 last_status = qtd_copy_status(ehci, urb,
405 qtd->length, token);
406 if (last_status == -EREMOTEIO
407 && (qtd->hw_alt_next
408 & EHCI_LIST_END(ehci)))
409 last_status = -EINPROGRESS;
401 } 410 }
402 if (likely(last_status == -EINPROGRESS))
403 last_status = qtd_status;
404 411
412 /* if we're removing something not at the queue head,
413 * patch the hardware queue pointer.
414 */
405 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { 415 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
406 last = list_entry (qtd->qtd_list.prev, 416 last = list_entry (qtd->qtd_list.prev,
407 struct ehci_qtd, qtd_list); 417 struct ehci_qtd, qtd_list);
408 last->hw_next = qtd->hw_next; 418 last->hw_next = qtd->hw_next;
409 } 419 }
420
421 /* remove qtd; it's recycled after possible urb completion */
410 list_del (&qtd->qtd_list); 422 list_del (&qtd->qtd_list);
411 last = qtd; 423 last = qtd;
412 } 424 }
@@ -431,7 +443,15 @@ halt:
431 qh_refresh(ehci, qh); 443 qh_refresh(ehci, qh);
432 break; 444 break;
433 case QH_STATE_LINKED: 445 case QH_STATE_LINKED:
434 /* should be rare for periodic transfers, 446 /* We won't refresh a QH that's linked (after the HC
447 * stopped the queue). That avoids a race:
448 * - HC reads first part of QH;
449 * - CPU updates that first part and the token;
450 * - HC reads rest of that QH, including token
451 * Result: HC gets an inconsistent image, and then
452 * DMAs to/from the wrong memory (corrupting it).
453 *
454 * That should be rare for interrupt transfers,
435 * except maybe high bandwidth ... 455 * except maybe high bandwidth ...
436 */ 456 */
437 if ((cpu_to_hc32(ehci, QH_SMASK) 457 if ((cpu_to_hc32(ehci, QH_SMASK)
@@ -549,6 +569,12 @@ qh_urb_transaction (
549 this_qtd_len = qtd_fill(ehci, qtd, buf, len, token, maxpacket); 569 this_qtd_len = qtd_fill(ehci, qtd, buf, len, token, maxpacket);
550 len -= this_qtd_len; 570 len -= this_qtd_len;
551 buf += this_qtd_len; 571 buf += this_qtd_len;
572
573 /*
574 * short reads advance to a "magic" dummy instead of the next
575 * qtd ... that forces the queue to stop, for manual cleanup.
576 * (this will usually be overridden later.)
577 */
552 if (is_input) 578 if (is_input)
553 qtd->hw_alt_next = ehci->async->hw_alt_next; 579 qtd->hw_alt_next = ehci->async->hw_alt_next;
554 580
@@ -568,8 +594,10 @@ qh_urb_transaction (
568 list_add_tail (&qtd->qtd_list, head); 594 list_add_tail (&qtd->qtd_list, head);
569 } 595 }
570 596
571 /* unless the bulk/interrupt caller wants a chance to clean 597 /*
572 * up after short reads, hc should advance qh past this urb 598 * unless the caller requires manual cleanup after short reads,
599 * have the alt_next mechanism keep the queue running after the
600 * last data qtd (the only one, for control and most other cases).
573 */ 601 */
574 if (likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 602 if (likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0
575 || usb_pipecontrol (urb->pipe))) 603 || usb_pipecontrol (urb->pipe)))
@@ -657,6 +685,14 @@ qh_make (
657 type = usb_pipetype (urb->pipe); 685 type = usb_pipetype (urb->pipe);
658 maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input); 686 maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
659 687
688 /* 1024 byte maxpacket is a hardware ceiling. High bandwidth
689 * acts like up to 3KB, but is built from smaller packets.
690 */
691 if (max_packet(maxp) > 1024) {
692 ehci_dbg(ehci, "bogus qh maxpacket %d\n", max_packet(maxp));
693 goto done;
694 }
695
660 /* Compute interrupt scheduling parameters just once, and save. 696 /* Compute interrupt scheduling parameters just once, and save.
661 * - allowing for high bandwidth, how many nsec/uframe are used? 697 * - allowing for high bandwidth, how many nsec/uframe are used?
662 * - split transactions need a second CSPLIT uframe; same question 698 * - split transactions need a second CSPLIT uframe; same question
@@ -757,7 +793,13 @@ qh_make (
757 info2 |= (EHCI_TUNE_MULT_HS << 30); 793 info2 |= (EHCI_TUNE_MULT_HS << 30);
758 } else if (type == PIPE_BULK) { 794 } else if (type == PIPE_BULK) {
759 info1 |= (EHCI_TUNE_RL_HS << 28); 795 info1 |= (EHCI_TUNE_RL_HS << 28);
760 info1 |= 512 << 16; /* usb2 fixed maxpacket */ 796 /* The USB spec says that high speed bulk endpoints
797 * always use 512 byte maxpacket. But some device
798 * vendors decided to ignore that, and MSFT is happy
799 * to help them do so. So now people expect to use
800 * such nonconformant devices with Linux too; sigh.
801 */
802 info1 |= max_packet(maxp) << 16;
761 info2 |= (EHCI_TUNE_MULT_HS << 30); 803 info2 |= (EHCI_TUNE_MULT_HS << 30);
762 } else { /* PIPE_INTERRUPT */ 804 } else { /* PIPE_INTERRUPT */
763 info1 |= max_packet (maxp) << 16; 805 info1 |= max_packet (maxp) << 16;
@@ -932,7 +974,7 @@ submit_async (
932#ifdef EHCI_URB_TRACE 974#ifdef EHCI_URB_TRACE
933 ehci_dbg (ehci, 975 ehci_dbg (ehci,
934 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", 976 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
935 __FUNCTION__, urb->dev->devpath, urb, 977 __func__, urb->dev->devpath, urb,
936 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", 978 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
937 urb->transfer_buffer_length, 979 urb->transfer_buffer_length,
938 qtd, urb->ep->hcpriv); 980 qtd, urb->ep->hcpriv);
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 8a8e08a51ba3..be575e46eac3 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -440,11 +440,10 @@ static int enable_periodic (struct ehci_hcd *ehci)
440 /* did clearing PSE did take effect yet? 440 /* did clearing PSE did take effect yet?
441 * takes effect only at frame boundaries... 441 * takes effect only at frame boundaries...
442 */ 442 */
443 status = handshake(ehci, &ehci->regs->status, STS_PSS, 0, 9 * 125); 443 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
444 if (status != 0) { 444 STS_PSS, 0, 9 * 125);
445 ehci_to_hcd(ehci)->state = HC_STATE_HALT; 445 if (status)
446 return status; 446 return status;
447 }
448 447
449 cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE; 448 cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE;
450 ehci_writel(ehci, cmd, &ehci->regs->command); 449 ehci_writel(ehci, cmd, &ehci->regs->command);
@@ -465,11 +464,10 @@ static int disable_periodic (struct ehci_hcd *ehci)
465 /* did setting PSE not take effect yet? 464 /* did setting PSE not take effect yet?
466 * takes effect only at frame boundaries... 465 * takes effect only at frame boundaries...
467 */ 466 */
468 status = handshake(ehci, &ehci->regs->status, STS_PSS, STS_PSS, 9 * 125); 467 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
469 if (status != 0) { 468 STS_PSS, STS_PSS, 9 * 125);
470 ehci_to_hcd(ehci)->state = HC_STATE_HALT; 469 if (status)
471 return status; 470 return status;
472 }
473 471
474 cmd = ehci_readl(ehci, &ehci->regs->command) & ~CMD_PSE; 472 cmd = ehci_readl(ehci, &ehci->regs->command) & ~CMD_PSE;
475 ehci_writel(ehci, cmd, &ehci->regs->command); 473 ehci_writel(ehci, cmd, &ehci->regs->command);
@@ -1183,21 +1181,18 @@ itd_urb_transaction (
1183 struct ehci_itd, itd_list); 1181 struct ehci_itd, itd_list);
1184 list_del (&itd->itd_list); 1182 list_del (&itd->itd_list);
1185 itd_dma = itd->itd_dma; 1183 itd_dma = itd->itd_dma;
1186 } else 1184 } else {
1187 itd = NULL;
1188
1189 if (!itd) {
1190 spin_unlock_irqrestore (&ehci->lock, flags); 1185 spin_unlock_irqrestore (&ehci->lock, flags);
1191 itd = dma_pool_alloc (ehci->itd_pool, mem_flags, 1186 itd = dma_pool_alloc (ehci->itd_pool, mem_flags,
1192 &itd_dma); 1187 &itd_dma);
1193 spin_lock_irqsave (&ehci->lock, flags); 1188 spin_lock_irqsave (&ehci->lock, flags);
1189 if (!itd) {
1190 iso_sched_free(stream, sched);
1191 spin_unlock_irqrestore(&ehci->lock, flags);
1192 return -ENOMEM;
1193 }
1194 } 1194 }
1195 1195
1196 if (unlikely (NULL == itd)) {
1197 iso_sched_free (stream, sched);
1198 spin_unlock_irqrestore (&ehci->lock, flags);
1199 return -ENOMEM;
1200 }
1201 memset (itd, 0, sizeof *itd); 1196 memset (itd, 0, sizeof *itd);
1202 itd->itd_dma = itd_dma; 1197 itd->itd_dma = itd_dma;
1203 list_add (&itd->itd_list, &sched->td_list); 1198 list_add (&itd->itd_list, &sched->td_list);
@@ -1682,7 +1677,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1682#ifdef EHCI_URB_TRACE 1677#ifdef EHCI_URB_TRACE
1683 ehci_dbg (ehci, 1678 ehci_dbg (ehci,
1684 "%s %s urb %p ep%d%s len %d, %d pkts %d uframes [%p]\n", 1679 "%s %s urb %p ep%d%s len %d, %d pkts %d uframes [%p]\n",
1685 __FUNCTION__, urb->dev->devpath, urb, 1680 __func__, urb->dev->devpath, urb,
1686 usb_pipeendpoint (urb->pipe), 1681 usb_pipeendpoint (urb->pipe),
1687 usb_pipein (urb->pipe) ? "in" : "out", 1682 usb_pipein (urb->pipe) ? "in" : "out",
1688 urb->transfer_buffer_length, 1683 urb->transfer_buffer_length,
@@ -1816,21 +1811,18 @@ sitd_urb_transaction (
1816 struct ehci_sitd, sitd_list); 1811 struct ehci_sitd, sitd_list);
1817 list_del (&sitd->sitd_list); 1812 list_del (&sitd->sitd_list);
1818 sitd_dma = sitd->sitd_dma; 1813 sitd_dma = sitd->sitd_dma;
1819 } else 1814 } else {
1820 sitd = NULL;
1821
1822 if (!sitd) {
1823 spin_unlock_irqrestore (&ehci->lock, flags); 1815 spin_unlock_irqrestore (&ehci->lock, flags);
1824 sitd = dma_pool_alloc (ehci->sitd_pool, mem_flags, 1816 sitd = dma_pool_alloc (ehci->sitd_pool, mem_flags,
1825 &sitd_dma); 1817 &sitd_dma);
1826 spin_lock_irqsave (&ehci->lock, flags); 1818 spin_lock_irqsave (&ehci->lock, flags);
1819 if (!sitd) {
1820 iso_sched_free(stream, iso_sched);
1821 spin_unlock_irqrestore(&ehci->lock, flags);
1822 return -ENOMEM;
1823 }
1827 } 1824 }
1828 1825
1829 if (!sitd) {
1830 iso_sched_free (stream, iso_sched);
1831 spin_unlock_irqrestore (&ehci->lock, flags);
1832 return -ENOMEM;
1833 }
1834 memset (sitd, 0, sizeof *sitd); 1826 memset (sitd, 0, sizeof *sitd);
1835 sitd->sitd_dma = sitd_dma; 1827 sitd->sitd_dma = sitd_dma;
1836 list_add (&sitd->sitd_list, &iso_sched->td_list); 1828 list_add (&sitd->sitd_list, &iso_sched->td_list);
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 203a3359a648..20b9a0d07420 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1400,7 +1400,7 @@ static int isp116x_bus_suspend(struct usb_hcd *hcd)
1400 spin_unlock_irqrestore(&isp116x->lock, flags); 1400 spin_unlock_irqrestore(&isp116x->lock, flags);
1401 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE); 1401 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1402 val |= HCCONTROL_USB_SUSPEND; 1402 val |= HCCONTROL_USB_SUSPEND;
1403 if (device_may_wakeup(&hcd->self.root_hub->dev)) 1403 if (hcd->self.root_hub->do_remote_wakeup)
1404 val |= HCCONTROL_RWE; 1404 val |= HCCONTROL_RWE;
1405 /* Wait for usb transfers to finish */ 1405 /* Wait for usb transfers to finish */
1406 msleep(2); 1406 msleep(2);
@@ -1442,11 +1442,6 @@ static int isp116x_bus_resume(struct usb_hcd *hcd)
1442 break; 1442 break;
1443 case HCCONTROL_USB_OPER: 1443 case HCCONTROL_USB_OPER:
1444 spin_unlock_irq(&isp116x->lock); 1444 spin_unlock_irq(&isp116x->lock);
1445 /* Without setting power_state here the
1446 SUSPENDED state won't be removed from
1447 sysfs/usbN/power.state as a response to remote
1448 wakeup. Maybe in the future. */
1449 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1450 return 0; 1445 return 0;
1451 default: 1446 default:
1452 /* HCCONTROL_USB_RESET: this may happen, when during 1447 /* HCCONTROL_USB_RESET: this may happen, when during
@@ -1460,7 +1455,6 @@ static int isp116x_bus_resume(struct usb_hcd *hcd)
1460 if ((isp116x->rhdesca & RH_A_NDP) == 2) 1455 if ((isp116x->rhdesca & RH_A_NDP) == 2)
1461 isp116x_hub_control(hcd, SetPortFeature, 1456 isp116x_hub_control(hcd, SetPortFeature,
1462 USB_PORT_FEAT_POWER, 2, NULL, 0); 1457 USB_PORT_FEAT_POWER, 2, NULL, 0);
1463 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1464 return 0; 1458 return 0;
1465 } 1459 }
1466 1460
@@ -1486,8 +1480,6 @@ static int isp116x_bus_resume(struct usb_hcd *hcd)
1486 isp116x_write_reg32(isp116x, HCCONTROL, 1480 isp116x_write_reg32(isp116x, HCCONTROL,
1487 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER); 1481 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1488 spin_unlock_irq(&isp116x->lock); 1482 spin_unlock_irq(&isp116x->lock);
1489 /* see analogous comment above */
1490 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1491 hcd->state = HC_STATE_RUNNING; 1483 hcd->state = HC_STATE_RUNNING;
1492 1484
1493 return 0; 1485 return 0;
@@ -1663,7 +1655,6 @@ static int __devinit isp116x_probe(struct platform_device *pdev)
1663static int isp116x_suspend(struct platform_device *dev, pm_message_t state) 1655static int isp116x_suspend(struct platform_device *dev, pm_message_t state)
1664{ 1656{
1665 VDBG("%s: state %x\n", __func__, state.event); 1657 VDBG("%s: state %x\n", __func__, state.event);
1666 dev->dev.power.power_state = state;
1667 return 0; 1658 return 0;
1668} 1659}
1669 1660
@@ -1672,8 +1663,7 @@ static int isp116x_suspend(struct platform_device *dev, pm_message_t state)
1672*/ 1663*/
1673static int isp116x_resume(struct platform_device *dev) 1664static int isp116x_resume(struct platform_device *dev)
1674{ 1665{
1675 VDBG("%s: state %x\n", __func__, dev->power.power_state.event); 1666 VDBG("%s\n", __func__);
1676 dev->dev.power.power_state = PMSG_ON;
1677 return 0; 1667 return 0;
1678} 1668}
1679 1669
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index d72dc07dda01..c96db1153dcf 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -261,7 +261,6 @@ static const struct hc_driver ohci_at91_hc_driver = {
261 */ 261 */
262 .hub_status_data = ohci_hub_status_data, 262 .hub_status_data = ohci_hub_status_data,
263 .hub_control = ohci_hub_control, 263 .hub_control = ohci_hub_control,
264 .hub_irq_enable = ohci_rhsc_enable,
265#ifdef CONFIG_PM 264#ifdef CONFIG_PM
266 .bus_suspend = ohci_bus_suspend, 265 .bus_suspend = ohci_bus_suspend,
267 .bus_resume = ohci_bus_resume, 266 .bus_resume = ohci_bus_resume,
@@ -348,6 +347,7 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
348 if (!clocked) 347 if (!clocked)
349 at91_start_clock(); 348 at91_start_clock();
350 349
350 ohci_finish_controller_resume(hcd);
351 return 0; 351 return 0;
352} 352}
353#else 353#else
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index f90fe0c7373f..1b9abdba920b 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -288,7 +288,6 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
288 */ 288 */
289 .hub_status_data = ohci_hub_status_data, 289 .hub_status_data = ohci_hub_status_data,
290 .hub_control = ohci_hub_control, 290 .hub_control = ohci_hub_control,
291 .hub_irq_enable = ohci_rhsc_enable,
292#ifdef CONFIG_PM 291#ifdef CONFIG_PM
293 .bus_suspend = ohci_bus_suspend, 292 .bus_suspend = ohci_bus_suspend,
294 .bus_resume = ohci_bus_resume, 293 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index a22c30aa745d..e06bfaebec54 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -655,7 +655,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
655 hcd->product_desc, 655 hcd->product_desc,
656 hcd_name); 656 hcd_name);
657 657
658 if (bus->controller->power.power_state.event) { 658 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
659 size -= scnprintf (next, size, 659 size -= scnprintf (next, size,
660 "SUSPENDED (no register access)\n"); 660 "SUSPENDED (no register access)\n");
661 goto done; 661 goto done;
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 156e93a9d0df..06aadfb0ec29 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -135,7 +135,6 @@ static struct hc_driver ohci_ep93xx_hc_driver = {
135 .get_frame_number = ohci_get_frame, 135 .get_frame_number = ohci_get_frame,
136 .hub_status_data = ohci_hub_status_data, 136 .hub_status_data = ohci_hub_status_data,
137 .hub_control = ohci_hub_control, 137 .hub_control = ohci_hub_control,
138 .hub_irq_enable = ohci_rhsc_enable,
139#ifdef CONFIG_PM 138#ifdef CONFIG_PM
140 .bus_suspend = ohci_bus_suspend, 139 .bus_suspend = ohci_bus_suspend,
141 .bus_resume = ohci_bus_resume, 140 .bus_resume = ohci_bus_resume,
@@ -177,7 +176,6 @@ static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_
177 176
178 ep93xx_stop_hc(&pdev->dev); 177 ep93xx_stop_hc(&pdev->dev);
179 hcd->state = HC_STATE_SUSPENDED; 178 hcd->state = HC_STATE_SUSPENDED;
180 pdev->dev.power.power_state = PMSG_SUSPEND;
181 179
182 return 0; 180 return 0;
183} 181}
@@ -193,9 +191,8 @@ static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
193 ohci->next_statechange = jiffies; 191 ohci->next_statechange = jiffies;
194 192
195 ep93xx_start_hc(&pdev->dev); 193 ep93xx_start_hc(&pdev->dev);
196 pdev->dev.power.power_state = PMSG_ON;
197 usb_hcd_resume_root_hub(hcd);
198 194
195 ohci_finish_controller_resume(hcd);
199 return 0; 196 return 0;
200} 197}
201#endif 198#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 48e4b11f4d3e..5be3bb3e6a9d 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -36,18 +36,6 @@
36 36
37/*-------------------------------------------------------------------------*/ 37/*-------------------------------------------------------------------------*/
38 38
39/* hcd->hub_irq_enable() */
40static void ohci_rhsc_enable (struct usb_hcd *hcd)
41{
42 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
43
44 spin_lock_irq(&ohci->lock);
45 if (!ohci->autostop)
46 del_timer(&hcd->rh_timer); /* Prevent next poll */
47 ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable);
48 spin_unlock_irq(&ohci->lock);
49}
50
51#define OHCI_SCHED_ENABLES \ 39#define OHCI_SCHED_ENABLES \
52 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 40 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
53 41
@@ -103,11 +91,11 @@ __acquires(ohci->lock)
103 finish_unlinks (ohci, ohci_frame_no(ohci)); 91 finish_unlinks (ohci, ohci_frame_no(ohci));
104 92
105 /* maybe resume can wake root hub */ 93 /* maybe resume can wake root hub */
106 if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) || 94 if (ohci_to_hcd(ohci)->self.root_hub->do_remote_wakeup || autostop) {
107 autostop)
108 ohci->hc_control |= OHCI_CTRL_RWE; 95 ohci->hc_control |= OHCI_CTRL_RWE;
109 else { 96 } else {
110 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable); 97 ohci_writel(ohci, OHCI_INTR_RHSC | OHCI_INTR_RD,
98 &ohci->regs->intrdisable);
111 ohci->hc_control &= ~OHCI_CTRL_RWE; 99 ohci->hc_control &= ~OHCI_CTRL_RWE;
112 } 100 }
113 101
@@ -326,23 +314,76 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
326 return rc; 314 return rc;
327} 315}
328 316
317/* Carry out the final steps of resuming the controller device */
318static void ohci_finish_controller_resume(struct usb_hcd *hcd)
319{
320 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
321 int port;
322 bool need_reinit = false;
323
324 /* See if the controller is already running or has been reset */
325 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
326 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
327 need_reinit = true;
328 } else {
329 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
330 case OHCI_USB_OPER:
331 case OHCI_USB_RESET:
332 need_reinit = true;
333 }
334 }
335
336 /* If needed, reinitialize and suspend the root hub */
337 if (need_reinit) {
338 spin_lock_irq(&ohci->lock);
339 hcd->state = HC_STATE_RESUMING;
340 ohci_rh_resume(ohci);
341 hcd->state = HC_STATE_QUIESCING;
342 ohci_rh_suspend(ohci, 0);
343 hcd->state = HC_STATE_SUSPENDED;
344 spin_unlock_irq(&ohci->lock);
345 }
346
347 /* Normally just turn on port power and enable interrupts */
348 else {
349 ohci_dbg(ohci, "powerup ports\n");
350 for (port = 0; port < ohci->num_ports; port++)
351 ohci_writel(ohci, RH_PS_PPS,
352 &ohci->regs->roothub.portstatus[port]);
353
354 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
355 ohci_readl(ohci, &ohci->regs->intrenable);
356 msleep(20);
357 }
358}
359
329/* Carry out polling-, autostop-, and autoresume-related state changes */ 360/* Carry out polling-, autostop-, and autoresume-related state changes */
330static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 361static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
331 int any_connected) 362 int any_connected)
332{ 363{
333 int poll_rh = 1; 364 int poll_rh = 1;
365 int rhsc;
334 366
367 rhsc = ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC;
335 switch (ohci->hc_control & OHCI_CTRL_HCFS) { 368 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
336 369
337 case OHCI_USB_OPER: 370 case OHCI_USB_OPER:
338 /* keep on polling until we know a device is connected 371 /* If no status changes are pending, enable status-change
339 * and RHSC is enabled */ 372 * interrupts.
373 */
374 if (!rhsc && !changed) {
375 rhsc = OHCI_INTR_RHSC;
376 ohci_writel(ohci, rhsc, &ohci->regs->intrenable);
377 }
378
379 /* Keep on polling until we know a device is connected
380 * and RHSC is enabled, or until we autostop.
381 */
340 if (!ohci->autostop) { 382 if (!ohci->autostop) {
341 if (any_connected || 383 if (any_connected ||
342 !device_may_wakeup(&ohci_to_hcd(ohci) 384 !device_may_wakeup(&ohci_to_hcd(ohci)
343 ->self.root_hub->dev)) { 385 ->self.root_hub->dev)) {
344 if (ohci_readl(ohci, &ohci->regs->intrenable) & 386 if (rhsc)
345 OHCI_INTR_RHSC)
346 poll_rh = 0; 387 poll_rh = 0;
347 } else { 388 } else {
348 ohci->autostop = 1; 389 ohci->autostop = 1;
@@ -355,12 +396,13 @@ static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
355 ohci->autostop = 0; 396 ohci->autostop = 0;
356 ohci->next_statechange = jiffies + 397 ohci->next_statechange = jiffies +
357 STATECHANGE_DELAY; 398 STATECHANGE_DELAY;
358 } else if (time_after_eq(jiffies, 399 } else if (rhsc && time_after_eq(jiffies,
359 ohci->next_statechange) 400 ohci->next_statechange)
360 && !ohci->ed_rm_list 401 && !ohci->ed_rm_list
361 && !(ohci->hc_control & 402 && !(ohci->hc_control &
362 OHCI_SCHED_ENABLES)) { 403 OHCI_SCHED_ENABLES)) {
363 ohci_rh_suspend(ohci, 1); 404 ohci_rh_suspend(ohci, 1);
405 poll_rh = 0;
364 } 406 }
365 } 407 }
366 break; 408 break;
@@ -374,6 +416,12 @@ static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
374 else 416 else
375 usb_hcd_resume_root_hub(ohci_to_hcd(ohci)); 417 usb_hcd_resume_root_hub(ohci_to_hcd(ohci));
376 } else { 418 } else {
419 if (!rhsc && (ohci->autostop ||
420 ohci_to_hcd(ohci)->self.root_hub->
421 do_remote_wakeup))
422 ohci_writel(ohci, OHCI_INTR_RHSC,
423 &ohci->regs->intrenable);
424
377 /* everything is idle, no need for polling */ 425 /* everything is idle, no need for polling */
378 poll_rh = 0; 426 poll_rh = 0;
379 } 427 }
@@ -395,12 +443,16 @@ static inline int ohci_rh_resume(struct ohci_hcd *ohci)
395static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, 443static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
396 int any_connected) 444 int any_connected)
397{ 445{
398 int poll_rh = 1; 446 /* If RHSC is enabled, don't poll */
399
400 /* keep on polling until RHSC is enabled */
401 if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC) 447 if (ohci_readl(ohci, &ohci->regs->intrenable) & OHCI_INTR_RHSC)
402 poll_rh = 0; 448 return 0;
403 return poll_rh; 449
450 /* If no status changes are pending, enable status-change interrupts */
451 if (!changed) {
452 ohci_writel(ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable);
453 return 0;
454 }
455 return 1;
404} 456}
405 457
406#endif /* CONFIG_PM */ 458#endif /* CONFIG_PM */
@@ -564,14 +616,18 @@ static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
564 u32 temp; 616 u32 temp;
565 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber); 617 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
566 u16 reset_done = now + PORT_RESET_MSEC; 618 u16 reset_done = now + PORT_RESET_MSEC;
619 int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC);
567 620
568 /* build a "continuous enough" reset signal, with up to 621 /* build a "continuous enough" reset signal, with up to
569 * 3msec gap between pulses. scheduler HZ==100 must work; 622 * 3msec gap between pulses. scheduler HZ==100 must work;
570 * this might need to be deadline-scheduled. 623 * this might need to be deadline-scheduled.
571 */ 624 */
572 do { 625 do {
626 int limit_2;
627
573 /* spin until any current reset finishes */ 628 /* spin until any current reset finishes */
574 for (;;) { 629 limit_2 = PORT_RESET_HW_MSEC * 2;
630 while (--limit_2 >= 0) {
575 temp = ohci_readl (ohci, portstat); 631 temp = ohci_readl (ohci, portstat);
576 /* handle e.g. CardBus eject */ 632 /* handle e.g. CardBus eject */
577 if (temp == ~(u32)0) 633 if (temp == ~(u32)0)
@@ -581,6 +637,17 @@ static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
581 udelay (500); 637 udelay (500);
582 } 638 }
583 639
640 /* timeout (a hardware error) has been observed when
641 * EHCI sets CF while this driver is resetting a port;
642 * presumably other disconnect paths might do it too.
643 */
644 if (limit_2 < 0) {
645 ohci_dbg(ohci,
646 "port[%d] reset timeout, stat %08x\n",
647 port, temp);
648 break;
649 }
650
584 if (!(temp & RH_PS_CCS)) 651 if (!(temp & RH_PS_CCS))
585 break; 652 break;
586 if (temp & RH_PS_PRSC) 653 if (temp & RH_PS_PRSC)
@@ -590,8 +657,11 @@ static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
590 ohci_writel (ohci, RH_PS_PRS, portstat); 657 ohci_writel (ohci, RH_PS_PRS, portstat);
591 msleep(PORT_RESET_HW_MSEC); 658 msleep(PORT_RESET_HW_MSEC);
592 now = ohci_readl(ohci, &ohci->regs->fmnumber); 659 now = ohci_readl(ohci, &ohci->regs->fmnumber);
593 } while (tick_before(now, reset_done)); 660 } while (tick_before(now, reset_done) && --limit_1 >= 0);
594 /* caller synchronizes using PRSC */ 661
662 /* caller synchronizes using PRSC ... and handles PRS
663 * still being set when this returns.
664 */
595 665
596 return 0; 666 return 0;
597} 667}
diff --git a/drivers/usb/host/ohci-lh7a404.c b/drivers/usb/host/ohci-lh7a404.c
index 13c12ed22252..96d14fa1d833 100644
--- a/drivers/usb/host/ohci-lh7a404.c
+++ b/drivers/usb/host/ohci-lh7a404.c
@@ -193,7 +193,6 @@ static const struct hc_driver ohci_lh7a404_hc_driver = {
193 */ 193 */
194 .hub_status_data = ohci_hub_status_data, 194 .hub_status_data = ohci_hub_status_data,
195 .hub_control = ohci_hub_control, 195 .hub_control = ohci_hub_control,
196 .hub_irq_enable = ohci_rhsc_enable,
197#ifdef CONFIG_PM 196#ifdef CONFIG_PM
198 .bus_suspend = ohci_bus_suspend, 197 .bus_suspend = ohci_bus_suspend,
199 .bus_resume = ohci_bus_resume, 198 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 7bfca1ed1b58..6859fb5f1d6f 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -466,7 +466,6 @@ static const struct hc_driver ohci_omap_hc_driver = {
466 */ 466 */
467 .hub_status_data = ohci_hub_status_data, 467 .hub_status_data = ohci_hub_status_data,
468 .hub_control = ohci_hub_control, 468 .hub_control = ohci_hub_control,
469 .hub_irq_enable = ohci_rhsc_enable,
470#ifdef CONFIG_PM 469#ifdef CONFIG_PM
471 .bus_suspend = ohci_bus_suspend, 470 .bus_suspend = ohci_bus_suspend,
472 .bus_resume = ohci_bus_resume, 471 .bus_resume = ohci_bus_resume,
@@ -505,21 +504,20 @@ static int ohci_omap_suspend(struct platform_device *dev, pm_message_t message)
505 504
506 omap_ohci_clock_power(0); 505 omap_ohci_clock_power(0);
507 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 506 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
508 dev->dev.power.power_state = PMSG_SUSPEND;
509 return 0; 507 return 0;
510} 508}
511 509
512static int ohci_omap_resume(struct platform_device *dev) 510static int ohci_omap_resume(struct platform_device *dev)
513{ 511{
514 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(dev)); 512 struct usb_hcd *hcd = platform_get_drvdata(dev);
513 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
515 514
516 if (time_before(jiffies, ohci->next_statechange)) 515 if (time_before(jiffies, ohci->next_statechange))
517 msleep(5); 516 msleep(5);
518 ohci->next_statechange = jiffies; 517 ohci->next_statechange = jiffies;
519 518
520 omap_ohci_clock_power(1); 519 omap_ohci_clock_power(1);
521 dev->dev.power.power_state = PMSG_ON; 520 ohci_finish_controller_resume(hcd);
522 usb_hcd_resume_root_hub(platform_get_drvdata(dev));
523 return 0; 521 return 0;
524} 522}
525 523
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index d0360f65ebd9..3bf175d95a23 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -238,42 +238,6 @@ static int __devinit ohci_pci_start (struct usb_hcd *hcd)
238 return ret; 238 return ret;
239} 239}
240 240
241#if defined(CONFIG_USB_PERSIST) && (defined(CONFIG_USB_EHCI_HCD) || \
242 defined(CONFIG_USB_EHCI_HCD_MODULE))
243
244/* Following a power loss, we must prepare to regain control of the ports
245 * we used to own. This means turning on the port power before ehci-hcd
246 * tries to switch ownership.
247 *
248 * This isn't a 100% perfect solution. On most systems the OHCI controllers
249 * lie at lower PCI addresses than the EHCI controller, so they will be
250 * discovered (and hence resumed) first. But there is no guarantee things
251 * will always work this way. If the EHCI controller is resumed first and
252 * the OHCI ports are unpowered, then the handover will fail.
253 */
254static void prepare_for_handover(struct usb_hcd *hcd)
255{
256 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
257 int port;
258
259 /* Here we "know" root ports should always stay powered */
260 ohci_dbg(ohci, "powerup ports\n");
261 for (port = 0; port < ohci->num_ports; port++)
262 ohci_writel(ohci, RH_PS_PPS,
263 &ohci->regs->roothub.portstatus[port]);
264
265 /* Flush those writes */
266 ohci_readl(ohci, &ohci->regs->control);
267 msleep(20);
268}
269
270#else
271
272static inline void prepare_for_handover(struct usb_hcd *hcd)
273{ }
274
275#endif /* CONFIG_USB_PERSIST etc. */
276
277#ifdef CONFIG_PM 241#ifdef CONFIG_PM
278 242
279static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message) 243static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
@@ -313,10 +277,7 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
313static int ohci_pci_resume (struct usb_hcd *hcd) 277static int ohci_pci_resume (struct usb_hcd *hcd)
314{ 278{
315 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 279 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
316 280 ohci_finish_controller_resume(hcd);
317 /* FIXME: we should try to detect loss of VBUS power here */
318 prepare_for_handover(hcd);
319
320 return 0; 281 return 0;
321} 282}
322 283
@@ -345,9 +306,8 @@ static const struct hc_driver ohci_pci_hc_driver = {
345 .shutdown = ohci_shutdown, 306 .shutdown = ohci_shutdown,
346 307
347#ifdef CONFIG_PM 308#ifdef CONFIG_PM
348 /* these suspend/resume entries are for upstream PCI glue ONLY */ 309 .pci_suspend = ohci_pci_suspend,
349 .suspend = ohci_pci_suspend, 310 .pci_resume = ohci_pci_resume,
350 .resume = ohci_pci_resume,
351#endif 311#endif
352 312
353 /* 313 /*
@@ -367,7 +327,6 @@ static const struct hc_driver ohci_pci_hc_driver = {
367 */ 327 */
368 .hub_status_data = ohci_hub_status_data, 328 .hub_status_data = ohci_hub_status_data,
369 .hub_control = ohci_hub_control, 329 .hub_control = ohci_hub_control,
370 .hub_irq_enable = ohci_rhsc_enable,
371#ifdef CONFIG_PM 330#ifdef CONFIG_PM
372 .bus_suspend = ohci_bus_suspend, 331 .bus_suspend = ohci_bus_suspend,
373 .bus_resume = ohci_bus_resume, 332 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index 28b458f20cc3..664f07ee8732 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -280,7 +280,6 @@ static const struct hc_driver ohci_pnx4008_hc_driver = {
280 */ 280 */
281 .hub_status_data = ohci_hub_status_data, 281 .hub_status_data = ohci_hub_status_data,
282 .hub_control = ohci_hub_control, 282 .hub_control = ohci_hub_control,
283 .hub_irq_enable = ohci_rhsc_enable,
284#ifdef CONFIG_PM 283#ifdef CONFIG_PM
285 .bus_suspend = ohci_bus_suspend, 284 .bus_suspend = ohci_bus_suspend,
286 .bus_resume = ohci_bus_resume, 285 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-pnx8550.c b/drivers/usb/host/ohci-pnx8550.c
index 605d59cba28e..28467e288a93 100644
--- a/drivers/usb/host/ohci-pnx8550.c
+++ b/drivers/usb/host/ohci-pnx8550.c
@@ -201,7 +201,6 @@ static const struct hc_driver ohci_pnx8550_hc_driver = {
201 */ 201 */
202 .hub_status_data = ohci_hub_status_data, 202 .hub_status_data = ohci_hub_status_data,
203 .hub_control = ohci_hub_control, 203 .hub_control = ohci_hub_control,
204 .hub_irq_enable = ohci_rhsc_enable,
205#ifdef CONFIG_PM 204#ifdef CONFIG_PM
206 .bus_suspend = ohci_bus_suspend, 205 .bus_suspend = ohci_bus_suspend,
207 .bus_resume = ohci_bus_resume, 206 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index a67252791223..50e55db13636 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -72,7 +72,6 @@ static const struct hc_driver ohci_ppc_of_hc_driver = {
72 */ 72 */
73 .hub_status_data = ohci_hub_status_data, 73 .hub_status_data = ohci_hub_status_data,
74 .hub_control = ohci_hub_control, 74 .hub_control = ohci_hub_control,
75 .hub_irq_enable = ohci_rhsc_enable,
76#ifdef CONFIG_PM 75#ifdef CONFIG_PM
77 .bus_suspend = ohci_bus_suspend, 76 .bus_suspend = ohci_bus_suspend,
78 .bus_resume = ohci_bus_resume, 77 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index 523c30125577..cd3398b675b2 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -172,7 +172,6 @@ static const struct hc_driver ohci_ppc_soc_hc_driver = {
172 */ 172 */
173 .hub_status_data = ohci_hub_status_data, 173 .hub_status_data = ohci_hub_status_data,
174 .hub_control = ohci_hub_control, 174 .hub_control = ohci_hub_control,
175 .hub_irq_enable = ohci_rhsc_enable,
176#ifdef CONFIG_PM 175#ifdef CONFIG_PM
177 .bus_suspend = ohci_bus_suspend, 176 .bus_suspend = ohci_bus_suspend,
178 .bus_resume = ohci_bus_resume, 177 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-ps3.c b/drivers/usb/host/ohci-ps3.c
index 01a0caeaa6bc..bfdeb0d22d05 100644
--- a/drivers/usb/host/ohci-ps3.c
+++ b/drivers/usb/host/ohci-ps3.c
@@ -68,7 +68,6 @@ static const struct hc_driver ps3_ohci_hc_driver = {
68 .get_frame_number = ohci_get_frame, 68 .get_frame_number = ohci_get_frame,
69 .hub_status_data = ohci_hub_status_data, 69 .hub_status_data = ohci_hub_status_data,
70 .hub_control = ohci_hub_control, 70 .hub_control = ohci_hub_control,
71 .hub_irq_enable = ohci_rhsc_enable,
72 .start_port_reset = ohci_start_port_reset, 71 .start_port_reset = ohci_start_port_reset,
73#if defined(CONFIG_PM) 72#if defined(CONFIG_PM)
74 .bus_suspend = ohci_bus_suspend, 73 .bus_suspend = ohci_bus_suspend,
@@ -127,7 +126,6 @@ static int ps3_ohci_probe(struct ps3_system_bus_device *dev)
127 goto fail_irq; 126 goto fail_irq;
128 } 127 }
129 128
130 dev->core.power.power_state = PMSG_ON;
131 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */ 129 dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
132 130
133 hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev->core.bus_id); 131 hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev->core.bus_id);
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 8ad9b3b604b5..70b0d4b459e7 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -298,7 +298,6 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
298 */ 298 */
299 .hub_status_data = ohci_hub_status_data, 299 .hub_status_data = ohci_hub_status_data,
300 .hub_control = ohci_hub_control, 300 .hub_control = ohci_hub_control,
301 .hub_irq_enable = ohci_rhsc_enable,
302#ifdef CONFIG_PM 301#ifdef CONFIG_PM
303 .bus_suspend = ohci_bus_suspend, 302 .bus_suspend = ohci_bus_suspend,
304 .bus_resume = ohci_bus_resume, 303 .bus_resume = ohci_bus_resume,
@@ -339,7 +338,6 @@ static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_
339 338
340 pxa27x_stop_hc(&pdev->dev); 339 pxa27x_stop_hc(&pdev->dev);
341 hcd->state = HC_STATE_SUSPENDED; 340 hcd->state = HC_STATE_SUSPENDED;
342 pdev->dev.power.power_state = PMSG_SUSPEND;
343 341
344 return 0; 342 return 0;
345} 343}
@@ -357,9 +355,7 @@ static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
357 if ((status = pxa27x_start_hc(&pdev->dev)) < 0) 355 if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
358 return status; 356 return status;
359 357
360 pdev->dev.power.power_state = PMSG_ON; 358 ohci_finish_controller_resume(hcd);
361 usb_hcd_resume_root_hub(hcd);
362
363 return 0; 359 return 0;
364} 360}
365#endif 361#endif
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index ead4772f0f27..a73d2ff322e2 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -466,7 +466,6 @@ static const struct hc_driver ohci_s3c2410_hc_driver = {
466 */ 466 */
467 .hub_status_data = ohci_s3c2410_hub_status_data, 467 .hub_status_data = ohci_s3c2410_hub_status_data,
468 .hub_control = ohci_s3c2410_hub_control, 468 .hub_control = ohci_s3c2410_hub_control,
469 .hub_irq_enable = ohci_rhsc_enable,
470#ifdef CONFIG_PM 469#ifdef CONFIG_PM
471 .bus_suspend = ohci_bus_suspend, 470 .bus_suspend = ohci_bus_suspend,
472 .bus_resume = ohci_bus_resume, 471 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index 0f48f2d99226..99438c65981b 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -231,7 +231,6 @@ static const struct hc_driver ohci_sa1111_hc_driver = {
231 */ 231 */
232 .hub_status_data = ohci_hub_status_data, 232 .hub_status_data = ohci_hub_status_data,
233 .hub_control = ohci_hub_control, 233 .hub_control = ohci_hub_control,
234 .hub_irq_enable = ohci_rhsc_enable,
235#ifdef CONFIG_PM 234#ifdef CONFIG_PM
236 .bus_suspend = ohci_bus_suspend, 235 .bus_suspend = ohci_bus_suspend,
237 .bus_resume = ohci_bus_resume, 236 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-sh.c b/drivers/usb/host/ohci-sh.c
index e7ee607278fe..60f03cc7ec4f 100644
--- a/drivers/usb/host/ohci-sh.c
+++ b/drivers/usb/host/ohci-sh.c
@@ -68,7 +68,6 @@ static const struct hc_driver ohci_sh_hc_driver = {
68 */ 68 */
69 .hub_status_data = ohci_hub_status_data, 69 .hub_status_data = ohci_hub_status_data,
70 .hub_control = ohci_hub_control, 70 .hub_control = ohci_hub_control,
71 .hub_irq_enable = ohci_rhsc_enable,
72#ifdef CONFIG_PM 71#ifdef CONFIG_PM
73 .bus_suspend = ohci_bus_suspend, 72 .bus_suspend = ohci_bus_suspend,
74 .bus_resume = ohci_bus_resume, 73 .bus_resume = ohci_bus_resume,
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
index 4ea92762fb28..77204f001b9a 100644
--- a/drivers/usb/host/ohci-sm501.c
+++ b/drivers/usb/host/ohci-sm501.c
@@ -75,7 +75,6 @@ static const struct hc_driver ohci_sm501_hc_driver = {
75 */ 75 */
76 .hub_status_data = ohci_hub_status_data, 76 .hub_status_data = ohci_hub_status_data,
77 .hub_control = ohci_hub_control, 77 .hub_control = ohci_hub_control,
78 .hub_irq_enable = ohci_rhsc_enable,
79#ifdef CONFIG_PM 78#ifdef CONFIG_PM
80 .bus_suspend = ohci_bus_suspend, 79 .bus_suspend = ohci_bus_suspend,
81 .bus_resume = ohci_bus_resume, 80 .bus_resume = ohci_bus_resume,
@@ -199,7 +198,8 @@ static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev)
199 usb_put_hcd(hcd); 198 usb_put_hcd(hcd);
200 dma_release_declared_memory(&pdev->dev); 199 dma_release_declared_memory(&pdev->dev);
201 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); 200 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
202 release_mem_region(mem->start, mem->end - mem->start + 1); 201 if (mem)
202 release_mem_region(mem->start, mem->end - mem->start + 1);
203 203
204 /* mask interrupts and disable power */ 204 /* mask interrupts and disable power */
205 205
@@ -224,24 +224,26 @@ static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg)
224 224
225 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0); 225 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0);
226 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 226 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
227 dev->power.power_state = PMSG_SUSPEND;
228 return 0; 227 return 0;
229} 228}
230 229
231static int ohci_sm501_resume(struct platform_device *pdev) 230static int ohci_sm501_resume(struct platform_device *pdev)
232{ 231{
233 struct device *dev = &pdev->dev; 232 struct device *dev = &pdev->dev;
234 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev)); 233 struct usb_hcd *hcd = platform_get_drvdata(pdev);
234 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
235 235
236 if (time_before(jiffies, ohci->next_statechange)) 236 if (time_before(jiffies, ohci->next_statechange))
237 msleep(5); 237 msleep(5);
238 ohci->next_statechange = jiffies; 238 ohci->next_statechange = jiffies;
239 239
240 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1); 240 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1);
241 dev->power.power_state = PMSG_ON; 241 ohci_finish_controller_resume(hcd);
242 usb_hcd_resume_root_hub(platform_get_drvdata(pdev));
243 return 0; 242 return 0;
244} 243}
244#else
245#define ohci_sm501_suspend NULL
246#define ohci_sm501_resume NULL
245#endif 247#endif
246 248
247/*-------------------------------------------------------------------------*/ 249/*-------------------------------------------------------------------------*/
@@ -253,10 +255,8 @@ static struct platform_driver ohci_hcd_sm501_driver = {
253 .probe = ohci_hcd_sm501_drv_probe, 255 .probe = ohci_hcd_sm501_drv_probe,
254 .remove = ohci_hcd_sm501_drv_remove, 256 .remove = ohci_hcd_sm501_drv_remove,
255 .shutdown = usb_hcd_platform_shutdown, 257 .shutdown = usb_hcd_platform_shutdown,
256#ifdef CONFIG_PM
257 .suspend = ohci_sm501_suspend, 258 .suspend = ohci_sm501_suspend,
258 .resume = ohci_sm501_resume, 259 .resume = ohci_sm501_resume,
259#endif
260 .driver = { 260 .driver = {
261 .owner = THIS_MODULE, 261 .owner = THIS_MODULE,
262 .name = "sm501-usb", 262 .name = "sm501-usb",
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
index 6e9c2d6db887..c4265caec780 100644
--- a/drivers/usb/host/ohci-ssb.c
+++ b/drivers/usb/host/ohci-ssb.c
@@ -60,36 +60,6 @@ static int ssb_ohci_start(struct usb_hcd *hcd)
60 return err; 60 return err;
61} 61}
62 62
63#ifdef CONFIG_PM
64static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
65{
66 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
67 struct ohci_hcd *ohci = &ohcidev->ohci;
68 unsigned long flags;
69
70 spin_lock_irqsave(&ohci->lock, flags);
71
72 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
73 ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
74
75 /* make sure snapshot being resumed re-enumerates everything */
76 if (message.event == PM_EVENT_PRETHAW)
77 ohci_usb_reset(ohci);
78
79 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
80
81 spin_unlock_irqrestore(&ohci->lock, flags);
82 return 0;
83}
84
85static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
86{
87 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
88 usb_hcd_resume_root_hub(hcd);
89 return 0;
90}
91#endif /* CONFIG_PM */
92
93static const struct hc_driver ssb_ohci_hc_driver = { 63static const struct hc_driver ssb_ohci_hc_driver = {
94 .description = "ssb-usb-ohci", 64 .description = "ssb-usb-ohci",
95 .product_desc = "SSB OHCI Controller", 65 .product_desc = "SSB OHCI Controller",
@@ -103,11 +73,6 @@ static const struct hc_driver ssb_ohci_hc_driver = {
103 .stop = ohci_stop, 73 .stop = ohci_stop,
104 .shutdown = ohci_shutdown, 74 .shutdown = ohci_shutdown,
105 75
106#ifdef CONFIG_PM
107 .suspend = ssb_ohci_hcd_suspend,
108 .resume = ssb_ohci_hcd_resume,
109#endif
110
111 .urb_enqueue = ohci_urb_enqueue, 76 .urb_enqueue = ohci_urb_enqueue,
112 .urb_dequeue = ohci_urb_dequeue, 77 .urb_dequeue = ohci_urb_dequeue,
113 .endpoint_disable = ohci_endpoint_disable, 78 .endpoint_disable = ohci_endpoint_disable,
@@ -116,7 +81,6 @@ static const struct hc_driver ssb_ohci_hc_driver = {
116 81
117 .hub_status_data = ohci_hub_status_data, 82 .hub_status_data = ohci_hub_status_data,
118 .hub_control = ohci_hub_control, 83 .hub_control = ohci_hub_control,
119 .hub_irq_enable = ohci_rhsc_enable,
120#ifdef CONFIG_PM 84#ifdef CONFIG_PM
121 .bus_suspend = ohci_bus_suspend, 85 .bus_suspend = ohci_bus_suspend,
122 .bus_resume = ohci_bus_resume, 86 .bus_resume = ohci_bus_resume,
@@ -224,6 +188,7 @@ static int ssb_ohci_resume(struct ssb_device *dev)
224 188
225 ssb_device_enable(dev, ohcidev->enable_flags); 189 ssb_device_enable(dev, ohcidev->enable_flags);
226 190
191 ohci_finish_controller_resume(hcd);
227 return 0; 192 return 0;
228} 193}
229 194
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 0ee694f043cc..ae6e70edd745 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -106,7 +106,7 @@ int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base)
106 pci_read_config_word(pdev, UHCI_USBLEGSUP, &legsup); 106 pci_read_config_word(pdev, UHCI_USBLEGSUP, &legsup);
107 if (legsup & ~(UHCI_USBLEGSUP_RO | UHCI_USBLEGSUP_RWC)) { 107 if (legsup & ~(UHCI_USBLEGSUP_RO | UHCI_USBLEGSUP_RWC)) {
108 dev_dbg(&pdev->dev, "%s: legsup = 0x%04x\n", 108 dev_dbg(&pdev->dev, "%s: legsup = 0x%04x\n",
109 __FUNCTION__, legsup); 109 __func__, legsup);
110 goto reset_needed; 110 goto reset_needed;
111 } 111 }
112 112
@@ -114,14 +114,14 @@ int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base)
114 if ((cmd & UHCI_USBCMD_RUN) || !(cmd & UHCI_USBCMD_CONFIGURE) || 114 if ((cmd & UHCI_USBCMD_RUN) || !(cmd & UHCI_USBCMD_CONFIGURE) ||
115 !(cmd & UHCI_USBCMD_EGSM)) { 115 !(cmd & UHCI_USBCMD_EGSM)) {
116 dev_dbg(&pdev->dev, "%s: cmd = 0x%04x\n", 116 dev_dbg(&pdev->dev, "%s: cmd = 0x%04x\n",
117 __FUNCTION__, cmd); 117 __func__, cmd);
118 goto reset_needed; 118 goto reset_needed;
119 } 119 }
120 120
121 intr = inw(base + UHCI_USBINTR); 121 intr = inw(base + UHCI_USBINTR);
122 if (intr & (~UHCI_USBINTR_RESUME)) { 122 if (intr & (~UHCI_USBINTR_RESUME)) {
123 dev_dbg(&pdev->dev, "%s: intr = 0x%04x\n", 123 dev_dbg(&pdev->dev, "%s: intr = 0x%04x\n",
124 __FUNCTION__, intr); 124 __func__, intr);
125 goto reset_needed; 125 goto reset_needed;
126 } 126 }
127 return 0; 127 return 0;
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 9f80e5285575..f4fa93dabdde 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -46,15 +46,17 @@ MODULE_LICENSE("GPL");
46MODULE_AUTHOR("Yoshihiro Shimoda"); 46MODULE_AUTHOR("Yoshihiro Shimoda");
47MODULE_ALIAS("platform:r8a66597_hcd"); 47MODULE_ALIAS("platform:r8a66597_hcd");
48 48
49#define DRIVER_VERSION "29 May 2007" 49#define DRIVER_VERSION "10 Apr 2008"
50 50
51static const char hcd_name[] = "r8a66597_hcd"; 51static const char hcd_name[] = "r8a66597_hcd";
52 52
53/* module parameters */ 53/* module parameters */
54#if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
54static unsigned short clock = XTAL12; 55static unsigned short clock = XTAL12;
55module_param(clock, ushort, 0644); 56module_param(clock, ushort, 0644);
56MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 " 57MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
57 "(default=0)"); 58 "(default=0)");
59#endif
58 60
59static unsigned short vif = LDRV; 61static unsigned short vif = LDRV;
60module_param(vif, ushort, 0644); 62module_param(vif, ushort, 0644);
@@ -106,11 +108,22 @@ static void set_devadd_reg(struct r8a66597 *r8a66597, u8 r8a66597_address,
106 r8a66597_write(r8a66597, val, devadd_reg); 108 r8a66597_write(r8a66597, val, devadd_reg);
107} 109}
108 110
109static int enable_controller(struct r8a66597 *r8a66597) 111static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
110{ 112{
111 u16 tmp; 113 u16 tmp;
112 int i = 0; 114 int i = 0;
113 115
116#if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
117 do {
118 r8a66597_write(r8a66597, SCKE, SYSCFG0);
119 tmp = r8a66597_read(r8a66597, SYSCFG0);
120 if (i++ > 1000) {
121 err("register access fail.");
122 return -ENXIO;
123 }
124 } while ((tmp & SCKE) != SCKE);
125 r8a66597_write(r8a66597, 0x04, 0x02);
126#else
114 do { 127 do {
115 r8a66597_write(r8a66597, USBE, SYSCFG0); 128 r8a66597_write(r8a66597, USBE, SYSCFG0);
116 tmp = r8a66597_read(r8a66597, SYSCFG0); 129 tmp = r8a66597_read(r8a66597, SYSCFG0);
@@ -132,13 +145,63 @@ static int enable_controller(struct r8a66597 *r8a66597)
132 return -ENXIO; 145 return -ENXIO;
133 } 146 }
134 } while ((tmp & SCKE) != SCKE); 147 } while ((tmp & SCKE) != SCKE);
148#endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
149
150 return 0;
151}
152
153static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
154{
155 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
156 udelay(1);
157#if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
158 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
159 r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
160 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
161#endif
162}
163
164static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port)
165{
166 u16 val;
167
168 val = port ? DRPD : DCFM | DRPD;
169 r8a66597_bset(r8a66597, val, get_syscfg_reg(port));
170 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
171
172 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, get_dmacfg_reg(port));
173 r8a66597_bclr(r8a66597, DTCHE, get_intenb_reg(port));
174 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
175}
135 176
136 r8a66597_bset(r8a66597, DCFM | DRPD, SYSCFG0); 177static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port)
137 r8a66597_bset(r8a66597, DRPD, SYSCFG1); 178{
179 u16 val, tmp;
180
181 r8a66597_write(r8a66597, 0, get_intenb_reg(port));
182 r8a66597_write(r8a66597, 0, get_intsts_reg(port));
183
184 r8a66597_port_power(r8a66597, port, 0);
185
186 do {
187 tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
188 udelay(640);
189 } while (tmp == EDGESTS);
190
191 val = port ? DRPD : DCFM | DRPD;
192 r8a66597_bclr(r8a66597, val, get_syscfg_reg(port));
193 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
194}
195
196static int enable_controller(struct r8a66597 *r8a66597)
197{
198 int ret, port;
199
200 ret = r8a66597_clock_enable(r8a66597);
201 if (ret < 0)
202 return ret;
138 203
139 r8a66597_bset(r8a66597, vif & LDRV, PINCFG); 204 r8a66597_bset(r8a66597, vif & LDRV, PINCFG);
140 r8a66597_bset(r8a66597, HSE, SYSCFG0);
141 r8a66597_bset(r8a66597, HSE, SYSCFG1);
142 r8a66597_bset(r8a66597, USBE, SYSCFG0); 205 r8a66597_bset(r8a66597, USBE, SYSCFG0);
143 206
144 r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0); 207 r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
@@ -146,53 +209,30 @@ static int enable_controller(struct r8a66597 *r8a66597)
146 r8a66597_bset(r8a66597, BRDY0, BRDYENB); 209 r8a66597_bset(r8a66597, BRDY0, BRDYENB);
147 r8a66597_bset(r8a66597, BEMP0, BEMPENB); 210 r8a66597_bset(r8a66597, BEMP0, BEMPENB);
148 211
149 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, DMA0CFG);
150 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, DMA1CFG);
151
152 r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL); 212 r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL);
153 r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL); 213 r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL);
154 r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL); 214 r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL);
155
156 r8a66597_bset(r8a66597, TRNENSEL, SOFCFG); 215 r8a66597_bset(r8a66597, TRNENSEL, SOFCFG);
157 216
158 r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1); 217 r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1);
159 r8a66597_bclr(r8a66597, DTCHE, INTENB1); 218
160 r8a66597_bset(r8a66597, ATTCHE, INTENB1); 219 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
161 r8a66597_bclr(r8a66597, DTCHE, INTENB2); 220 r8a66597_enable_port(r8a66597, port);
162 r8a66597_bset(r8a66597, ATTCHE, INTENB2);
163 221
164 return 0; 222 return 0;
165} 223}
166 224
167static void disable_controller(struct r8a66597 *r8a66597) 225static void disable_controller(struct r8a66597 *r8a66597)
168{ 226{
169 u16 tmp; 227 int port;
170 228
171 r8a66597_write(r8a66597, 0, INTENB0); 229 r8a66597_write(r8a66597, 0, INTENB0);
172 r8a66597_write(r8a66597, 0, INTENB1);
173 r8a66597_write(r8a66597, 0, INTENB2);
174 r8a66597_write(r8a66597, 0, INTSTS0); 230 r8a66597_write(r8a66597, 0, INTSTS0);
175 r8a66597_write(r8a66597, 0, INTSTS1);
176 r8a66597_write(r8a66597, 0, INTSTS2);
177
178 r8a66597_port_power(r8a66597, 0, 0);
179 r8a66597_port_power(r8a66597, 1, 0);
180
181 do {
182 tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
183 udelay(640);
184 } while (tmp == EDGESTS);
185 231
186 r8a66597_bclr(r8a66597, DCFM | DRPD, SYSCFG0); 232 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
187 r8a66597_bclr(r8a66597, DRPD, SYSCFG1); 233 r8a66597_disable_port(r8a66597, port);
188 r8a66597_bclr(r8a66597, HSE, SYSCFG0);
189 r8a66597_bclr(r8a66597, HSE, SYSCFG1);
190 234
191 r8a66597_bclr(r8a66597, SCKE, SYSCFG0); 235 r8a66597_clock_disable(r8a66597);
192 udelay(1);
193 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
194 r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
195 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
196} 236}
197 237
198static int get_parent_r8a66597_address(struct r8a66597 *r8a66597, 238static int get_parent_r8a66597_address(struct r8a66597 *r8a66597,
@@ -577,13 +617,9 @@ static void pipe_buffer_setting(struct r8a66597 *r8a66597,
577 PIPEBUF); 617 PIPEBUF);
578 r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket, 618 r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket,
579 PIPEMAXP); 619 PIPEMAXP);
580 if (info->interval)
581 info->interval--;
582 r8a66597_write(r8a66597, info->interval, PIPEPERI); 620 r8a66597_write(r8a66597, info->interval, PIPEPERI);
583} 621}
584 622
585
586
587/* this function must be called with interrupt disabled */ 623/* this function must be called with interrupt disabled */
588static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td) 624static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td)
589{ 625{
@@ -715,6 +751,7 @@ static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597,
715 struct r8a66597_pipe *pipe, 751 struct r8a66597_pipe *pipe,
716 struct urb *urb) 752 struct urb *urb)
717{ 753{
754#if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
718 int i; 755 int i;
719 struct r8a66597_pipe_info *info = &pipe->info; 756 struct r8a66597_pipe_info *info = &pipe->info;
720 757
@@ -742,6 +779,7 @@ static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597,
742 break; 779 break;
743 } 780 }
744 } 781 }
782#endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
745} 783}
746 784
747/* this function must be called with interrupt disabled */ 785/* this function must be called with interrupt disabled */
@@ -825,6 +863,25 @@ static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597,
825 dev->dma_map = 0; 863 dev->dma_map = 0;
826} 864}
827 865
866static unsigned long get_timer_interval(struct urb *urb, __u8 interval)
867{
868 __u8 i;
869 unsigned long time = 1;
870
871 if (usb_pipeisoc(urb->pipe))
872 return 0;
873
874 if (get_r8a66597_usb_speed(urb->dev->speed) == HSMODE) {
875 for (i = 0; i < (interval - 1); i++)
876 time *= 2;
877 time = time * 125 / 1000; /* uSOF -> msec */
878 } else {
879 time = interval;
880 }
881
882 return time;
883}
884
828/* this function must be called with interrupt disabled */ 885/* this function must be called with interrupt disabled */
829static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb, 886static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
830 struct usb_host_endpoint *hep, 887 struct usb_host_endpoint *hep,
@@ -840,7 +897,16 @@ static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
840 & USB_ENDPOINT_XFERTYPE_MASK); 897 & USB_ENDPOINT_XFERTYPE_MASK);
841 info.bufnum = get_bufnum(info.pipenum); 898 info.bufnum = get_bufnum(info.pipenum);
842 info.buf_bsize = get_buf_bsize(info.pipenum); 899 info.buf_bsize = get_buf_bsize(info.pipenum);
843 info.interval = ep->bInterval; 900 if (info.type == R8A66597_BULK) {
901 info.interval = 0;
902 info.timer_interval = 0;
903 } else {
904 if (ep->bInterval > IITV)
905 info.interval = IITV;
906 else
907 info.interval = ep->bInterval ? ep->bInterval - 1 : 0;
908 info.timer_interval = get_timer_interval(urb, ep->bInterval);
909 }
844 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 910 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
845 info.dir_in = 1; 911 info.dir_in = 1;
846 else 912 else
@@ -876,10 +942,19 @@ static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum)
876} 942}
877 943
878/* this function must be called with interrupt disabled */ 944/* this function must be called with interrupt disabled */
879static void r8a66597_usb_preconnect(struct r8a66597 *r8a66597, int port) 945static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
946 u16 syssts)
880{ 947{
881 r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION) 948 if (syssts == SE0) {
882 | (1 << USB_PORT_FEAT_C_CONNECTION); 949 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
950 return;
951 }
952
953 if (syssts == FS_JSTS)
954 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
955 else if (syssts == LS_JSTS)
956 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
957
883 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port)); 958 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
884 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); 959 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
885} 960}
@@ -960,9 +1035,9 @@ static void prepare_packet_read(struct r8a66597 *r8a66597,
960 r8a66597_write(r8a66597, TRCLR, 1035 r8a66597_write(r8a66597, TRCLR,
961 td->pipe->pipetre); 1036 td->pipe->pipetre);
962 r8a66597_write(r8a66597, 1037 r8a66597_write(r8a66597,
963 (urb->transfer_buffer_length 1038 DIV_ROUND_UP
964 + td->maxpacket - 1) 1039 (urb->transfer_buffer_length,
965 / td->maxpacket, 1040 td->maxpacket),
966 td->pipe->pipetrn); 1041 td->pipe->pipetrn);
967 r8a66597_bset(r8a66597, TRENB, 1042 r8a66597_bset(r8a66597, TRENB,
968 td->pipe->pipetre); 1043 td->pipe->pipetre);
@@ -1021,8 +1096,7 @@ static void prepare_status_packet(struct r8a66597 *r8a66597,
1021 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); 1096 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
1022 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); 1097 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1023 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS); 1098 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
1024 r8a66597_write(r8a66597, BCLR, CFIFOCTR); 1099 r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR);
1025 r8a66597_write(r8a66597, BVAL, CFIFOCTR);
1026 enable_irq_empty(r8a66597, 0); 1100 enable_irq_empty(r8a66597, 0);
1027 } else { 1101 } else {
1028 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); 1102 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
@@ -1454,13 +1528,21 @@ static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
1454 } 1528 }
1455} 1529}
1456 1530
1531static void r8a66597_root_hub_start_polling(struct r8a66597 *r8a66597)
1532{
1533 mod_timer(&r8a66597->rh_timer,
1534 jiffies + msecs_to_jiffies(R8A66597_RH_POLL_TIME));
1535}
1536
1457static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port) 1537static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port)
1458{ 1538{
1459 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; 1539 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
1460 1540
1461 rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST; 1541 rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
1462 rh->scount = R8A66597_MAX_SAMPLING; 1542 rh->scount = R8A66597_MAX_SAMPLING;
1463 mod_timer(&r8a66597->rh_timer, jiffies + msecs_to_jiffies(50)); 1543 r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION)
1544 | (1 << USB_PORT_FEAT_C_CONNECTION);
1545 r8a66597_root_hub_start_polling(r8a66597);
1464} 1546}
1465 1547
1466static irqreturn_t r8a66597_irq(struct usb_hcd *hcd) 1548static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
@@ -1547,41 +1629,55 @@ static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
1547 if ((tmp & USBRST) == USBRST) { 1629 if ((tmp & USBRST) == USBRST) {
1548 r8a66597_mdfy(r8a66597, UACT, USBRST | UACT, 1630 r8a66597_mdfy(r8a66597, UACT, USBRST | UACT,
1549 dvstctr_reg); 1631 dvstctr_reg);
1550 mod_timer(&r8a66597->rh_timer, 1632 r8a66597_root_hub_start_polling(r8a66597);
1551 jiffies + msecs_to_jiffies(50));
1552 } else 1633 } else
1553 r8a66597_usb_connect(r8a66597, port); 1634 r8a66597_usb_connect(r8a66597, port);
1554 } 1635 }
1555 1636
1637 if (!(rh->port & (1 << USB_PORT_FEAT_CONNECTION))) {
1638 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
1639 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
1640 }
1641
1556 if (rh->scount > 0) { 1642 if (rh->scount > 0) {
1557 tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST; 1643 tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
1558 if (tmp == rh->old_syssts) { 1644 if (tmp == rh->old_syssts) {
1559 rh->scount--; 1645 rh->scount--;
1560 if (rh->scount == 0) { 1646 if (rh->scount == 0)
1561 if (tmp == FS_JSTS) { 1647 r8a66597_check_syssts(r8a66597, port, tmp);
1562 r8a66597_bset(r8a66597, HSE, 1648 else
1563 get_syscfg_reg(port)); 1649 r8a66597_root_hub_start_polling(r8a66597);
1564 r8a66597_usb_preconnect(r8a66597, port);
1565 } else if (tmp == LS_JSTS) {
1566 r8a66597_bclr(r8a66597, HSE,
1567 get_syscfg_reg(port));
1568 r8a66597_usb_preconnect(r8a66597, port);
1569 } else if (tmp == SE0)
1570 r8a66597_bset(r8a66597, ATTCHE,
1571 get_intenb_reg(port));
1572 } else {
1573 mod_timer(&r8a66597->rh_timer,
1574 jiffies + msecs_to_jiffies(50));
1575 }
1576 } else { 1650 } else {
1577 rh->scount = R8A66597_MAX_SAMPLING; 1651 rh->scount = R8A66597_MAX_SAMPLING;
1578 rh->old_syssts = tmp; 1652 rh->old_syssts = tmp;
1579 mod_timer(&r8a66597->rh_timer, 1653 r8a66597_root_hub_start_polling(r8a66597);
1580 jiffies + msecs_to_jiffies(50));
1581 } 1654 }
1582 } 1655 }
1583} 1656}
1584 1657
1658static void r8a66597_interval_timer(unsigned long _r8a66597)
1659{
1660 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1661 unsigned long flags;
1662 u16 pipenum;
1663 struct r8a66597_td *td;
1664
1665 spin_lock_irqsave(&r8a66597->lock, flags);
1666
1667 for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1668 if (!(r8a66597->interval_map & (1 << pipenum)))
1669 continue;
1670 if (timer_pending(&r8a66597->interval_timer[pipenum]))
1671 continue;
1672
1673 td = r8a66597_get_td(r8a66597, pipenum);
1674 if (td)
1675 start_transfer(r8a66597, td);
1676 }
1677
1678 spin_unlock_irqrestore(&r8a66597->lock, flags);
1679}
1680
1585static void r8a66597_td_timer(unsigned long _r8a66597) 1681static void r8a66597_td_timer(unsigned long _r8a66597)
1586{ 1682{
1587 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; 1683 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
@@ -1763,10 +1859,17 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1763 urb->hcpriv = td; 1859 urb->hcpriv = td;
1764 1860
1765 if (request) { 1861 if (request) {
1766 ret = start_transfer(r8a66597, td); 1862 if (td->pipe->info.timer_interval) {
1767 if (ret < 0) { 1863 r8a66597->interval_map |= 1 << td->pipenum;
1768 list_del(&td->queue); 1864 mod_timer(&r8a66597->interval_timer[td->pipenum],
1769 kfree(td); 1865 jiffies + msecs_to_jiffies(
1866 td->pipe->info.timer_interval));
1867 } else {
1868 ret = start_transfer(r8a66597, td);
1869 if (ret < 0) {
1870 list_del(&td->queue);
1871 kfree(td);
1872 }
1770 } 1873 }
1771 } else 1874 } else
1772 set_td_timer(r8a66597, td); 1875 set_td_timer(r8a66597, td);
@@ -2107,13 +2210,11 @@ static struct hc_driver r8a66597_hc_driver = {
2107#if defined(CONFIG_PM) 2210#if defined(CONFIG_PM)
2108static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state) 2211static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state)
2109{ 2212{
2110 pdev->dev.power.power_state = state;
2111 return 0; 2213 return 0;
2112} 2214}
2113 2215
2114static int r8a66597_resume(struct platform_device *pdev) 2216static int r8a66597_resume(struct platform_device *pdev)
2115{ 2217{
2116 pdev->dev.power.power_state = PMSG_ON;
2117 return 0; 2218 return 0;
2118} 2219}
2119#else /* if defined(CONFIG_PM) */ 2220#else /* if defined(CONFIG_PM) */
@@ -2194,6 +2295,9 @@ static int __init r8a66597_probe(struct platform_device *pdev)
2194 init_timer(&r8a66597->td_timer[i]); 2295 init_timer(&r8a66597->td_timer[i]);
2195 r8a66597->td_timer[i].function = r8a66597_td_timer; 2296 r8a66597->td_timer[i].function = r8a66597_td_timer;
2196 r8a66597->td_timer[i].data = (unsigned long)r8a66597; 2297 r8a66597->td_timer[i].data = (unsigned long)r8a66597;
2298 setup_timer(&r8a66597->interval_timer[i],
2299 r8a66597_interval_timer,
2300 (unsigned long)r8a66597);
2197 } 2301 }
2198 INIT_LIST_HEAD(&r8a66597->child_device); 2302 INIT_LIST_HEAD(&r8a66597->child_device);
2199 2303
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h
index 57388252b693..84ee01417315 100644
--- a/drivers/usb/host/r8a66597.h
+++ b/drivers/usb/host/r8a66597.h
@@ -187,7 +187,11 @@
187#define REW 0x4000 /* b14: Buffer rewind */ 187#define REW 0x4000 /* b14: Buffer rewind */
188#define DCLRM 0x2000 /* b13: DMA buffer clear mode */ 188#define DCLRM 0x2000 /* b13: DMA buffer clear mode */
189#define DREQE 0x1000 /* b12: DREQ output enable */ 189#define DREQE 0x1000 /* b12: DREQ output enable */
190#if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
191#define MBW 0x0800
192#else
190#define MBW 0x0400 /* b10: Maximum bit width for FIFO access */ 193#define MBW 0x0400 /* b10: Maximum bit width for FIFO access */
194#endif
191#define MBW_8 0x0000 /* 8bit */ 195#define MBW_8 0x0000 /* 8bit */
192#define MBW_16 0x0400 /* 16bit */ 196#define MBW_16 0x0400 /* 16bit */
193#define BIGEND 0x0100 /* b8: Big endian mode */ 197#define BIGEND 0x0100 /* b8: Big endian mode */
@@ -395,8 +399,13 @@
395#define R8A66597_MAX_NUM_PIPE 10 399#define R8A66597_MAX_NUM_PIPE 10
396#define R8A66597_BUF_BSIZE 8 400#define R8A66597_BUF_BSIZE 8
397#define R8A66597_MAX_DEVICE 10 401#define R8A66597_MAX_DEVICE 10
402#if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
403#define R8A66597_MAX_ROOT_HUB 1
404#else
398#define R8A66597_MAX_ROOT_HUB 2 405#define R8A66597_MAX_ROOT_HUB 2
399#define R8A66597_MAX_SAMPLING 10 406#endif
407#define R8A66597_MAX_SAMPLING 5
408#define R8A66597_RH_POLL_TIME 10
400#define R8A66597_MAX_DMA_CHANNEL 2 409#define R8A66597_MAX_DMA_CHANNEL 2
401#define R8A66597_PIPE_NO_DMA R8A66597_MAX_DMA_CHANNEL 410#define R8A66597_PIPE_NO_DMA R8A66597_MAX_DMA_CHANNEL
402#define check_bulk_or_isoc(pipenum) ((pipenum >= 1 && pipenum <= 5)) 411#define check_bulk_or_isoc(pipenum) ((pipenum >= 1 && pipenum <= 5))
@@ -404,6 +413,7 @@
404#define make_devsel(addr) (addr << 12) 413#define make_devsel(addr) (addr << 12)
405 414
406struct r8a66597_pipe_info { 415struct r8a66597_pipe_info {
416 unsigned long timer_interval;
407 u16 pipenum; 417 u16 pipenum;
408 u16 address; /* R8A66597 HCD usb address */ 418 u16 address; /* R8A66597 HCD usb address */
409 u16 epnum; 419 u16 epnum;
@@ -478,9 +488,11 @@ struct r8a66597 {
478 488
479 struct timer_list rh_timer; 489 struct timer_list rh_timer;
480 struct timer_list td_timer[R8A66597_MAX_NUM_PIPE]; 490 struct timer_list td_timer[R8A66597_MAX_NUM_PIPE];
491 struct timer_list interval_timer[R8A66597_MAX_NUM_PIPE];
481 492
482 unsigned short address_map; 493 unsigned short address_map;
483 unsigned short timeout_map; 494 unsigned short timeout_map;
495 unsigned short interval_map;
484 unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE]; 496 unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE];
485 unsigned char dma_map; 497 unsigned char dma_map;
486 498
@@ -526,8 +538,21 @@ static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597,
526 unsigned long offset, u16 *buf, 538 unsigned long offset, u16 *buf,
527 int len) 539 int len)
528{ 540{
541#if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
542 unsigned long fifoaddr = r8a66597->reg + offset;
543 unsigned long count;
544
545 count = len / 4;
546 insl(fifoaddr, buf, count);
547
548 if (len & 0x00000003) {
549 unsigned long tmp = inl(fifoaddr);
550 memcpy((unsigned char *)buf + count * 4, &tmp, len & 0x03);
551 }
552#else
529 len = (len + 1) / 2; 553 len = (len + 1) / 2;
530 insw(r8a66597->reg + offset, buf, len); 554 insw(r8a66597->reg + offset, buf, len);
555#endif
531} 556}
532 557
533static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val, 558static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val,
@@ -541,6 +566,24 @@ static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
541 int len) 566 int len)
542{ 567{
543 unsigned long fifoaddr = r8a66597->reg + offset; 568 unsigned long fifoaddr = r8a66597->reg + offset;
569#if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
570 unsigned long count;
571 unsigned char *pb;
572 int i;
573
574 count = len / 4;
575 outsl(fifoaddr, buf, count);
576
577 if (len & 0x00000003) {
578 pb = (unsigned char *)buf + count * 4;
579 for (i = 0; i < (len & 0x00000003); i++) {
580 if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND)
581 outb(pb[i], fifoaddr + i);
582 else
583 outb(pb[i], fifoaddr + 3 - i);
584 }
585 }
586#else
544 int odd = len & 0x0001; 587 int odd = len & 0x0001;
545 588
546 len = len / 2; 589 len = len / 2;
@@ -549,6 +592,7 @@ static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
549 buf = &buf[len]; 592 buf = &buf[len];
550 outb((unsigned char)*buf, fifoaddr); 593 outb((unsigned char)*buf, fifoaddr);
551 } 594 }
595#endif
552} 596}
553 597
554static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, 598static inline void r8a66597_mdfy(struct r8a66597 *r8a66597,
@@ -581,6 +625,11 @@ static inline unsigned long get_dvstctr_reg(int port)
581 return port == 0 ? DVSTCTR0 : DVSTCTR1; 625 return port == 0 ? DVSTCTR0 : DVSTCTR1;
582} 626}
583 627
628static inline unsigned long get_dmacfg_reg(int port)
629{
630 return port == 0 ? DMA0CFG : DMA1CFG;
631}
632
584static inline unsigned long get_intenb_reg(int port) 633static inline unsigned long get_intenb_reg(int port)
585{ 634{
586 return port == 0 ? INTENB1 : INTENB2; 635 return port == 0 ? INTENB1 : INTENB2;
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 629bca0ebe8f..274276cf8621 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -94,12 +94,10 @@ static void port_power(struct sl811 *sl811, int is_on)
94 94
95 sl811->port1 = (1 << USB_PORT_FEAT_POWER); 95 sl811->port1 = (1 << USB_PORT_FEAT_POWER);
96 sl811->irq_enable = SL11H_INTMASK_INSRMV; 96 sl811->irq_enable = SL11H_INTMASK_INSRMV;
97 hcd->self.controller->power.power_state = PMSG_ON;
98 } else { 97 } else {
99 sl811->port1 = 0; 98 sl811->port1 = 0;
100 sl811->irq_enable = 0; 99 sl811->irq_enable = 0;
101 hcd->state = HC_STATE_HALT; 100 hcd->state = HC_STATE_HALT;
102 hcd->self.controller->power.power_state = PMSG_SUSPEND;
103 } 101 }
104 sl811->ctrl1 = 0; 102 sl811->ctrl1 = 0;
105 sl811_write(sl811, SL11H_IRQ_ENABLE, 0); 103 sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
@@ -1337,7 +1335,7 @@ static int
1337sl811h_bus_suspend(struct usb_hcd *hcd) 1335sl811h_bus_suspend(struct usb_hcd *hcd)
1338{ 1336{
1339 // SOFs off 1337 // SOFs off
1340 DBG("%s\n", __FUNCTION__); 1338 DBG("%s\n", __func__);
1341 return 0; 1339 return 0;
1342} 1340}
1343 1341
@@ -1345,7 +1343,7 @@ static int
1345sl811h_bus_resume(struct usb_hcd *hcd) 1343sl811h_bus_resume(struct usb_hcd *hcd)
1346{ 1344{
1347 // SOFs on 1345 // SOFs on
1348 DBG("%s\n", __FUNCTION__); 1346 DBG("%s\n", __func__);
1349 return 0; 1347 return 0;
1350} 1348}
1351 1349
@@ -1772,8 +1770,6 @@ sl811h_suspend(struct platform_device *dev, pm_message_t state)
1772 port_power(sl811, 0); 1770 port_power(sl811, 0);
1773 break; 1771 break;
1774 } 1772 }
1775 if (retval == 0)
1776 dev->dev.power.power_state = state;
1777 return retval; 1773 return retval;
1778} 1774}
1779 1775
@@ -1786,15 +1782,13 @@ sl811h_resume(struct platform_device *dev)
1786 /* with no "check to see if VBUS is still powered" board hook, 1782 /* with no "check to see if VBUS is still powered" board hook,
1787 * let's assume it'd only be powered to enable remote wakeup. 1783 * let's assume it'd only be powered to enable remote wakeup.
1788 */ 1784 */
1789 if (dev->dev.power.power_state.event == PM_EVENT_SUSPEND 1785 if (!sl811->port1 || !device_can_wakeup(&hcd->self.root_hub->dev)) {
1790 || !device_can_wakeup(&hcd->self.root_hub->dev)) {
1791 sl811->port1 = 0; 1786 sl811->port1 = 0;
1792 port_power(sl811, 1); 1787 port_power(sl811, 1);
1793 usb_root_hub_lost_power(hcd->self.root_hub); 1788 usb_root_hub_lost_power(hcd->self.root_hub);
1794 return 0; 1789 return 0;
1795 } 1790 }
1796 1791
1797 dev->dev.power.power_state = PMSG_ON;
1798 return sl811h_bus_resume(hcd); 1792 return sl811h_bus_resume(hcd);
1799} 1793}
1800 1794
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 8e117a795e93..f29307405bb3 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -67,7 +67,7 @@
67#include "ohci.h" 67#include "ohci.h"
68#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR 68#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
69#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ 69#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
70 OHCI_INTR_WDH) 70 OHCI_INTR_WDH)
71MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited"); 71MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
72MODULE_DESCRIPTION("U132 USB Host Controller Driver"); 72MODULE_DESCRIPTION("U132 USB Host Controller Driver");
73MODULE_LICENSE("GPL"); 73MODULE_LICENSE("GPL");
@@ -77,15 +77,15 @@ INT_MODULE_PARM(testing, 0);
77static int distrust_firmware = 1; 77static int distrust_firmware = 1;
78module_param(distrust_firmware, bool, 0); 78module_param(distrust_firmware, bool, 0);
79MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren" 79MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
80 "t setup"); 80 "t setup");
81static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait); 81static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
82/* 82/*
83* u132_module_lock exists to protect access to global variables 83* u132_module_lock exists to protect access to global variables
84* 84*
85*/ 85*/
86static struct mutex u132_module_lock; 86static struct mutex u132_module_lock;
87static int u132_exiting = 0; 87static int u132_exiting;
88static int u132_instances = 0; 88static int u132_instances;
89static struct list_head u132_static_list; 89static struct list_head u132_static_list;
90/* 90/*
91* end of the global variables protected by u132_module_lock 91* end of the global variables protected by u132_module_lock
@@ -97,115 +97,115 @@ static struct workqueue_struct *workqueue;
97#define MAX_U132_ENDPS 100 97#define MAX_U132_ENDPS 100
98#define MAX_U132_RINGS 4 98#define MAX_U132_RINGS 4
99static const char *cc_to_text[16] = { 99static const char *cc_to_text[16] = {
100 "No Error ", 100 "No Error ",
101 "CRC Error ", 101 "CRC Error ",
102 "Bit Stuff ", 102 "Bit Stuff ",
103 "Data Togg ", 103 "Data Togg ",
104 "Stall ", 104 "Stall ",
105 "DevNotResp ", 105 "DevNotResp ",
106 "PIDCheck ", 106 "PIDCheck ",
107 "UnExpPID ", 107 "UnExpPID ",
108 "DataOver ", 108 "DataOver ",
109 "DataUnder ", 109 "DataUnder ",
110 "(for hw) ", 110 "(for hw) ",
111 "(for hw) ", 111 "(for hw) ",
112 "BufferOver ", 112 "BufferOver ",
113 "BuffUnder ", 113 "BuffUnder ",
114 "(for HCD) ", 114 "(for HCD) ",
115 "(for HCD) " 115 "(for HCD) "
116}; 116};
117struct u132_port { 117struct u132_port {
118 struct u132 *u132; 118 struct u132 *u132;
119 int reset; 119 int reset;
120 int enable; 120 int enable;
121 int power; 121 int power;
122 int Status; 122 int Status;
123}; 123};
124struct u132_addr { 124struct u132_addr {
125 u8 address; 125 u8 address;
126}; 126};
127struct u132_udev { 127struct u132_udev {
128 struct kref kref; 128 struct kref kref;
129 struct usb_device *usb_device; 129 struct usb_device *usb_device;
130 u8 enumeration; 130 u8 enumeration;
131 u8 udev_number; 131 u8 udev_number;
132 u8 usb_addr; 132 u8 usb_addr;
133 u8 portnumber; 133 u8 portnumber;
134 u8 endp_number_in[16]; 134 u8 endp_number_in[16];
135 u8 endp_number_out[16]; 135 u8 endp_number_out[16];
136}; 136};
137#define ENDP_QUEUE_SHIFT 3 137#define ENDP_QUEUE_SHIFT 3
138#define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT) 138#define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
139#define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1) 139#define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
140struct u132_urbq { 140struct u132_urbq {
141 struct list_head urb_more; 141 struct list_head urb_more;
142 struct urb *urb; 142 struct urb *urb;
143}; 143};
144struct u132_spin { 144struct u132_spin {
145 spinlock_t slock; 145 spinlock_t slock;
146}; 146};
147struct u132_endp { 147struct u132_endp {
148 struct kref kref; 148 struct kref kref;
149 u8 udev_number; 149 u8 udev_number;
150 u8 endp_number; 150 u8 endp_number;
151 u8 usb_addr; 151 u8 usb_addr;
152 u8 usb_endp; 152 u8 usb_endp;
153 struct u132 *u132; 153 struct u132 *u132;
154 struct list_head endp_ring; 154 struct list_head endp_ring;
155 struct u132_ring *ring; 155 struct u132_ring *ring;
156 unsigned toggle_bits:2; 156 unsigned toggle_bits:2;
157 unsigned active:1; 157 unsigned active:1;
158 unsigned delayed:1; 158 unsigned delayed:1;
159 unsigned input:1; 159 unsigned input:1;
160 unsigned output:1; 160 unsigned output:1;
161 unsigned pipetype:2; 161 unsigned pipetype:2;
162 unsigned dequeueing:1; 162 unsigned dequeueing:1;
163 unsigned edset_flush:1; 163 unsigned edset_flush:1;
164 unsigned spare_bits:14; 164 unsigned spare_bits:14;
165 unsigned long jiffies; 165 unsigned long jiffies;
166 struct usb_host_endpoint *hep; 166 struct usb_host_endpoint *hep;
167 struct u132_spin queue_lock; 167 struct u132_spin queue_lock;
168 u16 queue_size; 168 u16 queue_size;
169 u16 queue_last; 169 u16 queue_last;
170 u16 queue_next; 170 u16 queue_next;
171 struct urb *urb_list[ENDP_QUEUE_SIZE]; 171 struct urb *urb_list[ENDP_QUEUE_SIZE];
172 struct list_head urb_more; 172 struct list_head urb_more;
173 struct delayed_work scheduler; 173 struct delayed_work scheduler;
174}; 174};
175struct u132_ring { 175struct u132_ring {
176 unsigned in_use:1; 176 unsigned in_use:1;
177 unsigned length:7; 177 unsigned length:7;
178 u8 number; 178 u8 number;
179 struct u132 *u132; 179 struct u132 *u132;
180 struct u132_endp *curr_endp; 180 struct u132_endp *curr_endp;
181 struct delayed_work scheduler; 181 struct delayed_work scheduler;
182}; 182};
183struct u132 { 183struct u132 {
184 struct kref kref; 184 struct kref kref;
185 struct list_head u132_list; 185 struct list_head u132_list;
186 struct mutex sw_lock; 186 struct mutex sw_lock;
187 struct semaphore scheduler_lock; 187 struct mutex scheduler_lock;
188 struct u132_platform_data *board; 188 struct u132_platform_data *board;
189 struct platform_device *platform_dev; 189 struct platform_device *platform_dev;
190 struct u132_ring ring[MAX_U132_RINGS]; 190 struct u132_ring ring[MAX_U132_RINGS];
191 int sequence_num; 191 int sequence_num;
192 int going; 192 int going;
193 int power; 193 int power;
194 int reset; 194 int reset;
195 int num_ports; 195 int num_ports;
196 u32 hc_control; 196 u32 hc_control;
197 u32 hc_fminterval; 197 u32 hc_fminterval;
198 u32 hc_roothub_status; 198 u32 hc_roothub_status;
199 u32 hc_roothub_a; 199 u32 hc_roothub_a;
200 u32 hc_roothub_portstatus[MAX_ROOT_PORTS]; 200 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
201 int flags; 201 int flags;
202 unsigned long next_statechange; 202 unsigned long next_statechange;
203 struct delayed_work monitor; 203 struct delayed_work monitor;
204 int num_endpoints; 204 int num_endpoints;
205 struct u132_addr addr[MAX_U132_ADDRS]; 205 struct u132_addr addr[MAX_U132_ADDRS];
206 struct u132_udev udev[MAX_U132_UDEVS]; 206 struct u132_udev udev[MAX_U132_UDEVS];
207 struct u132_port port[MAX_U132_PORTS]; 207 struct u132_port port[MAX_U132_PORTS];
208 struct u132_endp *endp[MAX_U132_ENDPS]; 208 struct u132_endp *endp[MAX_U132_ENDPS];
209}; 209};
210 210
211/* 211/*
@@ -213,34 +213,34 @@ struct u132 {
213* Does anyone have a better way????? 213* Does anyone have a better way?????
214*/ 214*/
215#define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \ 215#define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
216 offsetof(struct ohci_regs, member), 0, data); 216 offsetof(struct ohci_regs, member), 0, data);
217#define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \ 217#define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
218 offsetof(struct ohci_regs, member), 0, data); 218 offsetof(struct ohci_regs, member), 0, data);
219#define u132_read_pcimem(u132, member, data) \ 219#define u132_read_pcimem(u132, member, data) \
220 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \ 220 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
221 ohci_regs, member), 0, data); 221 ohci_regs, member), 0, data);
222#define u132_write_pcimem(u132, member, data) \ 222#define u132_write_pcimem(u132, member, data) \
223 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \ 223 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
224 ohci_regs, member), 0, data); 224 ohci_regs, member), 0, data);
225static inline struct u132 *udev_to_u132(struct u132_udev *udev) 225static inline struct u132 *udev_to_u132(struct u132_udev *udev)
226{ 226{
227 u8 udev_number = udev->udev_number; 227 u8 udev_number = udev->udev_number;
228 return container_of(udev, struct u132, udev[udev_number]); 228 return container_of(udev, struct u132, udev[udev_number]);
229} 229}
230 230
231static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd) 231static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
232{ 232{
233 return (struct u132 *)(hcd->hcd_priv); 233 return (struct u132 *)(hcd->hcd_priv);
234} 234}
235 235
236static inline struct usb_hcd *u132_to_hcd(struct u132 *u132) 236static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
237{ 237{
238 return container_of((void *)u132, struct usb_hcd, hcd_priv); 238 return container_of((void *)u132, struct usb_hcd, hcd_priv);
239} 239}
240 240
241static inline void u132_disable(struct u132 *u132) 241static inline void u132_disable(struct u132 *u132)
242{ 242{
243 u132_to_hcd(u132)->state = HC_STATE_HALT; 243 u132_to_hcd(u132)->state = HC_STATE_HALT;
244} 244}
245 245
246 246
@@ -250,147 +250,147 @@ static inline void u132_disable(struct u132 *u132)
250#include "../misc/usb_u132.h" 250#include "../misc/usb_u132.h"
251static const char hcd_name[] = "u132_hcd"; 251static const char hcd_name[] = "u132_hcd";
252#define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \ 252#define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
253 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \ 253 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
254 USB_PORT_STAT_C_RESET) << 16) 254 USB_PORT_STAT_C_RESET) << 16)
255static void u132_hcd_delete(struct kref *kref) 255static void u132_hcd_delete(struct kref *kref)
256{ 256{
257 struct u132 *u132 = kref_to_u132(kref); 257 struct u132 *u132 = kref_to_u132(kref);
258 struct platform_device *pdev = u132->platform_dev; 258 struct platform_device *pdev = u132->platform_dev;
259 struct usb_hcd *hcd = u132_to_hcd(u132); 259 struct usb_hcd *hcd = u132_to_hcd(u132);
260 u132->going += 1; 260 u132->going += 1;
261 mutex_lock(&u132_module_lock); 261 mutex_lock(&u132_module_lock);
262 list_del_init(&u132->u132_list); 262 list_del_init(&u132->u132_list);
263 u132_instances -= 1; 263 u132_instances -= 1;
264 mutex_unlock(&u132_module_lock); 264 mutex_unlock(&u132_module_lock);
265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" 265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); 266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
267 usb_put_hcd(hcd); 267 usb_put_hcd(hcd);
268} 268}
269 269
270static inline void u132_u132_put_kref(struct u132 *u132) 270static inline void u132_u132_put_kref(struct u132 *u132)
271{ 271{
272 kref_put(&u132->kref, u132_hcd_delete); 272 kref_put(&u132->kref, u132_hcd_delete);
273} 273}
274 274
275static inline void u132_u132_init_kref(struct u132 *u132) 275static inline void u132_u132_init_kref(struct u132 *u132)
276{ 276{
277 kref_init(&u132->kref); 277 kref_init(&u132->kref);
278} 278}
279 279
280static void u132_udev_delete(struct kref *kref) 280static void u132_udev_delete(struct kref *kref)
281{ 281{
282 struct u132_udev *udev = kref_to_u132_udev(kref); 282 struct u132_udev *udev = kref_to_u132_udev(kref);
283 udev->udev_number = 0; 283 udev->udev_number = 0;
284 udev->usb_device = NULL; 284 udev->usb_device = NULL;
285 udev->usb_addr = 0; 285 udev->usb_addr = 0;
286 udev->enumeration = 0; 286 udev->enumeration = 0;
287} 287}
288 288
289static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev) 289static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
290{ 290{
291 kref_put(&udev->kref, u132_udev_delete); 291 kref_put(&udev->kref, u132_udev_delete);
292} 292}
293 293
294static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev) 294static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
295{ 295{
296 kref_get(&udev->kref); 296 kref_get(&udev->kref);
297} 297}
298 298
299static inline void u132_udev_init_kref(struct u132 *u132, 299static inline void u132_udev_init_kref(struct u132 *u132,
300 struct u132_udev *udev) 300 struct u132_udev *udev)
301{ 301{
302 kref_init(&udev->kref); 302 kref_init(&udev->kref);
303} 303}
304 304
305static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring) 305static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
306{ 306{
307 kref_put(&u132->kref, u132_hcd_delete); 307 kref_put(&u132->kref, u132_hcd_delete);
308} 308}
309 309
310static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring, 310static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
311 unsigned int delta) 311 unsigned int delta)
312{ 312{
313 if (delta > 0) { 313 if (delta > 0) {
314 if (queue_delayed_work(workqueue, &ring->scheduler, delta)) 314 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
315 return; 315 return;
316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0)) 316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
317 return; 317 return;
318 kref_put(&u132->kref, u132_hcd_delete); 318 kref_put(&u132->kref, u132_hcd_delete);
319 return; 319 return;
320} 320}
321 321
322static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring, 322static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
323 unsigned int delta) 323 unsigned int delta)
324{ 324{
325 kref_get(&u132->kref); 325 kref_get(&u132->kref);
326 u132_ring_requeue_work(u132, ring, delta); 326 u132_ring_requeue_work(u132, ring, delta);
327 return; 327 return;
328} 328}
329 329
330static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring) 330static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
331{ 331{
332 if (cancel_delayed_work(&ring->scheduler)) { 332 if (cancel_delayed_work(&ring->scheduler))
333 kref_put(&u132->kref, u132_hcd_delete); 333 kref_put(&u132->kref, u132_hcd_delete);
334 }
335} 334}
336 335
337static void u132_endp_delete(struct kref *kref) 336static void u132_endp_delete(struct kref *kref)
338{ 337{
339 struct u132_endp *endp = kref_to_u132_endp(kref); 338 struct u132_endp *endp = kref_to_u132_endp(kref);
340 struct u132 *u132 = endp->u132; 339 struct u132 *u132 = endp->u132;
341 u8 usb_addr = endp->usb_addr; 340 u8 usb_addr = endp->usb_addr;
342 u8 usb_endp = endp->usb_endp; 341 u8 usb_endp = endp->usb_endp;
343 u8 address = u132->addr[usb_addr].address; 342 u8 address = u132->addr[usb_addr].address;
344 struct u132_udev *udev = &u132->udev[address]; 343 struct u132_udev *udev = &u132->udev[address];
345 u8 endp_number = endp->endp_number; 344 u8 endp_number = endp->endp_number;
346 struct usb_host_endpoint *hep = endp->hep; 345 struct usb_host_endpoint *hep = endp->hep;
347 struct u132_ring *ring = endp->ring; 346 struct u132_ring *ring = endp->ring;
348 struct list_head *head = &endp->endp_ring; 347 struct list_head *head = &endp->endp_ring;
349 ring->length -= 1; 348 ring->length -= 1;
350 if (endp == ring->curr_endp) { 349 if (endp == ring->curr_endp) {
351 if (list_empty(head)) { 350 if (list_empty(head)) {
352 ring->curr_endp = NULL; 351 ring->curr_endp = NULL;
353 list_del(head); 352 list_del(head);
354 } else { 353 } else {
355 struct u132_endp *next_endp = list_entry(head->next, 354 struct u132_endp *next_endp = list_entry(head->next,
356 struct u132_endp, endp_ring); 355 struct u132_endp, endp_ring);
357 ring->curr_endp = next_endp; 356 ring->curr_endp = next_endp;
358 list_del(head); 357 list_del(head);
359 }} else 358 }
360 list_del(head); 359 } else
361 if (endp->input) { 360 list_del(head);
362 udev->endp_number_in[usb_endp] = 0; 361 if (endp->input) {
363 u132_udev_put_kref(u132, udev); 362 udev->endp_number_in[usb_endp] = 0;
364 } 363 u132_udev_put_kref(u132, udev);
365 if (endp->output) { 364 }
366 udev->endp_number_out[usb_endp] = 0; 365 if (endp->output) {
367 u132_udev_put_kref(u132, udev); 366 udev->endp_number_out[usb_endp] = 0;
368 } 367 u132_udev_put_kref(u132, udev);
369 u132->endp[endp_number - 1] = NULL; 368 }
370 hep->hcpriv = NULL; 369 u132->endp[endp_number - 1] = NULL;
371 kfree(endp); 370 hep->hcpriv = NULL;
372 u132_u132_put_kref(u132); 371 kfree(endp);
372 u132_u132_put_kref(u132);
373} 373}
374 374
375static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp) 375static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
376{ 376{
377 kref_put(&endp->kref, u132_endp_delete); 377 kref_put(&endp->kref, u132_endp_delete);
378} 378}
379 379
380static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp) 380static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
381{ 381{
382 kref_get(&endp->kref); 382 kref_get(&endp->kref);
383} 383}
384 384
385static inline void u132_endp_init_kref(struct u132 *u132, 385static inline void u132_endp_init_kref(struct u132 *u132,
386 struct u132_endp *endp) 386 struct u132_endp *endp)
387{ 387{
388 kref_init(&endp->kref); 388 kref_init(&endp->kref);
389 kref_get(&u132->kref); 389 kref_get(&u132->kref);
390} 390}
391 391
392static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp, 392static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
393 unsigned int delta) 393 unsigned int delta)
394{ 394{
395 if (queue_delayed_work(workqueue, &endp->scheduler, delta)) 395 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
396 kref_get(&endp->kref); 396 kref_get(&endp->kref);
@@ -398,13 +398,13 @@ static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
398 398
399static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp) 399static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
400{ 400{
401 if (cancel_delayed_work(&endp->scheduler)) 401 if (cancel_delayed_work(&endp->scheduler))
402 kref_put(&endp->kref, u132_endp_delete); 402 kref_put(&endp->kref, u132_endp_delete);
403} 403}
404 404
405static inline void u132_monitor_put_kref(struct u132 *u132) 405static inline void u132_monitor_put_kref(struct u132 *u132)
406{ 406{
407 kref_put(&u132->kref, u132_hcd_delete); 407 kref_put(&u132->kref, u132_hcd_delete);
408} 408}
409 409
410static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta) 410static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
@@ -421,200 +421,201 @@ static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
421 421
422static void u132_monitor_cancel_work(struct u132 *u132) 422static void u132_monitor_cancel_work(struct u132 *u132)
423{ 423{
424 if (cancel_delayed_work(&u132->monitor)) 424 if (cancel_delayed_work(&u132->monitor))
425 kref_put(&u132->kref, u132_hcd_delete); 425 kref_put(&u132->kref, u132_hcd_delete);
426} 426}
427 427
428static int read_roothub_info(struct u132 *u132) 428static int read_roothub_info(struct u132 *u132)
429{ 429{
430 u32 revision; 430 u32 revision;
431 int retval; 431 int retval;
432 retval = u132_read_pcimem(u132, revision, &revision); 432 retval = u132_read_pcimem(u132, revision, &revision);
433 if (retval) { 433 if (retval) {
434 dev_err(&u132->platform_dev->dev, "error %d accessing device co" 434 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
435 "ntrol\n", retval); 435 "ntrol\n", retval);
436 return retval; 436 return retval;
437 } else if ((revision & 0xFF) == 0x10) { 437 } else if ((revision & 0xFF) == 0x10) {
438 } else if ((revision & 0xFF) == 0x11) { 438 } else if ((revision & 0xFF) == 0x11) {
439 } else { 439 } else {
440 dev_err(&u132->platform_dev->dev, "device revision is not valid" 440 dev_err(&u132->platform_dev->dev, "device revision is not valid"
441 " %08X\n", revision); 441 " %08X\n", revision);
442 return -ENODEV; 442 return -ENODEV;
443 } 443 }
444 retval = u132_read_pcimem(u132, control, &u132->hc_control); 444 retval = u132_read_pcimem(u132, control, &u132->hc_control);
445 if (retval) { 445 if (retval) {
446 dev_err(&u132->platform_dev->dev, "error %d accessing device co" 446 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
447 "ntrol\n", retval); 447 "ntrol\n", retval);
448 return retval; 448 return retval;
449 } 449 }
450 retval = u132_read_pcimem(u132, roothub.status, 450 retval = u132_read_pcimem(u132, roothub.status,
451 &u132->hc_roothub_status); 451 &u132->hc_roothub_status);
452 if (retval) { 452 if (retval) {
453 dev_err(&u132->platform_dev->dev, "error %d accessing device re" 453 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
454 "g roothub.status\n", retval); 454 "g roothub.status\n", retval);
455 return retval; 455 return retval;
456 } 456 }
457 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a); 457 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
458 if (retval) { 458 if (retval) {
459 dev_err(&u132->platform_dev->dev, "error %d accessing device re" 459 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
460 "g roothub.a\n", retval); 460 "g roothub.a\n", retval);
461 return retval; 461 return retval;
462 } 462 }
463 { 463 {
464 int I = u132->num_ports; 464 int I = u132->num_ports;
465 int i = 0; 465 int i = 0;
466 while (I-- > 0) { 466 while (I-- > 0) {
467 retval = u132_read_pcimem(u132, roothub.portstatus[i], 467 retval = u132_read_pcimem(u132, roothub.portstatus[i],
468 &u132->hc_roothub_portstatus[i]); 468 &u132->hc_roothub_portstatus[i]);
469 if (retval) { 469 if (retval) {
470 dev_err(&u132->platform_dev->dev, "error %d acc" 470 dev_err(&u132->platform_dev->dev, "error %d acc"
471 "essing device roothub.portstatus[%d]\n" 471 "essing device roothub.portstatus[%d]\n"
472 , retval, i); 472 , retval, i);
473 return retval; 473 return retval;
474 } else 474 } else
475 i += 1; 475 i += 1;
476 } 476 }
477 } 477 }
478 return 0; 478 return 0;
479} 479}
480 480
481static void u132_hcd_monitor_work(struct work_struct *work) 481static void u132_hcd_monitor_work(struct work_struct *work)
482{ 482{
483 struct u132 *u132 = container_of(work, struct u132, monitor.work); 483 struct u132 *u132 = container_of(work, struct u132, monitor.work);
484 if (u132->going > 1) { 484 if (u132->going > 1) {
485 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 485 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
486 , u132->going); 486 , u132->going);
487 u132_monitor_put_kref(u132); 487 u132_monitor_put_kref(u132);
488 return; 488 return;
489 } else if (u132->going > 0) { 489 } else if (u132->going > 0) {
490 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 490 dev_err(&u132->platform_dev->dev, "device is being removed\n");
491 u132_monitor_put_kref(u132); 491 u132_monitor_put_kref(u132);
492 return; 492 return;
493 } else { 493 } else {
494 int retval; 494 int retval;
495 mutex_lock(&u132->sw_lock); 495 mutex_lock(&u132->sw_lock);
496 retval = read_roothub_info(u132); 496 retval = read_roothub_info(u132);
497 if (retval) { 497 if (retval) {
498 struct usb_hcd *hcd = u132_to_hcd(u132); 498 struct usb_hcd *hcd = u132_to_hcd(u132);
499 u132_disable(u132); 499 u132_disable(u132);
500 u132->going = 1; 500 u132->going = 1;
501 mutex_unlock(&u132->sw_lock); 501 mutex_unlock(&u132->sw_lock);
502 usb_hc_died(hcd); 502 usb_hc_died(hcd);
503 ftdi_elan_gone_away(u132->platform_dev); 503 ftdi_elan_gone_away(u132->platform_dev);
504 u132_monitor_put_kref(u132); 504 u132_monitor_put_kref(u132);
505 return; 505 return;
506 } else { 506 } else {
507 u132_monitor_requeue_work(u132, 500); 507 u132_monitor_requeue_work(u132, 500);
508 mutex_unlock(&u132->sw_lock); 508 mutex_unlock(&u132->sw_lock);
509 return; 509 return;
510 } 510 }
511 } 511 }
512} 512}
513 513
514static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp, 514static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
515 struct urb *urb, int status) 515 struct urb *urb, int status)
516{ 516{
517 struct u132_ring *ring; 517 struct u132_ring *ring;
518 unsigned long irqs; 518 unsigned long irqs;
519 struct usb_hcd *hcd = u132_to_hcd(u132); 519 struct usb_hcd *hcd = u132_to_hcd(u132);
520 urb->error_count = 0; 520 urb->error_count = 0;
521 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 521 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
522 usb_hcd_unlink_urb_from_ep(hcd, urb); 522 usb_hcd_unlink_urb_from_ep(hcd, urb);
523 endp->queue_next += 1; 523 endp->queue_next += 1;
524 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 524 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
525 endp->active = 0; 525 endp->active = 0;
526 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 526 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
527 } else { 527 } else {
528 struct list_head *next = endp->urb_more.next; 528 struct list_head *next = endp->urb_more.next;
529 struct u132_urbq *urbq = list_entry(next, struct u132_urbq, 529 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
530 urb_more); 530 urb_more);
531 list_del(next); 531 list_del(next);
532 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = 532 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
533 urbq->urb; 533 urbq->urb;
534 endp->active = 0; 534 endp->active = 0;
535 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 535 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
536 kfree(urbq); 536 kfree(urbq);
537 } down(&u132->scheduler_lock); 537 }
538 ring = endp->ring; 538 mutex_lock(&u132->scheduler_lock);
539 ring->in_use = 0; 539 ring = endp->ring;
540 u132_ring_cancel_work(u132, ring); 540 ring->in_use = 0;
541 u132_ring_queue_work(u132, ring, 0); 541 u132_ring_cancel_work(u132, ring);
542 up(&u132->scheduler_lock); 542 u132_ring_queue_work(u132, ring, 0);
543 u132_endp_put_kref(u132, endp); 543 mutex_unlock(&u132->scheduler_lock);
544 u132_endp_put_kref(u132, endp);
544 usb_hcd_giveback_urb(hcd, urb, status); 545 usb_hcd_giveback_urb(hcd, urb, status);
545 return; 546 return;
546} 547}
547 548
548static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp, 549static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
549 struct urb *urb, int status) 550 struct urb *urb, int status)
550{ 551{
551 u132_endp_put_kref(u132, endp); 552 u132_endp_put_kref(u132, endp);
552} 553}
553 554
554static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp, 555static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
555 struct urb *urb, int status) 556 struct urb *urb, int status)
556{ 557{
557 unsigned long irqs; 558 unsigned long irqs;
558 struct usb_hcd *hcd = u132_to_hcd(u132); 559 struct usb_hcd *hcd = u132_to_hcd(u132);
559 urb->error_count = 0; 560 urb->error_count = 0;
560 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 561 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
561 usb_hcd_unlink_urb_from_ep(hcd, urb); 562 usb_hcd_unlink_urb_from_ep(hcd, urb);
562 endp->queue_next += 1; 563 endp->queue_next += 1;
563 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 564 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
564 endp->active = 0; 565 endp->active = 0;
565 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 566 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
566 } else { 567 } else {
567 struct list_head *next = endp->urb_more.next; 568 struct list_head *next = endp->urb_more.next;
568 struct u132_urbq *urbq = list_entry(next, struct u132_urbq, 569 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
569 urb_more); 570 urb_more);
570 list_del(next); 571 list_del(next);
571 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = 572 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
572 urbq->urb; 573 urbq->urb;
573 endp->active = 0; 574 endp->active = 0;
574 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 575 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
575 kfree(urbq); 576 kfree(urbq);
576 } usb_hcd_giveback_urb(hcd, urb, status); 577 } usb_hcd_giveback_urb(hcd, urb, status);
577 return; 578 return;
578} 579}
579 580
580static inline int edset_input(struct u132 *u132, struct u132_ring *ring, 581static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
581 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 582 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
582 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 583 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
583 int toggle_bits, int error_count, int condition_code, int repeat_number, 584 int toggle_bits, int error_count, int condition_code, int repeat_number,
584 int halted, int skipped, int actual, int non_null)) 585 int halted, int skipped, int actual, int non_null))
585{ 586{
586 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp, 587 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
587 urb, address, endp->usb_endp, toggle_bits, callback); 588 urb, address, endp->usb_endp, toggle_bits, callback);
588} 589}
589 590
590static inline int edset_setup(struct u132 *u132, struct u132_ring *ring, 591static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
591 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 592 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
592 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 593 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
593 int toggle_bits, int error_count, int condition_code, int repeat_number, 594 int toggle_bits, int error_count, int condition_code, int repeat_number,
594 int halted, int skipped, int actual, int non_null)) 595 int halted, int skipped, int actual, int non_null))
595{ 596{
596 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp, 597 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
597 urb, address, endp->usb_endp, toggle_bits, callback); 598 urb, address, endp->usb_endp, toggle_bits, callback);
598} 599}
599 600
600static inline int edset_single(struct u132 *u132, struct u132_ring *ring, 601static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
601 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 602 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
602 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 603 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
603 int toggle_bits, int error_count, int condition_code, int repeat_number, 604 int toggle_bits, int error_count, int condition_code, int repeat_number,
604 int halted, int skipped, int actual, int non_null)) 605 int halted, int skipped, int actual, int non_null))
605{ 606{
606 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number, 607 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
607 endp, urb, address, endp->usb_endp, toggle_bits, callback); 608 endp, urb, address, endp->usb_endp, toggle_bits, callback);
608} 609}
609 610
610static inline int edset_output(struct u132 *u132, struct u132_ring *ring, 611static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
611 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 612 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
612 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 613 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
613 int toggle_bits, int error_count, int condition_code, int repeat_number, 614 int toggle_bits, int error_count, int condition_code, int repeat_number,
614 int halted, int skipped, int actual, int non_null)) 615 int halted, int skipped, int actual, int non_null))
615{ 616{
616 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number, 617 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
617 endp, urb, address, endp->usb_endp, toggle_bits, callback); 618 endp, urb, address, endp->usb_endp, toggle_bits, callback);
618} 619}
619 620
620 621
@@ -623,683 +624,678 @@ static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
623* 624*
624*/ 625*/
625static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf, 626static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
626 int len, int toggle_bits, int error_count, int condition_code, 627 int len, int toggle_bits, int error_count, int condition_code,
627 int repeat_number, int halted, int skipped, int actual, int non_null) 628 int repeat_number, int halted, int skipped, int actual, int non_null)
628{ 629{
629 struct u132_endp *endp = data; 630 struct u132_endp *endp = data;
630 struct u132 *u132 = endp->u132; 631 struct u132 *u132 = endp->u132;
631 u8 address = u132->addr[endp->usb_addr].address; 632 u8 address = u132->addr[endp->usb_addr].address;
632 struct u132_udev *udev = &u132->udev[address]; 633 struct u132_udev *udev = &u132->udev[address];
633 down(&u132->scheduler_lock); 634 mutex_lock(&u132->scheduler_lock);
634 if (u132->going > 1) { 635 if (u132->going > 1) {
635 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 636 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
636 , u132->going); 637 , u132->going);
637 up(&u132->scheduler_lock); 638 mutex_unlock(&u132->scheduler_lock);
638 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 639 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
639 return; 640 return;
640 } else if (endp->dequeueing) { 641 } else if (endp->dequeueing) {
641 endp->dequeueing = 0; 642 endp->dequeueing = 0;
642 up(&u132->scheduler_lock); 643 mutex_unlock(&u132->scheduler_lock);
643 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 644 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
644 return; 645 return;
645 } else if (u132->going > 0) { 646 } else if (u132->going > 0) {
646 dev_err(&u132->platform_dev->dev, "device is being removed " 647 dev_err(&u132->platform_dev->dev, "device is being removed "
647 "urb=%p\n", urb); 648 "urb=%p\n", urb);
648 up(&u132->scheduler_lock); 649 mutex_unlock(&u132->scheduler_lock);
649 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 650 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
650 return; 651 return;
651 } else if (!urb->unlinked) { 652 } else if (!urb->unlinked) {
652 struct u132_ring *ring = endp->ring; 653 struct u132_ring *ring = endp->ring;
653 u8 *u = urb->transfer_buffer + urb->actual_length; 654 u8 *u = urb->transfer_buffer + urb->actual_length;
654 u8 *b = buf; 655 u8 *b = buf;
655 int L = len; 656 int L = len;
656 while (L-- > 0) { 657
657 *u++ = *b++; 658 while (L-- > 0)
658 } 659 *u++ = *b++;
659 urb->actual_length += len; 660
660 if ((condition_code == TD_CC_NOERROR) && 661 urb->actual_length += len;
661 (urb->transfer_buffer_length > urb->actual_length)) { 662 if ((condition_code == TD_CC_NOERROR) &&
662 endp->toggle_bits = toggle_bits; 663 (urb->transfer_buffer_length > urb->actual_length)) {
663 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 664 endp->toggle_bits = toggle_bits;
664 1 & toggle_bits); 665 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
665 if (urb->actual_length > 0) { 666 1 & toggle_bits);
666 int retval; 667 if (urb->actual_length > 0) {
667 up(&u132->scheduler_lock); 668 int retval;
668 retval = edset_single(u132, ring, endp, urb, 669 mutex_unlock(&u132->scheduler_lock);
669 address, endp->toggle_bits, 670 retval = edset_single(u132, ring, endp, urb,
670 u132_hcd_interrupt_recv); 671 address, endp->toggle_bits,
671 if (retval == 0) { 672 u132_hcd_interrupt_recv);
672 } else 673 if (retval != 0)
673 u132_hcd_giveback_urb(u132, endp, urb, 674 u132_hcd_giveback_urb(u132, endp, urb,
674 retval); 675 retval);
675 } else { 676 } else {
676 ring->in_use = 0; 677 ring->in_use = 0;
677 endp->active = 0; 678 endp->active = 0;
678 endp->jiffies = jiffies + 679 endp->jiffies = jiffies +
679 msecs_to_jiffies(urb->interval); 680 msecs_to_jiffies(urb->interval);
680 u132_ring_cancel_work(u132, ring); 681 u132_ring_cancel_work(u132, ring);
681 u132_ring_queue_work(u132, ring, 0); 682 u132_ring_queue_work(u132, ring, 0);
682 up(&u132->scheduler_lock); 683 mutex_unlock(&u132->scheduler_lock);
683 u132_endp_put_kref(u132, endp); 684 u132_endp_put_kref(u132, endp);
684 } 685 }
685 return; 686 return;
686 } else if ((condition_code == TD_DATAUNDERRUN) && 687 } else if ((condition_code == TD_DATAUNDERRUN) &&
687 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { 688 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
688 endp->toggle_bits = toggle_bits; 689 endp->toggle_bits = toggle_bits;
689 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 690 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
690 1 & toggle_bits); 691 1 & toggle_bits);
691 up(&u132->scheduler_lock); 692 mutex_unlock(&u132->scheduler_lock);
692 u132_hcd_giveback_urb(u132, endp, urb, 0); 693 u132_hcd_giveback_urb(u132, endp, urb, 0);
693 return; 694 return;
694 } else { 695 } else {
695 if (condition_code == TD_CC_NOERROR) { 696 if (condition_code == TD_CC_NOERROR) {
696 endp->toggle_bits = toggle_bits; 697 endp->toggle_bits = toggle_bits;
697 usb_settoggle(udev->usb_device, endp->usb_endp, 698 usb_settoggle(udev->usb_device, endp->usb_endp,
698 0, 1 & toggle_bits); 699 0, 1 & toggle_bits);
699 } else if (condition_code == TD_CC_STALL) { 700 } else if (condition_code == TD_CC_STALL) {
700 endp->toggle_bits = 0x2; 701 endp->toggle_bits = 0x2;
701 usb_settoggle(udev->usb_device, endp->usb_endp, 702 usb_settoggle(udev->usb_device, endp->usb_endp,
702 0, 0); 703 0, 0);
703 } else { 704 } else {
704 endp->toggle_bits = 0x2; 705 endp->toggle_bits = 0x2;
705 usb_settoggle(udev->usb_device, endp->usb_endp, 706 usb_settoggle(udev->usb_device, endp->usb_endp,
706 0, 0); 707 0, 0);
707 dev_err(&u132->platform_dev->dev, "urb=%p givin" 708 dev_err(&u132->platform_dev->dev, "urb=%p givin"
708 "g back INTERRUPT %s\n", urb, 709 "g back INTERRUPT %s\n", urb,
709 cc_to_text[condition_code]); 710 cc_to_text[condition_code]);
710 } 711 }
711 up(&u132->scheduler_lock); 712 mutex_unlock(&u132->scheduler_lock);
712 u132_hcd_giveback_urb(u132, endp, urb, 713 u132_hcd_giveback_urb(u132, endp, urb,
713 cc_to_error[condition_code]); 714 cc_to_error[condition_code]);
714 return; 715 return;
715 } 716 }
716 } else { 717 } else {
717 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 718 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
718 "unlinked=%d\n", urb, urb->unlinked); 719 "unlinked=%d\n", urb, urb->unlinked);
719 up(&u132->scheduler_lock); 720 mutex_unlock(&u132->scheduler_lock);
720 u132_hcd_giveback_urb(u132, endp, urb, 0); 721 u132_hcd_giveback_urb(u132, endp, urb, 0);
721 return; 722 return;
722 } 723 }
723} 724}
724 725
725static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf, 726static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
726 int len, int toggle_bits, int error_count, int condition_code, 727 int len, int toggle_bits, int error_count, int condition_code,
727 int repeat_number, int halted, int skipped, int actual, int non_null) 728 int repeat_number, int halted, int skipped, int actual, int non_null)
728{ 729{
729 struct u132_endp *endp = data; 730 struct u132_endp *endp = data;
730 struct u132 *u132 = endp->u132; 731 struct u132 *u132 = endp->u132;
731 u8 address = u132->addr[endp->usb_addr].address; 732 u8 address = u132->addr[endp->usb_addr].address;
732 down(&u132->scheduler_lock); 733 mutex_lock(&u132->scheduler_lock);
733 if (u132->going > 1) { 734 if (u132->going > 1) {
734 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 735 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
735 , u132->going); 736 , u132->going);
736 up(&u132->scheduler_lock); 737 mutex_unlock(&u132->scheduler_lock);
737 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 738 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
738 return; 739 return;
739 } else if (endp->dequeueing) { 740 } else if (endp->dequeueing) {
740 endp->dequeueing = 0; 741 endp->dequeueing = 0;
741 up(&u132->scheduler_lock); 742 mutex_unlock(&u132->scheduler_lock);
742 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 743 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
743 return; 744 return;
744 } else if (u132->going > 0) { 745 } else if (u132->going > 0) {
745 dev_err(&u132->platform_dev->dev, "device is being removed " 746 dev_err(&u132->platform_dev->dev, "device is being removed "
746 "urb=%p\n", urb); 747 "urb=%p\n", urb);
747 up(&u132->scheduler_lock); 748 mutex_unlock(&u132->scheduler_lock);
748 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 749 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
749 return; 750 return;
750 } else if (!urb->unlinked) { 751 } else if (!urb->unlinked) {
751 struct u132_ring *ring = endp->ring; 752 struct u132_ring *ring = endp->ring;
752 urb->actual_length += len; 753 urb->actual_length += len;
753 endp->toggle_bits = toggle_bits; 754 endp->toggle_bits = toggle_bits;
754 if (urb->transfer_buffer_length > urb->actual_length) { 755 if (urb->transfer_buffer_length > urb->actual_length) {
755 int retval; 756 int retval;
756 up(&u132->scheduler_lock); 757 mutex_unlock(&u132->scheduler_lock);
757 retval = edset_output(u132, ring, endp, urb, address, 758 retval = edset_output(u132, ring, endp, urb, address,
758 endp->toggle_bits, u132_hcd_bulk_output_sent); 759 endp->toggle_bits, u132_hcd_bulk_output_sent);
759 if (retval == 0) { 760 if (retval != 0)
760 } else 761 u132_hcd_giveback_urb(u132, endp, urb, retval);
761 u132_hcd_giveback_urb(u132, endp, urb, retval); 762 return;
762 return; 763 } else {
763 } else { 764 mutex_unlock(&u132->scheduler_lock);
764 up(&u132->scheduler_lock); 765 u132_hcd_giveback_urb(u132, endp, urb, 0);
765 u132_hcd_giveback_urb(u132, endp, urb, 0); 766 return;
766 return; 767 }
767 } 768 } else {
768 } else {
769 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 769 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
770 "unlinked=%d\n", urb, urb->unlinked); 770 "unlinked=%d\n", urb, urb->unlinked);
771 up(&u132->scheduler_lock); 771 mutex_unlock(&u132->scheduler_lock);
772 u132_hcd_giveback_urb(u132, endp, urb, 0); 772 u132_hcd_giveback_urb(u132, endp, urb, 0);
773 return; 773 return;
774 } 774 }
775} 775}
776 776
777static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf, 777static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
778 int len, int toggle_bits, int error_count, int condition_code, 778 int len, int toggle_bits, int error_count, int condition_code,
779 int repeat_number, int halted, int skipped, int actual, int non_null) 779 int repeat_number, int halted, int skipped, int actual, int non_null)
780{ 780{
781 struct u132_endp *endp = data; 781 struct u132_endp *endp = data;
782 struct u132 *u132 = endp->u132; 782 struct u132 *u132 = endp->u132;
783 u8 address = u132->addr[endp->usb_addr].address; 783 u8 address = u132->addr[endp->usb_addr].address;
784 struct u132_udev *udev = &u132->udev[address]; 784 struct u132_udev *udev = &u132->udev[address];
785 down(&u132->scheduler_lock); 785 mutex_lock(&u132->scheduler_lock);
786 if (u132->going > 1) { 786 if (u132->going > 1) {
787 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 787 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
788 , u132->going); 788 , u132->going);
789 up(&u132->scheduler_lock); 789 mutex_unlock(&u132->scheduler_lock);
790 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 790 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
791 return; 791 return;
792 } else if (endp->dequeueing) { 792 } else if (endp->dequeueing) {
793 endp->dequeueing = 0; 793 endp->dequeueing = 0;
794 up(&u132->scheduler_lock); 794 mutex_unlock(&u132->scheduler_lock);
795 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 795 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
796 return; 796 return;
797 } else if (u132->going > 0) { 797 } else if (u132->going > 0) {
798 dev_err(&u132->platform_dev->dev, "device is being removed " 798 dev_err(&u132->platform_dev->dev, "device is being removed "
799 "urb=%p\n", urb); 799 "urb=%p\n", urb);
800 up(&u132->scheduler_lock); 800 mutex_unlock(&u132->scheduler_lock);
801 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 801 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
802 return; 802 return;
803 } else if (!urb->unlinked) { 803 } else if (!urb->unlinked) {
804 struct u132_ring *ring = endp->ring; 804 struct u132_ring *ring = endp->ring;
805 u8 *u = urb->transfer_buffer + urb->actual_length; 805 u8 *u = urb->transfer_buffer + urb->actual_length;
806 u8 *b = buf; 806 u8 *b = buf;
807 int L = len; 807 int L = len;
808 while (L-- > 0) { 808
809 *u++ = *b++; 809 while (L-- > 0)
810 } 810 *u++ = *b++;
811 urb->actual_length += len; 811
812 if ((condition_code == TD_CC_NOERROR) && 812 urb->actual_length += len;
813 (urb->transfer_buffer_length > urb->actual_length)) { 813 if ((condition_code == TD_CC_NOERROR) &&
814 int retval; 814 (urb->transfer_buffer_length > urb->actual_length)) {
815 endp->toggle_bits = toggle_bits; 815 int retval;
816 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 816 endp->toggle_bits = toggle_bits;
817 1 & toggle_bits); 817 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
818 up(&u132->scheduler_lock); 818 1 & toggle_bits);
819 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 819 mutex_unlock(&u132->scheduler_lock);
820 ring->number, endp, urb, address, 820 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
821 endp->usb_endp, endp->toggle_bits, 821 ring->number, endp, urb, address,
822 u132_hcd_bulk_input_recv); 822 endp->usb_endp, endp->toggle_bits,
823 if (retval == 0) { 823 u132_hcd_bulk_input_recv);
824 } else 824 if (retval != 0)
825 u132_hcd_giveback_urb(u132, endp, urb, retval); 825 u132_hcd_giveback_urb(u132, endp, urb, retval);
826 return; 826 return;
827 } else if (condition_code == TD_CC_NOERROR) { 827 } else if (condition_code == TD_CC_NOERROR) {
828 endp->toggle_bits = toggle_bits; 828 endp->toggle_bits = toggle_bits;
829 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 829 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
830 1 & toggle_bits); 830 1 & toggle_bits);
831 up(&u132->scheduler_lock); 831 mutex_unlock(&u132->scheduler_lock);
832 u132_hcd_giveback_urb(u132, endp, urb, 832 u132_hcd_giveback_urb(u132, endp, urb,
833 cc_to_error[condition_code]); 833 cc_to_error[condition_code]);
834 return; 834 return;
835 } else if ((condition_code == TD_DATAUNDERRUN) && 835 } else if ((condition_code == TD_DATAUNDERRUN) &&
836 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { 836 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
837 endp->toggle_bits = toggle_bits; 837 endp->toggle_bits = toggle_bits;
838 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 838 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
839 1 & toggle_bits); 839 1 & toggle_bits);
840 up(&u132->scheduler_lock); 840 mutex_unlock(&u132->scheduler_lock);
841 u132_hcd_giveback_urb(u132, endp, urb, 0); 841 u132_hcd_giveback_urb(u132, endp, urb, 0);
842 return; 842 return;
843 } else if (condition_code == TD_DATAUNDERRUN) { 843 } else if (condition_code == TD_DATAUNDERRUN) {
844 endp->toggle_bits = toggle_bits; 844 endp->toggle_bits = toggle_bits;
845 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 845 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
846 1 & toggle_bits); 846 1 & toggle_bits);
847 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK" 847 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
848 ") giving back BULK IN %s\n", urb, 848 ") giving back BULK IN %s\n", urb,
849 cc_to_text[condition_code]); 849 cc_to_text[condition_code]);
850 up(&u132->scheduler_lock); 850 mutex_unlock(&u132->scheduler_lock);
851 u132_hcd_giveback_urb(u132, endp, urb, 0); 851 u132_hcd_giveback_urb(u132, endp, urb, 0);
852 return; 852 return;
853 } else if (condition_code == TD_CC_STALL) { 853 } else if (condition_code == TD_CC_STALL) {
854 endp->toggle_bits = 0x2; 854 endp->toggle_bits = 0x2;
855 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); 855 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
856 up(&u132->scheduler_lock); 856 mutex_unlock(&u132->scheduler_lock);
857 u132_hcd_giveback_urb(u132, endp, urb, 857 u132_hcd_giveback_urb(u132, endp, urb,
858 cc_to_error[condition_code]); 858 cc_to_error[condition_code]);
859 return; 859 return;
860 } else { 860 } else {
861 endp->toggle_bits = 0x2; 861 endp->toggle_bits = 0x2;
862 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); 862 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
863 dev_err(&u132->platform_dev->dev, "urb=%p giving back B" 863 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
864 "ULK IN code=%d %s\n", urb, condition_code, 864 "ULK IN code=%d %s\n", urb, condition_code,
865 cc_to_text[condition_code]); 865 cc_to_text[condition_code]);
866 up(&u132->scheduler_lock); 866 mutex_unlock(&u132->scheduler_lock);
867 u132_hcd_giveback_urb(u132, endp, urb, 867 u132_hcd_giveback_urb(u132, endp, urb,
868 cc_to_error[condition_code]); 868 cc_to_error[condition_code]);
869 return; 869 return;
870 } 870 }
871 } else { 871 } else {
872 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 872 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
873 "unlinked=%d\n", urb, urb->unlinked); 873 "unlinked=%d\n", urb, urb->unlinked);
874 up(&u132->scheduler_lock); 874 mutex_unlock(&u132->scheduler_lock);
875 u132_hcd_giveback_urb(u132, endp, urb, 0); 875 u132_hcd_giveback_urb(u132, endp, urb, 0);
876 return; 876 return;
877 } 877 }
878} 878}
879 879
880static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf, 880static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
881 int len, int toggle_bits, int error_count, int condition_code, 881 int len, int toggle_bits, int error_count, int condition_code,
882 int repeat_number, int halted, int skipped, int actual, int non_null) 882 int repeat_number, int halted, int skipped, int actual, int non_null)
883{ 883{
884 struct u132_endp *endp = data; 884 struct u132_endp *endp = data;
885 struct u132 *u132 = endp->u132; 885 struct u132 *u132 = endp->u132;
886 down(&u132->scheduler_lock); 886 mutex_lock(&u132->scheduler_lock);
887 if (u132->going > 1) { 887 if (u132->going > 1) {
888 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 888 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
889 , u132->going); 889 , u132->going);
890 up(&u132->scheduler_lock); 890 mutex_unlock(&u132->scheduler_lock);
891 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 891 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
892 return; 892 return;
893 } else if (endp->dequeueing) { 893 } else if (endp->dequeueing) {
894 endp->dequeueing = 0; 894 endp->dequeueing = 0;
895 up(&u132->scheduler_lock); 895 mutex_unlock(&u132->scheduler_lock);
896 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 896 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
897 return; 897 return;
898 } else if (u132->going > 0) { 898 } else if (u132->going > 0) {
899 dev_err(&u132->platform_dev->dev, "device is being removed " 899 dev_err(&u132->platform_dev->dev, "device is being removed "
900 "urb=%p\n", urb); 900 "urb=%p\n", urb);
901 up(&u132->scheduler_lock); 901 mutex_unlock(&u132->scheduler_lock);
902 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 902 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
903 return; 903 return;
904 } else if (!urb->unlinked) { 904 } else if (!urb->unlinked) {
905 up(&u132->scheduler_lock); 905 mutex_unlock(&u132->scheduler_lock);
906 u132_hcd_giveback_urb(u132, endp, urb, 0); 906 u132_hcd_giveback_urb(u132, endp, urb, 0);
907 return; 907 return;
908 } else { 908 } else {
909 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 909 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
910 "unlinked=%d\n", urb, urb->unlinked); 910 "unlinked=%d\n", urb, urb->unlinked);
911 up(&u132->scheduler_lock); 911 mutex_unlock(&u132->scheduler_lock);
912 u132_hcd_giveback_urb(u132, endp, urb, 0); 912 u132_hcd_giveback_urb(u132, endp, urb, 0);
913 return; 913 return;
914 } 914 }
915} 915}
916 916
917static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf, 917static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
918 int len, int toggle_bits, int error_count, int condition_code, 918 int len, int toggle_bits, int error_count, int condition_code,
919 int repeat_number, int halted, int skipped, int actual, int non_null) 919 int repeat_number, int halted, int skipped, int actual, int non_null)
920{ 920{
921 struct u132_endp *endp = data; 921 struct u132_endp *endp = data;
922 struct u132 *u132 = endp->u132; 922 struct u132 *u132 = endp->u132;
923 u8 address = u132->addr[endp->usb_addr].address; 923 u8 address = u132->addr[endp->usb_addr].address;
924 down(&u132->scheduler_lock); 924 mutex_lock(&u132->scheduler_lock);
925 if (u132->going > 1) { 925 if (u132->going > 1) {
926 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 926 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
927 , u132->going); 927 , u132->going);
928 up(&u132->scheduler_lock); 928 mutex_unlock(&u132->scheduler_lock);
929 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 929 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
930 return; 930 return;
931 } else if (endp->dequeueing) { 931 } else if (endp->dequeueing) {
932 endp->dequeueing = 0; 932 endp->dequeueing = 0;
933 up(&u132->scheduler_lock); 933 mutex_unlock(&u132->scheduler_lock);
934 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 934 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
935 return; 935 return;
936 } else if (u132->going > 0) { 936 } else if (u132->going > 0) {
937 dev_err(&u132->platform_dev->dev, "device is being removed " 937 dev_err(&u132->platform_dev->dev, "device is being removed "
938 "urb=%p\n", urb); 938 "urb=%p\n", urb);
939 up(&u132->scheduler_lock); 939 mutex_unlock(&u132->scheduler_lock);
940 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 940 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
941 return; 941 return;
942 } else if (!urb->unlinked) { 942 } else if (!urb->unlinked) {
943 struct u132_ring *ring = endp->ring; 943 struct u132_ring *ring = endp->ring;
944 u8 *u = urb->transfer_buffer; 944 u8 *u = urb->transfer_buffer;
945 u8 *b = buf; 945 u8 *b = buf;
946 int L = len; 946 int L = len;
947 while (L-- > 0) { 947
948 *u++ = *b++; 948 while (L-- > 0)
949 } 949 *u++ = *b++;
950 urb->actual_length = len; 950
951 if ((condition_code == TD_CC_NOERROR) || ((condition_code == 951 urb->actual_length = len;
952 TD_DATAUNDERRUN) && ((urb->transfer_flags & 952 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
953 URB_SHORT_NOT_OK) == 0))) { 953 TD_DATAUNDERRUN) && ((urb->transfer_flags &
954 int retval; 954 URB_SHORT_NOT_OK) == 0))) {
955 up(&u132->scheduler_lock); 955 int retval;
956 retval = usb_ftdi_elan_edset_empty(u132->platform_dev, 956 mutex_unlock(&u132->scheduler_lock);
957 ring->number, endp, urb, address, 957 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
958 endp->usb_endp, 0x3, 958 ring->number, endp, urb, address,
959 u132_hcd_configure_empty_sent); 959 endp->usb_endp, 0x3,
960 if (retval == 0) { 960 u132_hcd_configure_empty_sent);
961 } else 961 if (retval != 0)
962 u132_hcd_giveback_urb(u132, endp, urb, retval); 962 u132_hcd_giveback_urb(u132, endp, urb, retval);
963 return; 963 return;
964 } else if (condition_code == TD_CC_STALL) { 964 } else if (condition_code == TD_CC_STALL) {
965 up(&u132->scheduler_lock); 965 mutex_unlock(&u132->scheduler_lock);
966 dev_warn(&u132->platform_dev->dev, "giving back SETUP I" 966 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
967 "NPUT STALL urb %p\n", urb); 967 "NPUT STALL urb %p\n", urb);
968 u132_hcd_giveback_urb(u132, endp, urb, 968 u132_hcd_giveback_urb(u132, endp, urb,
969 cc_to_error[condition_code]); 969 cc_to_error[condition_code]);
970 return; 970 return;
971 } else { 971 } else {
972 up(&u132->scheduler_lock); 972 mutex_unlock(&u132->scheduler_lock);
973 dev_err(&u132->platform_dev->dev, "giving back SETUP IN" 973 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
974 "PUT %s urb %p\n", cc_to_text[condition_code], 974 "PUT %s urb %p\n", cc_to_text[condition_code],
975 urb); 975 urb);
976 u132_hcd_giveback_urb(u132, endp, urb, 976 u132_hcd_giveback_urb(u132, endp, urb,
977 cc_to_error[condition_code]); 977 cc_to_error[condition_code]);
978 return; 978 return;
979 } 979 }
980 } else { 980 } else {
981 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 981 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
982 "unlinked=%d\n", urb, urb->unlinked); 982 "unlinked=%d\n", urb, urb->unlinked);
983 up(&u132->scheduler_lock); 983 mutex_unlock(&u132->scheduler_lock);
984 u132_hcd_giveback_urb(u132, endp, urb, 0); 984 u132_hcd_giveback_urb(u132, endp, urb, 0);
985 return; 985 return;
986 } 986 }
987} 987}
988 988
989static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf, 989static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
990 int len, int toggle_bits, int error_count, int condition_code, 990 int len, int toggle_bits, int error_count, int condition_code,
991 int repeat_number, int halted, int skipped, int actual, int non_null) 991 int repeat_number, int halted, int skipped, int actual, int non_null)
992{ 992{
993 struct u132_endp *endp = data; 993 struct u132_endp *endp = data;
994 struct u132 *u132 = endp->u132; 994 struct u132 *u132 = endp->u132;
995 down(&u132->scheduler_lock); 995 mutex_lock(&u132->scheduler_lock);
996 if (u132->going > 1) { 996 if (u132->going > 1) {
997 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 997 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
998 , u132->going); 998 , u132->going);
999 up(&u132->scheduler_lock); 999 mutex_unlock(&u132->scheduler_lock);
1000 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1000 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1001 return; 1001 return;
1002 } else if (endp->dequeueing) { 1002 } else if (endp->dequeueing) {
1003 endp->dequeueing = 0; 1003 endp->dequeueing = 0;
1004 up(&u132->scheduler_lock); 1004 mutex_unlock(&u132->scheduler_lock);
1005 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1005 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1006 return; 1006 return;
1007 } else if (u132->going > 0) { 1007 } else if (u132->going > 0) {
1008 dev_err(&u132->platform_dev->dev, "device is being removed " 1008 dev_err(&u132->platform_dev->dev, "device is being removed "
1009 "urb=%p\n", urb); 1009 "urb=%p\n", urb);
1010 up(&u132->scheduler_lock); 1010 mutex_unlock(&u132->scheduler_lock);
1011 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1011 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1012 return; 1012 return;
1013 } else if (!urb->unlinked) { 1013 } else if (!urb->unlinked) {
1014 up(&u132->scheduler_lock); 1014 mutex_unlock(&u132->scheduler_lock);
1015 u132_hcd_giveback_urb(u132, endp, urb, 0); 1015 u132_hcd_giveback_urb(u132, endp, urb, 0);
1016 return; 1016 return;
1017 } else { 1017 } else {
1018 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1018 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1019 "unlinked=%d\n", urb, urb->unlinked); 1019 "unlinked=%d\n", urb, urb->unlinked);
1020 up(&u132->scheduler_lock); 1020 mutex_unlock(&u132->scheduler_lock);
1021 u132_hcd_giveback_urb(u132, endp, urb, 0); 1021 u132_hcd_giveback_urb(u132, endp, urb, 0);
1022 return; 1022 return;
1023 } 1023 }
1024} 1024}
1025 1025
1026static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf, 1026static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1027 int len, int toggle_bits, int error_count, int condition_code, 1027 int len, int toggle_bits, int error_count, int condition_code,
1028 int repeat_number, int halted, int skipped, int actual, int non_null) 1028 int repeat_number, int halted, int skipped, int actual, int non_null)
1029{ 1029{
1030 struct u132_endp *endp = data; 1030 struct u132_endp *endp = data;
1031 struct u132 *u132 = endp->u132; 1031 struct u132 *u132 = endp->u132;
1032 u8 address = u132->addr[endp->usb_addr].address; 1032 u8 address = u132->addr[endp->usb_addr].address;
1033 down(&u132->scheduler_lock); 1033 mutex_lock(&u132->scheduler_lock);
1034 if (u132->going > 1) { 1034 if (u132->going > 1) {
1035 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1035 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1036 , u132->going); 1036 , u132->going);
1037 up(&u132->scheduler_lock); 1037 mutex_unlock(&u132->scheduler_lock);
1038 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1038 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1039 return; 1039 return;
1040 } else if (endp->dequeueing) { 1040 } else if (endp->dequeueing) {
1041 endp->dequeueing = 0; 1041 endp->dequeueing = 0;
1042 up(&u132->scheduler_lock); 1042 mutex_unlock(&u132->scheduler_lock);
1043 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1043 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1044 return; 1044 return;
1045 } else if (u132->going > 0) { 1045 } else if (u132->going > 0) {
1046 dev_err(&u132->platform_dev->dev, "device is being removed " 1046 dev_err(&u132->platform_dev->dev, "device is being removed "
1047 "urb=%p\n", urb); 1047 "urb=%p\n", urb);
1048 up(&u132->scheduler_lock); 1048 mutex_unlock(&u132->scheduler_lock);
1049 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1049 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1050 return; 1050 return;
1051 } else if (!urb->unlinked) { 1051 } else if (!urb->unlinked) {
1052 if (usb_pipein(urb->pipe)) { 1052 if (usb_pipein(urb->pipe)) {
1053 int retval; 1053 int retval;
1054 struct u132_ring *ring = endp->ring; 1054 struct u132_ring *ring = endp->ring;
1055 up(&u132->scheduler_lock); 1055 mutex_unlock(&u132->scheduler_lock);
1056 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1056 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1057 ring->number, endp, urb, address, 1057 ring->number, endp, urb, address,
1058 endp->usb_endp, 0, 1058 endp->usb_endp, 0,
1059 u132_hcd_configure_input_recv); 1059 u132_hcd_configure_input_recv);
1060 if (retval == 0) { 1060 if (retval != 0)
1061 } else 1061 u132_hcd_giveback_urb(u132, endp, urb, retval);
1062 u132_hcd_giveback_urb(u132, endp, urb, retval); 1062 return;
1063 return; 1063 } else {
1064 } else { 1064 int retval;
1065 int retval; 1065 struct u132_ring *ring = endp->ring;
1066 struct u132_ring *ring = endp->ring; 1066 mutex_unlock(&u132->scheduler_lock);
1067 up(&u132->scheduler_lock); 1067 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1068 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1068 ring->number, endp, urb, address,
1069 ring->number, endp, urb, address, 1069 endp->usb_endp, 0,
1070 endp->usb_endp, 0, 1070 u132_hcd_configure_empty_recv);
1071 u132_hcd_configure_empty_recv); 1071 if (retval != 0)
1072 if (retval == 0) { 1072 u132_hcd_giveback_urb(u132, endp, urb, retval);
1073 } else 1073 return;
1074 u132_hcd_giveback_urb(u132, endp, urb, retval); 1074 }
1075 return; 1075 } else {
1076 }
1077 } else {
1078 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1076 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1079 "unlinked=%d\n", urb, urb->unlinked); 1077 "unlinked=%d\n", urb, urb->unlinked);
1080 up(&u132->scheduler_lock); 1078 mutex_unlock(&u132->scheduler_lock);
1081 u132_hcd_giveback_urb(u132, endp, urb, 0); 1079 u132_hcd_giveback_urb(u132, endp, urb, 0);
1082 return; 1080 return;
1083 } 1081 }
1084} 1082}
1085 1083
1086static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb, 1084static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1087 u8 *buf, int len, int toggle_bits, int error_count, int condition_code, 1085 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1088 int repeat_number, int halted, int skipped, int actual, int non_null) 1086 int repeat_number, int halted, int skipped, int actual, int non_null)
1089{ 1087{
1090 struct u132_endp *endp = data; 1088 struct u132_endp *endp = data;
1091 struct u132 *u132 = endp->u132; 1089 struct u132 *u132 = endp->u132;
1092 u8 address = u132->addr[endp->usb_addr].address; 1090 u8 address = u132->addr[endp->usb_addr].address;
1093 struct u132_udev *udev = &u132->udev[address]; 1091 struct u132_udev *udev = &u132->udev[address];
1094 down(&u132->scheduler_lock); 1092 mutex_lock(&u132->scheduler_lock);
1095 if (u132->going > 1) { 1093 if (u132->going > 1) {
1096 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1094 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1097 , u132->going); 1095 , u132->going);
1098 up(&u132->scheduler_lock); 1096 mutex_unlock(&u132->scheduler_lock);
1099 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1097 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1100 return; 1098 return;
1101 } else if (endp->dequeueing) { 1099 } else if (endp->dequeueing) {
1102 endp->dequeueing = 0; 1100 endp->dequeueing = 0;
1103 up(&u132->scheduler_lock); 1101 mutex_unlock(&u132->scheduler_lock);
1104 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1102 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1105 return; 1103 return;
1106 } else if (u132->going > 0) { 1104 } else if (u132->going > 0) {
1107 dev_err(&u132->platform_dev->dev, "device is being removed " 1105 dev_err(&u132->platform_dev->dev, "device is being removed "
1108 "urb=%p\n", urb); 1106 "urb=%p\n", urb);
1109 up(&u132->scheduler_lock); 1107 mutex_unlock(&u132->scheduler_lock);
1110 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1108 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1111 return; 1109 return;
1112 } else if (!urb->unlinked) { 1110 } else if (!urb->unlinked) {
1113 u132->addr[0].address = 0; 1111 u132->addr[0].address = 0;
1114 endp->usb_addr = udev->usb_addr; 1112 endp->usb_addr = udev->usb_addr;
1115 up(&u132->scheduler_lock); 1113 mutex_unlock(&u132->scheduler_lock);
1116 u132_hcd_giveback_urb(u132, endp, urb, 0); 1114 u132_hcd_giveback_urb(u132, endp, urb, 0);
1117 return; 1115 return;
1118 } else { 1116 } else {
1119 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1117 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1120 "unlinked=%d\n", urb, urb->unlinked); 1118 "unlinked=%d\n", urb, urb->unlinked);
1121 up(&u132->scheduler_lock); 1119 mutex_unlock(&u132->scheduler_lock);
1122 u132_hcd_giveback_urb(u132, endp, urb, 0); 1120 u132_hcd_giveback_urb(u132, endp, urb, 0);
1123 return; 1121 return;
1124 } 1122 }
1125} 1123}
1126 1124
1127static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb, 1125static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1128 u8 *buf, int len, int toggle_bits, int error_count, int condition_code, 1126 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1129 int repeat_number, int halted, int skipped, int actual, int non_null) 1127 int repeat_number, int halted, int skipped, int actual, int non_null)
1130{ 1128{
1131 struct u132_endp *endp = data; 1129 struct u132_endp *endp = data;
1132 struct u132 *u132 = endp->u132; 1130 struct u132 *u132 = endp->u132;
1133 down(&u132->scheduler_lock); 1131 mutex_lock(&u132->scheduler_lock);
1134 if (u132->going > 1) { 1132 if (u132->going > 1) {
1135 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1133 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1136 , u132->going); 1134 , u132->going);
1137 up(&u132->scheduler_lock); 1135 mutex_unlock(&u132->scheduler_lock);
1138 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1136 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1139 return; 1137 return;
1140 } else if (endp->dequeueing) { 1138 } else if (endp->dequeueing) {
1141 endp->dequeueing = 0; 1139 endp->dequeueing = 0;
1142 up(&u132->scheduler_lock); 1140 mutex_unlock(&u132->scheduler_lock);
1143 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1141 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1144 return; 1142 return;
1145 } else if (u132->going > 0) { 1143 } else if (u132->going > 0) {
1146 dev_err(&u132->platform_dev->dev, "device is being removed " 1144 dev_err(&u132->platform_dev->dev, "device is being removed "
1147 "urb=%p\n", urb); 1145 "urb=%p\n", urb);
1148 up(&u132->scheduler_lock); 1146 mutex_unlock(&u132->scheduler_lock);
1149 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1147 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1150 return; 1148 return;
1151 } else if (!urb->unlinked) { 1149 } else if (!urb->unlinked) {
1152 int retval; 1150 int retval;
1153 struct u132_ring *ring = endp->ring; 1151 struct u132_ring *ring = endp->ring;
1154 up(&u132->scheduler_lock); 1152 mutex_unlock(&u132->scheduler_lock);
1155 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1153 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1156 ring->number, endp, urb, 0, endp->usb_endp, 0, 1154 ring->number, endp, urb, 0, endp->usb_endp, 0,
1157 u132_hcd_enumeration_empty_recv); 1155 u132_hcd_enumeration_empty_recv);
1158 if (retval == 0) { 1156 if (retval != 0)
1159 } else 1157 u132_hcd_giveback_urb(u132, endp, urb, retval);
1160 u132_hcd_giveback_urb(u132, endp, urb, retval); 1158 return;
1161 return; 1159 } else {
1162 } else {
1163 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1160 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1164 "unlinked=%d\n", urb, urb->unlinked); 1161 "unlinked=%d\n", urb, urb->unlinked);
1165 up(&u132->scheduler_lock); 1162 mutex_unlock(&u132->scheduler_lock);
1166 u132_hcd_giveback_urb(u132, endp, urb, 0); 1163 u132_hcd_giveback_urb(u132, endp, urb, 0);
1167 return; 1164 return;
1168 } 1165 }
1169} 1166}
1170 1167
1171static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf, 1168static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1172 int len, int toggle_bits, int error_count, int condition_code, 1169 int len, int toggle_bits, int error_count, int condition_code,
1173 int repeat_number, int halted, int skipped, int actual, int non_null) 1170 int repeat_number, int halted, int skipped, int actual, int non_null)
1174{ 1171{
1175 struct u132_endp *endp = data; 1172 struct u132_endp *endp = data;
1176 struct u132 *u132 = endp->u132; 1173 struct u132 *u132 = endp->u132;
1177 down(&u132->scheduler_lock); 1174 mutex_lock(&u132->scheduler_lock);
1178 if (u132->going > 1) { 1175 if (u132->going > 1) {
1179 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1176 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1180 , u132->going); 1177 , u132->going);
1181 up(&u132->scheduler_lock); 1178 mutex_unlock(&u132->scheduler_lock);
1182 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1179 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1183 return; 1180 return;
1184 } else if (endp->dequeueing) { 1181 } else if (endp->dequeueing) {
1185 endp->dequeueing = 0; 1182 endp->dequeueing = 0;
1186 up(&u132->scheduler_lock); 1183 mutex_unlock(&u132->scheduler_lock);
1187 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1184 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1188 return; 1185 return;
1189 } else if (u132->going > 0) { 1186 } else if (u132->going > 0) {
1190 dev_err(&u132->platform_dev->dev, "device is being removed " 1187 dev_err(&u132->platform_dev->dev, "device is being removed "
1191 "urb=%p\n", urb); 1188 "urb=%p\n", urb);
1192 up(&u132->scheduler_lock); 1189 mutex_unlock(&u132->scheduler_lock);
1193 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1190 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1194 return; 1191 return;
1195 } else if (!urb->unlinked) { 1192 } else if (!urb->unlinked) {
1196 up(&u132->scheduler_lock); 1193 mutex_unlock(&u132->scheduler_lock);
1197 u132_hcd_giveback_urb(u132, endp, urb, 0); 1194 u132_hcd_giveback_urb(u132, endp, urb, 0);
1198 return; 1195 return;
1199 } else { 1196 } else {
1200 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1197 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1201 "unlinked=%d\n", urb, urb->unlinked); 1198 "unlinked=%d\n", urb, urb->unlinked);
1202 up(&u132->scheduler_lock); 1199 mutex_unlock(&u132->scheduler_lock);
1203 u132_hcd_giveback_urb(u132, endp, urb, 0); 1200 u132_hcd_giveback_urb(u132, endp, urb, 0);
1204 return; 1201 return;
1205 } 1202 }
1206} 1203}
1207 1204
1208static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf, 1205static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1209 int len, int toggle_bits, int error_count, int condition_code, 1206 int len, int toggle_bits, int error_count, int condition_code,
1210 int repeat_number, int halted, int skipped, int actual, int non_null) 1207 int repeat_number, int halted, int skipped, int actual, int non_null)
1211{ 1208{
1212 struct u132_endp *endp = data; 1209 struct u132_endp *endp = data;
1213 struct u132 *u132 = endp->u132; 1210 struct u132 *u132 = endp->u132;
1214 u8 address = u132->addr[endp->usb_addr].address; 1211 u8 address = u132->addr[endp->usb_addr].address;
1215 down(&u132->scheduler_lock); 1212 mutex_lock(&u132->scheduler_lock);
1216 if (u132->going > 1) { 1213 if (u132->going > 1) {
1217 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1214 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1218 , u132->going); 1215 , u132->going);
1219 up(&u132->scheduler_lock); 1216 mutex_unlock(&u132->scheduler_lock);
1220 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1217 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1221 return; 1218 return;
1222 } else if (endp->dequeueing) { 1219 } else if (endp->dequeueing) {
1223 endp->dequeueing = 0; 1220 endp->dequeueing = 0;
1224 up(&u132->scheduler_lock); 1221 mutex_unlock(&u132->scheduler_lock);
1225 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1222 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1226 return; 1223 return;
1227 } else if (u132->going > 0) { 1224 } else if (u132->going > 0) {
1228 dev_err(&u132->platform_dev->dev, "device is being removed " 1225 dev_err(&u132->platform_dev->dev, "device is being removed "
1229 "urb=%p\n", urb); 1226 "urb=%p\n", urb);
1230 up(&u132->scheduler_lock); 1227 mutex_unlock(&u132->scheduler_lock);
1231 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1228 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1232 return; 1229 return;
1233 } else if (!urb->unlinked) { 1230 } else if (!urb->unlinked) {
1234 int retval; 1231 int retval;
1235 struct u132_ring *ring = endp->ring; 1232 struct u132_ring *ring = endp->ring;
1236 u8 *u = urb->transfer_buffer; 1233 u8 *u = urb->transfer_buffer;
1237 u8 *b = buf; 1234 u8 *b = buf;
1238 int L = len; 1235 int L = len;
1239 while (L-- > 0) { 1236
1240 *u++ = *b++; 1237 while (L-- > 0)
1241 } 1238 *u++ = *b++;
1242 urb->actual_length = len; 1239
1243 up(&u132->scheduler_lock); 1240 urb->actual_length = len;
1244 retval = usb_ftdi_elan_edset_empty(u132->platform_dev, 1241 mutex_unlock(&u132->scheduler_lock);
1245 ring->number, endp, urb, address, endp->usb_endp, 0x3, 1242 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1246 u132_hcd_initial_empty_sent); 1243 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1247 if (retval == 0) { 1244 u132_hcd_initial_empty_sent);
1248 } else 1245 if (retval != 0)
1249 u132_hcd_giveback_urb(u132, endp, urb, retval); 1246 u132_hcd_giveback_urb(u132, endp, urb, retval);
1250 return; 1247 return;
1251 } else { 1248 } else {
1252 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1249 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1253 "unlinked=%d\n", urb, urb->unlinked); 1250 "unlinked=%d\n", urb, urb->unlinked);
1254 up(&u132->scheduler_lock); 1251 mutex_unlock(&u132->scheduler_lock);
1255 u132_hcd_giveback_urb(u132, endp, urb, 0); 1252 u132_hcd_giveback_urb(u132, endp, urb, 0);
1256 return; 1253 return;
1257 } 1254 }
1258} 1255}
1259 1256
1260static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf, 1257static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1261 int len, int toggle_bits, int error_count, int condition_code, 1258 int len, int toggle_bits, int error_count, int condition_code,
1262 int repeat_number, int halted, int skipped, int actual, int non_null) 1259 int repeat_number, int halted, int skipped, int actual, int non_null)
1263{ 1260{
1264 struct u132_endp *endp = data; 1261 struct u132_endp *endp = data;
1265 struct u132 *u132 = endp->u132; 1262 struct u132 *u132 = endp->u132;
1266 u8 address = u132->addr[endp->usb_addr].address; 1263 u8 address = u132->addr[endp->usb_addr].address;
1267 down(&u132->scheduler_lock); 1264 mutex_lock(&u132->scheduler_lock);
1268 if (u132->going > 1) { 1265 if (u132->going > 1) {
1269 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1266 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1270 , u132->going); 1267 , u132->going);
1271 up(&u132->scheduler_lock); 1268 mutex_unlock(&u132->scheduler_lock);
1272 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1269 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1273 return; 1270 return;
1274 } else if (endp->dequeueing) { 1271 } else if (endp->dequeueing) {
1275 endp->dequeueing = 0; 1272 endp->dequeueing = 0;
1276 up(&u132->scheduler_lock); 1273 mutex_unlock(&u132->scheduler_lock);
1277 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1274 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1278 return; 1275 return;
1279 } else if (u132->going > 0) { 1276 } else if (u132->going > 0) {
1280 dev_err(&u132->platform_dev->dev, "device is being removed " 1277 dev_err(&u132->platform_dev->dev, "device is being removed "
1281 "urb=%p\n", urb); 1278 "urb=%p\n", urb);
1282 up(&u132->scheduler_lock); 1279 mutex_unlock(&u132->scheduler_lock);
1283 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1280 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1284 return; 1281 return;
1285 } else if (!urb->unlinked) { 1282 } else if (!urb->unlinked) {
1286 int retval; 1283 int retval;
1287 struct u132_ring *ring = endp->ring; 1284 struct u132_ring *ring = endp->ring;
1288 up(&u132->scheduler_lock); 1285 mutex_unlock(&u132->scheduler_lock);
1289 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1286 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1290 ring->number, endp, urb, address, endp->usb_endp, 0, 1287 ring->number, endp, urb, address, endp->usb_endp, 0,
1291 u132_hcd_initial_input_recv); 1288 u132_hcd_initial_input_recv);
1292 if (retval == 0) { 1289 if (retval != 0)
1293 } else 1290 u132_hcd_giveback_urb(u132, endp, urb, retval);
1294 u132_hcd_giveback_urb(u132, endp, urb, retval); 1291 return;
1295 return; 1292 } else {
1296 } else {
1297 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1293 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1298 "unlinked=%d\n", urb, urb->unlinked); 1294 "unlinked=%d\n", urb, urb->unlinked);
1299 up(&u132->scheduler_lock); 1295 mutex_unlock(&u132->scheduler_lock);
1300 u132_hcd_giveback_urb(u132, endp, urb, 0); 1296 u132_hcd_giveback_urb(u132, endp, urb, 0);
1301 return; 1297 return;
1302 } 1298 }
1303} 1299}
1304 1300
1305/* 1301/*
@@ -1308,302 +1304,296 @@ static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1308*/ 1304*/
1309static void u132_hcd_ring_work_scheduler(struct work_struct *work) 1305static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1310{ 1306{
1311 struct u132_ring *ring = 1307 struct u132_ring *ring =
1312 container_of(work, struct u132_ring, scheduler.work); 1308 container_of(work, struct u132_ring, scheduler.work);
1313 struct u132 *u132 = ring->u132; 1309 struct u132 *u132 = ring->u132;
1314 down(&u132->scheduler_lock); 1310 mutex_lock(&u132->scheduler_lock);
1315 if (ring->in_use) { 1311 if (ring->in_use) {
1316 up(&u132->scheduler_lock); 1312 mutex_unlock(&u132->scheduler_lock);
1317 u132_ring_put_kref(u132, ring); 1313 u132_ring_put_kref(u132, ring);
1318 return; 1314 return;
1319 } else if (ring->curr_endp) { 1315 } else if (ring->curr_endp) {
1320 struct u132_endp *last_endp = ring->curr_endp; 1316 struct u132_endp *last_endp = ring->curr_endp;
1321 struct list_head *scan; 1317 struct list_head *scan;
1322 struct list_head *head = &last_endp->endp_ring; 1318 struct list_head *head = &last_endp->endp_ring;
1323 unsigned long wakeup = 0; 1319 unsigned long wakeup = 0;
1324 list_for_each(scan, head) { 1320 list_for_each(scan, head) {
1325 struct u132_endp *endp = list_entry(scan, 1321 struct u132_endp *endp = list_entry(scan,
1326 struct u132_endp, endp_ring); 1322 struct u132_endp, endp_ring);
1327 if (endp->queue_next == endp->queue_last) { 1323 if (endp->queue_next == endp->queue_last) {
1328 } else if ((endp->delayed == 0) 1324 } else if ((endp->delayed == 0)
1329 || time_after_eq(jiffies, endp->jiffies)) { 1325 || time_after_eq(jiffies, endp->jiffies)) {
1330 ring->curr_endp = endp; 1326 ring->curr_endp = endp;
1331 u132_endp_cancel_work(u132, last_endp); 1327 u132_endp_cancel_work(u132, last_endp);
1332 u132_endp_queue_work(u132, last_endp, 0); 1328 u132_endp_queue_work(u132, last_endp, 0);
1333 up(&u132->scheduler_lock); 1329 mutex_unlock(&u132->scheduler_lock);
1334 u132_ring_put_kref(u132, ring); 1330 u132_ring_put_kref(u132, ring);
1335 return; 1331 return;
1336 } else { 1332 } else {
1337 unsigned long delta = endp->jiffies - jiffies; 1333 unsigned long delta = endp->jiffies - jiffies;
1338 if (delta > wakeup) 1334 if (delta > wakeup)
1339 wakeup = delta; 1335 wakeup = delta;
1340 } 1336 }
1341 } 1337 }
1342 if (last_endp->queue_next == last_endp->queue_last) { 1338 if (last_endp->queue_next == last_endp->queue_last) {
1343 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies, 1339 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1344 last_endp->jiffies)) { 1340 last_endp->jiffies)) {
1345 u132_endp_cancel_work(u132, last_endp); 1341 u132_endp_cancel_work(u132, last_endp);
1346 u132_endp_queue_work(u132, last_endp, 0); 1342 u132_endp_queue_work(u132, last_endp, 0);
1347 up(&u132->scheduler_lock); 1343 mutex_unlock(&u132->scheduler_lock);
1348 u132_ring_put_kref(u132, ring); 1344 u132_ring_put_kref(u132, ring);
1349 return; 1345 return;
1350 } else { 1346 } else {
1351 unsigned long delta = last_endp->jiffies - jiffies; 1347 unsigned long delta = last_endp->jiffies - jiffies;
1352 if (delta > wakeup) 1348 if (delta > wakeup)
1353 wakeup = delta; 1349 wakeup = delta;
1354 } 1350 }
1355 if (wakeup > 0) { 1351 if (wakeup > 0) {
1356 u132_ring_requeue_work(u132, ring, wakeup); 1352 u132_ring_requeue_work(u132, ring, wakeup);
1357 up(&u132->scheduler_lock); 1353 mutex_unlock(&u132->scheduler_lock);
1358 return; 1354 return;
1359 } else { 1355 } else {
1360 up(&u132->scheduler_lock); 1356 mutex_unlock(&u132->scheduler_lock);
1361 u132_ring_put_kref(u132, ring); 1357 u132_ring_put_kref(u132, ring);
1362 return; 1358 return;
1363 } 1359 }
1364 } else { 1360 } else {
1365 up(&u132->scheduler_lock); 1361 mutex_unlock(&u132->scheduler_lock);
1366 u132_ring_put_kref(u132, ring); 1362 u132_ring_put_kref(u132, ring);
1367 return; 1363 return;
1368 } 1364 }
1369} 1365}
1370 1366
1371static void u132_hcd_endp_work_scheduler(struct work_struct *work) 1367static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1372{ 1368{
1373 struct u132_ring *ring; 1369 struct u132_ring *ring;
1374 struct u132_endp *endp = 1370 struct u132_endp *endp =
1375 container_of(work, struct u132_endp, scheduler.work); 1371 container_of(work, struct u132_endp, scheduler.work);
1376 struct u132 *u132 = endp->u132; 1372 struct u132 *u132 = endp->u132;
1377 down(&u132->scheduler_lock); 1373 mutex_lock(&u132->scheduler_lock);
1378 ring = endp->ring; 1374 ring = endp->ring;
1379 if (endp->edset_flush) { 1375 if (endp->edset_flush) {
1380 endp->edset_flush = 0; 1376 endp->edset_flush = 0;
1381 if (endp->dequeueing) 1377 if (endp->dequeueing)
1382 usb_ftdi_elan_edset_flush(u132->platform_dev, 1378 usb_ftdi_elan_edset_flush(u132->platform_dev,
1383 ring->number, endp); 1379 ring->number, endp);
1384 up(&u132->scheduler_lock); 1380 mutex_unlock(&u132->scheduler_lock);
1385 u132_endp_put_kref(u132, endp); 1381 u132_endp_put_kref(u132, endp);
1386 return; 1382 return;
1387 } else if (endp->active) { 1383 } else if (endp->active) {
1388 up(&u132->scheduler_lock); 1384 mutex_unlock(&u132->scheduler_lock);
1389 u132_endp_put_kref(u132, endp); 1385 u132_endp_put_kref(u132, endp);
1390 return; 1386 return;
1391 } else if (ring->in_use) { 1387 } else if (ring->in_use) {
1392 up(&u132->scheduler_lock); 1388 mutex_unlock(&u132->scheduler_lock);
1393 u132_endp_put_kref(u132, endp); 1389 u132_endp_put_kref(u132, endp);
1394 return; 1390 return;
1395 } else if (endp->queue_next == endp->queue_last) { 1391 } else if (endp->queue_next == endp->queue_last) {
1396 up(&u132->scheduler_lock); 1392 mutex_unlock(&u132->scheduler_lock);
1397 u132_endp_put_kref(u132, endp); 1393 u132_endp_put_kref(u132, endp);
1398 return; 1394 return;
1399 } else if (endp->pipetype == PIPE_INTERRUPT) { 1395 } else if (endp->pipetype == PIPE_INTERRUPT) {
1400 u8 address = u132->addr[endp->usb_addr].address; 1396 u8 address = u132->addr[endp->usb_addr].address;
1401 if (ring->in_use) { 1397 if (ring->in_use) {
1402 up(&u132->scheduler_lock); 1398 mutex_unlock(&u132->scheduler_lock);
1403 u132_endp_put_kref(u132, endp); 1399 u132_endp_put_kref(u132, endp);
1404 return; 1400 return;
1405 } else { 1401 } else {
1406 int retval; 1402 int retval;
1407 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1403 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1408 endp->queue_next]; 1404 endp->queue_next];
1409 endp->active = 1; 1405 endp->active = 1;
1410 ring->curr_endp = endp; 1406 ring->curr_endp = endp;
1411 ring->in_use = 1; 1407 ring->in_use = 1;
1412 up(&u132->scheduler_lock); 1408 mutex_unlock(&u132->scheduler_lock);
1413 retval = edset_single(u132, ring, endp, urb, address, 1409 retval = edset_single(u132, ring, endp, urb, address,
1414 endp->toggle_bits, u132_hcd_interrupt_recv); 1410 endp->toggle_bits, u132_hcd_interrupt_recv);
1415 if (retval == 0) { 1411 if (retval != 0)
1416 } else 1412 u132_hcd_giveback_urb(u132, endp, urb, retval);
1417 u132_hcd_giveback_urb(u132, endp, urb, retval); 1413 return;
1418 return; 1414 }
1419 } 1415 } else if (endp->pipetype == PIPE_CONTROL) {
1420 } else if (endp->pipetype == PIPE_CONTROL) { 1416 u8 address = u132->addr[endp->usb_addr].address;
1421 u8 address = u132->addr[endp->usb_addr].address; 1417 if (ring->in_use) {
1422 if (ring->in_use) { 1418 mutex_unlock(&u132->scheduler_lock);
1423 up(&u132->scheduler_lock); 1419 u132_endp_put_kref(u132, endp);
1424 u132_endp_put_kref(u132, endp); 1420 return;
1425 return; 1421 } else if (address == 0) {
1426 } else if (address == 0) { 1422 int retval;
1427 int retval; 1423 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1428 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1424 endp->queue_next];
1429 endp->queue_next]; 1425 endp->active = 1;
1430 endp->active = 1; 1426 ring->curr_endp = endp;
1431 ring->curr_endp = endp; 1427 ring->in_use = 1;
1432 ring->in_use = 1; 1428 mutex_unlock(&u132->scheduler_lock);
1433 up(&u132->scheduler_lock); 1429 retval = edset_setup(u132, ring, endp, urb, address,
1434 retval = edset_setup(u132, ring, endp, urb, address, 1430 0x2, u132_hcd_initial_setup_sent);
1435 0x2, u132_hcd_initial_setup_sent); 1431 if (retval != 0)
1436 if (retval == 0) { 1432 u132_hcd_giveback_urb(u132, endp, urb, retval);
1437 } else 1433 return;
1438 u132_hcd_giveback_urb(u132, endp, urb, retval); 1434 } else if (endp->usb_addr == 0) {
1439 return; 1435 int retval;
1440 } else if (endp->usb_addr == 0) { 1436 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1441 int retval; 1437 endp->queue_next];
1442 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1438 endp->active = 1;
1443 endp->queue_next]; 1439 ring->curr_endp = endp;
1444 endp->active = 1; 1440 ring->in_use = 1;
1445 ring->curr_endp = endp; 1441 mutex_unlock(&u132->scheduler_lock);
1446 ring->in_use = 1; 1442 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1447 up(&u132->scheduler_lock); 1443 u132_hcd_enumeration_address_sent);
1448 retval = edset_setup(u132, ring, endp, urb, 0, 0x2, 1444 if (retval != 0)
1449 u132_hcd_enumeration_address_sent); 1445 u132_hcd_giveback_urb(u132, endp, urb, retval);
1450 if (retval == 0) { 1446 return;
1451 } else 1447 } else {
1452 u132_hcd_giveback_urb(u132, endp, urb, retval); 1448 int retval;
1453 return; 1449 u8 address = u132->addr[endp->usb_addr].address;
1454 } else { 1450 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1455 int retval; 1451 endp->queue_next];
1456 u8 address = u132->addr[endp->usb_addr].address; 1452 endp->active = 1;
1457 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1453 ring->curr_endp = endp;
1458 endp->queue_next]; 1454 ring->in_use = 1;
1459 endp->active = 1; 1455 mutex_unlock(&u132->scheduler_lock);
1460 ring->curr_endp = endp; 1456 retval = edset_setup(u132, ring, endp, urb, address,
1461 ring->in_use = 1; 1457 0x2, u132_hcd_configure_setup_sent);
1462 up(&u132->scheduler_lock); 1458 if (retval != 0)
1463 retval = edset_setup(u132, ring, endp, urb, address, 1459 u132_hcd_giveback_urb(u132, endp, urb, retval);
1464 0x2, u132_hcd_configure_setup_sent); 1460 return;
1465 if (retval == 0) { 1461 }
1466 } else 1462 } else {
1467 u132_hcd_giveback_urb(u132, endp, urb, retval); 1463 if (endp->input) {
1468 return; 1464 u8 address = u132->addr[endp->usb_addr].address;
1469 } 1465 if (ring->in_use) {
1470 } else { 1466 mutex_unlock(&u132->scheduler_lock);
1471 if (endp->input) { 1467 u132_endp_put_kref(u132, endp);
1472 u8 address = u132->addr[endp->usb_addr].address; 1468 return;
1473 if (ring->in_use) { 1469 } else {
1474 up(&u132->scheduler_lock); 1470 int retval;
1475 u132_endp_put_kref(u132, endp); 1471 struct urb *urb = endp->urb_list[
1476 return; 1472 ENDP_QUEUE_MASK & endp->queue_next];
1477 } else { 1473 endp->active = 1;
1478 int retval; 1474 ring->curr_endp = endp;
1479 struct urb *urb = endp->urb_list[ 1475 ring->in_use = 1;
1480 ENDP_QUEUE_MASK & endp->queue_next]; 1476 mutex_unlock(&u132->scheduler_lock);
1481 endp->active = 1; 1477 retval = edset_input(u132, ring, endp, urb,
1482 ring->curr_endp = endp; 1478 address, endp->toggle_bits,
1483 ring->in_use = 1; 1479 u132_hcd_bulk_input_recv);
1484 up(&u132->scheduler_lock); 1480 if (retval == 0) {
1485 retval = edset_input(u132, ring, endp, urb, 1481 } else
1486 address, endp->toggle_bits, 1482 u132_hcd_giveback_urb(u132, endp, urb,
1487 u132_hcd_bulk_input_recv); 1483 retval);
1488 if (retval == 0) { 1484 return;
1489 } else 1485 }
1490 u132_hcd_giveback_urb(u132, endp, urb, 1486 } else { /* output pipe */
1491 retval); 1487 u8 address = u132->addr[endp->usb_addr].address;
1492 return; 1488 if (ring->in_use) {
1493 } 1489 mutex_unlock(&u132->scheduler_lock);
1494 } else { /* output pipe */ 1490 u132_endp_put_kref(u132, endp);
1495 u8 address = u132->addr[endp->usb_addr].address; 1491 return;
1496 if (ring->in_use) { 1492 } else {
1497 up(&u132->scheduler_lock); 1493 int retval;
1498 u132_endp_put_kref(u132, endp); 1494 struct urb *urb = endp->urb_list[
1499 return; 1495 ENDP_QUEUE_MASK & endp->queue_next];
1500 } else { 1496 endp->active = 1;
1501 int retval; 1497 ring->curr_endp = endp;
1502 struct urb *urb = endp->urb_list[ 1498 ring->in_use = 1;
1503 ENDP_QUEUE_MASK & endp->queue_next]; 1499 mutex_unlock(&u132->scheduler_lock);
1504 endp->active = 1; 1500 retval = edset_output(u132, ring, endp, urb,
1505 ring->curr_endp = endp; 1501 address, endp->toggle_bits,
1506 ring->in_use = 1; 1502 u132_hcd_bulk_output_sent);
1507 up(&u132->scheduler_lock); 1503 if (retval == 0) {
1508 retval = edset_output(u132, ring, endp, urb, 1504 } else
1509 address, endp->toggle_bits, 1505 u132_hcd_giveback_urb(u132, endp, urb,
1510 u132_hcd_bulk_output_sent); 1506 retval);
1511 if (retval == 0) { 1507 return;
1512 } else 1508 }
1513 u132_hcd_giveback_urb(u132, endp, urb, 1509 }
1514 retval); 1510 }
1515 return;
1516 }
1517 }
1518 }
1519} 1511}
1520#ifdef CONFIG_PM 1512#ifdef CONFIG_PM
1521 1513
1522static void port_power(struct u132 *u132, int pn, int is_on) 1514static void port_power(struct u132 *u132, int pn, int is_on)
1523{ 1515{
1524 u132->port[pn].power = is_on; 1516 u132->port[pn].power = is_on;
1525} 1517}
1526 1518
1527#endif 1519#endif
1528 1520
1529static void u132_power(struct u132 *u132, int is_on) 1521static void u132_power(struct u132 *u132, int is_on)
1530{ 1522{
1531 struct usb_hcd *hcd = u132_to_hcd(u132) 1523 struct usb_hcd *hcd = u132_to_hcd(u132)
1532 ; /* hub is inactive unless the port is powered */ 1524 ; /* hub is inactive unless the port is powered */
1533 if (is_on) { 1525 if (is_on) {
1534 if (u132->power) 1526 if (u132->power)
1535 return; 1527 return;
1536 u132->power = 1; 1528 u132->power = 1;
1537 hcd->self.controller->power.power_state = PMSG_ON; 1529 } else {
1538 } else { 1530 u132->power = 0;
1539 u132->power = 0; 1531 hcd->state = HC_STATE_HALT;
1540 hcd->state = HC_STATE_HALT; 1532 }
1541 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1542 }
1543} 1533}
1544 1534
1545static int u132_periodic_reinit(struct u132 *u132) 1535static int u132_periodic_reinit(struct u132 *u132)
1546{ 1536{
1547 int retval; 1537 int retval;
1548 u32 fi = u132->hc_fminterval & 0x03fff; 1538 u32 fi = u132->hc_fminterval & 0x03fff;
1549 u32 fit; 1539 u32 fit;
1550 u32 fminterval; 1540 u32 fminterval;
1551 retval = u132_read_pcimem(u132, fminterval, &fminterval); 1541 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1552 if (retval) 1542 if (retval)
1553 return retval; 1543 return retval;
1554 fit = fminterval & FIT; 1544 fit = fminterval & FIT;
1555 retval = u132_write_pcimem(u132, fminterval, 1545 retval = u132_write_pcimem(u132, fminterval,
1556 (fit ^ FIT) | u132->hc_fminterval); 1546 (fit ^ FIT) | u132->hc_fminterval);
1557 if (retval) 1547 if (retval)
1558 return retval; 1548 return retval;
1559 retval = u132_write_pcimem(u132, periodicstart, 1549 retval = u132_write_pcimem(u132, periodicstart,
1560 ((9 *fi) / 10) & 0x3fff); 1550 ((9 * fi) / 10) & 0x3fff);
1561 if (retval) 1551 if (retval)
1562 return retval; 1552 return retval;
1563 return 0; 1553 return 0;
1564} 1554}
1565 1555
1566static char *hcfs2string(int state) 1556static char *hcfs2string(int state)
1567{ 1557{
1568 switch (state) { 1558 switch (state) {
1569 case OHCI_USB_RESET: 1559 case OHCI_USB_RESET:
1570 return "reset"; 1560 return "reset";
1571 case OHCI_USB_RESUME: 1561 case OHCI_USB_RESUME:
1572 return "resume"; 1562 return "resume";
1573 case OHCI_USB_OPER: 1563 case OHCI_USB_OPER:
1574 return "operational"; 1564 return "operational";
1575 case OHCI_USB_SUSPEND: 1565 case OHCI_USB_SUSPEND:
1576 return "suspend"; 1566 return "suspend";
1577 } 1567 }
1578 return "?"; 1568 return "?";
1579} 1569}
1580 1570
1581static int u132_init(struct u132 *u132) 1571static int u132_init(struct u132 *u132)
1582{ 1572{
1583 int retval; 1573 int retval;
1584 u32 control; 1574 u32 control;
1585 u132_disable(u132); 1575 u132_disable(u132);
1586 u132->next_statechange = jiffies; 1576 u132->next_statechange = jiffies;
1587 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE); 1577 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1588 if (retval) 1578 if (retval)
1589 return retval; 1579 return retval;
1590 retval = u132_read_pcimem(u132, control, &control); 1580 retval = u132_read_pcimem(u132, control, &control);
1591 if (retval) 1581 if (retval)
1592 return retval; 1582 return retval;
1593 if (u132->num_ports == 0) { 1583 if (u132->num_ports == 0) {
1594 u32 rh_a = -1; 1584 u32 rh_a = -1;
1595 retval = u132_read_pcimem(u132, roothub.a, &rh_a); 1585 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1596 if (retval) 1586 if (retval)
1597 return retval; 1587 return retval;
1598 u132->num_ports = rh_a & RH_A_NDP; 1588 u132->num_ports = rh_a & RH_A_NDP;
1599 retval = read_roothub_info(u132); 1589 retval = read_roothub_info(u132);
1600 if (retval) 1590 if (retval)
1601 return retval; 1591 return retval;
1602 } 1592 }
1603 if (u132->num_ports > MAX_U132_PORTS) { 1593 if (u132->num_ports > MAX_U132_PORTS)
1604 return -EINVAL; 1594 return -EINVAL;
1605 } 1595
1606 return 0; 1596 return 0;
1607} 1597}
1608 1598
1609 1599
@@ -1613,280 +1603,278 @@ static int u132_init(struct u132 *u132)
1613*/ 1603*/
1614static int u132_run(struct u132 *u132) 1604static int u132_run(struct u132 *u132)
1615{ 1605{
1616 int retval; 1606 int retval;
1617 u32 control; 1607 u32 control;
1618 u32 status; 1608 u32 status;
1619 u32 fminterval; 1609 u32 fminterval;
1620 u32 periodicstart; 1610 u32 periodicstart;
1621 u32 cmdstatus; 1611 u32 cmdstatus;
1622 u32 roothub_a; 1612 u32 roothub_a;
1623 int mask = OHCI_INTR_INIT; 1613 int mask = OHCI_INTR_INIT;
1624 int first = u132->hc_fminterval == 0; 1614 int first = u132->hc_fminterval == 0;
1625 int sleep_time = 0; 1615 int sleep_time = 0;
1626 int reset_timeout = 30; /* ... allow extra time */ 1616 int reset_timeout = 30; /* ... allow extra time */
1627 u132_disable(u132); 1617 u132_disable(u132);
1628 if (first) { 1618 if (first) {
1629 u32 temp; 1619 u32 temp;
1630 retval = u132_read_pcimem(u132, fminterval, &temp); 1620 retval = u132_read_pcimem(u132, fminterval, &temp);
1631 if (retval) 1621 if (retval)
1632 return retval; 1622 return retval;
1633 u132->hc_fminterval = temp & 0x3fff; 1623 u132->hc_fminterval = temp & 0x3fff;
1634 if (u132->hc_fminterval != FI) { 1624 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1635 } 1625 }
1636 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16; 1626 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1637 } 1627 if (retval)
1638 retval = u132_read_pcimem(u132, control, &u132->hc_control); 1628 return retval;
1639 if (retval) 1629 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1640 return retval; 1630 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1641 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control " 1631 u132->hc_control);
1642 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS), 1632 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1643 u132->hc_control); 1633 case OHCI_USB_OPER:
1644 switch (u132->hc_control & OHCI_CTRL_HCFS) { 1634 sleep_time = 0;
1645 case OHCI_USB_OPER: 1635 break;
1646 sleep_time = 0; 1636 case OHCI_USB_SUSPEND:
1647 break; 1637 case OHCI_USB_RESUME:
1648 case OHCI_USB_SUSPEND: 1638 u132->hc_control &= OHCI_CTRL_RWC;
1649 case OHCI_USB_RESUME: 1639 u132->hc_control |= OHCI_USB_RESUME;
1650 u132->hc_control &= OHCI_CTRL_RWC; 1640 sleep_time = 10;
1651 u132->hc_control |= OHCI_USB_RESUME; 1641 break;
1652 sleep_time = 10; 1642 default:
1653 break; 1643 u132->hc_control &= OHCI_CTRL_RWC;
1654 default: 1644 u132->hc_control |= OHCI_USB_RESET;
1655 u132->hc_control &= OHCI_CTRL_RWC; 1645 sleep_time = 50;
1656 u132->hc_control |= OHCI_USB_RESET; 1646 break;
1657 sleep_time = 50; 1647 }
1658 break; 1648 retval = u132_write_pcimem(u132, control, u132->hc_control);
1659 } 1649 if (retval)
1660 retval = u132_write_pcimem(u132, control, u132->hc_control); 1650 return retval;
1661 if (retval) 1651 retval = u132_read_pcimem(u132, control, &control);
1662 return retval; 1652 if (retval)
1663 retval = u132_read_pcimem(u132, control, &control); 1653 return retval;
1664 if (retval) 1654 msleep(sleep_time);
1665 return retval; 1655 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1666 msleep(sleep_time); 1656 if (retval)
1667 retval = u132_read_pcimem(u132, roothub.a, &roothub_a); 1657 return retval;
1668 if (retval) 1658 if (!(roothub_a & RH_A_NPS)) {
1669 return retval; 1659 int temp; /* power down each port */
1670 if (!(roothub_a & RH_A_NPS)) { 1660 for (temp = 0; temp < u132->num_ports; temp++) {
1671 int temp; /* power down each port */ 1661 retval = u132_write_pcimem(u132,
1672 for (temp = 0; temp < u132->num_ports; temp++) { 1662 roothub.portstatus[temp], RH_PS_LSDA);
1673 retval = u132_write_pcimem(u132, 1663 if (retval)
1674 roothub.portstatus[temp], RH_PS_LSDA); 1664 return retval;
1675 if (retval) 1665 }
1676 return retval; 1666 }
1677 } 1667 retval = u132_read_pcimem(u132, control, &control);
1678 } 1668 if (retval)
1679 retval = u132_read_pcimem(u132, control, &control); 1669 return retval;
1680 if (retval) 1670retry:
1681 return retval; 1671 retval = u132_read_pcimem(u132, cmdstatus, &status);
1682 retry:retval = u132_read_pcimem(u132, cmdstatus, &status); 1672 if (retval)
1683 if (retval) 1673 return retval;
1684 return retval; 1674 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1685 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR); 1675 if (retval)
1686 if (retval) 1676 return retval;
1687 return retval; 1677extra: {
1688 extra:{ 1678 retval = u132_read_pcimem(u132, cmdstatus, &status);
1689 retval = u132_read_pcimem(u132, cmdstatus, &status); 1679 if (retval)
1690 if (retval) 1680 return retval;
1691 return retval; 1681 if (0 != (status & OHCI_HCR)) {
1692 if (0 != (status & OHCI_HCR)) { 1682 if (--reset_timeout == 0) {
1693 if (--reset_timeout == 0) { 1683 dev_err(&u132->platform_dev->dev, "USB HC reset"
1694 dev_err(&u132->platform_dev->dev, "USB HC reset" 1684 " timed out!\n");
1695 " timed out!\n"); 1685 return -ENODEV;
1696 return -ENODEV; 1686 } else {
1697 } else { 1687 msleep(5);
1698 msleep(5); 1688 goto extra;
1699 goto extra; 1689 }
1700 } 1690 }
1701 } 1691 }
1702 } 1692 if (u132->flags & OHCI_QUIRK_INITRESET) {
1703 if (u132->flags & OHCI_QUIRK_INITRESET) { 1693 retval = u132_write_pcimem(u132, control, u132->hc_control);
1704 retval = u132_write_pcimem(u132, control, u132->hc_control); 1694 if (retval)
1705 if (retval) 1695 return retval;
1706 return retval; 1696 retval = u132_read_pcimem(u132, control, &control);
1707 retval = u132_read_pcimem(u132, control, &control); 1697 if (retval)
1708 if (retval) 1698 return retval;
1709 return retval; 1699 }
1710 } 1700 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1711 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000); 1701 if (retval)
1712 if (retval) 1702 return retval;
1713 return retval; 1703 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1714 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000); 1704 if (retval)
1715 if (retval) 1705 return retval;
1716 return retval; 1706 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1717 retval = u132_write_pcimem(u132, hcca, 0x00000000); 1707 if (retval)
1718 if (retval) 1708 return retval;
1719 return retval; 1709 retval = u132_periodic_reinit(u132);
1720 retval = u132_periodic_reinit(u132); 1710 if (retval)
1721 if (retval) 1711 return retval;
1722 return retval; 1712 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1723 retval = u132_read_pcimem(u132, fminterval, &fminterval); 1713 if (retval)
1724 if (retval) 1714 return retval;
1725 return retval; 1715 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1726 retval = u132_read_pcimem(u132, periodicstart, &periodicstart); 1716 if (retval)
1727 if (retval) 1717 return retval;
1728 return retval; 1718 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1729 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) { 1719 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1730 if (!(u132->flags & OHCI_QUIRK_INITRESET)) { 1720 u132->flags |= OHCI_QUIRK_INITRESET;
1731 u132->flags |= OHCI_QUIRK_INITRESET; 1721 goto retry;
1732 goto retry; 1722 } else
1733 } else 1723 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1734 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)" 1724 "\n", fminterval, periodicstart);
1735 "\n", fminterval, periodicstart); 1725 } /* start controller operations */
1736 } /* start controller operations */ 1726 u132->hc_control &= OHCI_CTRL_RWC;
1737 u132->hc_control &= OHCI_CTRL_RWC; 1727 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1738 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER; 1728 retval = u132_write_pcimem(u132, control, u132->hc_control);
1739 retval = u132_write_pcimem(u132, control, u132->hc_control); 1729 if (retval)
1740 if (retval) 1730 return retval;
1741 return retval; 1731 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1742 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF); 1732 if (retval)
1743 if (retval) 1733 return retval;
1744 return retval; 1734 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1745 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus); 1735 if (retval)
1746 if (retval) 1736 return retval;
1747 return retval; 1737 retval = u132_read_pcimem(u132, control, &control);
1748 retval = u132_read_pcimem(u132, control, &control); 1738 if (retval)
1749 if (retval) 1739 return retval;
1750 return retval; 1740 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1751 u132_to_hcd(u132)->state = HC_STATE_RUNNING; 1741 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1752 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE); 1742 if (retval)
1753 if (retval) 1743 return retval;
1754 return retval; 1744 retval = u132_write_pcimem(u132, intrstatus, mask);
1755 retval = u132_write_pcimem(u132, intrstatus, mask); 1745 if (retval)
1756 if (retval) 1746 return retval;
1757 return retval; 1747 retval = u132_write_pcimem(u132, intrdisable,
1758 retval = u132_write_pcimem(u132, intrdisable, 1748 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1759 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO | 1749 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1760 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH | 1750 OHCI_INTR_SO);
1761 OHCI_INTR_SO); 1751 if (retval)
1762 if (retval) 1752 return retval; /* handle root hub init quirks ... */
1763 return retval; /* handle root hub init quirks ... */ 1753 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1764 retval = u132_read_pcimem(u132, roothub.a, &roothub_a); 1754 if (retval)
1765 if (retval) 1755 return retval;
1766 return retval; 1756 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1767 roothub_a &= ~(RH_A_PSM | RH_A_OCPM); 1757 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1768 if (u132->flags & OHCI_QUIRK_SUPERIO) { 1758 roothub_a |= RH_A_NOCP;
1769 roothub_a |= RH_A_NOCP; 1759 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1770 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS); 1760 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1771 retval = u132_write_pcimem(u132, roothub.a, roothub_a); 1761 if (retval)
1772 if (retval) 1762 return retval;
1773 return retval; 1763 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1774 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) { 1764 roothub_a |= RH_A_NPS;
1775 roothub_a |= RH_A_NPS; 1765 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1776 retval = u132_write_pcimem(u132, roothub.a, roothub_a); 1766 if (retval)
1777 if (retval) 1767 return retval;
1778 return retval; 1768 }
1779 } 1769 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1780 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC); 1770 if (retval)
1781 if (retval) 1771 return retval;
1782 return retval; 1772 retval = u132_write_pcimem(u132, roothub.b,
1783 retval = u132_write_pcimem(u132, roothub.b, 1773 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1784 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM); 1774 if (retval)
1785 if (retval) 1775 return retval;
1786 return retval; 1776 retval = u132_read_pcimem(u132, control, &control);
1787 retval = u132_read_pcimem(u132, control, &control); 1777 if (retval)
1788 if (retval) 1778 return retval;
1789 return retval; 1779 mdelay((roothub_a >> 23) & 0x1fe);
1790 mdelay((roothub_a >> 23) & 0x1fe); 1780 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1791 u132_to_hcd(u132)->state = HC_STATE_RUNNING; 1781 return 0;
1792 return 0;
1793} 1782}
1794 1783
1795static void u132_hcd_stop(struct usb_hcd *hcd) 1784static void u132_hcd_stop(struct usb_hcd *hcd)
1796{ 1785{
1797 struct u132 *u132 = hcd_to_u132(hcd); 1786 struct u132 *u132 = hcd_to_u132(hcd);
1798 if (u132->going > 1) { 1787 if (u132->going > 1) {
1799 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b" 1788 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1800 "een removed %d\n", u132, hcd, u132->going); 1789 "een removed %d\n", u132, hcd, u132->going);
1801 } else if (u132->going > 0) { 1790 } else if (u132->going > 0) {
1802 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 1791 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1803 "ed\n", hcd); 1792 "ed\n", hcd);
1804 } else { 1793 } else {
1805 mutex_lock(&u132->sw_lock); 1794 mutex_lock(&u132->sw_lock);
1806 msleep(100); 1795 msleep(100);
1807 u132_power(u132, 0); 1796 u132_power(u132, 0);
1808 mutex_unlock(&u132->sw_lock); 1797 mutex_unlock(&u132->sw_lock);
1809 } 1798 }
1810} 1799}
1811 1800
1812static int u132_hcd_start(struct usb_hcd *hcd) 1801static int u132_hcd_start(struct usb_hcd *hcd)
1813{ 1802{
1814 struct u132 *u132 = hcd_to_u132(hcd); 1803 struct u132 *u132 = hcd_to_u132(hcd);
1815 if (u132->going > 1) { 1804 if (u132->going > 1) {
1816 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1805 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1817 , u132->going); 1806 , u132->going);
1818 return -ENODEV; 1807 return -ENODEV;
1819 } else if (u132->going > 0) { 1808 } else if (u132->going > 0) {
1820 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 1809 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1821 return -ESHUTDOWN; 1810 return -ESHUTDOWN;
1822 } else if (hcd->self.controller) { 1811 } else if (hcd->self.controller) {
1823 int retval; 1812 int retval;
1824 struct platform_device *pdev = 1813 struct platform_device *pdev =
1825 to_platform_device(hcd->self.controller); 1814 to_platform_device(hcd->self.controller);
1826 u16 vendor = ((struct u132_platform_data *) 1815 u16 vendor = ((struct u132_platform_data *)
1827 (pdev->dev.platform_data))->vendor; 1816 (pdev->dev.platform_data))->vendor;
1828 u16 device = ((struct u132_platform_data *) 1817 u16 device = ((struct u132_platform_data *)
1829 (pdev->dev.platform_data))->device; 1818 (pdev->dev.platform_data))->device;
1830 mutex_lock(&u132->sw_lock); 1819 mutex_lock(&u132->sw_lock);
1831 msleep(10); 1820 msleep(10);
1832 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) { 1821 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1833 u132->flags = OHCI_QUIRK_AMD756; 1822 u132->flags = OHCI_QUIRK_AMD756;
1834 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) { 1823 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1835 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar" 1824 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1836 "ounds unavailable\n"); 1825 "ounds unavailable\n");
1837 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8) 1826 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1838 u132->flags |= OHCI_QUIRK_ZFMICRO; 1827 u132->flags |= OHCI_QUIRK_ZFMICRO;
1839 retval = u132_run(u132); 1828 retval = u132_run(u132);
1840 if (retval) { 1829 if (retval) {
1841 u132_disable(u132); 1830 u132_disable(u132);
1842 u132->going = 1; 1831 u132->going = 1;
1843 } 1832 }
1844 msleep(100); 1833 msleep(100);
1845 mutex_unlock(&u132->sw_lock); 1834 mutex_unlock(&u132->sw_lock);
1846 return retval; 1835 return retval;
1847 } else { 1836 } else {
1848 dev_err(&u132->platform_dev->dev, "platform_device missing\n"); 1837 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1849 return -ENODEV; 1838 return -ENODEV;
1850 } 1839 }
1851} 1840}
1852 1841
1853static int u132_hcd_reset(struct usb_hcd *hcd) 1842static int u132_hcd_reset(struct usb_hcd *hcd)
1854{ 1843{
1855 struct u132 *u132 = hcd_to_u132(hcd); 1844 struct u132 *u132 = hcd_to_u132(hcd);
1856 if (u132->going > 1) { 1845 if (u132->going > 1) {
1857 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1846 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1858 , u132->going); 1847 , u132->going);
1859 return -ENODEV; 1848 return -ENODEV;
1860 } else if (u132->going > 0) { 1849 } else if (u132->going > 0) {
1861 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 1850 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1862 return -ESHUTDOWN; 1851 return -ESHUTDOWN;
1863 } else { 1852 } else {
1864 int retval; 1853 int retval;
1865 mutex_lock(&u132->sw_lock); 1854 mutex_lock(&u132->sw_lock);
1866 retval = u132_init(u132); 1855 retval = u132_init(u132);
1867 if (retval) { 1856 if (retval) {
1868 u132_disable(u132); 1857 u132_disable(u132);
1869 u132->going = 1; 1858 u132->going = 1;
1870 } 1859 }
1871 mutex_unlock(&u132->sw_lock); 1860 mutex_unlock(&u132->sw_lock);
1872 return retval; 1861 return retval;
1873 } 1862 }
1874} 1863}
1875 1864
1876static int create_endpoint_and_queue_int(struct u132 *u132, 1865static int create_endpoint_and_queue_int(struct u132 *u132,
1877 struct u132_udev *udev, struct urb *urb, 1866 struct u132_udev *udev, struct urb *urb,
1878 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1867 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1879 gfp_t mem_flags) 1868 gfp_t mem_flags)
1880{ 1869{
1881 struct u132_ring *ring; 1870 struct u132_ring *ring;
1882 unsigned long irqs; 1871 unsigned long irqs;
1883 int rc; 1872 int rc;
1884 u8 endp_number; 1873 u8 endp_number;
1885 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); 1874 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1886 1875
1887 if (!endp) { 1876 if (!endp)
1888 return -ENOMEM; 1877 return -ENOMEM;
1889 }
1890 1878
1891 spin_lock_init(&endp->queue_lock.slock); 1879 spin_lock_init(&endp->queue_lock.slock);
1892 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 1880 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
@@ -1899,94 +1887,93 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1899 1887
1900 endp_number = ++u132->num_endpoints; 1888 endp_number = ++u132->num_endpoints;
1901 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; 1889 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1902 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 1890 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1903 INIT_LIST_HEAD(&endp->urb_more); 1891 INIT_LIST_HEAD(&endp->urb_more);
1904 ring = endp->ring = &u132->ring[0]; 1892 ring = endp->ring = &u132->ring[0];
1905 if (ring->curr_endp) { 1893 if (ring->curr_endp) {
1906 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); 1894 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1907 } else { 1895 } else {
1908 INIT_LIST_HEAD(&endp->endp_ring); 1896 INIT_LIST_HEAD(&endp->endp_ring);
1909 ring->curr_endp = endp; 1897 ring->curr_endp = endp;
1910 } 1898 }
1911 ring->length += 1; 1899 ring->length += 1;
1912 endp->dequeueing = 0; 1900 endp->dequeueing = 0;
1913 endp->edset_flush = 0; 1901 endp->edset_flush = 0;
1914 endp->active = 0; 1902 endp->active = 0;
1915 endp->delayed = 0; 1903 endp->delayed = 0;
1916 endp->endp_number = endp_number; 1904 endp->endp_number = endp_number;
1917 endp->u132 = u132; 1905 endp->u132 = u132;
1918 endp->hep = urb->ep; 1906 endp->hep = urb->ep;
1919 endp->pipetype = usb_pipetype(urb->pipe); 1907 endp->pipetype = usb_pipetype(urb->pipe);
1920 u132_endp_init_kref(u132, endp); 1908 u132_endp_init_kref(u132, endp);
1921 if (usb_pipein(urb->pipe)) { 1909 if (usb_pipein(urb->pipe)) {
1922 endp->toggle_bits = 0x2; 1910 endp->toggle_bits = 0x2;
1923 usb_settoggle(udev->usb_device, usb_endp, 0, 0); 1911 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1924 endp->input = 1; 1912 endp->input = 1;
1925 endp->output = 0; 1913 endp->output = 0;
1926 udev->endp_number_in[usb_endp] = endp_number; 1914 udev->endp_number_in[usb_endp] = endp_number;
1927 u132_udev_get_kref(u132, udev); 1915 u132_udev_get_kref(u132, udev);
1928 } else { 1916 } else {
1929 endp->toggle_bits = 0x2; 1917 endp->toggle_bits = 0x2;
1930 usb_settoggle(udev->usb_device, usb_endp, 1, 0); 1918 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1931 endp->input = 0; 1919 endp->input = 0;
1932 endp->output = 1; 1920 endp->output = 1;
1933 udev->endp_number_out[usb_endp] = endp_number; 1921 udev->endp_number_out[usb_endp] = endp_number;
1934 u132_udev_get_kref(u132, udev); 1922 u132_udev_get_kref(u132, udev);
1935 } 1923 }
1936 urb->hcpriv = u132; 1924 urb->hcpriv = u132;
1937 endp->delayed = 1; 1925 endp->delayed = 1;
1938 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); 1926 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1939 endp->udev_number = address; 1927 endp->udev_number = address;
1940 endp->usb_addr = usb_addr; 1928 endp->usb_addr = usb_addr;
1941 endp->usb_endp = usb_endp; 1929 endp->usb_endp = usb_endp;
1942 endp->queue_size = 1; 1930 endp->queue_size = 1;
1943 endp->queue_last = 0; 1931 endp->queue_last = 0;
1944 endp->queue_next = 0; 1932 endp->queue_next = 0;
1945 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 1933 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1946 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 1934 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1947 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval)); 1935 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1948 return 0; 1936 return 0;
1949} 1937}
1950 1938
1951static int queue_int_on_old_endpoint(struct u132 *u132, 1939static int queue_int_on_old_endpoint(struct u132 *u132,
1952 struct u132_udev *udev, struct urb *urb, 1940 struct u132_udev *udev, struct urb *urb,
1953 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 1941 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1954 u8 usb_endp, u8 address) 1942 u8 usb_endp, u8 address)
1955{ 1943{
1956 urb->hcpriv = u132; 1944 urb->hcpriv = u132;
1957 endp->delayed = 1; 1945 endp->delayed = 1;
1958 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); 1946 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1959 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 1947 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1960 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 1948 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1961 } else { 1949 } else {
1962 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), 1950 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1963 GFP_ATOMIC); 1951 GFP_ATOMIC);
1964 if (urbq == NULL) { 1952 if (urbq == NULL) {
1965 endp->queue_size -= 1; 1953 endp->queue_size -= 1;
1966 return -ENOMEM; 1954 return -ENOMEM;
1967 } else { 1955 } else {
1968 list_add_tail(&urbq->urb_more, &endp->urb_more); 1956 list_add_tail(&urbq->urb_more, &endp->urb_more);
1969 urbq->urb = urb; 1957 urbq->urb = urb;
1970 } 1958 }
1971 } 1959 }
1972 return 0; 1960 return 0;
1973} 1961}
1974 1962
1975static int create_endpoint_and_queue_bulk(struct u132 *u132, 1963static int create_endpoint_and_queue_bulk(struct u132 *u132,
1976 struct u132_udev *udev, struct urb *urb, 1964 struct u132_udev *udev, struct urb *urb,
1977 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1965 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1978 gfp_t mem_flags) 1966 gfp_t mem_flags)
1979{ 1967{
1980 int ring_number; 1968 int ring_number;
1981 struct u132_ring *ring; 1969 struct u132_ring *ring;
1982 unsigned long irqs; 1970 unsigned long irqs;
1983 int rc; 1971 int rc;
1984 u8 endp_number; 1972 u8 endp_number;
1985 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); 1973 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1986 1974
1987 if (!endp) { 1975 if (!endp)
1988 return -ENOMEM; 1976 return -ENOMEM;
1989 }
1990 1977
1991 spin_lock_init(&endp->queue_lock.slock); 1978 spin_lock_init(&endp->queue_lock.slock);
1992 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 1979 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
@@ -1999,91 +1986,90 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
1999 1986
2000 endp_number = ++u132->num_endpoints; 1987 endp_number = ++u132->num_endpoints;
2001 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; 1988 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2002 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 1989 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2003 INIT_LIST_HEAD(&endp->urb_more); 1990 INIT_LIST_HEAD(&endp->urb_more);
2004 endp->dequeueing = 0; 1991 endp->dequeueing = 0;
2005 endp->edset_flush = 0; 1992 endp->edset_flush = 0;
2006 endp->active = 0; 1993 endp->active = 0;
2007 endp->delayed = 0; 1994 endp->delayed = 0;
2008 endp->endp_number = endp_number; 1995 endp->endp_number = endp_number;
2009 endp->u132 = u132; 1996 endp->u132 = u132;
2010 endp->hep = urb->ep; 1997 endp->hep = urb->ep;
2011 endp->pipetype = usb_pipetype(urb->pipe); 1998 endp->pipetype = usb_pipetype(urb->pipe);
2012 u132_endp_init_kref(u132, endp); 1999 u132_endp_init_kref(u132, endp);
2013 if (usb_pipein(urb->pipe)) { 2000 if (usb_pipein(urb->pipe)) {
2014 endp->toggle_bits = 0x2; 2001 endp->toggle_bits = 0x2;
2015 usb_settoggle(udev->usb_device, usb_endp, 0, 0); 2002 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2016 ring_number = 3; 2003 ring_number = 3;
2017 endp->input = 1; 2004 endp->input = 1;
2018 endp->output = 0; 2005 endp->output = 0;
2019 udev->endp_number_in[usb_endp] = endp_number; 2006 udev->endp_number_in[usb_endp] = endp_number;
2020 u132_udev_get_kref(u132, udev); 2007 u132_udev_get_kref(u132, udev);
2021 } else { 2008 } else {
2022 endp->toggle_bits = 0x2; 2009 endp->toggle_bits = 0x2;
2023 usb_settoggle(udev->usb_device, usb_endp, 1, 0); 2010 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2024 ring_number = 2; 2011 ring_number = 2;
2025 endp->input = 0; 2012 endp->input = 0;
2026 endp->output = 1; 2013 endp->output = 1;
2027 udev->endp_number_out[usb_endp] = endp_number; 2014 udev->endp_number_out[usb_endp] = endp_number;
2028 u132_udev_get_kref(u132, udev); 2015 u132_udev_get_kref(u132, udev);
2029 } 2016 }
2030 ring = endp->ring = &u132->ring[ring_number - 1]; 2017 ring = endp->ring = &u132->ring[ring_number - 1];
2031 if (ring->curr_endp) { 2018 if (ring->curr_endp) {
2032 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); 2019 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2033 } else { 2020 } else {
2034 INIT_LIST_HEAD(&endp->endp_ring); 2021 INIT_LIST_HEAD(&endp->endp_ring);
2035 ring->curr_endp = endp; 2022 ring->curr_endp = endp;
2036 } 2023 }
2037 ring->length += 1; 2024 ring->length += 1;
2038 urb->hcpriv = u132; 2025 urb->hcpriv = u132;
2039 endp->udev_number = address; 2026 endp->udev_number = address;
2040 endp->usb_addr = usb_addr; 2027 endp->usb_addr = usb_addr;
2041 endp->usb_endp = usb_endp; 2028 endp->usb_endp = usb_endp;
2042 endp->queue_size = 1; 2029 endp->queue_size = 1;
2043 endp->queue_last = 0; 2030 endp->queue_last = 0;
2044 endp->queue_next = 0; 2031 endp->queue_next = 0;
2045 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2032 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2046 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2033 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2047 u132_endp_queue_work(u132, endp, 0); 2034 u132_endp_queue_work(u132, endp, 0);
2048 return 0; 2035 return 0;
2049} 2036}
2050 2037
2051static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, 2038static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2052 struct urb *urb, 2039 struct urb *urb,
2053 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2040 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2054 u8 usb_endp, u8 address) 2041 u8 usb_endp, u8 address)
2055{ 2042{
2056 urb->hcpriv = u132; 2043 urb->hcpriv = u132;
2057 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2044 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2058 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2045 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2059 } else { 2046 } else {
2060 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), 2047 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2061 GFP_ATOMIC); 2048 GFP_ATOMIC);
2062 if (urbq == NULL) { 2049 if (urbq == NULL) {
2063 endp->queue_size -= 1; 2050 endp->queue_size -= 1;
2064 return -ENOMEM; 2051 return -ENOMEM;
2065 } else { 2052 } else {
2066 list_add_tail(&urbq->urb_more, &endp->urb_more); 2053 list_add_tail(&urbq->urb_more, &endp->urb_more);
2067 urbq->urb = urb; 2054 urbq->urb = urb;
2068 } 2055 }
2069 } 2056 }
2070 return 0; 2057 return 0;
2071} 2058}
2072 2059
2073static int create_endpoint_and_queue_control(struct u132 *u132, 2060static int create_endpoint_and_queue_control(struct u132 *u132,
2074 struct urb *urb, 2061 struct urb *urb,
2075 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, 2062 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2076 gfp_t mem_flags) 2063 gfp_t mem_flags)
2077{ 2064{
2078 struct u132_ring *ring; 2065 struct u132_ring *ring;
2079 unsigned long irqs; 2066 unsigned long irqs;
2080 int rc; 2067 int rc;
2081 u8 endp_number; 2068 u8 endp_number;
2082 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); 2069 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2083 2070
2084 if (!endp) { 2071 if (!endp)
2085 return -ENOMEM; 2072 return -ENOMEM;
2086 }
2087 2073
2088 spin_lock_init(&endp->queue_lock.slock); 2074 spin_lock_init(&endp->queue_lock.slock);
2089 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 2075 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
@@ -2096,204 +2082,203 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2096 2082
2097 endp_number = ++u132->num_endpoints; 2083 endp_number = ++u132->num_endpoints;
2098 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; 2084 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2099 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 2085 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2100 INIT_LIST_HEAD(&endp->urb_more); 2086 INIT_LIST_HEAD(&endp->urb_more);
2101 ring = endp->ring = &u132->ring[0]; 2087 ring = endp->ring = &u132->ring[0];
2102 if (ring->curr_endp) { 2088 if (ring->curr_endp) {
2103 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); 2089 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2104 } else { 2090 } else {
2105 INIT_LIST_HEAD(&endp->endp_ring); 2091 INIT_LIST_HEAD(&endp->endp_ring);
2106 ring->curr_endp = endp; 2092 ring->curr_endp = endp;
2107 } 2093 }
2108 ring->length += 1; 2094 ring->length += 1;
2109 endp->dequeueing = 0; 2095 endp->dequeueing = 0;
2110 endp->edset_flush = 0; 2096 endp->edset_flush = 0;
2111 endp->active = 0; 2097 endp->active = 0;
2112 endp->delayed = 0; 2098 endp->delayed = 0;
2113 endp->endp_number = endp_number; 2099 endp->endp_number = endp_number;
2114 endp->u132 = u132; 2100 endp->u132 = u132;
2115 endp->hep = urb->ep; 2101 endp->hep = urb->ep;
2116 u132_endp_init_kref(u132, endp); 2102 u132_endp_init_kref(u132, endp);
2117 u132_endp_get_kref(u132, endp); 2103 u132_endp_get_kref(u132, endp);
2118 if (usb_addr == 0) { 2104 if (usb_addr == 0) {
2119 u8 address = u132->addr[usb_addr].address; 2105 u8 address = u132->addr[usb_addr].address;
2120 struct u132_udev *udev = &u132->udev[address]; 2106 struct u132_udev *udev = &u132->udev[address];
2121 endp->udev_number = address; 2107 endp->udev_number = address;
2122 endp->usb_addr = usb_addr; 2108 endp->usb_addr = usb_addr;
2123 endp->usb_endp = usb_endp; 2109 endp->usb_endp = usb_endp;
2124 endp->input = 1; 2110 endp->input = 1;
2125 endp->output = 1; 2111 endp->output = 1;
2126 endp->pipetype = usb_pipetype(urb->pipe); 2112 endp->pipetype = usb_pipetype(urb->pipe);
2127 u132_udev_init_kref(u132, udev); 2113 u132_udev_init_kref(u132, udev);
2128 u132_udev_get_kref(u132, udev); 2114 u132_udev_get_kref(u132, udev);
2129 udev->endp_number_in[usb_endp] = endp_number; 2115 udev->endp_number_in[usb_endp] = endp_number;
2130 udev->endp_number_out[usb_endp] = endp_number; 2116 udev->endp_number_out[usb_endp] = endp_number;
2131 urb->hcpriv = u132; 2117 urb->hcpriv = u132;
2132 endp->queue_size = 1; 2118 endp->queue_size = 1;
2133 endp->queue_last = 0; 2119 endp->queue_last = 0;
2134 endp->queue_next = 0; 2120 endp->queue_next = 0;
2135 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2121 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2136 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2122 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2137 u132_endp_queue_work(u132, endp, 0); 2123 u132_endp_queue_work(u132, endp, 0);
2138 return 0; 2124 return 0;
2139 } else { /*(usb_addr > 0) */ 2125 } else { /*(usb_addr > 0) */
2140 u8 address = u132->addr[usb_addr].address; 2126 u8 address = u132->addr[usb_addr].address;
2141 struct u132_udev *udev = &u132->udev[address]; 2127 struct u132_udev *udev = &u132->udev[address];
2142 endp->udev_number = address; 2128 endp->udev_number = address;
2143 endp->usb_addr = usb_addr; 2129 endp->usb_addr = usb_addr;
2144 endp->usb_endp = usb_endp; 2130 endp->usb_endp = usb_endp;
2145 endp->input = 1; 2131 endp->input = 1;
2146 endp->output = 1; 2132 endp->output = 1;
2147 endp->pipetype = usb_pipetype(urb->pipe); 2133 endp->pipetype = usb_pipetype(urb->pipe);
2148 u132_udev_get_kref(u132, udev); 2134 u132_udev_get_kref(u132, udev);
2149 udev->enumeration = 2; 2135 udev->enumeration = 2;
2150 udev->endp_number_in[usb_endp] = endp_number; 2136 udev->endp_number_in[usb_endp] = endp_number;
2151 udev->endp_number_out[usb_endp] = endp_number; 2137 udev->endp_number_out[usb_endp] = endp_number;
2152 urb->hcpriv = u132; 2138 urb->hcpriv = u132;
2153 endp->queue_size = 1; 2139 endp->queue_size = 1;
2154 endp->queue_last = 0; 2140 endp->queue_last = 0;
2155 endp->queue_next = 0; 2141 endp->queue_next = 0;
2156 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2142 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2157 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2143 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2158 u132_endp_queue_work(u132, endp, 0); 2144 u132_endp_queue_work(u132, endp, 0);
2159 return 0; 2145 return 0;
2160 } 2146 }
2161} 2147}
2162 2148
2163static int queue_control_on_old_endpoint(struct u132 *u132, 2149static int queue_control_on_old_endpoint(struct u132 *u132,
2164 struct urb *urb, 2150 struct urb *urb,
2165 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2151 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2166 u8 usb_endp) 2152 u8 usb_endp)
2167{ 2153{
2168 if (usb_addr == 0) { 2154 if (usb_addr == 0) {
2169 if (usb_pipein(urb->pipe)) { 2155 if (usb_pipein(urb->pipe)) {
2170 urb->hcpriv = u132; 2156 urb->hcpriv = u132;
2171 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2157 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2172 endp->urb_list[ENDP_QUEUE_MASK & 2158 endp->urb_list[ENDP_QUEUE_MASK &
2173 endp->queue_last++] = urb; 2159 endp->queue_last++] = urb;
2174 } else { 2160 } else {
2175 struct u132_urbq *urbq = 2161 struct u132_urbq *urbq =
2176 kmalloc(sizeof(struct u132_urbq), 2162 kmalloc(sizeof(struct u132_urbq),
2177 GFP_ATOMIC); 2163 GFP_ATOMIC);
2178 if (urbq == NULL) { 2164 if (urbq == NULL) {
2179 endp->queue_size -= 1; 2165 endp->queue_size -= 1;
2180 return -ENOMEM; 2166 return -ENOMEM;
2181 } else { 2167 } else {
2182 list_add_tail(&urbq->urb_more, 2168 list_add_tail(&urbq->urb_more,
2183 &endp->urb_more); 2169 &endp->urb_more);
2184 urbq->urb = urb; 2170 urbq->urb = urb;
2185 } 2171 }
2186 } 2172 }
2187 return 0; 2173 return 0;
2188 } else { /* usb_pipeout(urb->pipe) */ 2174 } else { /* usb_pipeout(urb->pipe) */
2189 struct u132_addr *addr = &u132->addr[usb_dev->devnum]; 2175 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2190 int I = MAX_U132_UDEVS; 2176 int I = MAX_U132_UDEVS;
2191 int i = 0; 2177 int i = 0;
2192 while (--I > 0) { 2178 while (--I > 0) {
2193 struct u132_udev *udev = &u132->udev[++i]; 2179 struct u132_udev *udev = &u132->udev[++i];
2194 if (udev->usb_device) { 2180 if (udev->usb_device) {
2195 continue; 2181 continue;
2196 } else { 2182 } else {
2197 udev->enumeration = 1; 2183 udev->enumeration = 1;
2198 u132->addr[0].address = i; 2184 u132->addr[0].address = i;
2199 endp->udev_number = i; 2185 endp->udev_number = i;
2200 udev->udev_number = i; 2186 udev->udev_number = i;
2201 udev->usb_addr = usb_dev->devnum; 2187 udev->usb_addr = usb_dev->devnum;
2202 u132_udev_init_kref(u132, udev); 2188 u132_udev_init_kref(u132, udev);
2203 udev->endp_number_in[usb_endp] = 2189 udev->endp_number_in[usb_endp] =
2204 endp->endp_number; 2190 endp->endp_number;
2205 u132_udev_get_kref(u132, udev); 2191 u132_udev_get_kref(u132, udev);
2206 udev->endp_number_out[usb_endp] = 2192 udev->endp_number_out[usb_endp] =
2207 endp->endp_number; 2193 endp->endp_number;
2208 udev->usb_device = usb_dev; 2194 udev->usb_device = usb_dev;
2209 ((u8 *) (urb->setup_packet))[2] = 2195 ((u8 *) (urb->setup_packet))[2] =
2210 addr->address = i; 2196 addr->address = i;
2211 u132_udev_get_kref(u132, udev); 2197 u132_udev_get_kref(u132, udev);
2212 break; 2198 break;
2213 } 2199 }
2214 } 2200 }
2215 if (I == 0) { 2201 if (I == 0) {
2216 dev_err(&u132->platform_dev->dev, "run out of d" 2202 dev_err(&u132->platform_dev->dev, "run out of d"
2217 "evice space\n"); 2203 "evice space\n");
2218 return -EINVAL; 2204 return -EINVAL;
2219 } 2205 }
2220 urb->hcpriv = u132; 2206 urb->hcpriv = u132;
2221 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2207 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2222 endp->urb_list[ENDP_QUEUE_MASK & 2208 endp->urb_list[ENDP_QUEUE_MASK &
2223 endp->queue_last++] = urb; 2209 endp->queue_last++] = urb;
2224 } else { 2210 } else {
2225 struct u132_urbq *urbq = 2211 struct u132_urbq *urbq =
2226 kmalloc(sizeof(struct u132_urbq), 2212 kmalloc(sizeof(struct u132_urbq),
2227 GFP_ATOMIC); 2213 GFP_ATOMIC);
2228 if (urbq == NULL) { 2214 if (urbq == NULL) {
2229 endp->queue_size -= 1; 2215 endp->queue_size -= 1;
2230 return -ENOMEM; 2216 return -ENOMEM;
2231 } else { 2217 } else {
2232 list_add_tail(&urbq->urb_more, 2218 list_add_tail(&urbq->urb_more,
2233 &endp->urb_more); 2219 &endp->urb_more);
2234 urbq->urb = urb; 2220 urbq->urb = urb;
2235 } 2221 }
2236 } 2222 }
2237 return 0; 2223 return 0;
2238 } 2224 }
2239 } else { /*(usb_addr > 0) */ 2225 } else { /*(usb_addr > 0) */
2240 u8 address = u132->addr[usb_addr].address; 2226 u8 address = u132->addr[usb_addr].address;
2241 struct u132_udev *udev = &u132->udev[address]; 2227 struct u132_udev *udev = &u132->udev[address];
2242 urb->hcpriv = u132; 2228 urb->hcpriv = u132;
2243 if (udev->enumeration == 2) { 2229 if (udev->enumeration != 2)
2244 } else 2230 udev->enumeration = 2;
2245 udev->enumeration = 2; 2231 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2246 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2232 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2247 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = 2233 urb;
2248 urb; 2234 } else {
2249 } else { 2235 struct u132_urbq *urbq =
2250 struct u132_urbq *urbq = 2236 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2251 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC); 2237 if (urbq == NULL) {
2252 if (urbq == NULL) { 2238 endp->queue_size -= 1;
2253 endp->queue_size -= 1; 2239 return -ENOMEM;
2254 return -ENOMEM; 2240 } else {
2255 } else { 2241 list_add_tail(&urbq->urb_more, &endp->urb_more);
2256 list_add_tail(&urbq->urb_more, &endp->urb_more); 2242 urbq->urb = urb;
2257 urbq->urb = urb; 2243 }
2258 } 2244 }
2259 } 2245 return 0;
2260 return 0; 2246 }
2261 }
2262} 2247}
2263 2248
2264static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, 2249static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2265 gfp_t mem_flags) 2250 gfp_t mem_flags)
2266{ 2251{
2267 struct u132 *u132 = hcd_to_u132(hcd); 2252 struct u132 *u132 = hcd_to_u132(hcd);
2268 if (irqs_disabled()) { 2253 if (irqs_disabled()) {
2269 if (__GFP_WAIT & mem_flags) { 2254 if (__GFP_WAIT & mem_flags) {
2270 printk(KERN_ERR "invalid context for function that migh" 2255 printk(KERN_ERR "invalid context for function that migh"
2271 "t sleep\n"); 2256 "t sleep\n");
2272 return -EINVAL; 2257 return -EINVAL;
2273 } 2258 }
2274 } 2259 }
2275 if (u132->going > 1) { 2260 if (u132->going > 1) {
2276 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2261 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2277 , u132->going); 2262 , u132->going);
2278 return -ENODEV; 2263 return -ENODEV;
2279 } else if (u132->going > 0) { 2264 } else if (u132->going > 0) {
2280 dev_err(&u132->platform_dev->dev, "device is being removed " 2265 dev_err(&u132->platform_dev->dev, "device is being removed "
2281 "urb=%p\n", urb); 2266 "urb=%p\n", urb);
2282 return -ESHUTDOWN; 2267 return -ESHUTDOWN;
2283 } else { 2268 } else {
2284 u8 usb_addr = usb_pipedevice(urb->pipe); 2269 u8 usb_addr = usb_pipedevice(urb->pipe);
2285 u8 usb_endp = usb_pipeendpoint(urb->pipe); 2270 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2286 struct usb_device *usb_dev = urb->dev; 2271 struct usb_device *usb_dev = urb->dev;
2287 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { 2272 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2288 u8 address = u132->addr[usb_addr].address; 2273 u8 address = u132->addr[usb_addr].address;
2289 struct u132_udev *udev = &u132->udev[address]; 2274 struct u132_udev *udev = &u132->udev[address];
2290 struct u132_endp *endp = urb->ep->hcpriv; 2275 struct u132_endp *endp = urb->ep->hcpriv;
2291 urb->actual_length = 0; 2276 urb->actual_length = 0;
2292 if (endp) { 2277 if (endp) {
2293 unsigned long irqs; 2278 unsigned long irqs;
2294 int retval; 2279 int retval;
2295 spin_lock_irqsave(&endp->queue_lock.slock, 2280 spin_lock_irqsave(&endp->queue_lock.slock,
2296 irqs); 2281 irqs);
2297 retval = usb_hcd_link_urb_to_ep(hcd, urb); 2282 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2298 if (retval == 0) { 2283 if (retval == 0) {
2299 retval = queue_int_on_old_endpoint( 2284 retval = queue_int_on_old_endpoint(
@@ -2303,39 +2288,39 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2303 address); 2288 address);
2304 if (retval) 2289 if (retval)
2305 usb_hcd_unlink_urb_from_ep( 2290 usb_hcd_unlink_urb_from_ep(
2306 hcd, urb); 2291 hcd, urb);
2307 } 2292 }
2308 spin_unlock_irqrestore(&endp->queue_lock.slock, 2293 spin_unlock_irqrestore(&endp->queue_lock.slock,
2309 irqs); 2294 irqs);
2310 if (retval) { 2295 if (retval) {
2311 return retval; 2296 return retval;
2312 } else { 2297 } else {
2313 u132_endp_queue_work(u132, endp, 2298 u132_endp_queue_work(u132, endp,
2314 msecs_to_jiffies(urb->interval)) 2299 msecs_to_jiffies(urb->interval))
2315 ; 2300 ;
2316 return 0; 2301 return 0;
2317 } 2302 }
2318 } else if (u132->num_endpoints == MAX_U132_ENDPS) { 2303 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2319 return -EINVAL; 2304 return -EINVAL;
2320 } else { /*(endp == NULL) */ 2305 } else { /*(endp == NULL) */
2321 return create_endpoint_and_queue_int(u132, udev, 2306 return create_endpoint_and_queue_int(u132, udev,
2322 urb, usb_dev, usb_addr, 2307 urb, usb_dev, usb_addr,
2323 usb_endp, address, mem_flags); 2308 usb_endp, address, mem_flags);
2324 } 2309 }
2325 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { 2310 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2326 dev_err(&u132->platform_dev->dev, "the hardware does no" 2311 dev_err(&u132->platform_dev->dev, "the hardware does no"
2327 "t support PIPE_ISOCHRONOUS\n"); 2312 "t support PIPE_ISOCHRONOUS\n");
2328 return -EINVAL; 2313 return -EINVAL;
2329 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { 2314 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2330 u8 address = u132->addr[usb_addr].address; 2315 u8 address = u132->addr[usb_addr].address;
2331 struct u132_udev *udev = &u132->udev[address]; 2316 struct u132_udev *udev = &u132->udev[address];
2332 struct u132_endp *endp = urb->ep->hcpriv; 2317 struct u132_endp *endp = urb->ep->hcpriv;
2333 urb->actual_length = 0; 2318 urb->actual_length = 0;
2334 if (endp) { 2319 if (endp) {
2335 unsigned long irqs; 2320 unsigned long irqs;
2336 int retval; 2321 int retval;
2337 spin_lock_irqsave(&endp->queue_lock.slock, 2322 spin_lock_irqsave(&endp->queue_lock.slock,
2338 irqs); 2323 irqs);
2339 retval = usb_hcd_link_urb_to_ep(hcd, urb); 2324 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2340 if (retval == 0) { 2325 if (retval == 0) {
2341 retval = queue_bulk_on_old_endpoint( 2326 retval = queue_bulk_on_old_endpoint(
@@ -2345,46 +2330,46 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2345 address); 2330 address);
2346 if (retval) 2331 if (retval)
2347 usb_hcd_unlink_urb_from_ep( 2332 usb_hcd_unlink_urb_from_ep(
2348 hcd, urb); 2333 hcd, urb);
2334 }
2335 spin_unlock_irqrestore(&endp->queue_lock.slock,
2336 irqs);
2337 if (retval) {
2338 return retval;
2339 } else {
2340 u132_endp_queue_work(u132, endp, 0);
2341 return 0;
2349 } 2342 }
2350 spin_unlock_irqrestore(&endp->queue_lock.slock, 2343 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2351 irqs); 2344 return -EINVAL;
2352 if (retval) { 2345 } else
2353 return retval; 2346 return create_endpoint_and_queue_bulk(u132,
2354 } else {
2355 u132_endp_queue_work(u132, endp, 0);
2356 return 0;
2357 }
2358 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2359 return -EINVAL;
2360 } else
2361 return create_endpoint_and_queue_bulk(u132,
2362 udev, urb, usb_dev, usb_addr, 2347 udev, urb, usb_dev, usb_addr,
2363 usb_endp, address, mem_flags); 2348 usb_endp, address, mem_flags);
2364 } else { 2349 } else {
2365 struct u132_endp *endp = urb->ep->hcpriv; 2350 struct u132_endp *endp = urb->ep->hcpriv;
2366 u16 urb_size = 8; 2351 u16 urb_size = 8;
2367 u8 *b = urb->setup_packet; 2352 u8 *b = urb->setup_packet;
2368 int i = 0; 2353 int i = 0;
2369 char data[30 *3 + 4]; 2354 char data[30 * 3 + 4];
2370 char *d = data; 2355 char *d = data;
2371 int m = (sizeof(data) - 1) / 3; 2356 int m = (sizeof(data) - 1) / 3;
2372 int l = 0; 2357 int l = 0;
2373 data[0] = 0; 2358 data[0] = 0;
2374 while (urb_size-- > 0) { 2359 while (urb_size-- > 0) {
2375 if (i > m) { 2360 if (i > m) {
2376 } else if (i++ < m) { 2361 } else if (i++ < m) {
2377 int w = sprintf(d, " %02X", *b++); 2362 int w = sprintf(d, " %02X", *b++);
2378 d += w; 2363 d += w;
2379 l += w; 2364 l += w;
2380 } else 2365 } else
2381 d += sprintf(d, " .."); 2366 d += sprintf(d, " ..");
2382 } 2367 }
2383 if (endp) { 2368 if (endp) {
2384 unsigned long irqs; 2369 unsigned long irqs;
2385 int retval; 2370 int retval;
2386 spin_lock_irqsave(&endp->queue_lock.slock, 2371 spin_lock_irqsave(&endp->queue_lock.slock,
2387 irqs); 2372 irqs);
2388 retval = usb_hcd_link_urb_to_ep(hcd, urb); 2373 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2389 if (retval == 0) { 2374 if (retval == 0) {
2390 retval = queue_control_on_old_endpoint( 2375 retval = queue_control_on_old_endpoint(
@@ -2395,267 +2380,267 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2395 usb_hcd_unlink_urb_from_ep( 2380 usb_hcd_unlink_urb_from_ep(
2396 hcd, urb); 2381 hcd, urb);
2397 } 2382 }
2398 spin_unlock_irqrestore(&endp->queue_lock.slock, 2383 spin_unlock_irqrestore(&endp->queue_lock.slock,
2399 irqs); 2384 irqs);
2400 if (retval) { 2385 if (retval) {
2401 return retval; 2386 return retval;
2402 } else { 2387 } else {
2403 u132_endp_queue_work(u132, endp, 0); 2388 u132_endp_queue_work(u132, endp, 0);
2404 return 0; 2389 return 0;
2405 } 2390 }
2406 } else if (u132->num_endpoints == MAX_U132_ENDPS) { 2391 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2407 return -EINVAL; 2392 return -EINVAL;
2408 } else 2393 } else
2409 return create_endpoint_and_queue_control(u132, 2394 return create_endpoint_and_queue_control(u132,
2410 urb, usb_dev, usb_addr, usb_endp, 2395 urb, usb_dev, usb_addr, usb_endp,
2411 mem_flags); 2396 mem_flags);
2412 } 2397 }
2413 } 2398 }
2414} 2399}
2415 2400
2416static int dequeue_from_overflow_chain(struct u132 *u132, 2401static int dequeue_from_overflow_chain(struct u132 *u132,
2417 struct u132_endp *endp, struct urb *urb) 2402 struct u132_endp *endp, struct urb *urb)
2418{ 2403{
2419 struct list_head *scan; 2404 struct list_head *scan;
2420 struct list_head *head = &endp->urb_more; 2405 struct list_head *head = &endp->urb_more;
2421 list_for_each(scan, head) { 2406 list_for_each(scan, head) {
2422 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq, 2407 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2423 urb_more); 2408 urb_more);
2424 if (urbq->urb == urb) { 2409 if (urbq->urb == urb) {
2425 struct usb_hcd *hcd = u132_to_hcd(u132); 2410 struct usb_hcd *hcd = u132_to_hcd(u132);
2426 list_del(scan); 2411 list_del(scan);
2427 endp->queue_size -= 1; 2412 endp->queue_size -= 1;
2428 urb->error_count = 0; 2413 urb->error_count = 0;
2429 usb_hcd_giveback_urb(hcd, urb, 0); 2414 usb_hcd_giveback_urb(hcd, urb, 0);
2430 return 0; 2415 return 0;
2431 } else 2416 } else
2432 continue; 2417 continue;
2433 } 2418 }
2434 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring" 2419 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2435 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X" 2420 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2436 "\n", urb, endp->endp_number, endp, endp->ring->number, 2421 "\n", urb, endp->endp_number, endp, endp->ring->number,
2437 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', 2422 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2438 endp->usb_endp, endp->usb_addr, endp->queue_size, 2423 endp->usb_endp, endp->usb_addr, endp->queue_size,
2439 endp->queue_next, endp->queue_last); 2424 endp->queue_next, endp->queue_last);
2440 return -EINVAL; 2425 return -EINVAL;
2441} 2426}
2442 2427
2443static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp, 2428static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2444 struct urb *urb, int status) 2429 struct urb *urb, int status)
2445{ 2430{
2446 unsigned long irqs; 2431 unsigned long irqs;
2447 int rc; 2432 int rc;
2448 2433
2449 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 2434 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2450 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status); 2435 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2451 if (rc) { 2436 if (rc) {
2452 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2437 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2453 return rc; 2438 return rc;
2454 } 2439 }
2455 if (endp->queue_size == 0) { 2440 if (endp->queue_size == 0) {
2456 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]" 2441 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2457 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb, 2442 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2458 endp->endp_number, endp, endp->ring->number, 2443 endp->endp_number, endp, endp->ring->number,
2459 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', 2444 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2460 endp->usb_endp, endp->usb_addr); 2445 endp->usb_endp, endp->usb_addr);
2461 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2446 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2462 return -EINVAL; 2447 return -EINVAL;
2463 } 2448 }
2464 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) { 2449 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2465 if (endp->active) { 2450 if (endp->active) {
2466 endp->dequeueing = 1; 2451 endp->dequeueing = 1;
2467 endp->edset_flush = 1; 2452 endp->edset_flush = 1;
2468 u132_endp_queue_work(u132, endp, 0); 2453 u132_endp_queue_work(u132, endp, 0);
2469 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2454 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2470 return 0; 2455 return 0;
2471 } else { 2456 } else {
2472 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2457 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2473 u132_hcd_abandon_urb(u132, endp, urb, status); 2458 u132_hcd_abandon_urb(u132, endp, urb, status);
2474 return 0; 2459 return 0;
2475 } 2460 }
2476 } else { 2461 } else {
2477 u16 queue_list = 0; 2462 u16 queue_list = 0;
2478 u16 queue_size = endp->queue_size; 2463 u16 queue_size = endp->queue_size;
2479 u16 queue_scan = endp->queue_next; 2464 u16 queue_scan = endp->queue_next;
2480 struct urb **urb_slot = NULL; 2465 struct urb **urb_slot = NULL;
2481 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { 2466 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2482 if (urb == endp->urb_list[ENDP_QUEUE_MASK & 2467 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2483 ++queue_scan]) { 2468 ++queue_scan]) {
2484 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & 2469 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2485 queue_scan]; 2470 queue_scan];
2486 break; 2471 break;
2487 } else 2472 } else
2488 continue; 2473 continue;
2489 } 2474 }
2490 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { 2475 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2491 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK & 2476 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2492 ++queue_scan]; 2477 ++queue_scan];
2493 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & 2478 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2494 queue_scan]; 2479 queue_scan];
2495 } 2480 }
2496 if (urb_slot) { 2481 if (urb_slot) {
2497 struct usb_hcd *hcd = u132_to_hcd(u132); 2482 struct usb_hcd *hcd = u132_to_hcd(u132);
2498 2483
2499 usb_hcd_unlink_urb_from_ep(hcd, urb); 2484 usb_hcd_unlink_urb_from_ep(hcd, urb);
2500 endp->queue_size -= 1; 2485 endp->queue_size -= 1;
2501 if (list_empty(&endp->urb_more)) { 2486 if (list_empty(&endp->urb_more)) {
2502 spin_unlock_irqrestore(&endp->queue_lock.slock, 2487 spin_unlock_irqrestore(&endp->queue_lock.slock,
2503 irqs); 2488 irqs);
2504 } else { 2489 } else {
2505 struct list_head *next = endp->urb_more.next; 2490 struct list_head *next = endp->urb_more.next;
2506 struct u132_urbq *urbq = list_entry(next, 2491 struct u132_urbq *urbq = list_entry(next,
2507 struct u132_urbq, urb_more); 2492 struct u132_urbq, urb_more);
2508 list_del(next); 2493 list_del(next);
2509 *urb_slot = urbq->urb; 2494 *urb_slot = urbq->urb;
2510 spin_unlock_irqrestore(&endp->queue_lock.slock, 2495 spin_unlock_irqrestore(&endp->queue_lock.slock,
2511 irqs); 2496 irqs);
2512 kfree(urbq); 2497 kfree(urbq);
2513 } urb->error_count = 0; 2498 } urb->error_count = 0;
2514 usb_hcd_giveback_urb(hcd, urb, status); 2499 usb_hcd_giveback_urb(hcd, urb, status);
2515 return 0; 2500 return 0;
2516 } else if (list_empty(&endp->urb_more)) { 2501 } else if (list_empty(&endp->urb_more)) {
2517 dev_err(&u132->platform_dev->dev, "urb=%p not found in " 2502 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2518 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr" 2503 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2519 "=%d size=%d next=%04X last=%04X\n", urb, 2504 "=%d size=%d next=%04X last=%04X\n", urb,
2520 endp->endp_number, endp, endp->ring->number, 2505 endp->endp_number, endp, endp->ring->number,
2521 endp->input ? 'I' : ' ', 2506 endp->input ? 'I' : ' ',
2522 endp->output ? 'O' : ' ', endp->usb_endp, 2507 endp->output ? 'O' : ' ', endp->usb_endp,
2523 endp->usb_addr, endp->queue_size, 2508 endp->usb_addr, endp->queue_size,
2524 endp->queue_next, endp->queue_last); 2509 endp->queue_next, endp->queue_last);
2525 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2510 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2526 return -EINVAL; 2511 return -EINVAL;
2527 } else { 2512 } else {
2528 int retval; 2513 int retval;
2529 2514
2530 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb); 2515 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2531 retval = dequeue_from_overflow_chain(u132, endp, 2516 retval = dequeue_from_overflow_chain(u132, endp,
2532 urb); 2517 urb);
2533 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2518 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2534 return retval; 2519 return retval;
2535 } 2520 }
2536 } 2521 }
2537} 2522}
2538 2523
2539static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 2524static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2540{ 2525{
2541 struct u132 *u132 = hcd_to_u132(hcd); 2526 struct u132 *u132 = hcd_to_u132(hcd);
2542 if (u132->going > 2) { 2527 if (u132->going > 2) {
2543 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2528 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2544 , u132->going); 2529 , u132->going);
2545 return -ENODEV; 2530 return -ENODEV;
2546 } else { 2531 } else {
2547 u8 usb_addr = usb_pipedevice(urb->pipe); 2532 u8 usb_addr = usb_pipedevice(urb->pipe);
2548 u8 usb_endp = usb_pipeendpoint(urb->pipe); 2533 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2549 u8 address = u132->addr[usb_addr].address; 2534 u8 address = u132->addr[usb_addr].address;
2550 struct u132_udev *udev = &u132->udev[address]; 2535 struct u132_udev *udev = &u132->udev[address];
2551 if (usb_pipein(urb->pipe)) { 2536 if (usb_pipein(urb->pipe)) {
2552 u8 endp_number = udev->endp_number_in[usb_endp]; 2537 u8 endp_number = udev->endp_number_in[usb_endp];
2553 struct u132_endp *endp = u132->endp[endp_number - 1]; 2538 struct u132_endp *endp = u132->endp[endp_number - 1];
2554 return u132_endp_urb_dequeue(u132, endp, urb, status); 2539 return u132_endp_urb_dequeue(u132, endp, urb, status);
2555 } else { 2540 } else {
2556 u8 endp_number = udev->endp_number_out[usb_endp]; 2541 u8 endp_number = udev->endp_number_out[usb_endp];
2557 struct u132_endp *endp = u132->endp[endp_number - 1]; 2542 struct u132_endp *endp = u132->endp[endp_number - 1];
2558 return u132_endp_urb_dequeue(u132, endp, urb, status); 2543 return u132_endp_urb_dequeue(u132, endp, urb, status);
2559 } 2544 }
2560 } 2545 }
2561} 2546}
2562 2547
2563static void u132_endpoint_disable(struct usb_hcd *hcd, 2548static void u132_endpoint_disable(struct usb_hcd *hcd,
2564 struct usb_host_endpoint *hep) 2549 struct usb_host_endpoint *hep)
2565{ 2550{
2566 struct u132 *u132 = hcd_to_u132(hcd); 2551 struct u132 *u132 = hcd_to_u132(hcd);
2567 if (u132->going > 2) { 2552 if (u132->going > 2) {
2568 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p" 2553 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2569 ") has been removed %d\n", u132, hcd, hep, 2554 ") has been removed %d\n", u132, hcd, hep,
2570 u132->going); 2555 u132->going);
2571 } else { 2556 } else {
2572 struct u132_endp *endp = hep->hcpriv; 2557 struct u132_endp *endp = hep->hcpriv;
2573 if (endp) 2558 if (endp)
2574 u132_endp_put_kref(u132, endp); 2559 u132_endp_put_kref(u132, endp);
2575 } 2560 }
2576} 2561}
2577 2562
2578static int u132_get_frame(struct usb_hcd *hcd) 2563static int u132_get_frame(struct usb_hcd *hcd)
2579{ 2564{
2580 struct u132 *u132 = hcd_to_u132(hcd); 2565 struct u132 *u132 = hcd_to_u132(hcd);
2581 if (u132->going > 1) { 2566 if (u132->going > 1) {
2582 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2567 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2583 , u132->going); 2568 , u132->going);
2584 return -ENODEV; 2569 return -ENODEV;
2585 } else if (u132->going > 0) { 2570 } else if (u132->going > 0) {
2586 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2571 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2587 return -ESHUTDOWN; 2572 return -ESHUTDOWN;
2588 } else { 2573 } else {
2589 int frame = 0; 2574 int frame = 0;
2590 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n"); 2575 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2591 msleep(100); 2576 msleep(100);
2592 return frame; 2577 return frame;
2593 } 2578 }
2594} 2579}
2595 2580
2596static int u132_roothub_descriptor(struct u132 *u132, 2581static int u132_roothub_descriptor(struct u132 *u132,
2597 struct usb_hub_descriptor *desc) 2582 struct usb_hub_descriptor *desc)
2598{ 2583{
2599 int retval; 2584 int retval;
2600 u16 temp; 2585 u16 temp;
2601 u32 rh_a = -1; 2586 u32 rh_a = -1;
2602 u32 rh_b = -1; 2587 u32 rh_b = -1;
2603 retval = u132_read_pcimem(u132, roothub.a, &rh_a); 2588 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2604 if (retval) 2589 if (retval)
2605 return retval; 2590 return retval;
2606 desc->bDescriptorType = 0x29; 2591 desc->bDescriptorType = 0x29;
2607 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24; 2592 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2608 desc->bHubContrCurrent = 0; 2593 desc->bHubContrCurrent = 0;
2609 desc->bNbrPorts = u132->num_ports; 2594 desc->bNbrPorts = u132->num_ports;
2610 temp = 1 + (u132->num_ports / 8); 2595 temp = 1 + (u132->num_ports / 8);
2611 desc->bDescLength = 7 + 2 *temp; 2596 desc->bDescLength = 7 + 2 * temp;
2612 temp = 0; 2597 temp = 0;
2613 if (rh_a & RH_A_NPS) 2598 if (rh_a & RH_A_NPS)
2614 temp |= 0x0002; 2599 temp |= 0x0002;
2615 if (rh_a & RH_A_PSM) 2600 if (rh_a & RH_A_PSM)
2616 temp |= 0x0001; 2601 temp |= 0x0001;
2617 if (rh_a & RH_A_NOCP) { 2602 if (rh_a & RH_A_NOCP)
2618 temp |= 0x0010; 2603 temp |= 0x0010;
2619 } else if (rh_a & RH_A_OCPM) 2604 else if (rh_a & RH_A_OCPM)
2620 temp |= 0x0008; 2605 temp |= 0x0008;
2621 desc->wHubCharacteristics = cpu_to_le16(temp); 2606 desc->wHubCharacteristics = cpu_to_le16(temp);
2622 retval = u132_read_pcimem(u132, roothub.b, &rh_b); 2607 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2623 if (retval) 2608 if (retval)
2624 return retval; 2609 return retval;
2625 memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 2610 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2626 desc->bitmap[0] = rh_b & RH_B_DR; 2611 desc->bitmap[0] = rh_b & RH_B_DR;
2627 if (u132->num_ports > 7) { 2612 if (u132->num_ports > 7) {
2628 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8; 2613 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2629 desc->bitmap[2] = 0xff; 2614 desc->bitmap[2] = 0xff;
2630 } else 2615 } else
2631 desc->bitmap[1] = 0xff; 2616 desc->bitmap[1] = 0xff;
2632 return 0; 2617 return 0;
2633} 2618}
2634 2619
2635static int u132_roothub_status(struct u132 *u132, __le32 *desc) 2620static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2636{ 2621{
2637 u32 rh_status = -1; 2622 u32 rh_status = -1;
2638 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status); 2623 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2639 *desc = cpu_to_le32(rh_status); 2624 *desc = cpu_to_le32(rh_status);
2640 return ret_status; 2625 return ret_status;
2641} 2626}
2642 2627
2643static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex) 2628static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2644{ 2629{
2645 if (wIndex == 0 || wIndex > u132->num_ports) { 2630 if (wIndex == 0 || wIndex > u132->num_ports) {
2646 return -EINVAL; 2631 return -EINVAL;
2647 } else { 2632 } else {
2648 int port = wIndex - 1; 2633 int port = wIndex - 1;
2649 u32 rh_portstatus = -1; 2634 u32 rh_portstatus = -1;
2650 int ret_portstatus = u132_read_pcimem(u132, 2635 int ret_portstatus = u132_read_pcimem(u132,
2651 roothub.portstatus[port], &rh_portstatus); 2636 roothub.portstatus[port], &rh_portstatus);
2652 *desc = cpu_to_le32(rh_portstatus); 2637 *desc = cpu_to_le32(rh_portstatus);
2653 if (*(u16 *) (desc + 2)) { 2638 if (*(u16 *) (desc + 2)) {
2654 dev_info(&u132->platform_dev->dev, "Port %d Status Chan" 2639 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2655 "ge = %08X\n", port, *desc); 2640 "ge = %08X\n", port, *desc);
2656 } 2641 }
2657 return ret_portstatus; 2642 return ret_portstatus;
2658 } 2643 }
2659} 2644}
2660 2645
2661 2646
@@ -2666,381 +2651,340 @@ static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2666#define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 2651#define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2667static int u132_roothub_portreset(struct u132 *u132, int port_index) 2652static int u132_roothub_portreset(struct u132 *u132, int port_index)
2668{ 2653{
2669 int retval; 2654 int retval;
2670 u32 fmnumber; 2655 u32 fmnumber;
2671 u16 now; 2656 u16 now;
2672 u16 reset_done; 2657 u16 reset_done;
2673 retval = u132_read_pcimem(u132, fmnumber, &fmnumber); 2658 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2674 if (retval) 2659 if (retval)
2675 return retval; 2660 return retval;
2676 now = fmnumber; 2661 now = fmnumber;
2677 reset_done = now + PORT_RESET_MSEC; 2662 reset_done = now + PORT_RESET_MSEC;
2678 do { 2663 do {
2679 u32 portstat; 2664 u32 portstat;
2680 do { 2665 do {
2681 retval = u132_read_pcimem(u132, 2666 retval = u132_read_pcimem(u132,
2682 roothub.portstatus[port_index], &portstat); 2667 roothub.portstatus[port_index], &portstat);
2683 if (retval) 2668 if (retval)
2684 return retval; 2669 return retval;
2685 if (RH_PS_PRS & portstat) { 2670 if (RH_PS_PRS & portstat)
2686 continue; 2671 continue;
2687 } else 2672 else
2688 break; 2673 break;
2689 } while (tick_before(now, reset_done)); 2674 } while (tick_before(now, reset_done));
2690 if (RH_PS_PRS & portstat) 2675 if (RH_PS_PRS & portstat)
2691 return -ENODEV; 2676 return -ENODEV;
2692 if (RH_PS_CCS & portstat) { 2677 if (RH_PS_CCS & portstat) {
2693 if (RH_PS_PRSC & portstat) { 2678 if (RH_PS_PRSC & portstat) {
2694 retval = u132_write_pcimem(u132, 2679 retval = u132_write_pcimem(u132,
2695 roothub.portstatus[port_index], 2680 roothub.portstatus[port_index],
2696 RH_PS_PRSC); 2681 RH_PS_PRSC);
2697 if (retval) 2682 if (retval)
2698 return retval; 2683 return retval;
2699 } 2684 }
2700 } else 2685 } else
2701 break; /* start the next reset, 2686 break; /* start the next reset,
2702 sleep till it's probably done */ 2687 sleep till it's probably done */
2703 retval = u132_write_pcimem(u132, roothub.portstatus[port_index], 2688 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2704 RH_PS_PRS); 2689 RH_PS_PRS);
2705 if (retval) 2690 if (retval)
2706 return retval; 2691 return retval;
2707 msleep(PORT_RESET_HW_MSEC); 2692 msleep(PORT_RESET_HW_MSEC);
2708 retval = u132_read_pcimem(u132, fmnumber, &fmnumber); 2693 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2709 if (retval) 2694 if (retval)
2710 return retval; 2695 return retval;
2711 now = fmnumber; 2696 now = fmnumber;
2712 } while (tick_before(now, reset_done)); 2697 } while (tick_before(now, reset_done));
2713 return 0; 2698 return 0;
2714} 2699}
2715 2700
2716static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue, 2701static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2717 u16 wIndex) 2702 u16 wIndex)
2718{ 2703{
2719 if (wIndex == 0 || wIndex > u132->num_ports) { 2704 if (wIndex == 0 || wIndex > u132->num_ports) {
2720 return -EINVAL; 2705 return -EINVAL;
2721 } else { 2706 } else {
2722 int retval; 2707 int retval;
2723 int port_index = wIndex - 1; 2708 int port_index = wIndex - 1;
2724 struct u132_port *port = &u132->port[port_index]; 2709 struct u132_port *port = &u132->port[port_index];
2725 port->Status &= ~(1 << wValue); 2710 port->Status &= ~(1 << wValue);
2726 switch (wValue) { 2711 switch (wValue) {
2727 case USB_PORT_FEAT_SUSPEND: 2712 case USB_PORT_FEAT_SUSPEND:
2728 retval = u132_write_pcimem(u132, 2713 retval = u132_write_pcimem(u132,
2729 roothub.portstatus[port_index], RH_PS_PSS); 2714 roothub.portstatus[port_index], RH_PS_PSS);
2730 if (retval) 2715 if (retval)
2731 return retval; 2716 return retval;
2732 return 0; 2717 return 0;
2733 case USB_PORT_FEAT_POWER: 2718 case USB_PORT_FEAT_POWER:
2734 retval = u132_write_pcimem(u132, 2719 retval = u132_write_pcimem(u132,
2735 roothub.portstatus[port_index], RH_PS_PPS); 2720 roothub.portstatus[port_index], RH_PS_PPS);
2736 if (retval) 2721 if (retval)
2737 return retval; 2722 return retval;
2738 return 0; 2723 return 0;
2739 case USB_PORT_FEAT_RESET: 2724 case USB_PORT_FEAT_RESET:
2740 retval = u132_roothub_portreset(u132, port_index); 2725 retval = u132_roothub_portreset(u132, port_index);
2741 if (retval) 2726 if (retval)
2742 return retval; 2727 return retval;
2743 return 0; 2728 return 0;
2744 default: 2729 default:
2745 return -EPIPE; 2730 return -EPIPE;
2746 } 2731 }
2747 } 2732 }
2748} 2733}
2749 2734
2750static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue, 2735static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2751 u16 wIndex) 2736 u16 wIndex)
2752{ 2737{
2753 if (wIndex == 0 || wIndex > u132->num_ports) { 2738 if (wIndex == 0 || wIndex > u132->num_ports) {
2754 return -EINVAL; 2739 return -EINVAL;
2755 } else { 2740 } else {
2756 int port_index = wIndex - 1; 2741 int port_index = wIndex - 1;
2757 u32 temp; 2742 u32 temp;
2758 int retval; 2743 int retval;
2759 struct u132_port *port = &u132->port[port_index]; 2744 struct u132_port *port = &u132->port[port_index];
2760 port->Status &= ~(1 << wValue); 2745 port->Status &= ~(1 << wValue);
2761 switch (wValue) { 2746 switch (wValue) {
2762 case USB_PORT_FEAT_ENABLE: 2747 case USB_PORT_FEAT_ENABLE:
2763 temp = RH_PS_CCS; 2748 temp = RH_PS_CCS;
2764 break; 2749 break;
2765 case USB_PORT_FEAT_C_ENABLE: 2750 case USB_PORT_FEAT_C_ENABLE:
2766 temp = RH_PS_PESC; 2751 temp = RH_PS_PESC;
2767 break; 2752 break;
2768 case USB_PORT_FEAT_SUSPEND: 2753 case USB_PORT_FEAT_SUSPEND:
2769 temp = RH_PS_POCI; 2754 temp = RH_PS_POCI;
2770 if ((u132->hc_control & OHCI_CTRL_HCFS) 2755 if ((u132->hc_control & OHCI_CTRL_HCFS)
2771 != OHCI_USB_OPER) { 2756 != OHCI_USB_OPER) {
2772 dev_err(&u132->platform_dev->dev, "TODO resume_" 2757 dev_err(&u132->platform_dev->dev, "TODO resume_"
2773 "root_hub\n"); 2758 "root_hub\n");
2774 } 2759 }
2775 break; 2760 break;
2776 case USB_PORT_FEAT_C_SUSPEND: 2761 case USB_PORT_FEAT_C_SUSPEND:
2777 temp = RH_PS_PSSC; 2762 temp = RH_PS_PSSC;
2778 break; 2763 break;
2779 case USB_PORT_FEAT_POWER: 2764 case USB_PORT_FEAT_POWER:
2780 temp = RH_PS_LSDA; 2765 temp = RH_PS_LSDA;
2781 break; 2766 break;
2782 case USB_PORT_FEAT_C_CONNECTION: 2767 case USB_PORT_FEAT_C_CONNECTION:
2783 temp = RH_PS_CSC; 2768 temp = RH_PS_CSC;
2784 break; 2769 break;
2785 case USB_PORT_FEAT_C_OVER_CURRENT: 2770 case USB_PORT_FEAT_C_OVER_CURRENT:
2786 temp = RH_PS_OCIC; 2771 temp = RH_PS_OCIC;
2787 break; 2772 break;
2788 case USB_PORT_FEAT_C_RESET: 2773 case USB_PORT_FEAT_C_RESET:
2789 temp = RH_PS_PRSC; 2774 temp = RH_PS_PRSC;
2790 break; 2775 break;
2791 default: 2776 default:
2792 return -EPIPE; 2777 return -EPIPE;
2793 } 2778 }
2794 retval = u132_write_pcimem(u132, roothub.portstatus[port_index], 2779 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2795 temp); 2780 temp);
2796 if (retval) 2781 if (retval)
2797 return retval; 2782 return retval;
2798 return 0; 2783 return 0;
2799 } 2784 }
2800} 2785}
2801 2786
2802 2787
2803/* the virtual root hub timer IRQ checks for hub status*/ 2788/* the virtual root hub timer IRQ checks for hub status*/
2804static int u132_hub_status_data(struct usb_hcd *hcd, char *buf) 2789static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2805{ 2790{
2806 struct u132 *u132 = hcd_to_u132(hcd); 2791 struct u132 *u132 = hcd_to_u132(hcd);
2807 if (u132->going > 1) { 2792 if (u132->going > 1) {
2808 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov" 2793 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2809 "ed %d\n", hcd, u132->going); 2794 "ed %d\n", hcd, u132->going);
2810 return -ENODEV; 2795 return -ENODEV;
2811 } else if (u132->going > 0) { 2796 } else if (u132->going > 0) {
2812 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 2797 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2813 "ed\n", hcd); 2798 "ed\n", hcd);
2814 return -ESHUTDOWN; 2799 return -ESHUTDOWN;
2815 } else { 2800 } else {
2816 int i, changed = 0, length = 1; 2801 int i, changed = 0, length = 1;
2817 if (u132->flags & OHCI_QUIRK_AMD756) { 2802 if (u132->flags & OHCI_QUIRK_AMD756) {
2818 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) { 2803 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2819 dev_err(&u132->platform_dev->dev, "bogus NDP, r" 2804 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2820 "ereads as NDP=%d\n", 2805 "ereads as NDP=%d\n",
2821 u132->hc_roothub_a & RH_A_NDP); 2806 u132->hc_roothub_a & RH_A_NDP);
2822 goto done; 2807 goto done;
2823 } 2808 }
2824 } 2809 }
2825 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) { 2810 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC))
2826 buf[0] = changed = 1; 2811 buf[0] = changed = 1;
2827 } else 2812 else
2828 buf[0] = 0; 2813 buf[0] = 0;
2829 if (u132->num_ports > 7) { 2814 if (u132->num_ports > 7) {
2830 buf[1] = 0; 2815 buf[1] = 0;
2831 length++; 2816 length++;
2832 } 2817 }
2833 for (i = 0; i < u132->num_ports; i++) { 2818 for (i = 0; i < u132->num_ports; i++) {
2834 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC | 2819 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2835 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC | 2820 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2836 RH_PS_PRSC)) { 2821 RH_PS_PRSC)) {
2837 changed = 1; 2822 changed = 1;
2838 if (i < 7) { 2823 if (i < 7)
2839 buf[0] |= 1 << (i + 1); 2824 buf[0] |= 1 << (i + 1);
2840 } else 2825 else
2841 buf[1] |= 1 << (i - 7); 2826 buf[1] |= 1 << (i - 7);
2842 continue; 2827 continue;
2843 } 2828 }
2844 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) { 2829 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS))
2845 continue; 2830 continue;
2846 } 2831
2847 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) { 2832 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS))
2848 continue; 2833 continue;
2849 } 2834 }
2850 } 2835done:
2851 done:return changed ? length : 0; 2836 return changed ? length : 0;
2852 } 2837 }
2853} 2838}
2854 2839
2855static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 2840static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2856 u16 wIndex, char *buf, u16 wLength) 2841 u16 wIndex, char *buf, u16 wLength)
2857{ 2842{
2858 struct u132 *u132 = hcd_to_u132(hcd); 2843 struct u132 *u132 = hcd_to_u132(hcd);
2859 if (u132->going > 1) { 2844 if (u132->going > 1) {
2860 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2845 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2861 , u132->going); 2846 , u132->going);
2862 return -ENODEV; 2847 return -ENODEV;
2863 } else if (u132->going > 0) { 2848 } else if (u132->going > 0) {
2864 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2849 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2865 return -ESHUTDOWN; 2850 return -ESHUTDOWN;
2866 } else { 2851 } else {
2867 int retval = 0; 2852 int retval = 0;
2868 mutex_lock(&u132->sw_lock); 2853 mutex_lock(&u132->sw_lock);
2869 switch (typeReq) { 2854 switch (typeReq) {
2870 case ClearHubFeature: 2855 case ClearHubFeature:
2871 switch (wValue) { 2856 switch (wValue) {
2872 case C_HUB_OVER_CURRENT: 2857 case C_HUB_OVER_CURRENT:
2873 case C_HUB_LOCAL_POWER: 2858 case C_HUB_LOCAL_POWER:
2874 break; 2859 break;
2875 default: 2860 default:
2876 goto stall; 2861 goto stall;
2877 } 2862 }
2878 break; 2863 break;
2879 case SetHubFeature: 2864 case SetHubFeature:
2880 switch (wValue) { 2865 switch (wValue) {
2881 case C_HUB_OVER_CURRENT: 2866 case C_HUB_OVER_CURRENT:
2882 case C_HUB_LOCAL_POWER: 2867 case C_HUB_LOCAL_POWER:
2883 break; 2868 break;
2884 default: 2869 default:
2885 goto stall; 2870 goto stall;
2886 } 2871 }
2887 break; 2872 break;
2888 case ClearPortFeature:{ 2873 case ClearPortFeature:{
2889 retval = u132_roothub_clearportfeature(u132, 2874 retval = u132_roothub_clearportfeature(u132,
2890 wValue, wIndex); 2875 wValue, wIndex);
2891 if (retval) 2876 if (retval)
2892 goto error; 2877 goto error;
2893 break; 2878 break;
2894 } 2879 }
2895 case GetHubDescriptor:{ 2880 case GetHubDescriptor:{
2896 retval = u132_roothub_descriptor(u132, 2881 retval = u132_roothub_descriptor(u132,
2897 (struct usb_hub_descriptor *)buf); 2882 (struct usb_hub_descriptor *)buf);
2898 if (retval) 2883 if (retval)
2899 goto error; 2884 goto error;
2900 break; 2885 break;
2901 } 2886 }
2902 case GetHubStatus:{ 2887 case GetHubStatus:{
2903 retval = u132_roothub_status(u132, 2888 retval = u132_roothub_status(u132,
2904 (__le32 *) buf); 2889 (__le32 *) buf);
2905 if (retval) 2890 if (retval)
2906 goto error; 2891 goto error;
2907 break; 2892 break;
2908 } 2893 }
2909 case GetPortStatus:{ 2894 case GetPortStatus:{
2910 retval = u132_roothub_portstatus(u132, 2895 retval = u132_roothub_portstatus(u132,
2911 (__le32 *) buf, wIndex); 2896 (__le32 *) buf, wIndex);
2912 if (retval) 2897 if (retval)
2913 goto error; 2898 goto error;
2914 break; 2899 break;
2915 } 2900 }
2916 case SetPortFeature:{ 2901 case SetPortFeature:{
2917 retval = u132_roothub_setportfeature(u132, 2902 retval = u132_roothub_setportfeature(u132,
2918 wValue, wIndex); 2903 wValue, wIndex);
2919 if (retval) 2904 if (retval)
2920 goto error; 2905 goto error;
2921 break; 2906 break;
2922 } 2907 }
2923 default: 2908 default:
2924 goto stall; 2909 goto stall;
2925 error:u132_disable(u132); 2910 error:
2926 u132->going = 1; 2911 u132_disable(u132);
2927 break; 2912 u132->going = 1;
2928 stall:retval = -EPIPE; 2913 break;
2929 break; 2914 stall:
2930 } 2915 retval = -EPIPE;
2931 mutex_unlock(&u132->sw_lock); 2916 break;
2932 return retval; 2917 }
2933 } 2918 mutex_unlock(&u132->sw_lock);
2919 return retval;
2920 }
2934} 2921}
2935 2922
2936static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num) 2923static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2937{ 2924{
2938 struct u132 *u132 = hcd_to_u132(hcd); 2925 struct u132 *u132 = hcd_to_u132(hcd);
2939 if (u132->going > 1) { 2926 if (u132->going > 1) {
2940 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2927 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2941 , u132->going); 2928 , u132->going);
2942 return -ENODEV; 2929 return -ENODEV;
2943 } else if (u132->going > 0) { 2930 } else if (u132->going > 0) {
2944 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2931 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2945 return -ESHUTDOWN; 2932 return -ESHUTDOWN;
2946 } else 2933 } else
2947 return 0; 2934 return 0;
2948}
2949
2950static void u132_hub_irq_enable(struct usb_hcd *hcd)
2951{
2952 struct u132 *u132 = hcd_to_u132(hcd);
2953 if (u132->going > 1) {
2954 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2955 , u132->going);
2956 } else if (u132->going > 0)
2957 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2958} 2935}
2959 2936
2960 2937
2961#ifdef CONFIG_PM 2938#ifdef CONFIG_PM
2962static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2963{
2964 struct u132 *u132 = hcd_to_u132(hcd);
2965 if (u132->going > 1) {
2966 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2967 , u132->going);
2968 return -ENODEV;
2969 } else if (u132->going > 0) {
2970 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2971 return -ESHUTDOWN;
2972 } else
2973 return 0;
2974}
2975
2976static int u132_hcd_resume(struct usb_hcd *hcd)
2977{
2978 struct u132 *u132 = hcd_to_u132(hcd);
2979 if (u132->going > 1) {
2980 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2981 , u132->going);
2982 return -ENODEV;
2983 } else if (u132->going > 0) {
2984 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2985 return -ESHUTDOWN;
2986 } else
2987 return 0;
2988}
2989
2990static int u132_bus_suspend(struct usb_hcd *hcd) 2939static int u132_bus_suspend(struct usb_hcd *hcd)
2991{ 2940{
2992 struct u132 *u132 = hcd_to_u132(hcd); 2941 struct u132 *u132 = hcd_to_u132(hcd);
2993 if (u132->going > 1) { 2942 if (u132->going > 1) {
2994 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2943 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2995 , u132->going); 2944 , u132->going);
2996 return -ENODEV; 2945 return -ENODEV;
2997 } else if (u132->going > 0) { 2946 } else if (u132->going > 0) {
2998 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2947 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2999 return -ESHUTDOWN; 2948 return -ESHUTDOWN;
3000 } else 2949 } else
3001 return 0; 2950 return 0;
3002} 2951}
3003 2952
3004static int u132_bus_resume(struct usb_hcd *hcd) 2953static int u132_bus_resume(struct usb_hcd *hcd)
3005{ 2954{
3006 struct u132 *u132 = hcd_to_u132(hcd); 2955 struct u132 *u132 = hcd_to_u132(hcd);
3007 if (u132->going > 1) { 2956 if (u132->going > 1) {
3008 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2957 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3009 , u132->going); 2958 , u132->going);
3010 return -ENODEV; 2959 return -ENODEV;
3011 } else if (u132->going > 0) { 2960 } else if (u132->going > 0) {
3012 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2961 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3013 return -ESHUTDOWN; 2962 return -ESHUTDOWN;
3014 } else 2963 } else
3015 return 0; 2964 return 0;
3016} 2965}
3017 2966
3018#else 2967#else
3019#define u132_hcd_suspend NULL
3020#define u132_hcd_resume NULL
3021#define u132_bus_suspend NULL 2968#define u132_bus_suspend NULL
3022#define u132_bus_resume NULL 2969#define u132_bus_resume NULL
3023#endif 2970#endif
3024static struct hc_driver u132_hc_driver = { 2971static struct hc_driver u132_hc_driver = {
3025 .description = hcd_name, 2972 .description = hcd_name,
3026 .hcd_priv_size = sizeof(struct u132), 2973 .hcd_priv_size = sizeof(struct u132),
3027 .irq = NULL, 2974 .irq = NULL,
3028 .flags = HCD_USB11 | HCD_MEMORY, 2975 .flags = HCD_USB11 | HCD_MEMORY,
3029 .reset = u132_hcd_reset, 2976 .reset = u132_hcd_reset,
3030 .start = u132_hcd_start, 2977 .start = u132_hcd_start,
3031 .suspend = u132_hcd_suspend, 2978 .stop = u132_hcd_stop,
3032 .resume = u132_hcd_resume, 2979 .urb_enqueue = u132_urb_enqueue,
3033 .stop = u132_hcd_stop, 2980 .urb_dequeue = u132_urb_dequeue,
3034 .urb_enqueue = u132_urb_enqueue, 2981 .endpoint_disable = u132_endpoint_disable,
3035 .urb_dequeue = u132_urb_dequeue, 2982 .get_frame_number = u132_get_frame,
3036 .endpoint_disable = u132_endpoint_disable, 2983 .hub_status_data = u132_hub_status_data,
3037 .get_frame_number = u132_get_frame, 2984 .hub_control = u132_hub_control,
3038 .hub_status_data = u132_hub_status_data, 2985 .bus_suspend = u132_bus_suspend,
3039 .hub_control = u132_hub_control, 2986 .bus_resume = u132_bus_resume,
3040 .bus_suspend = u132_bus_suspend, 2987 .start_port_reset = u132_start_port_reset,
3041 .bus_resume = u132_bus_resume,
3042 .start_port_reset = u132_start_port_reset,
3043 .hub_irq_enable = u132_hub_irq_enable,
3044}; 2988};
3045 2989
3046/* 2990/*
@@ -3051,148 +2995,152 @@ static struct hc_driver u132_hc_driver = {
3051*/ 2995*/
3052static int __devexit u132_remove(struct platform_device *pdev) 2996static int __devexit u132_remove(struct platform_device *pdev)
3053{ 2997{
3054 struct usb_hcd *hcd = platform_get_drvdata(pdev); 2998 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3055 if (hcd) { 2999 if (hcd) {
3056 struct u132 *u132 = hcd_to_u132(hcd); 3000 struct u132 *u132 = hcd_to_u132(hcd);
3057 if (u132->going++ > 1) { 3001 if (u132->going++ > 1) {
3058 dev_err(&u132->platform_dev->dev, "already being remove" 3002 dev_err(&u132->platform_dev->dev, "already being remove"
3059 "d\n"); 3003 "d\n");
3060 return -ENODEV; 3004 return -ENODEV;
3061 } else { 3005 } else {
3062 int rings = MAX_U132_RINGS; 3006 int rings = MAX_U132_RINGS;
3063 int endps = MAX_U132_ENDPS; 3007 int endps = MAX_U132_ENDPS;
3064 dev_err(&u132->platform_dev->dev, "removing device u132" 3008 dev_err(&u132->platform_dev->dev, "removing device u132"
3065 ".%d\n", u132->sequence_num); 3009 ".%d\n", u132->sequence_num);
3066 msleep(100); 3010 msleep(100);
3067 mutex_lock(&u132->sw_lock); 3011 mutex_lock(&u132->sw_lock);
3068 u132_monitor_cancel_work(u132); 3012 u132_monitor_cancel_work(u132);
3069 while (rings-- > 0) { 3013 while (rings-- > 0) {
3070 struct u132_ring *ring = &u132->ring[rings]; 3014 struct u132_ring *ring = &u132->ring[rings];
3071 u132_ring_cancel_work(u132, ring); 3015 u132_ring_cancel_work(u132, ring);
3072 } while (endps-- > 0) { 3016 } while (endps-- > 0) {
3073 struct u132_endp *endp = u132->endp[endps]; 3017 struct u132_endp *endp = u132->endp[endps];
3074 if (endp) 3018 if (endp)
3075 u132_endp_cancel_work(u132, endp); 3019 u132_endp_cancel_work(u132, endp);
3076 } 3020 }
3077 u132->going += 1; 3021 u132->going += 1;
3078 printk(KERN_INFO "removing device u132.%d\n", 3022 printk(KERN_INFO "removing device u132.%d\n",
3079 u132->sequence_num); 3023 u132->sequence_num);
3080 mutex_unlock(&u132->sw_lock); 3024 mutex_unlock(&u132->sw_lock);
3081 usb_remove_hcd(hcd); 3025 usb_remove_hcd(hcd);
3082 u132_u132_put_kref(u132); 3026 u132_u132_put_kref(u132);
3083 return 0; 3027 return 0;
3084 } 3028 }
3085 } else 3029 } else
3086 return 0; 3030 return 0;
3087} 3031}
3088 3032
3089static void u132_initialise(struct u132 *u132, struct platform_device *pdev) 3033static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3090{ 3034{
3091 int rings = MAX_U132_RINGS; 3035 int rings = MAX_U132_RINGS;
3092 int ports = MAX_U132_PORTS; 3036 int ports = MAX_U132_PORTS;
3093 int addrs = MAX_U132_ADDRS; 3037 int addrs = MAX_U132_ADDRS;
3094 int udevs = MAX_U132_UDEVS; 3038 int udevs = MAX_U132_UDEVS;
3095 int endps = MAX_U132_ENDPS; 3039 int endps = MAX_U132_ENDPS;
3096 u132->board = pdev->dev.platform_data; 3040 u132->board = pdev->dev.platform_data;
3097 u132->platform_dev = pdev; 3041 u132->platform_dev = pdev;
3098 u132->power = 0; 3042 u132->power = 0;
3099 u132->reset = 0; 3043 u132->reset = 0;
3100 mutex_init(&u132->sw_lock); 3044 mutex_init(&u132->sw_lock);
3101 init_MUTEX(&u132->scheduler_lock); 3045 mutex_init(&u132->scheduler_lock);
3102 while (rings-- > 0) { 3046 while (rings-- > 0) {
3103 struct u132_ring *ring = &u132->ring[rings]; 3047 struct u132_ring *ring = &u132->ring[rings];
3104 ring->u132 = u132; 3048 ring->u132 = u132;
3105 ring->number = rings + 1; 3049 ring->number = rings + 1;
3106 ring->length = 0; 3050 ring->length = 0;
3107 ring->curr_endp = NULL; 3051 ring->curr_endp = NULL;
3108 INIT_DELAYED_WORK(&ring->scheduler, 3052 INIT_DELAYED_WORK(&ring->scheduler,
3109 u132_hcd_ring_work_scheduler); 3053 u132_hcd_ring_work_scheduler);
3110 } mutex_lock(&u132->sw_lock); 3054 }
3111 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work); 3055 mutex_lock(&u132->sw_lock);
3112 while (ports-- > 0) { 3056 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3113 struct u132_port *port = &u132->port[ports]; 3057 while (ports-- > 0) {
3114 port->u132 = u132; 3058 struct u132_port *port = &u132->port[ports];
3115 port->reset = 0; 3059 port->u132 = u132;
3116 port->enable = 0; 3060 port->reset = 0;
3117 port->power = 0; 3061 port->enable = 0;
3118 port->Status = 0; 3062 port->power = 0;
3119 } while (addrs-- > 0) { 3063 port->Status = 0;
3120 struct u132_addr *addr = &u132->addr[addrs]; 3064 }
3121 addr->address = 0; 3065 while (addrs-- > 0) {
3122 } while (udevs-- > 0) { 3066 struct u132_addr *addr = &u132->addr[addrs];
3123 struct u132_udev *udev = &u132->udev[udevs]; 3067 addr->address = 0;
3124 int i = ARRAY_SIZE(udev->endp_number_in); 3068 }
3125 int o = ARRAY_SIZE(udev->endp_number_out); 3069 while (udevs-- > 0) {
3126 udev->usb_device = NULL; 3070 struct u132_udev *udev = &u132->udev[udevs];
3127 udev->udev_number = 0; 3071 int i = ARRAY_SIZE(udev->endp_number_in);
3128 udev->usb_addr = 0; 3072 int o = ARRAY_SIZE(udev->endp_number_out);
3129 udev->portnumber = 0; 3073 udev->usb_device = NULL;
3130 while (i-- > 0) { 3074 udev->udev_number = 0;
3131 udev->endp_number_in[i] = 0; 3075 udev->usb_addr = 0;
3132 } 3076 udev->portnumber = 0;
3133 while (o-- > 0) { 3077 while (i-- > 0)
3134 udev->endp_number_out[o] = 0; 3078 udev->endp_number_in[i] = 0;
3135 } 3079
3136 } 3080 while (o-- > 0)
3137 while (endps-- > 0) { 3081 udev->endp_number_out[o] = 0;
3138 u132->endp[endps] = NULL; 3082
3139 } 3083 }
3140 mutex_unlock(&u132->sw_lock); 3084 while (endps-- > 0)
3141 return; 3085 u132->endp[endps] = NULL;
3086
3087 mutex_unlock(&u132->sw_lock);
3088 return;
3142} 3089}
3143 3090
3144static int __devinit u132_probe(struct platform_device *pdev) 3091static int __devinit u132_probe(struct platform_device *pdev)
3145{ 3092{
3146 struct usb_hcd *hcd; 3093 struct usb_hcd *hcd;
3147 int retval; 3094 int retval;
3148 u32 control; 3095 u32 control;
3149 u32 rh_a = -1; 3096 u32 rh_a = -1;
3150 u32 num_ports; 3097 u32 num_ports;
3151 msleep(100); 3098
3152 if (u132_exiting > 0) { 3099 msleep(100);
3153 return -ENODEV; 3100 if (u132_exiting > 0)
3154 } 3101 return -ENODEV;
3155 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE); 3102
3156 if (retval) 3103 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3157 return retval; 3104 if (retval)
3158 retval = ftdi_read_pcimem(pdev, control, &control); 3105 return retval;
3159 if (retval) 3106 retval = ftdi_read_pcimem(pdev, control, &control);
3160 return retval; 3107 if (retval)
3161 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a); 3108 return retval;
3162 if (retval) 3109 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3163 return retval; 3110 if (retval)
3164 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */ 3111 return retval;
3165 if (pdev->dev.dma_mask) { 3112 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3166 return -EINVAL; 3113 if (pdev->dev.dma_mask)
3167 } 3114 return -EINVAL;
3168 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id); 3115
3169 if (!hcd) { 3116 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3170 printk(KERN_ERR "failed to create the usb hcd struct for U132\n" 3117 if (!hcd) {
3171 ); 3118 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3172 ftdi_elan_gone_away(pdev); 3119 );
3173 return -ENOMEM; 3120 ftdi_elan_gone_away(pdev);
3174 } else { 3121 return -ENOMEM;
3175 int retval = 0; 3122 } else {
3176 struct u132 *u132 = hcd_to_u132(hcd); 3123 int retval = 0;
3177 hcd->rsrc_start = 0; 3124 struct u132 *u132 = hcd_to_u132(hcd);
3178 mutex_lock(&u132_module_lock); 3125 hcd->rsrc_start = 0;
3179 list_add_tail(&u132->u132_list, &u132_static_list); 3126 mutex_lock(&u132_module_lock);
3180 u132->sequence_num = ++u132_instances; 3127 list_add_tail(&u132->u132_list, &u132_static_list);
3181 mutex_unlock(&u132_module_lock); 3128 u132->sequence_num = ++u132_instances;
3182 u132_u132_init_kref(u132); 3129 mutex_unlock(&u132_module_lock);
3183 u132_initialise(u132, pdev); 3130 u132_u132_init_kref(u132);
3184 hcd->product_desc = "ELAN U132 Host Controller"; 3131 u132_initialise(u132, pdev);
3185 retval = usb_add_hcd(hcd, 0, 0); 3132 hcd->product_desc = "ELAN U132 Host Controller";
3186 if (retval != 0) { 3133 retval = usb_add_hcd(hcd, 0, 0);
3187 dev_err(&u132->platform_dev->dev, "init error %d\n", 3134 if (retval != 0) {
3188 retval); 3135 dev_err(&u132->platform_dev->dev, "init error %d\n",
3189 u132_u132_put_kref(u132); 3136 retval);
3190 return retval; 3137 u132_u132_put_kref(u132);
3191 } else { 3138 return retval;
3192 u132_monitor_queue_work(u132, 100); 3139 } else {
3193 return 0; 3140 u132_monitor_queue_work(u132, 100);
3194 } 3141 return 0;
3195 } 3142 }
3143 }
3196} 3144}
3197 3145
3198 3146
@@ -3203,61 +3151,58 @@ static int __devinit u132_probe(struct platform_device *pdev)
3203*/ 3151*/
3204static int u132_suspend(struct platform_device *pdev, pm_message_t state) 3152static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3205{ 3153{
3206 struct usb_hcd *hcd = platform_get_drvdata(pdev); 3154 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3207 struct u132 *u132 = hcd_to_u132(hcd); 3155 struct u132 *u132 = hcd_to_u132(hcd);
3208 if (u132->going > 1) { 3156 if (u132->going > 1) {
3209 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 3157 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3210 , u132->going); 3158 , u132->going);
3211 return -ENODEV; 3159 return -ENODEV;
3212 } else if (u132->going > 0) { 3160 } else if (u132->going > 0) {
3213 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 3161 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3214 return -ESHUTDOWN; 3162 return -ESHUTDOWN;
3215 } else { 3163 } else {
3216 int retval = 0, ports; 3164 int retval = 0, ports;
3217 3165
3218 switch (state.event) { 3166 switch (state.event) {
3219 case PM_EVENT_FREEZE: 3167 case PM_EVENT_FREEZE:
3220 retval = u132_bus_suspend(hcd); 3168 retval = u132_bus_suspend(hcd);
3221 break; 3169 break;
3222 case PM_EVENT_SUSPEND: 3170 case PM_EVENT_SUSPEND:
3223 case PM_EVENT_HIBERNATE: 3171 case PM_EVENT_HIBERNATE:
3224 ports = MAX_U132_PORTS; 3172 ports = MAX_U132_PORTS;
3225 while (ports-- > 0) { 3173 while (ports-- > 0) {
3226 port_power(u132, ports, 0); 3174 port_power(u132, ports, 0);
3227 } 3175 }
3228 break; 3176 break;
3229 } 3177 }
3230 if (retval == 0) 3178 return retval;
3231 pdev->dev.power.power_state = state; 3179 }
3232 return retval;
3233 }
3234} 3180}
3235 3181
3236static int u132_resume(struct platform_device *pdev) 3182static int u132_resume(struct platform_device *pdev)
3237{ 3183{
3238 struct usb_hcd *hcd = platform_get_drvdata(pdev); 3184 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3239 struct u132 *u132 = hcd_to_u132(hcd); 3185 struct u132 *u132 = hcd_to_u132(hcd);
3240 if (u132->going > 1) { 3186 if (u132->going > 1) {
3241 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 3187 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3242 , u132->going); 3188 , u132->going);
3243 return -ENODEV; 3189 return -ENODEV;
3244 } else if (u132->going > 0) { 3190 } else if (u132->going > 0) {
3245 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 3191 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3246 return -ESHUTDOWN; 3192 return -ESHUTDOWN;
3247 } else { 3193 } else {
3248 int retval = 0; 3194 int retval = 0;
3249 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { 3195 if (!u132->port[0].power) {
3250 int ports = MAX_U132_PORTS; 3196 int ports = MAX_U132_PORTS;
3251 while (ports-- > 0) { 3197 while (ports-- > 0) {
3252 port_power(u132, ports, 1); 3198 port_power(u132, ports, 1);
3253 } 3199 }
3254 retval = 0; 3200 retval = 0;
3255 } else { 3201 } else {
3256 pdev->dev.power.power_state = PMSG_ON; 3202 retval = u132_bus_resume(hcd);
3257 retval = u132_bus_resume(hcd); 3203 }
3258 } 3204 return retval;
3259 return retval; 3205 }
3260 }
3261} 3206}
3262 3207
3263#else 3208#else
@@ -3270,47 +3215,48 @@ static int u132_resume(struct platform_device *pdev)
3270* the platform_driver struct is static because it is per type of module 3215* the platform_driver struct is static because it is per type of module
3271*/ 3216*/
3272static struct platform_driver u132_platform_driver = { 3217static struct platform_driver u132_platform_driver = {
3273 .probe = u132_probe, 3218 .probe = u132_probe,
3274 .remove = __devexit_p(u132_remove), 3219 .remove = __devexit_p(u132_remove),
3275 .suspend = u132_suspend, 3220 .suspend = u132_suspend,
3276 .resume = u132_resume, 3221 .resume = u132_resume,
3277 .driver = { 3222 .driver = {
3278 .name = (char *)hcd_name, 3223 .name = (char *)hcd_name,
3279 .owner = THIS_MODULE, 3224 .owner = THIS_MODULE,
3280 }, 3225 },
3281}; 3226};
3282static int __init u132_hcd_init(void) 3227static int __init u132_hcd_init(void)
3283{ 3228{
3284 int retval; 3229 int retval;
3285 INIT_LIST_HEAD(&u132_static_list); 3230 INIT_LIST_HEAD(&u132_static_list);
3286 u132_instances = 0; 3231 u132_instances = 0;
3287 u132_exiting = 0; 3232 u132_exiting = 0;
3288 mutex_init(&u132_module_lock); 3233 mutex_init(&u132_module_lock);
3289 if (usb_disabled()) 3234 if (usb_disabled())
3290 return -ENODEV; 3235 return -ENODEV;
3291 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, 3236 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3292 __DATE__); 3237 __DATE__);
3293 workqueue = create_singlethread_workqueue("u132"); 3238 workqueue = create_singlethread_workqueue("u132");
3294 retval = platform_driver_register(&u132_platform_driver); 3239 retval = platform_driver_register(&u132_platform_driver);
3295 return retval; 3240 return retval;
3296} 3241}
3297 3242
3298 3243
3299module_init(u132_hcd_init); 3244module_init(u132_hcd_init);
3300static void __exit u132_hcd_exit(void) 3245static void __exit u132_hcd_exit(void)
3301{ 3246{
3302 struct u132 *u132; 3247 struct u132 *u132;
3303 struct u132 *temp; 3248 struct u132 *temp;
3304 mutex_lock(&u132_module_lock); 3249 mutex_lock(&u132_module_lock);
3305 u132_exiting += 1; 3250 u132_exiting += 1;
3306 mutex_unlock(&u132_module_lock); 3251 mutex_unlock(&u132_module_lock);
3307 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) { 3252 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3308 platform_device_unregister(u132->platform_dev); 3253 platform_device_unregister(u132->platform_dev);
3309 } platform_driver_unregister(&u132_platform_driver); 3254 }
3310 printk(KERN_INFO "u132-hcd driver deregistered\n"); 3255 platform_driver_unregister(&u132_platform_driver);
3311 wait_event(u132_hcd_wait, u132_instances == 0); 3256 printk(KERN_INFO "u132-hcd driver deregistered\n");
3312 flush_workqueue(workqueue); 3257 wait_event(u132_hcd_wait, u132_instances == 0);
3313 destroy_workqueue(workqueue); 3258 flush_workqueue(workqueue);
3259 destroy_workqueue(workqueue);
3314} 3260}
3315 3261
3316 3262
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index ec987897b8ed..d3e0d8aa3980 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -262,20 +262,12 @@ __acquires(uhci->lock)
262{ 262{
263 int auto_stop; 263 int auto_stop;
264 int int_enable, egsm_enable; 264 int int_enable, egsm_enable;
265 struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
265 266
266 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED); 267 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
267 dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev, 268 dev_dbg(&rhdev->dev, "%s%s\n", __func__,
268 "%s%s\n", __FUNCTION__,
269 (auto_stop ? " (auto-stop)" : "")); 269 (auto_stop ? " (auto-stop)" : ""));
270 270
271 /* If we get a suspend request when we're already auto-stopped
272 * then there's nothing to do.
273 */
274 if (uhci->rh_state == UHCI_RH_AUTO_STOPPED) {
275 uhci->rh_state = new_state;
276 return;
277 }
278
279 /* Enable resume-detect interrupts if they work. 271 /* Enable resume-detect interrupts if they work.
280 * Then enter Global Suspend mode if _it_ works, still configured. 272 * Then enter Global Suspend mode if _it_ works, still configured.
281 */ 273 */
@@ -285,8 +277,10 @@ __acquires(uhci->lock)
285 if (remote_wakeup_is_broken(uhci)) 277 if (remote_wakeup_is_broken(uhci))
286 egsm_enable = 0; 278 egsm_enable = 0;
287 if (resume_detect_interrupts_are_broken(uhci) || !egsm_enable || 279 if (resume_detect_interrupts_are_broken(uhci) || !egsm_enable ||
288 !device_may_wakeup( 280#ifdef CONFIG_PM
289 &uhci_to_hcd(uhci)->self.root_hub->dev)) 281 (!auto_stop && !rhdev->do_remote_wakeup) ||
282#endif
283 (auto_stop && !device_may_wakeup(&rhdev->dev)))
290 uhci->working_RD = int_enable = 0; 284 uhci->working_RD = int_enable = 0;
291 285
292 outw(int_enable, uhci->io_addr + USBINTR); 286 outw(int_enable, uhci->io_addr + USBINTR);
@@ -308,8 +302,7 @@ __acquires(uhci->lock)
308 return; 302 return;
309 } 303 }
310 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) 304 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH))
311 dev_warn(&uhci_to_hcd(uhci)->self.root_hub->dev, 305 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n");
312 "Controller not stopped yet!\n");
313 306
314 uhci_get_current_frame_number(uhci); 307 uhci_get_current_frame_number(uhci);
315 308
@@ -342,7 +335,7 @@ __releases(uhci->lock)
342__acquires(uhci->lock) 335__acquires(uhci->lock)
343{ 336{
344 dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev, 337 dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev,
345 "%s%s\n", __FUNCTION__, 338 "%s%s\n", __func__,
346 uhci->rh_state == UHCI_RH_AUTO_STOPPED ? 339 uhci->rh_state == UHCI_RH_AUTO_STOPPED ?
347 " (auto-start)" : ""); 340 " (auto-start)" : "");
348 341
@@ -737,12 +730,12 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
737 return rc; 730 return rc;
738} 731}
739 732
740static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) 733static int uhci_pci_suspend(struct usb_hcd *hcd, pm_message_t message)
741{ 734{
742 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 735 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
743 int rc = 0; 736 int rc = 0;
744 737
745 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 738 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
746 739
747 spin_lock_irq(&uhci->lock); 740 spin_lock_irq(&uhci->lock);
748 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 741 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead)
@@ -774,11 +767,11 @@ done:
774 return rc; 767 return rc;
775} 768}
776 769
777static int uhci_resume(struct usb_hcd *hcd) 770static int uhci_pci_resume(struct usb_hcd *hcd)
778{ 771{
779 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 772 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
780 773
781 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 774 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
782 775
783 /* Since we aren't in D3 any more, it's safe to set this flag 776 /* Since we aren't in D3 any more, it's safe to set this flag
784 * even if the controller was dead. 777 * even if the controller was dead.
@@ -872,8 +865,8 @@ static const struct hc_driver uhci_driver = {
872 .reset = uhci_init, 865 .reset = uhci_init,
873 .start = uhci_start, 866 .start = uhci_start,
874#ifdef CONFIG_PM 867#ifdef CONFIG_PM
875 .suspend = uhci_suspend, 868 .pci_suspend = uhci_pci_suspend,
876 .resume = uhci_resume, 869 .pci_resume = uhci_pci_resume,
877 .bus_suspend = uhci_rh_suspend, 870 .bus_suspend = uhci_rh_suspend,
878 .bus_resume = uhci_rh_resume, 871 .bus_resume = uhci_rh_resume,
879#endif 872#endif
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 60379b17bbc1..db645936eedd 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -1171,7 +1171,7 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1171 /* Some debugging code */ 1171 /* Some debugging code */
1172 dev_dbg(&urb->dev->dev, 1172 dev_dbg(&urb->dev->dev,
1173 "%s: failed with status %x\n", 1173 "%s: failed with status %x\n",
1174 __FUNCTION__, status); 1174 __func__, status);
1175 1175
1176 if (debug > 1 && errbuf) { 1176 if (debug > 1 && errbuf) {
1177 /* Print the chain for debugging */ 1177 /* Print the chain for debugging */
diff --git a/drivers/usb/image/Kconfig b/drivers/usb/image/Kconfig
index 7595dfb38e3b..33350f9dd34f 100644
--- a/drivers/usb/image/Kconfig
+++ b/drivers/usb/image/Kconfig
@@ -5,8 +5,8 @@ comment "USB Imaging devices"
5 depends on USB 5 depends on USB
6 6
7config USB_MDC800 7config USB_MDC800
8 tristate "USB Mustek MDC800 Digital Camera support (EXPERIMENTAL)" 8 tristate "USB Mustek MDC800 Digital Camera support"
9 depends on USB && EXPERIMENTAL 9 depends on USB
10 ---help--- 10 ---help---
11 Say Y here if you want to connect this type of still camera to 11 Say Y here if you want to connect this type of still camera to
12 your computer's USB port. This driver can be used with gphoto 0.4.3 12 your computer's USB port. This driver can be used with gphoto 0.4.3
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index bc207e3c21f5..885867a86de8 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -185,7 +185,7 @@ static struct usb_driver mts_usb_driver = {
185 printk( KERN_DEBUG MTS_NAME x ) 185 printk( KERN_DEBUG MTS_NAME x )
186 186
187#define MTS_DEBUG_GOT_HERE() \ 187#define MTS_DEBUG_GOT_HERE() \
188 MTS_DEBUG("got to %s:%d (%s)\n", __FILE__, (int)__LINE__, __PRETTY_FUNCTION__ ) 188 MTS_DEBUG("got to %s:%d (%s)\n", __FILE__, (int)__LINE__, __func__ )
189#define MTS_DEBUG_INT() \ 189#define MTS_DEBUG_INT() \
190 do { MTS_DEBUG_GOT_HERE(); \ 190 do { MTS_DEBUG_GOT_HERE(); \
191 MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \ 191 MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \
@@ -794,7 +794,6 @@ static int mts_usb_probe(struct usb_interface *intf,
794 794
795 new_desc->usb_dev = dev; 795 new_desc->usb_dev = dev;
796 new_desc->usb_intf = intf; 796 new_desc->usb_intf = intf;
797 init_MUTEX(&new_desc->lock);
798 797
799 /* endpoints */ 798 /* endpoints */
800 new_desc->ep_out = ep_out; 799 new_desc->ep_out = ep_out;
diff --git a/drivers/usb/image/microtek.h b/drivers/usb/image/microtek.h
index d5d62a939058..ccce318f20a0 100644
--- a/drivers/usb/image/microtek.h
+++ b/drivers/usb/image/microtek.h
@@ -39,7 +39,6 @@ struct mts_desc {
39 u8 ep_image; 39 u8 ep_image;
40 40
41 struct Scsi_Host * host; 41 struct Scsi_Host * host;
42 struct semaphore lock;
43 42
44 struct urb *urb; 43 struct urb *urb;
45 struct mts_transfer_context context; 44 struct mts_transfer_context context;
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 9c7eb6144d02..a53db1d4e07a 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -33,8 +33,8 @@ config USB_EMI26
33 module will be called emi26. 33 module will be called emi26.
34 34
35config USB_ADUTUX 35config USB_ADUTUX
36 tristate "ADU devices from Ontrak Control Systems (EXPERIMENTAL)" 36 tristate "ADU devices from Ontrak Control Systems"
37 depends on USB && EXPERIMENTAL 37 depends on USB
38 help 38 help
39 Say Y if you want to use an ADU device from Ontrak Control 39 Say Y if you want to use an ADU device from Ontrak Control
40 Systems. 40 Systems.
@@ -43,8 +43,8 @@ config USB_ADUTUX
43 will be called adutux. 43 will be called adutux.
44 44
45config USB_AUERSWALD 45config USB_AUERSWALD
46 tristate "USB Auerswald ISDN support (EXPERIMENTAL)" 46 tristate "USB Auerswald ISDN support"
47 depends on USB && EXPERIMENTAL 47 depends on USB
48 help 48 help
49 Say Y here if you want to connect an Auerswald USB ISDN Device 49 Say Y here if you want to connect an Auerswald USB ISDN Device
50 to your computer's USB port. 50 to your computer's USB port.
@@ -53,8 +53,8 @@ config USB_AUERSWALD
53 module will be called auerswald. 53 module will be called auerswald.
54 54
55config USB_RIO500 55config USB_RIO500
56 tristate "USB Diamond Rio500 support (EXPERIMENTAL)" 56 tristate "USB Diamond Rio500 support"
57 depends on USB && EXPERIMENTAL 57 depends on USB
58 help 58 help
59 Say Y here if you want to connect a USB Rio500 mp3 player to your 59 Say Y here if you want to connect a USB Rio500 mp3 player to your
60 computer's USB port. Please read <file:Documentation/usb/rio.txt> 60 computer's USB port. Please read <file:Documentation/usb/rio.txt>
@@ -64,8 +64,8 @@ config USB_RIO500
64 module will be called rio500. 64 module will be called rio500.
65 65
66config USB_LEGOTOWER 66config USB_LEGOTOWER
67 tristate "USB Lego Infrared Tower support (EXPERIMENTAL)" 67 tristate "USB Lego Infrared Tower support"
68 depends on USB && EXPERIMENTAL 68 depends on USB
69 help 69 help
70 Say Y here if you want to connect a USB Lego Infrared Tower to your 70 Say Y here if you want to connect a USB Lego Infrared Tower to your
71 computer's USB port. 71 computer's USB port.
@@ -259,8 +259,8 @@ config USB_IOWARRIOR
259 module will be called iowarrior. 259 module will be called iowarrior.
260 260
261config USB_TEST 261config USB_TEST
262 tristate "USB testing driver (DEVELOPMENT)" 262 tristate "USB testing driver"
263 depends on USB && USB_DEVICEFS && EXPERIMENTAL 263 depends on USB && USB_DEVICEFS
264 help 264 help
265 This driver is for testing host controller software. It is used 265 This driver is for testing host controller software. It is used
266 with specialized device firmware for regression and stress testing, 266 with specialized device firmware for regression and stress testing,
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index 5a2c44e4c1f7..965f6eaea6a0 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -147,10 +147,10 @@ static void adu_abort_transfers(struct adu_device *dev)
147{ 147{
148 unsigned long flags; 148 unsigned long flags;
149 149
150 dbg(2," %s : enter", __FUNCTION__); 150 dbg(2," %s : enter", __func__);
151 151
152 if (dev->udev == NULL) { 152 if (dev->udev == NULL) {
153 dbg(1," %s : udev is null", __FUNCTION__); 153 dbg(1," %s : udev is null", __func__);
154 goto exit; 154 goto exit;
155 } 155 }
156 156
@@ -172,12 +172,12 @@ static void adu_abort_transfers(struct adu_device *dev)
172 spin_unlock_irqrestore(&dev->buflock, flags); 172 spin_unlock_irqrestore(&dev->buflock, flags);
173 173
174exit: 174exit:
175 dbg(2," %s : leave", __FUNCTION__); 175 dbg(2," %s : leave", __func__);
176} 176}
177 177
178static void adu_delete(struct adu_device *dev) 178static void adu_delete(struct adu_device *dev)
179{ 179{
180 dbg(2, "%s enter", __FUNCTION__); 180 dbg(2, "%s enter", __func__);
181 181
182 /* free data structures */ 182 /* free data structures */
183 usb_free_urb(dev->interrupt_in_urb); 183 usb_free_urb(dev->interrupt_in_urb);
@@ -188,7 +188,7 @@ static void adu_delete(struct adu_device *dev)
188 kfree(dev->interrupt_out_buffer); 188 kfree(dev->interrupt_out_buffer);
189 kfree(dev); 189 kfree(dev);
190 190
191 dbg(2, "%s : leave", __FUNCTION__); 191 dbg(2, "%s : leave", __func__);
192} 192}
193 193
194static void adu_interrupt_in_callback(struct urb *urb) 194static void adu_interrupt_in_callback(struct urb *urb)
@@ -196,8 +196,8 @@ static void adu_interrupt_in_callback(struct urb *urb)
196 struct adu_device *dev = urb->context; 196 struct adu_device *dev = urb->context;
197 int status = urb->status; 197 int status = urb->status;
198 198
199 dbg(4," %s : enter, status %d", __FUNCTION__, status); 199 dbg(4," %s : enter, status %d", __func__, status);
200 adu_debug_data(5, __FUNCTION__, urb->actual_length, 200 adu_debug_data(5, __func__, urb->actual_length,
201 urb->transfer_buffer); 201 urb->transfer_buffer);
202 202
203 spin_lock(&dev->buflock); 203 spin_lock(&dev->buflock);
@@ -206,7 +206,7 @@ static void adu_interrupt_in_callback(struct urb *urb)
206 if ((status != -ENOENT) && (status != -ECONNRESET) && 206 if ((status != -ENOENT) && (status != -ECONNRESET) &&
207 (status != -ESHUTDOWN)) { 207 (status != -ESHUTDOWN)) {
208 dbg(1," %s : nonzero status received: %d", 208 dbg(1," %s : nonzero status received: %d",
209 __FUNCTION__, status); 209 __func__, status);
210 } 210 }
211 goto exit; 211 goto exit;
212 } 212 }
@@ -220,10 +220,10 @@ static void adu_interrupt_in_callback(struct urb *urb)
220 dev->interrupt_in_buffer, urb->actual_length); 220 dev->interrupt_in_buffer, urb->actual_length);
221 221
222 dev->read_buffer_length += urb->actual_length; 222 dev->read_buffer_length += urb->actual_length;
223 dbg(2," %s reading %d ", __FUNCTION__, 223 dbg(2," %s reading %d ", __func__,
224 urb->actual_length); 224 urb->actual_length);
225 } else { 225 } else {
226 dbg(1," %s : read_buffer overflow", __FUNCTION__); 226 dbg(1," %s : read_buffer overflow", __func__);
227 } 227 }
228 } 228 }
229 229
@@ -232,9 +232,9 @@ exit:
232 spin_unlock(&dev->buflock); 232 spin_unlock(&dev->buflock);
233 /* always wake up so we recover from errors */ 233 /* always wake up so we recover from errors */
234 wake_up_interruptible(&dev->read_wait); 234 wake_up_interruptible(&dev->read_wait);
235 adu_debug_data(5, __FUNCTION__, urb->actual_length, 235 adu_debug_data(5, __func__, urb->actual_length,
236 urb->transfer_buffer); 236 urb->transfer_buffer);
237 dbg(4," %s : leave, status %d", __FUNCTION__, status); 237 dbg(4," %s : leave, status %d", __func__, status);
238} 238}
239 239
240static void adu_interrupt_out_callback(struct urb *urb) 240static void adu_interrupt_out_callback(struct urb *urb)
@@ -242,14 +242,14 @@ static void adu_interrupt_out_callback(struct urb *urb)
242 struct adu_device *dev = urb->context; 242 struct adu_device *dev = urb->context;
243 int status = urb->status; 243 int status = urb->status;
244 244
245 dbg(4," %s : enter, status %d", __FUNCTION__, status); 245 dbg(4," %s : enter, status %d", __func__, status);
246 adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer); 246 adu_debug_data(5,__func__, urb->actual_length, urb->transfer_buffer);
247 247
248 if (status != 0) { 248 if (status != 0) {
249 if ((status != -ENOENT) && 249 if ((status != -ENOENT) &&
250 (status != -ECONNRESET)) { 250 (status != -ECONNRESET)) {
251 dbg(1, " %s :nonzero status received: %d", 251 dbg(1, " %s :nonzero status received: %d",
252 __FUNCTION__, status); 252 __func__, status);
253 } 253 }
254 goto exit; 254 goto exit;
255 } 255 }
@@ -260,9 +260,9 @@ static void adu_interrupt_out_callback(struct urb *urb)
260 spin_unlock(&dev->buflock); 260 spin_unlock(&dev->buflock);
261exit: 261exit:
262 262
263 adu_debug_data(5, __FUNCTION__, urb->actual_length, 263 adu_debug_data(5, __func__, urb->actual_length,
264 urb->transfer_buffer); 264 urb->transfer_buffer);
265 dbg(4," %s : leave, status %d", __FUNCTION__, status); 265 dbg(4," %s : leave, status %d", __func__, status);
266} 266}
267 267
268static int adu_open(struct inode *inode, struct file *file) 268static int adu_open(struct inode *inode, struct file *file)
@@ -272,19 +272,19 @@ static int adu_open(struct inode *inode, struct file *file)
272 int subminor; 272 int subminor;
273 int retval; 273 int retval;
274 274
275 dbg(2,"%s : enter", __FUNCTION__); 275 dbg(2,"%s : enter", __func__);
276 276
277 subminor = iminor(inode); 277 subminor = iminor(inode);
278 278
279 if ((retval = mutex_lock_interruptible(&adutux_mutex))) { 279 if ((retval = mutex_lock_interruptible(&adutux_mutex))) {
280 dbg(2, "%s : mutex lock failed", __FUNCTION__); 280 dbg(2, "%s : mutex lock failed", __func__);
281 goto exit_no_lock; 281 goto exit_no_lock;
282 } 282 }
283 283
284 interface = usb_find_interface(&adu_driver, subminor); 284 interface = usb_find_interface(&adu_driver, subminor);
285 if (!interface) { 285 if (!interface) {
286 err("%s - error, can't find device for minor %d", 286 err("%s - error, can't find device for minor %d",
287 __FUNCTION__, subminor); 287 __func__, subminor);
288 retval = -ENODEV; 288 retval = -ENODEV;
289 goto exit_no_device; 289 goto exit_no_device;
290 } 290 }
@@ -302,7 +302,7 @@ static int adu_open(struct inode *inode, struct file *file)
302 } 302 }
303 303
304 ++dev->open_count; 304 ++dev->open_count;
305 dbg(2,"%s : open count %d", __FUNCTION__, dev->open_count); 305 dbg(2,"%s : open count %d", __func__, dev->open_count);
306 306
307 /* save device in the file's private structure */ 307 /* save device in the file's private structure */
308 file->private_data = dev; 308 file->private_data = dev;
@@ -332,23 +332,23 @@ static int adu_open(struct inode *inode, struct file *file)
332exit_no_device: 332exit_no_device:
333 mutex_unlock(&adutux_mutex); 333 mutex_unlock(&adutux_mutex);
334exit_no_lock: 334exit_no_lock:
335 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); 335 dbg(2,"%s : leave, return value %d ", __func__, retval);
336 return retval; 336 return retval;
337} 337}
338 338
339static void adu_release_internal(struct adu_device *dev) 339static void adu_release_internal(struct adu_device *dev)
340{ 340{
341 dbg(2," %s : enter", __FUNCTION__); 341 dbg(2," %s : enter", __func__);
342 342
343 /* decrement our usage count for the device */ 343 /* decrement our usage count for the device */
344 --dev->open_count; 344 --dev->open_count;
345 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); 345 dbg(2," %s : open count %d", __func__, dev->open_count);
346 if (dev->open_count <= 0) { 346 if (dev->open_count <= 0) {
347 adu_abort_transfers(dev); 347 adu_abort_transfers(dev);
348 dev->open_count = 0; 348 dev->open_count = 0;
349 } 349 }
350 350
351 dbg(2," %s : leave", __FUNCTION__); 351 dbg(2," %s : leave", __func__);
352} 352}
353 353
354static int adu_release(struct inode *inode, struct file *file) 354static int adu_release(struct inode *inode, struct file *file)
@@ -356,17 +356,17 @@ static int adu_release(struct inode *inode, struct file *file)
356 struct adu_device *dev; 356 struct adu_device *dev;
357 int retval = 0; 357 int retval = 0;
358 358
359 dbg(2," %s : enter", __FUNCTION__); 359 dbg(2," %s : enter", __func__);
360 360
361 if (file == NULL) { 361 if (file == NULL) {
362 dbg(1," %s : file is NULL", __FUNCTION__); 362 dbg(1," %s : file is NULL", __func__);
363 retval = -ENODEV; 363 retval = -ENODEV;
364 goto exit; 364 goto exit;
365 } 365 }
366 366
367 dev = file->private_data; 367 dev = file->private_data;
368 if (dev == NULL) { 368 if (dev == NULL) {
369 dbg(1," %s : object is NULL", __FUNCTION__); 369 dbg(1," %s : object is NULL", __func__);
370 retval = -ENODEV; 370 retval = -ENODEV;
371 goto exit; 371 goto exit;
372 } 372 }
@@ -374,7 +374,7 @@ static int adu_release(struct inode *inode, struct file *file)
374 mutex_lock(&adutux_mutex); /* not interruptible */ 374 mutex_lock(&adutux_mutex); /* not interruptible */
375 375
376 if (dev->open_count <= 0) { 376 if (dev->open_count <= 0) {
377 dbg(1," %s : device not opened", __FUNCTION__); 377 dbg(1," %s : device not opened", __func__);
378 retval = -ENODEV; 378 retval = -ENODEV;
379 goto exit; 379 goto exit;
380 } 380 }
@@ -388,7 +388,7 @@ static int adu_release(struct inode *inode, struct file *file)
388 388
389exit: 389exit:
390 mutex_unlock(&adutux_mutex); 390 mutex_unlock(&adutux_mutex);
391 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 391 dbg(2," %s : leave, return value %d", __func__, retval);
392 return retval; 392 return retval;
393} 393}
394 394
@@ -405,10 +405,10 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
405 unsigned long flags; 405 unsigned long flags;
406 DECLARE_WAITQUEUE(wait, current); 406 DECLARE_WAITQUEUE(wait, current);
407 407
408 dbg(2," %s : enter, count = %Zd, file=%p", __FUNCTION__, count, file); 408 dbg(2," %s : enter, count = %Zd, file=%p", __func__, count, file);
409 409
410 dev = file->private_data; 410 dev = file->private_data;
411 dbg(2," %s : dev=%p", __FUNCTION__, dev); 411 dbg(2," %s : dev=%p", __func__, dev);
412 412
413 if (mutex_lock_interruptible(&dev->mtx)) 413 if (mutex_lock_interruptible(&dev->mtx))
414 return -ERESTARTSYS; 414 return -ERESTARTSYS;
@@ -422,16 +422,16 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
422 422
423 /* verify that some data was requested */ 423 /* verify that some data was requested */
424 if (count == 0) { 424 if (count == 0) {
425 dbg(1," %s : read request of 0 bytes", __FUNCTION__); 425 dbg(1," %s : read request of 0 bytes", __func__);
426 goto exit; 426 goto exit;
427 } 427 }
428 428
429 timeout = COMMAND_TIMEOUT; 429 timeout = COMMAND_TIMEOUT;
430 dbg(2," %s : about to start looping", __FUNCTION__); 430 dbg(2," %s : about to start looping", __func__);
431 while (bytes_to_read) { 431 while (bytes_to_read) {
432 int data_in_secondary = dev->secondary_tail - dev->secondary_head; 432 int data_in_secondary = dev->secondary_tail - dev->secondary_head;
433 dbg(2," %s : while, data_in_secondary=%d, status=%d", 433 dbg(2," %s : while, data_in_secondary=%d, status=%d",
434 __FUNCTION__, data_in_secondary, 434 __func__, data_in_secondary,
435 dev->interrupt_in_urb->status); 435 dev->interrupt_in_urb->status);
436 436
437 if (data_in_secondary) { 437 if (data_in_secondary) {
@@ -456,7 +456,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
456 /* we secure access to the primary */ 456 /* we secure access to the primary */
457 char *tmp; 457 char *tmp;
458 dbg(2," %s : swap, read_buffer_length = %d", 458 dbg(2," %s : swap, read_buffer_length = %d",
459 __FUNCTION__, dev->read_buffer_length); 459 __func__, dev->read_buffer_length);
460 tmp = dev->read_buffer_secondary; 460 tmp = dev->read_buffer_secondary;
461 dev->read_buffer_secondary = dev->read_buffer_primary; 461 dev->read_buffer_secondary = dev->read_buffer_primary;
462 dev->read_buffer_primary = tmp; 462 dev->read_buffer_primary = tmp;
@@ -471,10 +471,10 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
471 if (!dev->read_urb_finished) { 471 if (!dev->read_urb_finished) {
472 /* somebody is doing IO */ 472 /* somebody is doing IO */
473 spin_unlock_irqrestore(&dev->buflock, flags); 473 spin_unlock_irqrestore(&dev->buflock, flags);
474 dbg(2," %s : submitted already", __FUNCTION__); 474 dbg(2," %s : submitted already", __func__);
475 } else { 475 } else {
476 /* we must initiate input */ 476 /* we must initiate input */
477 dbg(2," %s : initiate input", __FUNCTION__); 477 dbg(2," %s : initiate input", __func__);
478 dev->read_urb_finished = 0; 478 dev->read_urb_finished = 0;
479 spin_unlock_irqrestore(&dev->buflock, flags); 479 spin_unlock_irqrestore(&dev->buflock, flags);
480 480
@@ -492,7 +492,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
492 if (retval == -ENOMEM) { 492 if (retval == -ENOMEM) {
493 retval = bytes_read ? bytes_read : -ENOMEM; 493 retval = bytes_read ? bytes_read : -ENOMEM;
494 } 494 }
495 dbg(2," %s : submit failed", __FUNCTION__); 495 dbg(2," %s : submit failed", __func__);
496 goto exit; 496 goto exit;
497 } 497 }
498 } 498 }
@@ -511,13 +511,13 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
511 remove_wait_queue(&dev->read_wait, &wait); 511 remove_wait_queue(&dev->read_wait, &wait);
512 512
513 if (timeout <= 0) { 513 if (timeout <= 0) {
514 dbg(2," %s : timeout", __FUNCTION__); 514 dbg(2," %s : timeout", __func__);
515 retval = bytes_read ? bytes_read : -ETIMEDOUT; 515 retval = bytes_read ? bytes_read : -ETIMEDOUT;
516 goto exit; 516 goto exit;
517 } 517 }
518 518
519 if (signal_pending(current)) { 519 if (signal_pending(current)) {
520 dbg(2," %s : signal pending", __FUNCTION__); 520 dbg(2," %s : signal pending", __func__);
521 retval = bytes_read ? bytes_read : -EINTR; 521 retval = bytes_read ? bytes_read : -EINTR;
522 goto exit; 522 goto exit;
523 } 523 }
@@ -550,7 +550,7 @@ exit:
550 /* unlock the device */ 550 /* unlock the device */
551 mutex_unlock(&dev->mtx); 551 mutex_unlock(&dev->mtx);
552 552
553 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 553 dbg(2," %s : leave, return value %d", __func__, retval);
554 return retval; 554 return retval;
555} 555}
556 556
@@ -565,7 +565,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
565 unsigned long flags; 565 unsigned long flags;
566 int retval; 566 int retval;
567 567
568 dbg(2," %s : enter, count = %Zd", __FUNCTION__, count); 568 dbg(2," %s : enter, count = %Zd", __func__, count);
569 569
570 dev = file->private_data; 570 dev = file->private_data;
571 571
@@ -582,7 +582,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
582 582
583 /* verify that we actually have some data to write */ 583 /* verify that we actually have some data to write */
584 if (count == 0) { 584 if (count == 0) {
585 dbg(1," %s : write request of 0 bytes", __FUNCTION__); 585 dbg(1," %s : write request of 0 bytes", __func__);
586 goto exit; 586 goto exit;
587 } 587 }
588 588
@@ -595,13 +595,13 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
595 595
596 mutex_unlock(&dev->mtx); 596 mutex_unlock(&dev->mtx);
597 if (signal_pending(current)) { 597 if (signal_pending(current)) {
598 dbg(1," %s : interrupted", __FUNCTION__); 598 dbg(1," %s : interrupted", __func__);
599 set_current_state(TASK_RUNNING); 599 set_current_state(TASK_RUNNING);
600 retval = -EINTR; 600 retval = -EINTR;
601 goto exit_onqueue; 601 goto exit_onqueue;
602 } 602 }
603 if (schedule_timeout(COMMAND_TIMEOUT) == 0) { 603 if (schedule_timeout(COMMAND_TIMEOUT) == 0) {
604 dbg(1, "%s - command timed out.", __FUNCTION__); 604 dbg(1, "%s - command timed out.", __func__);
605 retval = -ETIMEDOUT; 605 retval = -ETIMEDOUT;
606 goto exit_onqueue; 606 goto exit_onqueue;
607 } 607 }
@@ -612,18 +612,18 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
612 goto exit_nolock; 612 goto exit_nolock;
613 } 613 }
614 614
615 dbg(4," %s : in progress, count = %Zd", __FUNCTION__, count); 615 dbg(4," %s : in progress, count = %Zd", __func__, count);
616 } else { 616 } else {
617 spin_unlock_irqrestore(&dev->buflock, flags); 617 spin_unlock_irqrestore(&dev->buflock, flags);
618 set_current_state(TASK_RUNNING); 618 set_current_state(TASK_RUNNING);
619 remove_wait_queue(&dev->write_wait, &waita); 619 remove_wait_queue(&dev->write_wait, &waita);
620 dbg(4," %s : sending, count = %Zd", __FUNCTION__, count); 620 dbg(4," %s : sending, count = %Zd", __func__, count);
621 621
622 /* write the data into interrupt_out_buffer from userspace */ 622 /* write the data into interrupt_out_buffer from userspace */
623 buffer_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize); 623 buffer_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize);
624 bytes_to_write = count > buffer_size ? buffer_size : count; 624 bytes_to_write = count > buffer_size ? buffer_size : count;
625 dbg(4," %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd", 625 dbg(4," %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd",
626 __FUNCTION__, buffer_size, count, bytes_to_write); 626 __func__, buffer_size, count, bytes_to_write);
627 627
628 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) { 628 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {
629 retval = -EFAULT; 629 retval = -EFAULT;
@@ -661,7 +661,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
661exit: 661exit:
662 mutex_unlock(&dev->mtx); 662 mutex_unlock(&dev->mtx);
663exit_nolock: 663exit_nolock:
664 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 664 dbg(2," %s : leave, return value %d", __func__, retval);
665 return retval; 665 return retval;
666 666
667exit_onqueue: 667exit_onqueue:
@@ -706,7 +706,7 @@ static int adu_probe(struct usb_interface *interface,
706 int out_end_size; 706 int out_end_size;
707 int i; 707 int i;
708 708
709 dbg(2," %s : enter", __FUNCTION__); 709 dbg(2," %s : enter", __func__);
710 710
711 if (udev == NULL) { 711 if (udev == NULL) {
712 dev_err(&interface->dev, "udev is NULL.\n"); 712 dev_err(&interface->dev, "udev is NULL.\n");
@@ -807,7 +807,7 @@ static int adu_probe(struct usb_interface *interface,
807 dev_err(&interface->dev, "Could not retrieve serial number\n"); 807 dev_err(&interface->dev, "Could not retrieve serial number\n");
808 goto error; 808 goto error;
809 } 809 }
810 dbg(2," %s : serial_number=%s", __FUNCTION__, dev->serial_number); 810 dbg(2," %s : serial_number=%s", __func__, dev->serial_number);
811 811
812 /* we can register the device now, as it is ready */ 812 /* we can register the device now, as it is ready */
813 usb_set_intfdata(interface, dev); 813 usb_set_intfdata(interface, dev);
@@ -828,7 +828,7 @@ static int adu_probe(struct usb_interface *interface,
828 udev->descriptor.idProduct, dev->serial_number, 828 udev->descriptor.idProduct, dev->serial_number,
829 (dev->minor - ADU_MINOR_BASE)); 829 (dev->minor - ADU_MINOR_BASE));
830exit: 830exit:
831 dbg(2," %s : leave, return value %p (dev)", __FUNCTION__, dev); 831 dbg(2," %s : leave, return value %p (dev)", __func__, dev);
832 832
833 return retval; 833 return retval;
834 834
@@ -847,7 +847,7 @@ static void adu_disconnect(struct usb_interface *interface)
847 struct adu_device *dev; 847 struct adu_device *dev;
848 int minor; 848 int minor;
849 849
850 dbg(2," %s : enter", __FUNCTION__); 850 dbg(2," %s : enter", __func__);
851 851
852 dev = usb_get_intfdata(interface); 852 dev = usb_get_intfdata(interface);
853 853
@@ -861,7 +861,7 @@ static void adu_disconnect(struct usb_interface *interface)
861 usb_set_intfdata(interface, NULL); 861 usb_set_intfdata(interface, NULL);
862 862
863 /* if the device is not opened, then we clean up right now */ 863 /* if the device is not opened, then we clean up right now */
864 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); 864 dbg(2," %s : open count %d", __func__, dev->open_count);
865 if (!dev->open_count) 865 if (!dev->open_count)
866 adu_delete(dev); 866 adu_delete(dev);
867 867
@@ -870,7 +870,7 @@ static void adu_disconnect(struct usb_interface *interface)
870 dev_info(&interface->dev, "ADU device adutux%d now disconnected\n", 870 dev_info(&interface->dev, "ADU device adutux%d now disconnected\n",
871 (minor - ADU_MINOR_BASE)); 871 (minor - ADU_MINOR_BASE));
872 872
873 dbg(2," %s : leave", __FUNCTION__); 873 dbg(2," %s : leave", __func__);
874} 874}
875 875
876/* usb specific object needed to register this driver with the usb subsystem */ 876/* usb specific object needed to register this driver with the usb subsystem */
@@ -885,7 +885,7 @@ static int __init adu_init(void)
885{ 885{
886 int result; 886 int result;
887 887
888 dbg(2," %s : enter", __FUNCTION__); 888 dbg(2," %s : enter", __func__);
889 889
890 /* register this driver with the USB subsystem */ 890 /* register this driver with the USB subsystem */
891 result = usb_register(&adu_driver); 891 result = usb_register(&adu_driver);
@@ -899,17 +899,17 @@ static int __init adu_init(void)
899 info("adutux is an experimental driver. Use at your own risk"); 899 info("adutux is an experimental driver. Use at your own risk");
900 900
901exit: 901exit:
902 dbg(2," %s : leave, return value %d", __FUNCTION__, result); 902 dbg(2," %s : leave, return value %d", __func__, result);
903 903
904 return result; 904 return result;
905} 905}
906 906
907static void __exit adu_exit(void) 907static void __exit adu_exit(void)
908{ 908{
909 dbg(2," %s : enter", __FUNCTION__); 909 dbg(2," %s : enter", __func__);
910 /* deregister this driver with the USB subsystem */ 910 /* deregister this driver with the USB subsystem */
911 usb_deregister(&adu_driver); 911 usb_deregister(&adu_driver);
912 dbg(2," %s : leave", __FUNCTION__); 912 dbg(2," %s : leave", __func__);
913} 913}
914 914
915module_init(adu_init); 915module_init(adu_init);
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index a5e4c3545c72..a076c24a312a 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -103,11 +103,11 @@ static void appledisplay_complete(struct urb *urb)
103 case -ESHUTDOWN: 103 case -ESHUTDOWN:
104 /* This urb is terminated, clean up */ 104 /* This urb is terminated, clean up */
105 dbg("%s - urb shuttingdown with status: %d", 105 dbg("%s - urb shuttingdown with status: %d",
106 __FUNCTION__, status); 106 __func__, status);
107 return; 107 return;
108 default: 108 default:
109 dbg("%s - nonzero urb status received: %d", 109 dbg("%s - nonzero urb status received: %d",
110 __FUNCTION__, status); 110 __func__, status);
111 goto exit; 111 goto exit;
112 } 112 }
113 113
@@ -131,7 +131,7 @@ exit:
131 retval = usb_submit_urb(pdata->urb, GFP_ATOMIC); 131 retval = usb_submit_urb(pdata->urb, GFP_ATOMIC);
132 if (retval) { 132 if (retval) {
133 err("%s - usb_submit_urb failed with result %d", 133 err("%s - usb_submit_urb failed with result %d",
134 __FUNCTION__, retval); 134 __func__, retval);
135 } 135 }
136} 136}
137 137
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index df7e1ecc810a..093938697426 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -31,6 +31,7 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/wait.h> 32#include <linux/wait.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/mutex.h>
34 35
35/*-------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------*/
36/* Debug support */ 37/* Debug support */
@@ -232,7 +233,7 @@ typedef struct auerscon
232/* USB device context */ 233/* USB device context */
233typedef struct 234typedef struct
234{ 235{
235 struct semaphore mutex; /* protection in user context */ 236 struct mutex mutex; /* protection in user context */
236 char name[20]; /* name of the /dev/usb entry */ 237 char name[20]; /* name of the /dev/usb entry */
237 unsigned int dtindex; /* index in the device table */ 238 unsigned int dtindex; /* index in the device table */
238 struct usb_device * usbdev; /* USB device handle */ 239 struct usb_device * usbdev; /* USB device handle */
@@ -253,12 +254,12 @@ typedef struct
253/* character device context */ 254/* character device context */
254typedef struct 255typedef struct
255{ 256{
256 struct semaphore mutex; /* protection in user context */ 257 struct mutex mutex; /* protection in user context */
257 pauerswald_t auerdev; /* context pointer of assigned device */ 258 pauerswald_t auerdev; /* context pointer of assigned device */
258 auerbufctl_t bufctl; /* controls the buffer chain */ 259 auerbufctl_t bufctl; /* controls the buffer chain */
259 auerscon_t scontext; /* service context */ 260 auerscon_t scontext; /* service context */
260 wait_queue_head_t readwait; /* for synchronous reading */ 261 wait_queue_head_t readwait; /* for synchronous reading */
261 struct semaphore readmutex; /* protection against multiple reads */ 262 struct mutex readmutex; /* protection against multiple reads */
262 pauerbuf_t readbuf; /* buffer held for partial reading */ 263 pauerbuf_t readbuf; /* buffer held for partial reading */
263 unsigned int readoffset; /* current offset in readbuf */ 264 unsigned int readoffset; /* current offset in readbuf */
264 unsigned int removed; /* is != 0 if device is removed */ 265 unsigned int removed; /* is != 0 if device is removed */
@@ -283,7 +284,7 @@ static void auerchain_complete (struct urb * urb)
283 int result; 284 int result;
284 285
285 /* get pointer to element and to chain */ 286 /* get pointer to element and to chain */
286 pauerchainelement_t acep = (pauerchainelement_t) urb->context; 287 pauerchainelement_t acep = urb->context;
287 pauerchain_t acp = acep->chain; 288 pauerchain_t acp = acep->chain;
288 289
289 /* restore original entries in urb */ 290 /* restore original entries in urb */
@@ -593,7 +594,7 @@ ac_fail:/* free the elements */
593/* completion handler for synchronous chained URBs */ 594/* completion handler for synchronous chained URBs */
594static void auerchain_blocking_completion (struct urb *urb) 595static void auerchain_blocking_completion (struct urb *urb)
595{ 596{
596 pauerchain_chs_t pchs = (pauerchain_chs_t)urb->context; 597 pauerchain_chs_t pchs = urb->context;
597 pchs->done = 1; 598 pchs->done = 1;
598 wmb(); 599 wmb();
599 wake_up (&pchs->wqh); 600 wake_up (&pchs->wqh);
@@ -846,7 +847,7 @@ static int auerswald_status_retry (int status)
846/* Completion of asynchronous write block */ 847/* Completion of asynchronous write block */
847static void auerchar_ctrlwrite_complete (struct urb * urb) 848static void auerchar_ctrlwrite_complete (struct urb * urb)
848{ 849{
849 pauerbuf_t bp = (pauerbuf_t) urb->context; 850 pauerbuf_t bp = urb->context;
850 pauerswald_t cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl))); 851 pauerswald_t cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl)));
851 dbg ("auerchar_ctrlwrite_complete called"); 852 dbg ("auerchar_ctrlwrite_complete called");
852 853
@@ -859,7 +860,7 @@ static void auerchar_ctrlwrite_complete (struct urb * urb)
859/* Completion handler for dummy retry packet */ 860/* Completion handler for dummy retry packet */
860static void auerswald_ctrlread_wretcomplete (struct urb * urb) 861static void auerswald_ctrlread_wretcomplete (struct urb * urb)
861{ 862{
862 pauerbuf_t bp = (pauerbuf_t) urb->context; 863 pauerbuf_t bp = urb->context;
863 pauerswald_t cp; 864 pauerswald_t cp;
864 int ret; 865 int ret;
865 int status = urb->status; 866 int status = urb->status;
@@ -903,7 +904,7 @@ static void auerswald_ctrlread_complete (struct urb * urb)
903 unsigned int serviceid; 904 unsigned int serviceid;
904 pauerswald_t cp; 905 pauerswald_t cp;
905 pauerscon_t scp; 906 pauerscon_t scp;
906 pauerbuf_t bp = (pauerbuf_t) urb->context; 907 pauerbuf_t bp = urb->context;
907 int status = urb->status; 908 int status = urb->status;
908 int ret; 909 int ret;
909 910
@@ -980,9 +981,9 @@ static void auerswald_int_complete (struct urb * urb)
980 int ret; 981 int ret;
981 int status = urb->status; 982 int status = urb->status;
982 pauerbuf_t bp = NULL; 983 pauerbuf_t bp = NULL;
983 pauerswald_t cp = (pauerswald_t) urb->context; 984 pauerswald_t cp = urb->context;
984 985
985 dbg ("%s called", __FUNCTION__); 986 dbg ("%s called", __func__);
986 987
987 switch (status) { 988 switch (status) {
988 case 0: 989 case 0:
@@ -992,10 +993,10 @@ static void auerswald_int_complete (struct urb * urb)
992 case -ENOENT: 993 case -ENOENT:
993 case -ESHUTDOWN: 994 case -ESHUTDOWN:
994 /* this urb is terminated, clean up */ 995 /* this urb is terminated, clean up */
995 dbg("%s - urb shutting down with status: %d", __FUNCTION__, status); 996 dbg("%s - urb shutting down with status: %d", __func__, status);
996 return; 997 return;
997 default: 998 default:
998 dbg("%s - nonzero urb status received: %d", __FUNCTION__, status); 999 dbg("%s - nonzero urb status received: %d", __func__, status);
999 goto exit; 1000 goto exit;
1000 } 1001 }
1001 1002
@@ -1080,7 +1081,7 @@ exit:
1080 ret = usb_submit_urb (urb, GFP_ATOMIC); 1081 ret = usb_submit_urb (urb, GFP_ATOMIC);
1081 if (ret) 1082 if (ret)
1082 err ("%s - usb_submit_urb failed with result %d", 1083 err ("%s - usb_submit_urb failed with result %d",
1083 __FUNCTION__, ret); 1084 __func__, ret);
1084} 1085}
1085 1086
1086/* int memory deallocation 1087/* int memory deallocation
@@ -1376,7 +1377,7 @@ static int auerchar_open (struct inode *inode, struct file *file)
1376 if (cp == NULL) { 1377 if (cp == NULL) {
1377 return -ENODEV; 1378 return -ENODEV;
1378 } 1379 }
1379 if (down_interruptible (&cp->mutex)) { 1380 if (mutex_lock_interruptible(&cp->mutex)) {
1380 return -ERESTARTSYS; 1381 return -ERESTARTSYS;
1381 } 1382 }
1382 1383
@@ -1389,8 +1390,8 @@ static int auerchar_open (struct inode *inode, struct file *file)
1389 } 1390 }
1390 1391
1391 /* Initialize device descriptor */ 1392 /* Initialize device descriptor */
1392 init_MUTEX( &ccp->mutex); 1393 mutex_init(&ccp->mutex);
1393 init_MUTEX( &ccp->readmutex); 1394 mutex_init(&ccp->readmutex);
1394 auerbuf_init (&ccp->bufctl); 1395 auerbuf_init (&ccp->bufctl);
1395 ccp->scontext.id = AUH_UNASSIGNED; 1396 ccp->scontext.id = AUH_UNASSIGNED;
1396 ccp->scontext.dispatch = auerchar_ctrlread_dispatch; 1397 ccp->scontext.dispatch = auerchar_ctrlread_dispatch;
@@ -1405,7 +1406,7 @@ static int auerchar_open (struct inode *inode, struct file *file)
1405 cp->open_count++; 1406 cp->open_count++;
1406 ccp->auerdev = cp; 1407 ccp->auerdev = cp;
1407 dbg("open %s as /dev/%s", cp->dev_desc, cp->name); 1408 dbg("open %s as /dev/%s", cp->dev_desc, cp->name);
1408 up (&cp->mutex); 1409 mutex_unlock(&cp->mutex);
1409 1410
1410 /* file IO stuff */ 1411 /* file IO stuff */
1411 file->f_pos = 0; 1412 file->f_pos = 0;
@@ -1413,7 +1414,7 @@ static int auerchar_open (struct inode *inode, struct file *file)
1413 return nonseekable_open(inode, file); 1414 return nonseekable_open(inode, file);
1414 1415
1415 /* Error exit */ 1416 /* Error exit */
1416ofail: up (&cp->mutex); 1417ofail: mutex_unlock(&cp->mutex);
1417 auerchar_delete (ccp); 1418 auerchar_delete (ccp);
1418 return ret; 1419 return ret;
1419} 1420}
@@ -1432,23 +1433,23 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int
1432 dbg ("ioctl"); 1433 dbg ("ioctl");
1433 1434
1434 /* get the mutexes */ 1435 /* get the mutexes */
1435 if (down_interruptible (&ccp->mutex)) { 1436 if (mutex_lock_interruptible(&ccp->mutex)) {
1436 return -ERESTARTSYS; 1437 return -ERESTARTSYS;
1437 } 1438 }
1438 cp = ccp->auerdev; 1439 cp = ccp->auerdev;
1439 if (!cp) { 1440 if (!cp) {
1440 up (&ccp->mutex); 1441 mutex_unlock(&ccp->mutex);
1441 return -ENODEV; 1442 return -ENODEV;
1442 } 1443 }
1443 if (down_interruptible (&cp->mutex)) { 1444 if (mutex_lock_interruptible(&cp->mutex)) {
1444 up(&ccp->mutex); 1445 mutex_unlock(&ccp->mutex);
1445 return -ERESTARTSYS; 1446 return -ERESTARTSYS;
1446 } 1447 }
1447 1448
1448 /* Check for removal */ 1449 /* Check for removal */
1449 if (!cp->usbdev) { 1450 if (!cp->usbdev) {
1450 up(&cp->mutex); 1451 mutex_unlock(&cp->mutex);
1451 up(&ccp->mutex); 1452 mutex_unlock(&ccp->mutex);
1452 return -ENODEV; 1453 return -ENODEV;
1453 } 1454 }
1454 1455
@@ -1550,8 +1551,8 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int
1550 break; 1551 break;
1551 } 1552 }
1552 /* release the mutexes */ 1553 /* release the mutexes */
1553 up(&cp->mutex); 1554 mutex_unlock(&cp->mutex);
1554 up(&ccp->mutex); 1555 mutex_unlock(&ccp->mutex);
1555 return ret; 1556 return ret;
1556} 1557}
1557 1558
@@ -1574,18 +1575,18 @@ static ssize_t auerchar_read (struct file *file, char __user *buf, size_t count,
1574 return 0; 1575 return 0;
1575 1576
1576 /* get the mutex */ 1577 /* get the mutex */
1577 if (down_interruptible (&ccp->mutex)) 1578 if (mutex_lock_interruptible(&ccp->mutex))
1578 return -ERESTARTSYS; 1579 return -ERESTARTSYS;
1579 1580
1580 /* Can we expect to read something? */ 1581 /* Can we expect to read something? */
1581 if (ccp->scontext.id == AUH_UNASSIGNED) { 1582 if (ccp->scontext.id == AUH_UNASSIGNED) {
1582 up (&ccp->mutex); 1583 mutex_unlock(&ccp->mutex);
1583 return -EIO; 1584 return -EIO;
1584 } 1585 }
1585 1586
1586 /* only one reader per device allowed */ 1587 /* only one reader per device allowed */
1587 if (down_interruptible (&ccp->readmutex)) { 1588 if (mutex_lock_interruptible(&ccp->readmutex)) {
1588 up (&ccp->mutex); 1589 mutex_unlock(&ccp->mutex);
1589 return -ERESTARTSYS; 1590 return -ERESTARTSYS;
1590 } 1591 }
1591 1592
@@ -1602,8 +1603,8 @@ doreadbuf:
1602 if (count) { 1603 if (count) {
1603 if (copy_to_user (buf, bp->bufp+ccp->readoffset, count)) { 1604 if (copy_to_user (buf, bp->bufp+ccp->readoffset, count)) {
1604 dbg ("auerswald_read: copy_to_user failed"); 1605 dbg ("auerswald_read: copy_to_user failed");
1605 up (&ccp->readmutex); 1606 mutex_unlock(&ccp->readmutex);
1606 up (&ccp->mutex); 1607 mutex_unlock(&ccp->mutex);
1607 return -EFAULT; 1608 return -EFAULT;
1608 } 1609 }
1609 } 1610 }
@@ -1617,8 +1618,8 @@ doreadbuf:
1617 } 1618 }
1618 /* return with number of bytes read */ 1619 /* return with number of bytes read */
1619 if (count) { 1620 if (count) {
1620 up (&ccp->readmutex); 1621 mutex_unlock(&ccp->readmutex);
1621 up (&ccp->mutex); 1622 mutex_unlock(&ccp->mutex);
1622 return count; 1623 return count;
1623 } 1624 }
1624 } 1625 }
@@ -1654,29 +1655,29 @@ doreadlist:
1654 dbg ("No read buffer available, returning -EAGAIN"); 1655 dbg ("No read buffer available, returning -EAGAIN");
1655 set_current_state (TASK_RUNNING); 1656 set_current_state (TASK_RUNNING);
1656 remove_wait_queue (&ccp->readwait, &wait); 1657 remove_wait_queue (&ccp->readwait, &wait);
1657 up (&ccp->readmutex); 1658 mutex_unlock(&ccp->readmutex);
1658 up (&ccp->mutex); 1659 mutex_unlock(&ccp->mutex);
1659 return -EAGAIN; /* nonblocking, no data available */ 1660 return -EAGAIN; /* nonblocking, no data available */
1660 } 1661 }
1661 1662
1662 /* yes, we should wait! */ 1663 /* yes, we should wait! */
1663 up (&ccp->mutex); /* allow other operations while we wait */ 1664 mutex_unlock(&ccp->mutex); /* allow other operations while we wait */
1664 schedule(); 1665 schedule();
1665 remove_wait_queue (&ccp->readwait, &wait); 1666 remove_wait_queue (&ccp->readwait, &wait);
1666 if (signal_pending (current)) { 1667 if (signal_pending (current)) {
1667 /* waked up by a signal */ 1668 /* waked up by a signal */
1668 up (&ccp->readmutex); 1669 mutex_unlock(&ccp->readmutex);
1669 return -ERESTARTSYS; 1670 return -ERESTARTSYS;
1670 } 1671 }
1671 1672
1672 /* Anything left to read? */ 1673 /* Anything left to read? */
1673 if ((ccp->scontext.id == AUH_UNASSIGNED) || ccp->removed) { 1674 if ((ccp->scontext.id == AUH_UNASSIGNED) || ccp->removed) {
1674 up (&ccp->readmutex); 1675 mutex_unlock(&ccp->readmutex);
1675 return -EIO; 1676 return -EIO;
1676 } 1677 }
1677 1678
1678 if (down_interruptible (&ccp->mutex)) { 1679 if (mutex_lock_interruptible(&ccp->mutex)) {
1679 up (&ccp->readmutex); 1680 mutex_unlock(&ccp->readmutex);
1680 return -ERESTARTSYS; 1681 return -ERESTARTSYS;
1681 } 1682 }
1682 1683
@@ -1707,27 +1708,27 @@ static ssize_t auerchar_write (struct file *file, const char __user *buf, size_t
1707 1708
1708write_again: 1709write_again:
1709 /* get the mutex */ 1710 /* get the mutex */
1710 if (down_interruptible (&ccp->mutex)) 1711 if (mutex_lock_interruptible(&ccp->mutex))
1711 return -ERESTARTSYS; 1712 return -ERESTARTSYS;
1712 1713
1713 /* Can we expect to write something? */ 1714 /* Can we expect to write something? */
1714 if (ccp->scontext.id == AUH_UNASSIGNED) { 1715 if (ccp->scontext.id == AUH_UNASSIGNED) {
1715 up (&ccp->mutex); 1716 mutex_unlock(&ccp->mutex);
1716 return -EIO; 1717 return -EIO;
1717 } 1718 }
1718 1719
1719 cp = ccp->auerdev; 1720 cp = ccp->auerdev;
1720 if (!cp) { 1721 if (!cp) {
1721 up (&ccp->mutex); 1722 mutex_unlock(&ccp->mutex);
1722 return -ERESTARTSYS; 1723 return -ERESTARTSYS;
1723 } 1724 }
1724 if (down_interruptible (&cp->mutex)) { 1725 if (mutex_lock_interruptible(&cp->mutex)) {
1725 up (&ccp->mutex); 1726 mutex_unlock(&ccp->mutex);
1726 return -ERESTARTSYS; 1727 return -ERESTARTSYS;
1727 } 1728 }
1728 if (!cp->usbdev) { 1729 if (!cp->usbdev) {
1729 up (&cp->mutex); 1730 mutex_unlock(&cp->mutex);
1730 up (&ccp->mutex); 1731 mutex_unlock(&ccp->mutex);
1731 return -EIO; 1732 return -EIO;
1732 } 1733 }
1733 /* Prepare for sleep */ 1734 /* Prepare for sleep */
@@ -1750,8 +1751,8 @@ write_again:
1750 1751
1751 /* are there any buffers left? */ 1752 /* are there any buffers left? */
1752 if (!bp) { 1753 if (!bp) {
1753 up (&cp->mutex); 1754 mutex_unlock(&cp->mutex);
1754 up (&ccp->mutex); 1755 mutex_unlock(&ccp->mutex);
1755 1756
1756 /* NONBLOCK: don't wait */ 1757 /* NONBLOCK: don't wait */
1757 if (file->f_flags & O_NONBLOCK) { 1758 if (file->f_flags & O_NONBLOCK) {
@@ -1783,8 +1784,8 @@ write_again:
1783 auerbuf_releasebuf (bp); 1784 auerbuf_releasebuf (bp);
1784 /* Wake up all processes waiting for a buffer */ 1785 /* Wake up all processes waiting for a buffer */
1785 wake_up (&cp->bufferwait); 1786 wake_up (&cp->bufferwait);
1786 up (&cp->mutex); 1787 mutex_unlock(&cp->mutex);
1787 up (&ccp->mutex); 1788 mutex_unlock(&ccp->mutex);
1788 return -EFAULT; 1789 return -EFAULT;
1789 } 1790 }
1790 1791
@@ -1803,18 +1804,18 @@ write_again:
1803 auerchar_ctrlwrite_complete, bp); 1804 auerchar_ctrlwrite_complete, bp);
1804 /* up we go */ 1805 /* up we go */
1805 ret = auerchain_submit_urb (&cp->controlchain, bp->urbp); 1806 ret = auerchain_submit_urb (&cp->controlchain, bp->urbp);
1806 up (&cp->mutex); 1807 mutex_unlock(&cp->mutex);
1807 if (ret) { 1808 if (ret) {
1808 dbg ("auerchar_write: nonzero result of auerchain_submit_urb %d", ret); 1809 dbg ("auerchar_write: nonzero result of auerchain_submit_urb %d", ret);
1809 auerbuf_releasebuf (bp); 1810 auerbuf_releasebuf (bp);
1810 /* Wake up all processes waiting for a buffer */ 1811 /* Wake up all processes waiting for a buffer */
1811 wake_up (&cp->bufferwait); 1812 wake_up (&cp->bufferwait);
1812 up (&ccp->mutex); 1813 mutex_unlock(&ccp->mutex);
1813 return -EIO; 1814 return -EIO;
1814 } 1815 }
1815 else { 1816 else {
1816 dbg ("auerchar_write: Write OK"); 1817 dbg ("auerchar_write: Write OK");
1817 up (&ccp->mutex); 1818 mutex_unlock(&ccp->mutex);
1818 return len; 1819 return len;
1819 } 1820 }
1820} 1821}
@@ -1827,24 +1828,24 @@ static int auerchar_release (struct inode *inode, struct file *file)
1827 pauerswald_t cp; 1828 pauerswald_t cp;
1828 dbg("release"); 1829 dbg("release");
1829 1830
1830 down(&ccp->mutex); 1831 mutex_lock(&ccp->mutex);
1831 cp = ccp->auerdev; 1832 cp = ccp->auerdev;
1832 if (cp) { 1833 if (cp) {
1833 down(&cp->mutex); 1834 mutex_lock(&cp->mutex);
1834 /* remove an open service */ 1835 /* remove an open service */
1835 auerswald_removeservice (cp, &ccp->scontext); 1836 auerswald_removeservice (cp, &ccp->scontext);
1836 /* detach from device */ 1837 /* detach from device */
1837 if ((--cp->open_count <= 0) && (cp->usbdev == NULL)) { 1838 if ((--cp->open_count <= 0) && (cp->usbdev == NULL)) {
1838 /* usb device waits for removal */ 1839 /* usb device waits for removal */
1839 up (&cp->mutex); 1840 mutex_unlock(&cp->mutex);
1840 auerswald_delete (cp); 1841 auerswald_delete (cp);
1841 } else { 1842 } else {
1842 up (&cp->mutex); 1843 mutex_unlock(&cp->mutex);
1843 } 1844 }
1844 cp = NULL; 1845 cp = NULL;
1845 ccp->auerdev = NULL; 1846 ccp->auerdev = NULL;
1846 } 1847 }
1847 up (&ccp->mutex); 1848 mutex_unlock(&ccp->mutex);
1848 auerchar_delete (ccp); 1849 auerchar_delete (ccp);
1849 1850
1850 return 0; 1851 return 0;
@@ -1917,7 +1918,7 @@ static int auerswald_probe (struct usb_interface *intf,
1917 } 1918 }
1918 1919
1919 /* Initialize device descriptor */ 1920 /* Initialize device descriptor */
1920 init_MUTEX (&cp->mutex); 1921 mutex_init(&cp->mutex);
1921 cp->usbdev = usbdev; 1922 cp->usbdev = usbdev;
1922 auerchain_init (&cp->controlchain); 1923 auerchain_init (&cp->controlchain);
1923 auerbuf_init (&cp->bufctl); 1924 auerbuf_init (&cp->bufctl);
@@ -2042,7 +2043,7 @@ static void auerswald_disconnect (struct usb_interface *intf)
2042 /* give back our USB minor number */ 2043 /* give back our USB minor number */
2043 usb_deregister_dev(intf, &auerswald_class); 2044 usb_deregister_dev(intf, &auerswald_class);
2044 2045
2045 down (&cp->mutex); 2046 mutex_lock(&cp->mutex);
2046 info ("device /dev/%s now disconnecting", cp->name); 2047 info ("device /dev/%s now disconnecting", cp->name);
2047 2048
2048 /* Stop the interrupt endpoint */ 2049 /* Stop the interrupt endpoint */
@@ -2057,16 +2058,18 @@ static void auerswald_disconnect (struct usb_interface *intf)
2057 2058
2058 if (cp->open_count == 0) { 2059 if (cp->open_count == 0) {
2059 /* nobody is using this device. So we can clean up now */ 2060 /* nobody is using this device. So we can clean up now */
2060 up (&cp->mutex);/* up() is possible here because no other task 2061 mutex_unlock(&cp->mutex);
2061 can open the device (see above). I don't want 2062 /* mutex_unlock() is possible here because no other task
2062 to kfree() a locked mutex. */ 2063 can open the device (see above). I don't want
2064 to kfree() a locked mutex. */
2065
2063 auerswald_delete (cp); 2066 auerswald_delete (cp);
2064 } else { 2067 } else {
2065 /* device is used. Remove the pointer to the 2068 /* device is used. Remove the pointer to the
2066 usb device (it's not valid any more). The last 2069 usb device (it's not valid any more). The last
2067 release() will do the clean up */ 2070 release() will do the clean up */
2068 cp->usbdev = NULL; 2071 cp->usbdev = NULL;
2069 up (&cp->mutex); 2072 mutex_unlock(&cp->mutex);
2070 /* Terminate waiting writers */ 2073 /* Terminate waiting writers */
2071 wake_up (&cp->bufferwait); 2074 wake_up (&cp->bufferwait);
2072 /* Inform all waiting readers */ 2075 /* Inform all waiting readers */
diff --git a/drivers/usb/misc/emi26.c b/drivers/usb/misc/emi26.c
index 4a09b87bdd28..4b9dc81b8453 100644
--- a/drivers/usb/misc/emi26.c
+++ b/drivers/usb/misc/emi26.c
@@ -70,8 +70,8 @@ static int emi26_writememory (struct usb_device *dev, int address, unsigned char
70static int emi26_set_reset (struct usb_device *dev, unsigned char reset_bit) 70static int emi26_set_reset (struct usb_device *dev, unsigned char reset_bit)
71{ 71{
72 int response; 72 int response;
73 info("%s - %d", __FUNCTION__, reset_bit); 73 info("%s - %d", __func__, reset_bit);
74 /* printk(KERN_DEBUG "%s - %d", __FUNCTION__, reset_bit); */ 74 /* printk(KERN_DEBUG "%s - %d", __func__, reset_bit); */
75 response = emi26_writememory (dev, CPUCS_REG, &reset_bit, 1, 0xa0); 75 response = emi26_writememory (dev, CPUCS_REG, &reset_bit, 1, 0xa0);
76 if (response < 0) { 76 if (response < 0) {
77 err("emi26: set_reset (%d) failed", reset_bit); 77 err("emi26: set_reset (%d) failed", reset_bit);
@@ -91,7 +91,7 @@ static int emi26_load_firmware (struct usb_device *dev)
91 91
92 buf = kmalloc(FW_LOAD_SIZE, GFP_KERNEL); 92 buf = kmalloc(FW_LOAD_SIZE, GFP_KERNEL);
93 if (!buf) { 93 if (!buf) {
94 err( "%s - error loading firmware: error = %d", __FUNCTION__, -ENOMEM); 94 err( "%s - error loading firmware: error = %d", __func__, -ENOMEM);
95 err = -ENOMEM; 95 err = -ENOMEM;
96 goto wraperr; 96 goto wraperr;
97 } 97 }
@@ -99,7 +99,7 @@ static int emi26_load_firmware (struct usb_device *dev)
99 /* Assert reset (stop the CPU in the EMI) */ 99 /* Assert reset (stop the CPU in the EMI) */
100 err = emi26_set_reset(dev,1); 100 err = emi26_set_reset(dev,1);
101 if (err < 0) { 101 if (err < 0) {
102 err( "%s - error loading firmware: error = %d", __FUNCTION__, err); 102 err( "%s - error loading firmware: error = %d", __func__, err);
103 goto wraperr; 103 goto wraperr;
104 } 104 }
105 105
@@ -107,7 +107,7 @@ static int emi26_load_firmware (struct usb_device *dev)
107 for (i=0; g_Loader[i].type == 0; i++) { 107 for (i=0; g_Loader[i].type == 0; i++) {
108 err = emi26_writememory(dev, g_Loader[i].address, g_Loader[i].data, g_Loader[i].length, ANCHOR_LOAD_INTERNAL); 108 err = emi26_writememory(dev, g_Loader[i].address, g_Loader[i].data, g_Loader[i].length, ANCHOR_LOAD_INTERNAL);
109 if (err < 0) { 109 if (err < 0) {
110 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 110 err("%s - error loading firmware: error = %d", __func__, err);
111 goto wraperr; 111 goto wraperr;
112 } 112 }
113 } 113 }
@@ -115,7 +115,7 @@ static int emi26_load_firmware (struct usb_device *dev)
115 /* De-assert reset (let the CPU run) */ 115 /* De-assert reset (let the CPU run) */
116 err = emi26_set_reset(dev,0); 116 err = emi26_set_reset(dev,0);
117 if (err < 0) { 117 if (err < 0) {
118 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 118 err("%s - error loading firmware: error = %d", __func__, err);
119 goto wraperr; 119 goto wraperr;
120 } 120 }
121 msleep(250); /* let device settle */ 121 msleep(250); /* let device settle */
@@ -135,7 +135,7 @@ static int emi26_load_firmware (struct usb_device *dev)
135 } 135 }
136 err = emi26_writememory(dev, addr, buf, i, ANCHOR_LOAD_FPGA); 136 err = emi26_writememory(dev, addr, buf, i, ANCHOR_LOAD_FPGA);
137 if (err < 0) { 137 if (err < 0) {
138 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 138 err("%s - error loading firmware: error = %d", __func__, err);
139 goto wraperr; 139 goto wraperr;
140 } 140 }
141 } while (i > 0); 141 } while (i > 0);
@@ -143,7 +143,7 @@ static int emi26_load_firmware (struct usb_device *dev)
143 /* Assert reset (stop the CPU in the EMI) */ 143 /* Assert reset (stop the CPU in the EMI) */
144 err = emi26_set_reset(dev,1); 144 err = emi26_set_reset(dev,1);
145 if (err < 0) { 145 if (err < 0) {
146 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 146 err("%s - error loading firmware: error = %d", __func__, err);
147 goto wraperr; 147 goto wraperr;
148 } 148 }
149 149
@@ -151,7 +151,7 @@ static int emi26_load_firmware (struct usb_device *dev)
151 for (i=0; g_Loader[i].type == 0; i++) { 151 for (i=0; g_Loader[i].type == 0; i++) {
152 err = emi26_writememory(dev, g_Loader[i].address, g_Loader[i].data, g_Loader[i].length, ANCHOR_LOAD_INTERNAL); 152 err = emi26_writememory(dev, g_Loader[i].address, g_Loader[i].data, g_Loader[i].length, ANCHOR_LOAD_INTERNAL);
153 if (err < 0) { 153 if (err < 0) {
154 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 154 err("%s - error loading firmware: error = %d", __func__, err);
155 goto wraperr; 155 goto wraperr;
156 } 156 }
157 } 157 }
@@ -160,7 +160,7 @@ static int emi26_load_firmware (struct usb_device *dev)
160 /* De-assert reset (let the CPU run) */ 160 /* De-assert reset (let the CPU run) */
161 err = emi26_set_reset(dev,0); 161 err = emi26_set_reset(dev,0);
162 if (err < 0) { 162 if (err < 0) {
163 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 163 err("%s - error loading firmware: error = %d", __func__, err);
164 goto wraperr; 164 goto wraperr;
165 } 165 }
166 166
@@ -169,7 +169,7 @@ static int emi26_load_firmware (struct usb_device *dev)
169 if (!INTERNAL_RAM(g_Firmware[i].address)) { 169 if (!INTERNAL_RAM(g_Firmware[i].address)) {
170 err = emi26_writememory(dev, g_Firmware[i].address, g_Firmware[i].data, g_Firmware[i].length, ANCHOR_LOAD_EXTERNAL); 170 err = emi26_writememory(dev, g_Firmware[i].address, g_Firmware[i].data, g_Firmware[i].length, ANCHOR_LOAD_EXTERNAL);
171 if (err < 0) { 171 if (err < 0) {
172 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 172 err("%s - error loading firmware: error = %d", __func__, err);
173 goto wraperr; 173 goto wraperr;
174 } 174 }
175 } 175 }
@@ -178,7 +178,7 @@ static int emi26_load_firmware (struct usb_device *dev)
178 /* Assert reset (stop the CPU in the EMI) */ 178 /* Assert reset (stop the CPU in the EMI) */
179 err = emi26_set_reset(dev,1); 179 err = emi26_set_reset(dev,1);
180 if (err < 0) { 180 if (err < 0) {
181 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 181 err("%s - error loading firmware: error = %d", __func__, err);
182 goto wraperr; 182 goto wraperr;
183 } 183 }
184 184
@@ -186,7 +186,7 @@ static int emi26_load_firmware (struct usb_device *dev)
186 if (INTERNAL_RAM(g_Firmware[i].address)) { 186 if (INTERNAL_RAM(g_Firmware[i].address)) {
187 err = emi26_writememory(dev, g_Firmware[i].address, g_Firmware[i].data, g_Firmware[i].length, ANCHOR_LOAD_INTERNAL); 187 err = emi26_writememory(dev, g_Firmware[i].address, g_Firmware[i].data, g_Firmware[i].length, ANCHOR_LOAD_INTERNAL);
188 if (err < 0) { 188 if (err < 0) {
189 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 189 err("%s - error loading firmware: error = %d", __func__, err);
190 goto wraperr; 190 goto wraperr;
191 } 191 }
192 } 192 }
@@ -195,7 +195,7 @@ static int emi26_load_firmware (struct usb_device *dev)
195 /* De-assert reset (let the CPU run) */ 195 /* De-assert reset (let the CPU run) */
196 err = emi26_set_reset(dev,0); 196 err = emi26_set_reset(dev,0);
197 if (err < 0) { 197 if (err < 0) {
198 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 198 err("%s - error loading firmware: error = %d", __func__, err);
199 goto wraperr; 199 goto wraperr;
200 } 200 }
201 msleep(250); /* let device settle */ 201 msleep(250); /* let device settle */
@@ -221,7 +221,7 @@ static int emi26_probe(struct usb_interface *intf, const struct usb_device_id *i
221{ 221{
222 struct usb_device *dev = interface_to_usbdev(intf); 222 struct usb_device *dev = interface_to_usbdev(intf);
223 223
224 info("%s start", __FUNCTION__); 224 info("%s start", __func__);
225 225
226 emi26_load_firmware(dev); 226 emi26_load_firmware(dev);
227 227
diff --git a/drivers/usb/misc/emi62.c b/drivers/usb/misc/emi62.c
index d1362415922c..1a2b79ac5e10 100644
--- a/drivers/usb/misc/emi62.c
+++ b/drivers/usb/misc/emi62.c
@@ -78,7 +78,7 @@ static int emi62_writememory (struct usb_device *dev, int address, unsigned char
78static int emi62_set_reset (struct usb_device *dev, unsigned char reset_bit) 78static int emi62_set_reset (struct usb_device *dev, unsigned char reset_bit)
79{ 79{
80 int response; 80 int response;
81 info("%s - %d", __FUNCTION__, reset_bit); 81 info("%s - %d", __func__, reset_bit);
82 82
83 response = emi62_writememory (dev, CPUCS_REG, &reset_bit, 1, 0xa0); 83 response = emi62_writememory (dev, CPUCS_REG, &reset_bit, 1, 0xa0);
84 if (response < 0) { 84 if (response < 0) {
@@ -100,7 +100,7 @@ static int emi62_load_firmware (struct usb_device *dev)
100 dev_dbg(&dev->dev, "load_firmware\n"); 100 dev_dbg(&dev->dev, "load_firmware\n");
101 buf = kmalloc(FW_LOAD_SIZE, GFP_KERNEL); 101 buf = kmalloc(FW_LOAD_SIZE, GFP_KERNEL);
102 if (!buf) { 102 if (!buf) {
103 err( "%s - error loading firmware: error = %d", __FUNCTION__, -ENOMEM); 103 err( "%s - error loading firmware: error = %d", __func__, -ENOMEM);
104 err = -ENOMEM; 104 err = -ENOMEM;
105 goto wraperr; 105 goto wraperr;
106 } 106 }
@@ -108,7 +108,7 @@ static int emi62_load_firmware (struct usb_device *dev)
108 /* Assert reset (stop the CPU in the EMI) */ 108 /* Assert reset (stop the CPU in the EMI) */
109 err = emi62_set_reset(dev,1); 109 err = emi62_set_reset(dev,1);
110 if (err < 0) { 110 if (err < 0) {
111 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 111 err("%s - error loading firmware: error = %d", __func__, err);
112 goto wraperr; 112 goto wraperr;
113 } 113 }
114 114
@@ -116,7 +116,7 @@ static int emi62_load_firmware (struct usb_device *dev)
116 for (i=0; g_emi62_loader[i].type == 0; i++) { 116 for (i=0; g_emi62_loader[i].type == 0; i++) {
117 err = emi62_writememory(dev, g_emi62_loader[i].address, g_emi62_loader[i].data, g_emi62_loader[i].length, ANCHOR_LOAD_INTERNAL); 117 err = emi62_writememory(dev, g_emi62_loader[i].address, g_emi62_loader[i].data, g_emi62_loader[i].length, ANCHOR_LOAD_INTERNAL);
118 if (err < 0) { 118 if (err < 0) {
119 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 119 err("%s - error loading firmware: error = %d", __func__, err);
120 goto wraperr; 120 goto wraperr;
121 } 121 }
122 } 122 }
@@ -124,7 +124,7 @@ static int emi62_load_firmware (struct usb_device *dev)
124 /* De-assert reset (let the CPU run) */ 124 /* De-assert reset (let the CPU run) */
125 err = emi62_set_reset(dev,0); 125 err = emi62_set_reset(dev,0);
126 if (err < 0) { 126 if (err < 0) {
127 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 127 err("%s - error loading firmware: error = %d", __func__, err);
128 goto wraperr; 128 goto wraperr;
129 } 129 }
130 msleep(250); /* let device settle */ 130 msleep(250); /* let device settle */
@@ -144,7 +144,7 @@ static int emi62_load_firmware (struct usb_device *dev)
144 } 144 }
145 err = emi62_writememory(dev, addr, buf, i, ANCHOR_LOAD_FPGA); 145 err = emi62_writememory(dev, addr, buf, i, ANCHOR_LOAD_FPGA);
146 if (err < 0) { 146 if (err < 0) {
147 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 147 err("%s - error loading firmware: error = %d", __func__, err);
148 goto wraperr; 148 goto wraperr;
149 } 149 }
150 } while (i > 0); 150 } while (i > 0);
@@ -152,7 +152,7 @@ static int emi62_load_firmware (struct usb_device *dev)
152 /* Assert reset (stop the CPU in the EMI) */ 152 /* Assert reset (stop the CPU in the EMI) */
153 err = emi62_set_reset(dev,1); 153 err = emi62_set_reset(dev,1);
154 if (err < 0) { 154 if (err < 0) {
155 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 155 err("%s - error loading firmware: error = %d", __func__, err);
156 goto wraperr; 156 goto wraperr;
157 } 157 }
158 158
@@ -160,7 +160,7 @@ static int emi62_load_firmware (struct usb_device *dev)
160 for (i=0; g_emi62_loader[i].type == 0; i++) { 160 for (i=0; g_emi62_loader[i].type == 0; i++) {
161 err = emi62_writememory(dev, g_emi62_loader[i].address, g_emi62_loader[i].data, g_emi62_loader[i].length, ANCHOR_LOAD_INTERNAL); 161 err = emi62_writememory(dev, g_emi62_loader[i].address, g_emi62_loader[i].data, g_emi62_loader[i].length, ANCHOR_LOAD_INTERNAL);
162 if (err < 0) { 162 if (err < 0) {
163 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 163 err("%s - error loading firmware: error = %d", __func__, err);
164 goto wraperr; 164 goto wraperr;
165 } 165 }
166 } 166 }
@@ -168,7 +168,7 @@ static int emi62_load_firmware (struct usb_device *dev)
168 /* De-assert reset (let the CPU run) */ 168 /* De-assert reset (let the CPU run) */
169 err = emi62_set_reset(dev,0); 169 err = emi62_set_reset(dev,0);
170 if (err < 0) { 170 if (err < 0) {
171 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 171 err("%s - error loading firmware: error = %d", __func__, err);
172 goto wraperr; 172 goto wraperr;
173 } 173 }
174 msleep(250); /* let device settle */ 174 msleep(250); /* let device settle */
@@ -181,7 +181,7 @@ static int emi62_load_firmware (struct usb_device *dev)
181 if (!INTERNAL_RAM(g_HexSpdifFw62[i].address)) { 181 if (!INTERNAL_RAM(g_HexSpdifFw62[i].address)) {
182 err = emi62_writememory(dev, g_HexSpdifFw62[i].address, g_HexSpdifFw62[i].data, g_HexSpdifFw62[i].length, ANCHOR_LOAD_EXTERNAL); 182 err = emi62_writememory(dev, g_HexSpdifFw62[i].address, g_HexSpdifFw62[i].data, g_HexSpdifFw62[i].length, ANCHOR_LOAD_EXTERNAL);
183 if (err < 0) { 183 if (err < 0) {
184 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 184 err("%s - error loading firmware: error = %d", __func__, err);
185 goto wraperr; 185 goto wraperr;
186 } 186 }
187 } 187 }
@@ -191,7 +191,7 @@ static int emi62_load_firmware (struct usb_device *dev)
191 if (!INTERNAL_RAM(g_HexMidiFw62[i].address)) { 191 if (!INTERNAL_RAM(g_HexMidiFw62[i].address)) {
192 err = emi62_writememory(dev, g_HexMidiFw62[i].address, g_HexMidiFw62[i].data, g_HexMidiFw62[i].length, ANCHOR_LOAD_EXTERNAL); 192 err = emi62_writememory(dev, g_HexMidiFw62[i].address, g_HexMidiFw62[i].data, g_HexMidiFw62[i].length, ANCHOR_LOAD_EXTERNAL);
193 if (err < 0) { 193 if (err < 0) {
194 err("%s - error loading firmware: error = %d\n", __FUNCTION__, err); 194 err("%s - error loading firmware: error = %d\n", __func__, err);
195 goto wraperr; 195 goto wraperr;
196 return err; 196 return err;
197 } 197 }
@@ -201,7 +201,7 @@ static int emi62_load_firmware (struct usb_device *dev)
201 /* Assert reset (stop the CPU in the EMI) */ 201 /* Assert reset (stop the CPU in the EMI) */
202 err = emi62_set_reset(dev,1); 202 err = emi62_set_reset(dev,1);
203 if (err < 0) { 203 if (err < 0) {
204 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 204 err("%s - error loading firmware: error = %d", __func__, err);
205 goto wraperr; 205 goto wraperr;
206 } 206 }
207 207
@@ -211,7 +211,7 @@ static int emi62_load_firmware (struct usb_device *dev)
211 if (INTERNAL_RAM(g_HexSpdifFw62[i].address)) { 211 if (INTERNAL_RAM(g_HexSpdifFw62[i].address)) {
212 err = emi62_writememory(dev, g_HexSpdifFw62[i].address, g_HexSpdifFw62[i].data, g_HexSpdifFw62[i].length, ANCHOR_LOAD_INTERNAL); 212 err = emi62_writememory(dev, g_HexSpdifFw62[i].address, g_HexSpdifFw62[i].data, g_HexSpdifFw62[i].length, ANCHOR_LOAD_INTERNAL);
213 if (err < 0) { 213 if (err < 0) {
214 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 214 err("%s - error loading firmware: error = %d", __func__, err);
215 goto wraperr; 215 goto wraperr;
216 } 216 }
217 } 217 }
@@ -221,7 +221,7 @@ static int emi62_load_firmware (struct usb_device *dev)
221 if (INTERNAL_RAM(g_HexMidiFw62[i].address)) { 221 if (INTERNAL_RAM(g_HexMidiFw62[i].address)) {
222 err = emi62_writememory(dev, g_HexMidiFw62[i].address, g_HexMidiFw62[i].data, g_HexMidiFw62[i].length, ANCHOR_LOAD_INTERNAL); 222 err = emi62_writememory(dev, g_HexMidiFw62[i].address, g_HexMidiFw62[i].data, g_HexMidiFw62[i].length, ANCHOR_LOAD_INTERNAL);
223 if (err < 0) { 223 if (err < 0) {
224 err("%s - error loading firmware: error = %d\n", __FUNCTION__, err); 224 err("%s - error loading firmware: error = %d\n", __func__, err);
225 goto wraperr; 225 goto wraperr;
226 } 226 }
227 } 227 }
@@ -231,7 +231,7 @@ static int emi62_load_firmware (struct usb_device *dev)
231 /* De-assert reset (let the CPU run) */ 231 /* De-assert reset (let the CPU run) */
232 err = emi62_set_reset(dev,0); 232 err = emi62_set_reset(dev,0);
233 if (err < 0) { 233 if (err < 0) {
234 err("%s - error loading firmware: error = %d", __FUNCTION__, err); 234 err("%s - error loading firmware: error = %d", __func__, err);
235 goto wraperr; 235 goto wraperr;
236 } 236 }
237 msleep(250); /* let device settle */ 237 msleep(250); /* let device settle */
@@ -260,7 +260,7 @@ static int emi62_probe(struct usb_interface *intf, const struct usb_device_id *i
260 struct usb_device *dev = interface_to_usbdev(intf); 260 struct usb_device *dev = interface_to_usbdev(intf);
261 dev_dbg(&intf->dev, "emi62_probe\n"); 261 dev_dbg(&intf->dev, "emi62_probe\n");
262 262
263 info("%s start", __FUNCTION__); 263 info("%s start", __func__);
264 264
265 emi62_load_firmware(dev); 265 emi62_load_firmware(dev);
266 266
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 148b7fe639b2..ec88b3bfee46 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -746,7 +746,7 @@ static ssize_t ftdi_elan_read(struct file *file, char __user *buffer,
746 746
747static void ftdi_elan_write_bulk_callback(struct urb *urb) 747static void ftdi_elan_write_bulk_callback(struct urb *urb)
748{ 748{
749 struct usb_ftdi *ftdi = (struct usb_ftdi *)urb->context; 749 struct usb_ftdi *ftdi = urb->context;
750 int status = urb->status; 750 int status = urb->status;
751 751
752 if (status && !(status == -ENOENT || status == -ECONNRESET || 752 if (status && !(status == -ENOENT || status == -ECONNRESET ||
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 801070502cc1..1cb54a28347f 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -154,7 +154,7 @@ MODULE_DEVICE_TABLE(usb, iowarrior_ids);
154 */ 154 */
155static void iowarrior_callback(struct urb *urb) 155static void iowarrior_callback(struct urb *urb)
156{ 156{
157 struct iowarrior *dev = (struct iowarrior *)urb->context; 157 struct iowarrior *dev = urb->context;
158 int intr_idx; 158 int intr_idx;
159 int read_idx; 159 int read_idx;
160 int aux_idx; 160 int aux_idx;
@@ -218,7 +218,7 @@ exit:
218 retval = usb_submit_urb(urb, GFP_ATOMIC); 218 retval = usb_submit_urb(urb, GFP_ATOMIC);
219 if (retval) 219 if (retval)
220 dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d\n", 220 dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d\n",
221 __FUNCTION__, retval); 221 __func__, retval);
222 222
223} 223}
224 224
@@ -230,7 +230,7 @@ static void iowarrior_write_callback(struct urb *urb)
230 struct iowarrior *dev; 230 struct iowarrior *dev;
231 int status = urb->status; 231 int status = urb->status;
232 232
233 dev = (struct iowarrior *)urb->context; 233 dev = urb->context;
234 /* sync/async unlink faults aren't errors */ 234 /* sync/async unlink faults aren't errors */
235 if (status && 235 if (status &&
236 !(status == -ENOENT || 236 !(status == -ENOENT ||
@@ -453,7 +453,7 @@ static ssize_t iowarrior_write(struct file *file,
453 default: 453 default:
454 /* what do we have here ? An unsupported Product-ID ? */ 454 /* what do we have here ? An unsupported Product-ID ? */
455 dev_err(&dev->interface->dev, "%s - not supported for product=0x%x\n", 455 dev_err(&dev->interface->dev, "%s - not supported for product=0x%x\n",
456 __FUNCTION__, dev->product_id); 456 __func__, dev->product_id);
457 retval = -EFAULT; 457 retval = -EFAULT;
458 goto exit; 458 goto exit;
459 break; 459 break;
@@ -604,7 +604,7 @@ static int iowarrior_open(struct inode *inode, struct file *file)
604 604
605 interface = usb_find_interface(&iowarrior_driver, subminor); 605 interface = usb_find_interface(&iowarrior_driver, subminor);
606 if (!interface) { 606 if (!interface) {
607 err("%s - error, can't find device for minor %d", __FUNCTION__, 607 err("%s - error, can't find device for minor %d", __func__,
608 subminor); 608 subminor);
609 return -ENODEV; 609 return -ENODEV;
610 } 610 }
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index c730d20eec66..11580e81e2c6 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -231,7 +231,7 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
231 goto exit; 231 goto exit;
232 } else { 232 } else {
233 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n", 233 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n",
234 __FUNCTION__, status); 234 __func__, status);
235 spin_lock(&dev->rbsl); 235 spin_lock(&dev->rbsl);
236 goto resubmit; /* maybe we can recover */ 236 goto resubmit; /* maybe we can recover */
237 } 237 }
@@ -247,7 +247,7 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
247 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length); 247 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length);
248 dev->ring_head = next_ring_head; 248 dev->ring_head = next_ring_head;
249 dbg_info(&dev->intf->dev, "%s: received %d bytes\n", 249 dbg_info(&dev->intf->dev, "%s: received %d bytes\n",
250 __FUNCTION__, urb->actual_length); 250 __func__, urb->actual_length);
251 } else { 251 } else {
252 dev_warn(&dev->intf->dev, 252 dev_warn(&dev->intf->dev,
253 "Ring buffer overflow, %d bytes dropped\n", 253 "Ring buffer overflow, %d bytes dropped\n",
@@ -286,7 +286,7 @@ static void ld_usb_interrupt_out_callback(struct urb *urb)
286 status == -ESHUTDOWN)) 286 status == -ESHUTDOWN))
287 dbg_info(&dev->intf->dev, 287 dbg_info(&dev->intf->dev,
288 "%s - nonzero write interrupt status received: %d\n", 288 "%s - nonzero write interrupt status received: %d\n",
289 __FUNCTION__, status); 289 __func__, status);
290 290
291 dev->interrupt_out_busy = 0; 291 dev->interrupt_out_busy = 0;
292 wake_up_interruptible(&dev->write_wait); 292 wake_up_interruptible(&dev->write_wait);
@@ -309,7 +309,7 @@ static int ld_usb_open(struct inode *inode, struct file *file)
309 309
310 if (!interface) { 310 if (!interface) {
311 err("%s - error, can't find device for minor %d\n", 311 err("%s - error, can't find device for minor %d\n",
312 __FUNCTION__, subminor); 312 __func__, subminor);
313 return -ENODEV; 313 return -ENODEV;
314 } 314 }
315 315
@@ -556,7 +556,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
556 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size); 556 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
557 if (bytes_to_write < count) 557 if (bytes_to_write < count)
558 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write); 558 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write);
559 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __FUNCTION__, count, bytes_to_write); 559 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __func__, count, bytes_to_write);
560 560
561 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) { 561 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
562 retval = -EFAULT; 562 retval = -EFAULT;
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 6664043f4645..9370326a5940 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -31,7 +31,7 @@
31 * - imported into lejos project 31 * - imported into lejos project
32 * - changed wake_up to wake_up_interruptible 32 * - changed wake_up to wake_up_interruptible
33 * - changed to use lego0 rather than tower0 33 * - changed to use lego0 rather than tower0
34 * - changed dbg() to use __func__ rather than deprecated __FUNCTION__ 34 * - changed dbg() to use __func__ rather than deprecated __func__
35 * 2003-01-12 - 0.53 david (david@csse.uwa.edu.au) 35 * 2003-01-12 - 0.53 david (david@csse.uwa.edu.au)
36 * - changed read and write to write everything or 36 * - changed read and write to write everything or
37 * timeout (from a patch by Chris Riesen and Brett Thaeler driver) 37 * timeout (from a patch by Chris Riesen and Brett Thaeler driver)
@@ -49,7 +49,7 @@
49 * - added poll 49 * - added poll
50 * - forbid seeking 50 * - forbid seeking
51 * - added nonblocking I/O 51 * - added nonblocking I/O
52 * - changed back __func__ to __FUNCTION__ 52 * - changed back __func__ to __func__
53 * - read and log tower firmware version 53 * - read and log tower firmware version
54 * - reset tower on probe, avoids failure of first write 54 * - reset tower on probe, avoids failure of first write
55 * 2004-03-09 - 0.7 Juergen Stuber <starblue@users.sourceforge.net> 55 * 2004-03-09 - 0.7 Juergen Stuber <starblue@users.sourceforge.net>
@@ -309,7 +309,7 @@ static inline void lego_usb_tower_debug_data (int level, const char *function, i
309 */ 309 */
310static inline void tower_delete (struct lego_usb_tower *dev) 310static inline void tower_delete (struct lego_usb_tower *dev)
311{ 311{
312 dbg(2, "%s: enter", __FUNCTION__); 312 dbg(2, "%s: enter", __func__);
313 313
314 tower_abort_transfers (dev); 314 tower_abort_transfers (dev);
315 315
@@ -321,7 +321,7 @@ static inline void tower_delete (struct lego_usb_tower *dev)
321 kfree (dev->interrupt_out_buffer); 321 kfree (dev->interrupt_out_buffer);
322 kfree (dev); 322 kfree (dev);
323 323
324 dbg(2, "%s: leave", __FUNCTION__); 324 dbg(2, "%s: leave", __func__);
325} 325}
326 326
327 327
@@ -337,7 +337,7 @@ static int tower_open (struct inode *inode, struct file *file)
337 struct tower_reset_reply reset_reply; 337 struct tower_reset_reply reset_reply;
338 int result; 338 int result;
339 339
340 dbg(2, "%s: enter", __FUNCTION__); 340 dbg(2, "%s: enter", __func__);
341 341
342 nonseekable_open(inode, file); 342 nonseekable_open(inode, file);
343 subminor = iminor(inode); 343 subminor = iminor(inode);
@@ -346,7 +346,7 @@ static int tower_open (struct inode *inode, struct file *file)
346 346
347 if (!interface) { 347 if (!interface) {
348 err ("%s - error, can't find device for minor %d", 348 err ("%s - error, can't find device for minor %d",
349 __FUNCTION__, subminor); 349 __func__, subminor);
350 retval = -ENODEV; 350 retval = -ENODEV;
351 goto exit; 351 goto exit;
352 } 352 }
@@ -424,7 +424,7 @@ unlock_exit:
424 mutex_unlock(&dev->lock); 424 mutex_unlock(&dev->lock);
425 425
426exit: 426exit:
427 dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval); 427 dbg(2, "%s: leave, return value %d ", __func__, retval);
428 428
429 return retval; 429 return retval;
430} 430}
@@ -437,12 +437,12 @@ static int tower_release (struct inode *inode, struct file *file)
437 struct lego_usb_tower *dev; 437 struct lego_usb_tower *dev;
438 int retval = 0; 438 int retval = 0;
439 439
440 dbg(2, "%s: enter", __FUNCTION__); 440 dbg(2, "%s: enter", __func__);
441 441
442 dev = (struct lego_usb_tower *)file->private_data; 442 dev = (struct lego_usb_tower *)file->private_data;
443 443
444 if (dev == NULL) { 444 if (dev == NULL) {
445 dbg(1, "%s: object is NULL", __FUNCTION__); 445 dbg(1, "%s: object is NULL", __func__);
446 retval = -ENODEV; 446 retval = -ENODEV;
447 goto exit_nolock; 447 goto exit_nolock;
448 } 448 }
@@ -454,7 +454,7 @@ static int tower_release (struct inode *inode, struct file *file)
454 } 454 }
455 455
456 if (dev->open_count != 1) { 456 if (dev->open_count != 1) {
457 dbg(1, "%s: device not opened exactly once", __FUNCTION__); 457 dbg(1, "%s: device not opened exactly once", __func__);
458 retval = -ENODEV; 458 retval = -ENODEV;
459 goto unlock_exit; 459 goto unlock_exit;
460 } 460 }
@@ -480,7 +480,7 @@ unlock_exit:
480exit: 480exit:
481 mutex_unlock(&open_disc_mutex); 481 mutex_unlock(&open_disc_mutex);
482exit_nolock: 482exit_nolock:
483 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval); 483 dbg(2, "%s: leave, return value %d", __func__, retval);
484 return retval; 484 return retval;
485} 485}
486 486
@@ -491,10 +491,10 @@ exit_nolock:
491 */ 491 */
492static void tower_abort_transfers (struct lego_usb_tower *dev) 492static void tower_abort_transfers (struct lego_usb_tower *dev)
493{ 493{
494 dbg(2, "%s: enter", __FUNCTION__); 494 dbg(2, "%s: enter", __func__);
495 495
496 if (dev == NULL) { 496 if (dev == NULL) {
497 dbg(1, "%s: dev is null", __FUNCTION__); 497 dbg(1, "%s: dev is null", __func__);
498 goto exit; 498 goto exit;
499 } 499 }
500 500
@@ -509,7 +509,7 @@ static void tower_abort_transfers (struct lego_usb_tower *dev)
509 usb_kill_urb(dev->interrupt_out_urb); 509 usb_kill_urb(dev->interrupt_out_urb);
510 510
511exit: 511exit:
512 dbg(2, "%s: leave", __FUNCTION__); 512 dbg(2, "%s: leave", __func__);
513} 513}
514 514
515 515
@@ -542,7 +542,7 @@ static unsigned int tower_poll (struct file *file, poll_table *wait)
542 struct lego_usb_tower *dev; 542 struct lego_usb_tower *dev;
543 unsigned int mask = 0; 543 unsigned int mask = 0;
544 544
545 dbg(2, "%s: enter", __FUNCTION__); 545 dbg(2, "%s: enter", __func__);
546 546
547 dev = file->private_data; 547 dev = file->private_data;
548 548
@@ -557,7 +557,7 @@ static unsigned int tower_poll (struct file *file, poll_table *wait)
557 mask |= POLLOUT | POLLWRNORM; 557 mask |= POLLOUT | POLLWRNORM;
558 } 558 }
559 559
560 dbg(2, "%s: leave, mask = %d", __FUNCTION__, mask); 560 dbg(2, "%s: leave, mask = %d", __func__, mask);
561 561
562 return mask; 562 return mask;
563} 563}
@@ -583,7 +583,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
583 int retval = 0; 583 int retval = 0;
584 unsigned long timeout = 0; 584 unsigned long timeout = 0;
585 585
586 dbg(2, "%s: enter, count = %Zd", __FUNCTION__, count); 586 dbg(2, "%s: enter, count = %Zd", __func__, count);
587 587
588 dev = (struct lego_usb_tower *)file->private_data; 588 dev = (struct lego_usb_tower *)file->private_data;
589 589
@@ -602,7 +602,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
602 602
603 /* verify that we actually have some data to read */ 603 /* verify that we actually have some data to read */
604 if (count == 0) { 604 if (count == 0) {
605 dbg(1, "%s: read request of 0 bytes", __FUNCTION__); 605 dbg(1, "%s: read request of 0 bytes", __func__);
606 goto unlock_exit; 606 goto unlock_exit;
607 } 607 }
608 608
@@ -658,7 +658,7 @@ unlock_exit:
658 mutex_unlock(&dev->lock); 658 mutex_unlock(&dev->lock);
659 659
660exit: 660exit:
661 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval); 661 dbg(2, "%s: leave, return value %d", __func__, retval);
662 return retval; 662 return retval;
663} 663}
664 664
@@ -672,7 +672,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
672 size_t bytes_to_write; 672 size_t bytes_to_write;
673 int retval = 0; 673 int retval = 0;
674 674
675 dbg(2, "%s: enter, count = %Zd", __FUNCTION__, count); 675 dbg(2, "%s: enter, count = %Zd", __func__, count);
676 676
677 dev = (struct lego_usb_tower *)file->private_data; 677 dev = (struct lego_usb_tower *)file->private_data;
678 678
@@ -691,7 +691,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
691 691
692 /* verify that we actually have some data to write */ 692 /* verify that we actually have some data to write */
693 if (count == 0) { 693 if (count == 0) {
694 dbg(1, "%s: write request of 0 bytes", __FUNCTION__); 694 dbg(1, "%s: write request of 0 bytes", __func__);
695 goto unlock_exit; 695 goto unlock_exit;
696 } 696 }
697 697
@@ -709,7 +709,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
709 709
710 /* write the data into interrupt_out_buffer from userspace */ 710 /* write the data into interrupt_out_buffer from userspace */
711 bytes_to_write = min_t(int, count, write_buffer_size); 711 bytes_to_write = min_t(int, count, write_buffer_size);
712 dbg(4, "%s: count = %Zd, bytes_to_write = %Zd", __FUNCTION__, count, bytes_to_write); 712 dbg(4, "%s: count = %Zd, bytes_to_write = %Zd", __func__, count, bytes_to_write);
713 713
714 if (copy_from_user (dev->interrupt_out_buffer, buffer, bytes_to_write)) { 714 if (copy_from_user (dev->interrupt_out_buffer, buffer, bytes_to_write)) {
715 retval = -EFAULT; 715 retval = -EFAULT;
@@ -742,7 +742,7 @@ unlock_exit:
742 mutex_unlock(&dev->lock); 742 mutex_unlock(&dev->lock);
743 743
744exit: 744exit:
745 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval); 745 dbg(2, "%s: leave, return value %d", __func__, retval);
746 746
747 return retval; 747 return retval;
748} 748}
@@ -753,13 +753,13 @@ exit:
753 */ 753 */
754static void tower_interrupt_in_callback (struct urb *urb) 754static void tower_interrupt_in_callback (struct urb *urb)
755{ 755{
756 struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; 756 struct lego_usb_tower *dev = urb->context;
757 int status = urb->status; 757 int status = urb->status;
758 int retval; 758 int retval;
759 759
760 dbg(4, "%s: enter, status %d", __FUNCTION__, status); 760 dbg(4, "%s: enter, status %d", __func__, status);
761 761
762 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 762 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
763 763
764 if (status) { 764 if (status) {
765 if (status == -ENOENT || 765 if (status == -ENOENT ||
@@ -767,7 +767,7 @@ static void tower_interrupt_in_callback (struct urb *urb)
767 status == -ESHUTDOWN) { 767 status == -ESHUTDOWN) {
768 goto exit; 768 goto exit;
769 } else { 769 } else {
770 dbg(1, "%s: nonzero status received: %d", __FUNCTION__, status); 770 dbg(1, "%s: nonzero status received: %d", __func__, status);
771 goto resubmit; /* maybe we can recover */ 771 goto resubmit; /* maybe we can recover */
772 } 772 }
773 } 773 }
@@ -780,9 +780,9 @@ static void tower_interrupt_in_callback (struct urb *urb)
780 urb->actual_length); 780 urb->actual_length);
781 dev->read_buffer_length += urb->actual_length; 781 dev->read_buffer_length += urb->actual_length;
782 dev->read_last_arrival = jiffies; 782 dev->read_last_arrival = jiffies;
783 dbg(3, "%s: received %d bytes", __FUNCTION__, urb->actual_length); 783 dbg(3, "%s: received %d bytes", __func__, urb->actual_length);
784 } else { 784 } else {
785 printk(KERN_WARNING "%s: read_buffer overflow, %d bytes dropped", __FUNCTION__, urb->actual_length); 785 printk(KERN_WARNING "%s: read_buffer overflow, %d bytes dropped", __func__, urb->actual_length);
786 } 786 }
787 spin_unlock (&dev->read_buffer_lock); 787 spin_unlock (&dev->read_buffer_lock);
788 } 788 }
@@ -792,7 +792,7 @@ resubmit:
792 if (dev->interrupt_in_running && dev->udev) { 792 if (dev->interrupt_in_running && dev->udev) {
793 retval = usb_submit_urb (dev->interrupt_in_urb, GFP_ATOMIC); 793 retval = usb_submit_urb (dev->interrupt_in_urb, GFP_ATOMIC);
794 if (retval) { 794 if (retval) {
795 err("%s: usb_submit_urb failed (%d)", __FUNCTION__, retval); 795 err("%s: usb_submit_urb failed (%d)", __func__, retval);
796 } 796 }
797 } 797 }
798 798
@@ -800,8 +800,8 @@ exit:
800 dev->interrupt_in_done = 1; 800 dev->interrupt_in_done = 1;
801 wake_up_interruptible (&dev->read_wait); 801 wake_up_interruptible (&dev->read_wait);
802 802
803 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 803 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
804 dbg(4, "%s: leave, status %d", __FUNCTION__, status); 804 dbg(4, "%s: leave, status %d", __func__, status);
805} 805}
806 806
807 807
@@ -810,25 +810,25 @@ exit:
810 */ 810 */
811static void tower_interrupt_out_callback (struct urb *urb) 811static void tower_interrupt_out_callback (struct urb *urb)
812{ 812{
813 struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; 813 struct lego_usb_tower *dev = urb->context;
814 int status = urb->status; 814 int status = urb->status;
815 815
816 dbg(4, "%s: enter, status %d", __FUNCTION__, status); 816 dbg(4, "%s: enter, status %d", __func__, status);
817 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 817 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
818 818
819 /* sync/async unlink faults aren't errors */ 819 /* sync/async unlink faults aren't errors */
820 if (status && !(status == -ENOENT || 820 if (status && !(status == -ENOENT ||
821 status == -ECONNRESET || 821 status == -ECONNRESET ||
822 status == -ESHUTDOWN)) { 822 status == -ESHUTDOWN)) {
823 dbg(1, "%s - nonzero write bulk status received: %d", 823 dbg(1, "%s - nonzero write bulk status received: %d",
824 __FUNCTION__, status); 824 __func__, status);
825 } 825 }
826 826
827 dev->interrupt_out_busy = 0; 827 dev->interrupt_out_busy = 0;
828 wake_up_interruptible(&dev->write_wait); 828 wake_up_interruptible(&dev->write_wait);
829 829
830 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 830 lego_usb_tower_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
831 dbg(4, "%s: leave, status %d", __FUNCTION__, status); 831 dbg(4, "%s: leave, status %d", __func__, status);
832} 832}
833 833
834 834
@@ -849,7 +849,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
849 int retval = -ENOMEM; 849 int retval = -ENOMEM;
850 int result; 850 int result;
851 851
852 dbg(2, "%s: enter", __FUNCTION__); 852 dbg(2, "%s: enter", __func__);
853 853
854 if (udev == NULL) { 854 if (udev == NULL) {
855 info ("udev is NULL."); 855 info ("udev is NULL.");
@@ -978,7 +978,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
978 978
979 979
980exit: 980exit:
981 dbg(2, "%s: leave, return value 0x%.8lx (dev)", __FUNCTION__, (long) dev); 981 dbg(2, "%s: leave, return value 0x%.8lx (dev)", __func__, (long) dev);
982 982
983 return retval; 983 return retval;
984 984
@@ -998,7 +998,7 @@ static void tower_disconnect (struct usb_interface *interface)
998 struct lego_usb_tower *dev; 998 struct lego_usb_tower *dev;
999 int minor; 999 int minor;
1000 1000
1001 dbg(2, "%s: enter", __FUNCTION__); 1001 dbg(2, "%s: enter", __func__);
1002 1002
1003 dev = usb_get_intfdata (interface); 1003 dev = usb_get_intfdata (interface);
1004 mutex_lock(&open_disc_mutex); 1004 mutex_lock(&open_disc_mutex);
@@ -1023,7 +1023,7 @@ static void tower_disconnect (struct usb_interface *interface)
1023 1023
1024 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE)); 1024 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE));
1025 1025
1026 dbg(2, "%s: leave", __FUNCTION__); 1026 dbg(2, "%s: leave", __func__);
1027} 1027}
1028 1028
1029 1029
@@ -1036,7 +1036,7 @@ static int __init lego_usb_tower_init(void)
1036 int result; 1036 int result;
1037 int retval = 0; 1037 int retval = 0;
1038 1038
1039 dbg(2, "%s: enter", __FUNCTION__); 1039 dbg(2, "%s: enter", __func__);
1040 1040
1041 /* register this driver with the USB subsystem */ 1041 /* register this driver with the USB subsystem */
1042 result = usb_register(&tower_driver); 1042 result = usb_register(&tower_driver);
@@ -1049,7 +1049,7 @@ static int __init lego_usb_tower_init(void)
1049 info(DRIVER_DESC " " DRIVER_VERSION); 1049 info(DRIVER_DESC " " DRIVER_VERSION);
1050 1050
1051exit: 1051exit:
1052 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval); 1052 dbg(2, "%s: leave, return value %d", __func__, retval);
1053 1053
1054 return retval; 1054 return retval;
1055} 1055}
@@ -1060,12 +1060,12 @@ exit:
1060 */ 1060 */
1061static void __exit lego_usb_tower_exit(void) 1061static void __exit lego_usb_tower_exit(void)
1062{ 1062{
1063 dbg(2, "%s: enter", __FUNCTION__); 1063 dbg(2, "%s: enter", __func__);
1064 1064
1065 /* deregister this driver with the USB subsystem */ 1065 /* deregister this driver with the USB subsystem */
1066 usb_deregister (&tower_driver); 1066 usb_deregister (&tower_driver);
1067 1067
1068 dbg(2, "%s: leave", __FUNCTION__); 1068 dbg(2, "%s: leave", __func__);
1069} 1069}
1070 1070
1071module_init (lego_usb_tower_init); 1071module_init (lego_usb_tower_init);
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
index aa9bcceabe74..24230c638b8e 100644
--- a/drivers/usb/misc/phidgetkit.c
+++ b/drivers/usb/misc/phidgetkit.c
@@ -113,7 +113,7 @@ static int set_outputs(struct interfacekit *kit)
113 113
114 buffer = kzalloc(4, GFP_KERNEL); 114 buffer = kzalloc(4, GFP_KERNEL);
115 if (!buffer) { 115 if (!buffer) {
116 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__); 116 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
117 return -ENOMEM; 117 return -ENOMEM;
118 } 118 }
119 buffer[0] = (u8)kit->outputs; 119 buffer[0] = (u8)kit->outputs;
@@ -146,7 +146,7 @@ static int change_string(struct interfacekit *kit, const char *display, unsigned
146 buffer = kmalloc(8, GFP_KERNEL); 146 buffer = kmalloc(8, GFP_KERNEL);
147 form_buffer = kmalloc(30, GFP_KERNEL); 147 form_buffer = kmalloc(30, GFP_KERNEL);
148 if ((!buffer) || (!form_buffer)) { 148 if ((!buffer) || (!form_buffer)) {
149 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__); 149 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
150 goto exit; 150 goto exit;
151 } 151 }
152 152
@@ -216,7 +216,7 @@ static ssize_t set_backlight(struct device *dev, struct device_attribute *attr,
216 216
217 buffer = kzalloc(8, GFP_KERNEL); 217 buffer = kzalloc(8, GFP_KERNEL);
218 if (!buffer) { 218 if (!buffer) {
219 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__); 219 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
220 goto exit; 220 goto exit;
221 } 221 }
222 222
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c
index 2ad09b1f4848..f0113c17cc5a 100644
--- a/drivers/usb/misc/phidgetmotorcontrol.c
+++ b/drivers/usb/misc/phidgetmotorcontrol.c
@@ -61,7 +61,7 @@ static int set_motor(struct motorcontrol *mc, int motor)
61 61
62 buffer = kzalloc(8, GFP_KERNEL); 62 buffer = kzalloc(8, GFP_KERNEL);
63 if (!buffer) { 63 if (!buffer) {
64 dev_err(&mc->intf->dev, "%s - out of memory\n", __FUNCTION__); 64 dev_err(&mc->intf->dev, "%s - out of memory\n", __func__);
65 return -ENOMEM; 65 return -ENOMEM;
66 } 66 }
67 67
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
index 0d9de2f73930..7d590c09434a 100644
--- a/drivers/usb/misc/phidgetservo.c
+++ b/drivers/usb/misc/phidgetservo.c
@@ -89,7 +89,7 @@ change_position_v30(struct phidget_servo *servo, int servo_no, int degrees,
89 buffer = kmalloc(6, GFP_KERNEL); 89 buffer = kmalloc(6, GFP_KERNEL);
90 if (!buffer) { 90 if (!buffer) {
91 dev_err(&servo->udev->dev, "%s - out of memory\n", 91 dev_err(&servo->udev->dev, "%s - out of memory\n",
92 __FUNCTION__); 92 __func__);
93 return -ENOMEM; 93 return -ENOMEM;
94 } 94 }
95 95
@@ -162,7 +162,7 @@ change_position_v20(struct phidget_servo *servo, int servo_no, int degrees,
162 buffer = kmalloc(2, GFP_KERNEL); 162 buffer = kmalloc(2, GFP_KERNEL);
163 if (!buffer) { 163 if (!buffer) {
164 dev_err(&servo->udev->dev, "%s - out of memory\n", 164 dev_err(&servo->udev->dev, "%s - out of memory\n",
165 __FUNCTION__); 165 __func__);
166 return -ENOMEM; 166 return -ENOMEM;
167 } 167 }
168 168
@@ -259,7 +259,7 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
259 259
260 dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL); 260 dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL);
261 if (dev == NULL) { 261 if (dev == NULL) {
262 dev_err(&interface->dev, "%s - out of memory\n", __FUNCTION__); 262 dev_err(&interface->dev, "%s - out of memory\n", __func__);
263 rc = -ENOMEM; 263 rc = -ENOMEM;
264 goto out; 264 goto out;
265 } 265 }
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 20777d01db62..7f7021ee4189 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -78,7 +78,7 @@ static int lcd_open(struct inode *inode, struct file *file)
78 interface = usb_find_interface(&lcd_driver, subminor); 78 interface = usb_find_interface(&lcd_driver, subminor);
79 if (!interface) { 79 if (!interface) {
80 err ("USBLCD: %s - error, can't find device for minor %d", 80 err ("USBLCD: %s - error, can't find device for minor %d",
81 __FUNCTION__, subminor); 81 __func__, subminor);
82 return -ENODEV; 82 return -ENODEV;
83 } 83 }
84 84
@@ -185,7 +185,7 @@ static void lcd_write_bulk_callback(struct urb *urb)
185 struct usb_lcd *dev; 185 struct usb_lcd *dev;
186 int status = urb->status; 186 int status = urb->status;
187 187
188 dev = (struct usb_lcd *)urb->context; 188 dev = urb->context;
189 189
190 /* sync/async unlink faults aren't errors */ 190 /* sync/async unlink faults aren't errors */
191 if (status && 191 if (status &&
@@ -193,7 +193,7 @@ static void lcd_write_bulk_callback(struct urb *urb)
193 status == -ECONNRESET || 193 status == -ECONNRESET ||
194 status == -ESHUTDOWN)) { 194 status == -ESHUTDOWN)) {
195 dbg("USBLCD: %s - nonzero write bulk status received: %d", 195 dbg("USBLCD: %s - nonzero write bulk status received: %d",
196 __FUNCTION__, status); 196 __func__, status);
197 } 197 }
198 198
199 /* free up our allocated buffer */ 199 /* free up our allocated buffer */
@@ -248,7 +248,7 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz
248 /* send the data out the bulk port */ 248 /* send the data out the bulk port */
249 retval = usb_submit_urb(urb, GFP_KERNEL); 249 retval = usb_submit_urb(urb, GFP_KERNEL);
250 if (retval) { 250 if (retval) {
251 err("USBLCD: %s - failed submitting write urb, error %d", __FUNCTION__, retval); 251 err("USBLCD: %s - failed submitting write urb, error %d", __func__, retval);
252 goto error_unanchor; 252 goto error_unanchor;
253 } 253 }
254 254
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index b6b5b2affad1..a51983854ca0 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -201,7 +201,7 @@ found:
201 201
202static void simple_callback (struct urb *urb) 202static void simple_callback (struct urb *urb)
203{ 203{
204 complete ((struct completion *) urb->context); 204 complete(urb->context);
205} 205}
206 206
207static struct urb *simple_alloc_urb ( 207static struct urb *simple_alloc_urb (
@@ -1046,7 +1046,7 @@ static void unlink1_callback (struct urb *urb)
1046 status = usb_submit_urb (urb, GFP_ATOMIC); 1046 status = usb_submit_urb (urb, GFP_ATOMIC);
1047 if (status) { 1047 if (status) {
1048 urb->status = status; 1048 urb->status = status;
1049 complete ((struct completion *) urb->context); 1049 complete(urb->context);
1050 } 1050 }
1051} 1051}
1052 1052
@@ -1136,7 +1136,7 @@ static int verify_not_halted (int ep, struct urb *urb)
1136 dbg ("ep %02x bogus status: %04x != 0", ep, status); 1136 dbg ("ep %02x bogus status: %04x != 0", ep, status);
1137 return -EINVAL; 1137 return -EINVAL;
1138 } 1138 }
1139 retval = simple_io (urb, 1, 0, 0, __FUNCTION__); 1139 retval = simple_io (urb, 1, 0, 0, __func__);
1140 if (retval != 0) 1140 if (retval != 0)
1141 return -EINVAL; 1141 return -EINVAL;
1142 return 0; 1142 return 0;
@@ -1158,7 +1158,7 @@ static int verify_halted (int ep, struct urb *urb)
1158 dbg ("ep %02x bogus status: %04x != 1", ep, status); 1158 dbg ("ep %02x bogus status: %04x != 1", ep, status);
1159 return -EINVAL; 1159 return -EINVAL;
1160 } 1160 }
1161 retval = simple_io (urb, 1, 0, -EPIPE, __FUNCTION__); 1161 retval = simple_io (urb, 1, 0, -EPIPE, __func__);
1162 if (retval != -EPIPE) 1162 if (retval != -EPIPE)
1163 return -EINVAL; 1163 return -EINVAL;
1164 retval = simple_io (urb, 1, 0, -EPIPE, "verify_still_halted"); 1164 retval = simple_io (urb, 1, 0, -EPIPE, "verify_still_halted");
@@ -1404,7 +1404,7 @@ static struct urb *iso_alloc_urb (
1404 return NULL; 1404 return NULL;
1405 maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); 1405 maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize);
1406 maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11)); 1406 maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11));
1407 packets = (bytes + maxp - 1) / maxp; 1407 packets = DIV_ROUND_UP(bytes, maxp);
1408 1408
1409 urb = usb_alloc_urb (packets, GFP_KERNEL); 1409 urb = usb_alloc_urb (packets, GFP_KERNEL);
1410 if (!urb) 1410 if (!urb)
@@ -1564,7 +1564,8 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1564 if (mutex_lock_interruptible(&dev->lock)) 1564 if (mutex_lock_interruptible(&dev->lock))
1565 return -ERESTARTSYS; 1565 return -ERESTARTSYS;
1566 1566
1567 if (intf->dev.power.power_state.event != PM_EVENT_ON) { 1567 /* FIXME: What if a system sleep starts while a test is running? */
1568 if (!intf->is_active) {
1568 mutex_unlock(&dev->lock); 1569 mutex_unlock(&dev->lock);
1569 return -EHOSTUNREACH; 1570 return -EHOSTUNREACH;
1570 } 1571 }
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile
index 90c59535778d..0f76ed5e1617 100644
--- a/drivers/usb/mon/Makefile
+++ b/drivers/usb/mon/Makefile
@@ -1,5 +1,5 @@
1# 1#
2# Makefile for USB Core files and filesystem 2# Makefile for USB monitor
3# 3#
4 4
5usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o mon_dma.o 5usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o mon_dma.o
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 1774ba5c4c3b..49145534e06e 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -1026,8 +1026,6 @@ mon_bin_poll(struct file *file, struct poll_table_struct *wait)
1026 return mask; 1026 return mask;
1027} 1027}
1028 1028
1029#if 0
1030
1031/* 1029/*
1032 * open and close: just keep track of how many times the device is 1030 * open and close: just keep track of how many times the device is
1033 * mapped, to use the proper memory allocation function. 1031 * mapped, to use the proper memory allocation function.
@@ -1063,13 +1061,13 @@ static int mon_bin_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1063 return 0; 1061 return 0;
1064} 1062}
1065 1063
1066struct vm_operations_struct mon_bin_vm_ops = { 1064static struct vm_operations_struct mon_bin_vm_ops = {
1067 .open = mon_bin_vma_open, 1065 .open = mon_bin_vma_open,
1068 .close = mon_bin_vma_close, 1066 .close = mon_bin_vma_close,
1069 .fault = mon_bin_vma_fault, 1067 .fault = mon_bin_vma_fault,
1070}; 1068};
1071 1069
1072int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma) 1070static int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
1073{ 1071{
1074 /* don't do anything here: "fault" will set up page table entries */ 1072 /* don't do anything here: "fault" will set up page table entries */
1075 vma->vm_ops = &mon_bin_vm_ops; 1073 vma->vm_ops = &mon_bin_vm_ops;
@@ -1079,8 +1077,6 @@ int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
1079 return 0; 1077 return 0;
1080} 1078}
1081 1079
1082#endif /* 0 */
1083
1084static const struct file_operations mon_fops_binary = { 1080static const struct file_operations mon_fops_binary = {
1085 .owner = THIS_MODULE, 1081 .owner = THIS_MODULE,
1086 .open = mon_bin_open, 1082 .open = mon_bin_open,
@@ -1090,6 +1086,7 @@ static const struct file_operations mon_fops_binary = {
1090 .poll = mon_bin_poll, 1086 .poll = mon_bin_poll,
1091 .ioctl = mon_bin_ioctl, 1087 .ioctl = mon_bin_ioctl,
1092 .release = mon_bin_release, 1088 .release = mon_bin_release,
1089 .mmap = mon_bin_mmap,
1093}; 1090};
1094 1091
1095static int mon_bin_wait_event(struct file *file, struct mon_reader_bin *rp) 1092static int mon_bin_wait_event(struct file *file, struct mon_reader_bin *rp)
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index b371ffd39d36..442d8076b201 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -129,8 +129,7 @@ static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error)
129 129
130/* 130/*
131 */ 131 */
132static void mon_bus_complete(struct mon_bus *mbus, struct urb *urb, 132static void mon_bus_complete(struct mon_bus *mbus, struct urb *urb, int status)
133 int status)
134{ 133{
135 unsigned long flags; 134 unsigned long flags;
136 struct list_head *pos; 135 struct list_head *pos;
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c
index f6d1491256c4..c7a595cd648a 100644
--- a/drivers/usb/mon/mon_stat.c
+++ b/drivers/usb/mon/mon_stat.c
@@ -59,6 +59,9 @@ static ssize_t mon_stat_read(struct file *file, char __user *buf,
59 59
60static int mon_stat_release(struct inode *inode, struct file *file) 60static int mon_stat_release(struct inode *inode, struct file *file)
61{ 61{
62 struct snap *sp = file->private_data;
63 file->private_data = NULL;
64 kfree(sp);
62 return 0; 65 return 0;
63} 66}
64 67
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index c1e65dfd9353..2cffec85ee7e 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -20,8 +20,8 @@ menuconfig USB_SERIAL
20if USB_SERIAL 20if USB_SERIAL
21 21
22config USB_SERIAL_CONSOLE 22config USB_SERIAL_CONSOLE
23 bool "USB Serial Console device support (EXPERIMENTAL)" 23 bool "USB Serial Console device support"
24 depends on USB_SERIAL=y && EXPERIMENTAL 24 depends on USB_SERIAL=y
25 ---help--- 25 ---help---
26 If you say Y here, it will be possible to use a USB to serial 26 If you say Y here, it will be possible to use a USB to serial
27 converter port as the system console (the system console is the 27 converter port as the system console (the system console is the
@@ -44,13 +44,11 @@ config USB_SERIAL_CONSOLE
44 44
45config USB_EZUSB 45config USB_EZUSB
46 bool "Functions for loading firmware on EZUSB chips" 46 bool "Functions for loading firmware on EZUSB chips"
47 depends on USB_SERIAL
48 help 47 help
49 Say Y here if you need EZUSB device support. 48 Say Y here if you need EZUSB device support.
50 49
51config USB_SERIAL_GENERIC 50config USB_SERIAL_GENERIC
52 bool "USB Generic Serial Driver" 51 bool "USB Generic Serial Driver"
53 depends on USB_SERIAL
54 help 52 help
55 Say Y here if you want to use the generic USB serial driver. Please 53 Say Y here if you want to use the generic USB serial driver. Please
56 read <file:Documentation/usb/usb-serial.txt> for more information on 54 read <file:Documentation/usb/usb-serial.txt> for more information on
@@ -59,8 +57,7 @@ config USB_SERIAL_GENERIC
59 properly. 57 properly.
60 58
61config USB_SERIAL_AIRCABLE 59config USB_SERIAL_AIRCABLE
62 tristate "USB AIRcable Bluetooth Dongle Driver (EXPERIMENTAL)" 60 tristate "USB AIRcable Bluetooth Dongle Driver"
63 depends on USB_SERIAL && EXPERIMENTAL
64 help 61 help
65 Say Y here if you want to use USB AIRcable Bluetooth Dongle. 62 Say Y here if you want to use USB AIRcable Bluetooth Dongle.
66 63
@@ -69,7 +66,6 @@ config USB_SERIAL_AIRCABLE
69 66
70config USB_SERIAL_AIRPRIME 67config USB_SERIAL_AIRPRIME
71 tristate "USB AirPrime CDMA Wireless Driver" 68 tristate "USB AirPrime CDMA Wireless Driver"
72 depends on USB_SERIAL
73 help 69 help
74 Say Y here if you want to use a AirPrime CDMA Wireless PC card. 70 Say Y here if you want to use a AirPrime CDMA Wireless PC card.
75 71
@@ -77,8 +73,7 @@ config USB_SERIAL_AIRPRIME
77 module will be called airprime. 73 module will be called airprime.
78 74
79config USB_SERIAL_ARK3116 75config USB_SERIAL_ARK3116
80 tristate "USB ARK Micro 3116 USB Serial Driver (EXPERIMENTAL)" 76 tristate "USB ARK Micro 3116 USB Serial Driver"
81 depends on USB_SERIAL && EXPERIMENTAL
82 help 77 help
83 Say Y here if you want to use a ARK Micro 3116 USB to Serial 78 Say Y here if you want to use a ARK Micro 3116 USB to Serial
84 device. 79 device.
@@ -88,7 +83,6 @@ config USB_SERIAL_ARK3116
88 83
89config USB_SERIAL_BELKIN 84config USB_SERIAL_BELKIN
90 tristate "USB Belkin and Peracom Single Port Serial Driver" 85 tristate "USB Belkin and Peracom Single Port Serial Driver"
91 depends on USB_SERIAL
92 help 86 help
93 Say Y here if you want to use a Belkin USB Serial single port 87 Say Y here if you want to use a Belkin USB Serial single port
94 adaptor (F5U103 is one of the model numbers) or the Peracom single 88 adaptor (F5U103 is one of the model numbers) or the Peracom single
@@ -99,7 +93,6 @@ config USB_SERIAL_BELKIN
99 93
100config USB_SERIAL_CH341 94config USB_SERIAL_CH341
101 tristate "USB Winchiphead CH341 Single Port Serial Driver" 95 tristate "USB Winchiphead CH341 Single Port Serial Driver"
102 depends on USB_SERIAL
103 help 96 help
104 Say Y here if you want to use a Winchiphead CH341 single port 97 Say Y here if you want to use a Winchiphead CH341 single port
105 USB to serial adapter. 98 USB to serial adapter.
@@ -109,7 +102,6 @@ config USB_SERIAL_CH341
109 102
110config USB_SERIAL_WHITEHEAT 103config USB_SERIAL_WHITEHEAT
111 tristate "USB ConnectTech WhiteHEAT Serial Driver" 104 tristate "USB ConnectTech WhiteHEAT Serial Driver"
112 depends on USB_SERIAL
113 select USB_EZUSB 105 select USB_EZUSB
114 help 106 help
115 Say Y here if you want to use a ConnectTech WhiteHEAT 4 port 107 Say Y here if you want to use a ConnectTech WhiteHEAT 4 port
@@ -120,7 +112,6 @@ config USB_SERIAL_WHITEHEAT
120 112
121config USB_SERIAL_DIGI_ACCELEPORT 113config USB_SERIAL_DIGI_ACCELEPORT
122 tristate "USB Digi International AccelePort USB Serial Driver" 114 tristate "USB Digi International AccelePort USB Serial Driver"
123 depends on USB_SERIAL
124 ---help--- 115 ---help---
125 Say Y here if you want to use Digi AccelePort USB 2 or 4 devices, 116 Say Y here if you want to use Digi AccelePort USB 2 or 4 devices,
126 2 port (plus parallel port) and 4 port USB serial converters. The 117 2 port (plus parallel port) and 4 port USB serial converters. The
@@ -135,7 +126,6 @@ config USB_SERIAL_DIGI_ACCELEPORT
135 126
136config USB_SERIAL_CP2101 127config USB_SERIAL_CP2101
137 tristate "USB CP2101 UART Bridge Controller" 128 tristate "USB CP2101 UART Bridge Controller"
138 depends on USB_SERIAL && EXPERIMENTAL
139 help 129 help
140 Say Y here if you want to use a CP2101/CP2102 based USB to RS232 130 Say Y here if you want to use a CP2101/CP2102 based USB to RS232
141 converter. 131 converter.
@@ -145,7 +135,6 @@ config USB_SERIAL_CP2101
145 135
146config USB_SERIAL_CYPRESS_M8 136config USB_SERIAL_CYPRESS_M8
147 tristate "USB Cypress M8 USB Serial Driver" 137 tristate "USB Cypress M8 USB Serial Driver"
148 depends on USB_SERIAL && EXPERIMENTAL
149 help 138 help
150 Say Y here if you want to use a device that contains the Cypress 139 Say Y here if you want to use a device that contains the Cypress
151 USB to Serial microcontroller, such as the DeLorme Earthmate GPS. 140 USB to Serial microcontroller, such as the DeLorme Earthmate GPS.
@@ -160,7 +149,6 @@ config USB_SERIAL_CYPRESS_M8
160 149
161config USB_SERIAL_EMPEG 150config USB_SERIAL_EMPEG
162 tristate "USB Empeg empeg-car Mark I/II Driver" 151 tristate "USB Empeg empeg-car Mark I/II Driver"
163 depends on USB_SERIAL
164 help 152 help
165 Say Y here if you want to connect to your Empeg empeg-car Mark I/II 153 Say Y here if you want to connect to your Empeg empeg-car Mark I/II
166 mp3 player via USB. The driver uses a single ttyUSB{0,1,2,...} 154 mp3 player via USB. The driver uses a single ttyUSB{0,1,2,...}
@@ -171,8 +159,7 @@ config USB_SERIAL_EMPEG
171 module will be called empeg. 159 module will be called empeg.
172 160
173config USB_SERIAL_FTDI_SIO 161config USB_SERIAL_FTDI_SIO
174 tristate "USB FTDI Single Port Serial Driver (EXPERIMENTAL)" 162 tristate "USB FTDI Single Port Serial Driver"
175 depends on USB_SERIAL && EXPERIMENTAL
176 ---help--- 163 ---help---
177 Say Y here if you want to use a FTDI SIO single port USB to serial 164 Say Y here if you want to use a FTDI SIO single port USB to serial
178 converter device. The implementation I have is called the USC-1000. 165 converter device. The implementation I have is called the USC-1000.
@@ -186,7 +173,6 @@ config USB_SERIAL_FTDI_SIO
186 173
187config USB_SERIAL_FUNSOFT 174config USB_SERIAL_FUNSOFT
188 tristate "USB Fundamental Software Dongle Driver" 175 tristate "USB Fundamental Software Dongle Driver"
189 depends on USB_SERIAL
190 ---help--- 176 ---help---
191 Say Y here if you want to use the Fundamental Software dongle. 177 Say Y here if you want to use the Fundamental Software dongle.
192 178
@@ -195,7 +181,6 @@ config USB_SERIAL_FUNSOFT
195 181
196config USB_SERIAL_VISOR 182config USB_SERIAL_VISOR
197 tristate "USB Handspring Visor / Palm m50x / Sony Clie Driver" 183 tristate "USB Handspring Visor / Palm m50x / Sony Clie Driver"
198 depends on USB_SERIAL
199 help 184 help
200 Say Y here if you want to connect to your HandSpring Visor, Palm 185 Say Y here if you want to connect to your HandSpring Visor, Palm
201 m500 or m505 through its USB docking station. See 186 m500 or m505 through its USB docking station. See
@@ -207,7 +192,6 @@ config USB_SERIAL_VISOR
207 192
208config USB_SERIAL_IPAQ 193config USB_SERIAL_IPAQ
209 tristate "USB PocketPC PDA Driver" 194 tristate "USB PocketPC PDA Driver"
210 depends on USB_SERIAL
211 help 195 help
212 Say Y here if you want to connect to your Compaq iPAQ, HP Jornada 196 Say Y here if you want to connect to your Compaq iPAQ, HP Jornada
213 or any other PDA running Windows CE 3.0 or PocketPC 2002 197 or any other PDA running Windows CE 3.0 or PocketPC 2002
@@ -218,8 +202,7 @@ config USB_SERIAL_IPAQ
218 module will be called ipaq. 202 module will be called ipaq.
219 203
220config USB_SERIAL_IR 204config USB_SERIAL_IR
221 tristate "USB IR Dongle Serial Driver (EXPERIMENTAL)" 205 tristate "USB IR Dongle Serial Driver"
222 depends on USB_SERIAL && EXPERIMENTAL
223 help 206 help
224 Say Y here if you want to enable simple serial support for USB IrDA 207 Say Y here if you want to enable simple serial support for USB IrDA
225 devices. This is useful if you do not want to use the full IrDA 208 devices. This is useful if you do not want to use the full IrDA
@@ -230,7 +213,6 @@ config USB_SERIAL_IR
230 213
231config USB_SERIAL_EDGEPORT 214config USB_SERIAL_EDGEPORT
232 tristate "USB Inside Out Edgeport Serial Driver" 215 tristate "USB Inside Out Edgeport Serial Driver"
233 depends on USB_SERIAL
234 ---help--- 216 ---help---
235 Say Y here if you want to use any of the following devices from 217 Say Y here if you want to use any of the following devices from
236 Inside Out Networks (Digi): 218 Inside Out Networks (Digi):
@@ -256,7 +238,6 @@ config USB_SERIAL_EDGEPORT
256 238
257config USB_SERIAL_EDGEPORT_TI 239config USB_SERIAL_EDGEPORT_TI
258 tristate "USB Inside Out Edgeport Serial Driver (TI devices)" 240 tristate "USB Inside Out Edgeport Serial Driver (TI devices)"
259 depends on USB_SERIAL
260 help 241 help
261 Say Y here if you want to use any of the devices from Inside Out 242 Say Y here if you want to use any of the devices from Inside Out
262 Networks (Digi) that are not supported by the io_edgeport driver. 243 Networks (Digi) that are not supported by the io_edgeport driver.
@@ -267,7 +248,6 @@ config USB_SERIAL_EDGEPORT_TI
267 248
268config USB_SERIAL_GARMIN 249config USB_SERIAL_GARMIN
269 tristate "USB Garmin GPS driver" 250 tristate "USB Garmin GPS driver"
270 depends on USB_SERIAL
271 help 251 help
272 Say Y here if you want to connect to your Garmin GPS. 252 Say Y here if you want to connect to your Garmin GPS.
273 Should work with most Garmin GPS devices which have a native USB port. 253 Should work with most Garmin GPS devices which have a native USB port.
@@ -279,8 +259,7 @@ config USB_SERIAL_GARMIN
279 module will be called garmin_gps. 259 module will be called garmin_gps.
280 260
281config USB_SERIAL_IPW 261config USB_SERIAL_IPW
282 tristate "USB IPWireless (3G UMTS TDD) Driver (EXPERIMENTAL)" 262 tristate "USB IPWireless (3G UMTS TDD) Driver"
283 depends on USB_SERIAL && EXPERIMENTAL
284 help 263 help
285 Say Y here if you want to use a IPWireless USB modem such as 264 Say Y here if you want to use a IPWireless USB modem such as
286 the ones supplied by Axity3G/Sentech South Africa. 265 the ones supplied by Axity3G/Sentech South Africa.
@@ -289,8 +268,7 @@ config USB_SERIAL_IPW
289 module will be called ipw. 268 module will be called ipw.
290 269
291config USB_SERIAL_IUU 270config USB_SERIAL_IUU
292 tristate "USB Infinity USB Unlimited Phoenix Driver (Experimental)" 271 tristate "USB Infinity USB Unlimited Phoenix Driver"
293 depends on USB_SERIAL && EXPERIMENTAL
294 help 272 help
295 Say Y here if you want to use a IUU in phoenix mode and get 273 Say Y here if you want to use a IUU in phoenix mode and get
296 an extra ttyUSBx device. More information available on 274 an extra ttyUSBx device. More information available on
@@ -301,7 +279,6 @@ config USB_SERIAL_IUU
301 279
302config USB_SERIAL_KEYSPAN_PDA 280config USB_SERIAL_KEYSPAN_PDA
303 tristate "USB Keyspan PDA Single Port Serial Driver" 281 tristate "USB Keyspan PDA Single Port Serial Driver"
304 depends on USB_SERIAL
305 select USB_EZUSB 282 select USB_EZUSB
306 help 283 help
307 Say Y here if you want to use a Keyspan PDA single port USB to 284 Say Y here if you want to use a Keyspan PDA single port USB to
@@ -313,7 +290,6 @@ config USB_SERIAL_KEYSPAN_PDA
313 290
314config USB_SERIAL_KEYSPAN 291config USB_SERIAL_KEYSPAN
315 tristate "USB Keyspan USA-xxx Serial Driver" 292 tristate "USB Keyspan USA-xxx Serial Driver"
316 depends on USB_SERIAL
317 select USB_EZUSB 293 select USB_EZUSB
318 ---help--- 294 ---help---
319 Say Y here if you want to use Keyspan USB to serial converter 295 Say Y here if you want to use Keyspan USB to serial converter
@@ -405,8 +381,7 @@ config USB_SERIAL_KEYSPAN_USA49WLC
405 Say Y here to include firmware for the USA-49WLC converter. 381 Say Y here to include firmware for the USA-49WLC converter.
406 382
407config USB_SERIAL_KLSI 383config USB_SERIAL_KLSI
408 tristate "USB KL5KUSB105 (Palmconnect) Driver (EXPERIMENTAL)" 384 tristate "USB KL5KUSB105 (Palmconnect) Driver"
409 depends on USB_SERIAL && EXPERIMENTAL
410 ---help--- 385 ---help---
411 Say Y here if you want to use a KL5KUSB105 - based single port 386 Say Y here if you want to use a KL5KUSB105 - based single port
412 serial adapter. The most widely known -- and currently the only 387 serial adapter. The most widely known -- and currently the only
@@ -422,7 +397,6 @@ config USB_SERIAL_KLSI
422 397
423config USB_SERIAL_KOBIL_SCT 398config USB_SERIAL_KOBIL_SCT
424 tristate "USB KOBIL chipcard reader" 399 tristate "USB KOBIL chipcard reader"
425 depends on USB_SERIAL
426 ---help--- 400 ---help---
427 Say Y here if you want to use one of the following KOBIL USB chipcard 401 Say Y here if you want to use one of the following KOBIL USB chipcard
428 readers: 402 readers:
@@ -440,7 +414,6 @@ config USB_SERIAL_KOBIL_SCT
440 414
441config USB_SERIAL_MCT_U232 415config USB_SERIAL_MCT_U232
442 tristate "USB MCT Single Port Serial Driver" 416 tristate "USB MCT Single Port Serial Driver"
443 depends on USB_SERIAL
444 ---help--- 417 ---help---
445 Say Y here if you want to use a USB Serial single port adapter from 418 Say Y here if you want to use a USB Serial single port adapter from
446 Magic Control Technology Corp. (U232 is one of the model numbers). 419 Magic Control Technology Corp. (U232 is one of the model numbers).
@@ -453,7 +426,6 @@ config USB_SERIAL_MCT_U232
453 426
454config USB_SERIAL_MOS7720 427config USB_SERIAL_MOS7720
455 tristate "USB Moschip 7720 Serial Driver" 428 tristate "USB Moschip 7720 Serial Driver"
456 depends on USB_SERIAL
457 ---help--- 429 ---help---
458 Say Y here if you want to use USB Serial single and double 430 Say Y here if you want to use USB Serial single and double
459 port adapters from Moschip Semiconductor Tech. 431 port adapters from Moschip Semiconductor Tech.
@@ -463,7 +435,6 @@ config USB_SERIAL_MOS7720
463 435
464config USB_SERIAL_MOS7840 436config USB_SERIAL_MOS7840
465 tristate "USB Moschip 7840/7820 USB Serial Driver" 437 tristate "USB Moschip 7840/7820 USB Serial Driver"
466 depends on USB_SERIAL
467 ---help--- 438 ---help---
468 Say Y here if you want to use a MCS7840 Quad-Serial or MCS7820 439 Say Y here if you want to use a MCS7840 Quad-Serial or MCS7820
469 Dual-Serial port device from MosChip Semiconductor. 440 Dual-Serial port device from MosChip Semiconductor.
@@ -478,14 +449,12 @@ config USB_SERIAL_MOS7840
478 449
479config USB_SERIAL_NAVMAN 450config USB_SERIAL_NAVMAN
480 tristate "USB Navman GPS device" 451 tristate "USB Navman GPS device"
481 depends on USB_SERIAL
482 help 452 help
483 To compile this driver as a module, choose M here: the 453 To compile this driver as a module, choose M here: the
484 module will be called navman. 454 module will be called navman.
485 455
486config USB_SERIAL_PL2303 456config USB_SERIAL_PL2303
487 tristate "USB Prolific 2303 Single Port Serial Driver" 457 tristate "USB Prolific 2303 Single Port Serial Driver"
488 depends on USB_SERIAL
489 help 458 help
490 Say Y here if you want to use the PL2303 USB Serial single port 459 Say Y here if you want to use the PL2303 USB Serial single port
491 adapter from Prolific. 460 adapter from Prolific.
@@ -494,8 +463,7 @@ config USB_SERIAL_PL2303
494 module will be called pl2303. 463 module will be called pl2303.
495 464
496config USB_SERIAL_OTI6858 465config USB_SERIAL_OTI6858
497 tristate "USB Ours Technology Inc. OTi-6858 USB To RS232 Bridge Controller (EXPERIMENTAL)" 466 tristate "USB Ours Technology Inc. OTi-6858 USB To RS232 Bridge Controller"
498 depends on USB_SERIAL
499 help 467 help
500 Say Y here if you want to use the OTi-6858 single port USB to serial 468 Say Y here if you want to use the OTi-6858 single port USB to serial
501 converter device. 469 converter device.
@@ -503,9 +471,17 @@ config USB_SERIAL_OTI6858
503 To compile this driver as a module, choose M here: the 471 To compile this driver as a module, choose M here: the
504 module will be called oti6858. 472 module will be called oti6858.
505 473
474config USB_SERIAL_SPCP8X5
475 tristate "USB SPCP8x5 USB To Serial Driver"
476 help
477 Say Y here if you want to use the spcp8x5 converter chip. This is
478 commonly found in some Z-Wave USB devices.
479
480 To compile this driver as a module, choose M here: the
481 module will be called spcp8x5.
482
506config USB_SERIAL_HP4X 483config USB_SERIAL_HP4X
507 tristate "USB HP4x Calculators support" 484 tristate "USB HP4x Calculators support"
508 depends on USB_SERIAL
509 help 485 help
510 Say Y here if you want to use an Hewlett-Packard 4x Calculator. 486 Say Y here if you want to use an Hewlett-Packard 4x Calculator.
511 487
@@ -513,8 +489,7 @@ config USB_SERIAL_HP4X
513 module will be called hp4x. 489 module will be called hp4x.
514 490
515config USB_SERIAL_SAFE 491config USB_SERIAL_SAFE
516 tristate "USB Safe Serial (Encapsulated) Driver (EXPERIMENTAL)" 492 tristate "USB Safe Serial (Encapsulated) Driver"
517 depends on USB_SERIAL && EXPERIMENTAL
518 493
519config USB_SERIAL_SAFE_PADDED 494config USB_SERIAL_SAFE_PADDED
520 bool "USB Secure Encapsulated Driver - Padded" 495 bool "USB Secure Encapsulated Driver - Padded"
@@ -522,7 +497,6 @@ config USB_SERIAL_SAFE_PADDED
522 497
523config USB_SERIAL_SIERRAWIRELESS 498config USB_SERIAL_SIERRAWIRELESS
524 tristate "USB Sierra Wireless Driver" 499 tristate "USB Sierra Wireless Driver"
525 depends on USB_SERIAL
526 help 500 help
527 Say M here if you want to use a Sierra Wireless device (if 501 Say M here if you want to use a Sierra Wireless device (if
528 using an PC 5220 or AC580 please use the Airprime driver 502 using an PC 5220 or AC580 please use the Airprime driver
@@ -533,7 +507,6 @@ config USB_SERIAL_SIERRAWIRELESS
533 507
534config USB_SERIAL_TI 508config USB_SERIAL_TI
535 tristate "USB TI 3410/5052 Serial Driver" 509 tristate "USB TI 3410/5052 Serial Driver"
536 depends on USB_SERIAL
537 help 510 help
538 Say Y here if you want to use the TI USB 3410 or 5052 511 Say Y here if you want to use the TI USB 3410 or 5052
539 serial devices. 512 serial devices.
@@ -542,8 +515,7 @@ config USB_SERIAL_TI
542 module will be called ti_usb_3410_5052. 515 module will be called ti_usb_3410_5052.
543 516
544config USB_SERIAL_CYBERJACK 517config USB_SERIAL_CYBERJACK
545 tristate "USB REINER SCT cyberJack pinpad/e-com chipcard reader (EXPERIMENTAL)" 518 tristate "USB REINER SCT cyberJack pinpad/e-com chipcard reader"
546 depends on USB_SERIAL && EXPERIMENTAL
547 ---help--- 519 ---help---
548 Say Y here if you want to use a cyberJack pinpad/e-com USB chipcard 520 Say Y here if you want to use a cyberJack pinpad/e-com USB chipcard
549 reader. This is an interface to ISO 7816 compatible contact-based 521 reader. This is an interface to ISO 7816 compatible contact-based
@@ -556,7 +528,6 @@ config USB_SERIAL_CYBERJACK
556 528
557config USB_SERIAL_XIRCOM 529config USB_SERIAL_XIRCOM
558 tristate "USB Xircom / Entregra Single Port Serial Driver" 530 tristate "USB Xircom / Entregra Single Port Serial Driver"
559 depends on USB_SERIAL
560 select USB_EZUSB 531 select USB_EZUSB
561 help 532 help
562 Say Y here if you want to use a Xircom or Entregra single port USB to 533 Say Y here if you want to use a Xircom or Entregra single port USB to
@@ -568,7 +539,6 @@ config USB_SERIAL_XIRCOM
568 539
569config USB_SERIAL_OPTION 540config USB_SERIAL_OPTION
570 tristate "USB driver for GSM and CDMA modems" 541 tristate "USB driver for GSM and CDMA modems"
571 depends on USB_SERIAL
572 help 542 help
573 Say Y here if you have a GSM or CDMA modem that's connected to USB. 543 Say Y here if you have a GSM or CDMA modem that's connected to USB.
574 544
@@ -586,8 +556,7 @@ config USB_SERIAL_OPTION
586 it might be accessible via the FTDI_SIO driver. 556 it might be accessible via the FTDI_SIO driver.
587 557
588config USB_SERIAL_OMNINET 558config USB_SERIAL_OMNINET
589 tristate "USB ZyXEL omni.net LCD Plus Driver (EXPERIMENTAL)" 559 tristate "USB ZyXEL omni.net LCD Plus Driver"
590 depends on USB_SERIAL && EXPERIMENTAL
591 help 560 help
592 Say Y here if you want to use a ZyXEL omni.net LCD ISDN TA. 561 Say Y here if you want to use a ZyXEL omni.net LCD ISDN TA.
593 562
@@ -596,7 +565,6 @@ config USB_SERIAL_OMNINET
596 565
597config USB_SERIAL_DEBUG 566config USB_SERIAL_DEBUG
598 tristate "USB Debugging Device" 567 tristate "USB Debugging Device"
599 depends on USB_SERIAL
600 help 568 help
601 Say Y here if you have a USB debugging device used to receive 569 Say Y here if you have a USB debugging device used to receive
602 debugging data from another machine. The most common of these 570 debugging data from another machine. The most common of these
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 0db109a54d10..756859510d8c 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -30,8 +30,8 @@ obj-$(CONFIG_USB_SERIAL_GARMIN) += garmin_gps.o
30obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o 30obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o
31obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o 31obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o
32obj-$(CONFIG_USB_SERIAL_IPW) += ipw.o 32obj-$(CONFIG_USB_SERIAL_IPW) += ipw.o
33obj-$(CONFIG_USB_SERIAL_IUU) += iuu_phoenix.o
34obj-$(CONFIG_USB_SERIAL_IR) += ir-usb.o 33obj-$(CONFIG_USB_SERIAL_IR) += ir-usb.o
34obj-$(CONFIG_USB_SERIAL_IUU) += iuu_phoenix.o
35obj-$(CONFIG_USB_SERIAL_KEYSPAN) += keyspan.o 35obj-$(CONFIG_USB_SERIAL_KEYSPAN) += keyspan.o
36obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o 36obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o
37obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o 37obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o
@@ -46,6 +46,7 @@ obj-$(CONFIG_USB_SERIAL_OTI6858) += oti6858.o
46obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o 46obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o
47obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o 47obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
48obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o 48obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o
49obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o
49obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 50obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
50obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 51obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
51obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 52obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index 1cd29cd6bd00..a238817762ad 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -210,7 +210,7 @@ static void aircable_send(struct usb_serial_port *port)
210 struct aircable_private *priv = usb_get_serial_port_data(port); 210 struct aircable_private *priv = usb_get_serial_port_data(port);
211 unsigned char* buf; 211 unsigned char* buf;
212 u16 *dbuf; 212 u16 *dbuf;
213 dbg("%s - port %d", __FUNCTION__, port->number); 213 dbg("%s - port %d", __func__, port->number);
214 if (port->write_urb_busy) 214 if (port->write_urb_busy)
215 return; 215 return;
216 216
@@ -220,7 +220,7 @@ static void aircable_send(struct usb_serial_port *port)
220 220
221 buf = kzalloc(count + HCI_HEADER_LENGTH, GFP_ATOMIC); 221 buf = kzalloc(count + HCI_HEADER_LENGTH, GFP_ATOMIC);
222 if (!buf) { 222 if (!buf) {
223 err("%s- kzalloc(%d) failed.", __FUNCTION__, 223 err("%s- kzalloc(%d) failed.", __func__,
224 count + HCI_HEADER_LENGTH); 224 count + HCI_HEADER_LENGTH);
225 return; 225 return;
226 } 226 }
@@ -236,7 +236,7 @@ static void aircable_send(struct usb_serial_port *port)
236 236
237 kfree(buf); 237 kfree(buf);
238 port->write_urb_busy = 1; 238 port->write_urb_busy = 1;
239 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 239 usb_serial_debug_data(debug, &port->dev, __func__,
240 count + HCI_HEADER_LENGTH, 240 count + HCI_HEADER_LENGTH,
241 port->write_urb->transfer_buffer); 241 port->write_urb->transfer_buffer);
242 port->write_urb->transfer_buffer_length = count + HCI_HEADER_LENGTH; 242 port->write_urb->transfer_buffer_length = count + HCI_HEADER_LENGTH;
@@ -246,7 +246,7 @@ static void aircable_send(struct usb_serial_port *port)
246 if (result) { 246 if (result) {
247 dev_err(&port->dev, 247 dev_err(&port->dev,
248 "%s - failed submitting write urb, error %d\n", 248 "%s - failed submitting write urb, error %d\n",
249 __FUNCTION__, result); 249 __func__, result);
250 port->write_urb_busy = 0; 250 port->write_urb_busy = 0;
251 } 251 }
252 252
@@ -275,7 +275,7 @@ static void aircable_read(struct work_struct *work)
275 275
276 if (!tty) { 276 if (!tty) {
277 schedule_work(&priv->rx_work); 277 schedule_work(&priv->rx_work);
278 err("%s - No tty available", __FUNCTION__); 278 err("%s - No tty available", __func__);
279 return ; 279 return ;
280 } 280 }
281 281
@@ -286,7 +286,7 @@ static void aircable_read(struct work_struct *work)
286 286
287 tty_prepare_flip_string(tty, &data, count); 287 tty_prepare_flip_string(tty, &data, count);
288 if (!data){ 288 if (!data){
289 err("%s- kzalloc(%d) failed.", __FUNCTION__, count); 289 err("%s- kzalloc(%d) failed.", __func__, count);
290 return; 290 return;
291 } 291 }
292 292
@@ -332,7 +332,7 @@ static int aircable_attach (struct usb_serial *serial)
332 332
333 priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL); 333 priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL);
334 if (!priv){ 334 if (!priv){
335 err("%s- kmalloc(%Zd) failed.", __FUNCTION__, 335 err("%s- kmalloc(%Zd) failed.", __func__,
336 sizeof(struct aircable_private)); 336 sizeof(struct aircable_private));
337 return -ENOMEM; 337 return -ENOMEM;
338 } 338 }
@@ -366,7 +366,7 @@ static void aircable_shutdown(struct usb_serial *serial)
366 struct usb_serial_port *port = serial->port[0]; 366 struct usb_serial_port *port = serial->port[0];
367 struct aircable_private *priv = usb_get_serial_port_data(port); 367 struct aircable_private *priv = usb_get_serial_port_data(port);
368 368
369 dbg("%s", __FUNCTION__); 369 dbg("%s", __func__);
370 370
371 if (priv) { 371 if (priv) {
372 serial_buf_free(priv->tx_buf); 372 serial_buf_free(priv->tx_buf);
@@ -388,12 +388,12 @@ static int aircable_write(struct usb_serial_port *port,
388 struct aircable_private *priv = usb_get_serial_port_data(port); 388 struct aircable_private *priv = usb_get_serial_port_data(port);
389 int temp; 389 int temp;
390 390
391 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); 391 dbg("%s - port %d, %d bytes", __func__, port->number, count);
392 392
393 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, source); 393 usb_serial_debug_data(debug, &port->dev, __func__, count, source);
394 394
395 if (!count){ 395 if (!count){
396 dbg("%s - write request of 0 bytes", __FUNCTION__); 396 dbg("%s - write request of 0 bytes", __func__);
397 return count; 397 return count;
398 } 398 }
399 399
@@ -414,7 +414,7 @@ static void aircable_write_bulk_callback(struct urb *urb)
414 int status = urb->status; 414 int status = urb->status;
415 int result; 415 int result;
416 416
417 dbg("%s - urb status: %d", __FUNCTION__ , status); 417 dbg("%s - urb status: %d", __func__ , status);
418 418
419 /* This has been taken from cypress_m8.c cypress_write_int_callback */ 419 /* This has been taken from cypress_m8.c cypress_write_int_callback */
420 switch (status) { 420 switch (status) {
@@ -426,21 +426,21 @@ static void aircable_write_bulk_callback(struct urb *urb)
426 case -ESHUTDOWN: 426 case -ESHUTDOWN:
427 /* this urb is terminated, clean up */ 427 /* this urb is terminated, clean up */
428 dbg("%s - urb shutting down with status: %d", 428 dbg("%s - urb shutting down with status: %d",
429 __FUNCTION__, status); 429 __func__, status);
430 port->write_urb_busy = 0; 430 port->write_urb_busy = 0;
431 return; 431 return;
432 default: 432 default:
433 /* error in the urb, so we have to resubmit it */ 433 /* error in the urb, so we have to resubmit it */
434 dbg("%s - Overflow in write", __FUNCTION__); 434 dbg("%s - Overflow in write", __func__);
435 dbg("%s - nonzero write bulk status received: %d", 435 dbg("%s - nonzero write bulk status received: %d",
436 __FUNCTION__, status); 436 __func__, status);
437 port->write_urb->transfer_buffer_length = 1; 437 port->write_urb->transfer_buffer_length = 1;
438 port->write_urb->dev = port->serial->dev; 438 port->write_urb->dev = port->serial->dev;
439 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 439 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
440 if (result) 440 if (result)
441 dev_err(&urb->dev->dev, 441 dev_err(&urb->dev->dev,
442 "%s - failed resubmitting write urb, error %d\n", 442 "%s - failed resubmitting write urb, error %d\n",
443 __FUNCTION__, result); 443 __func__, result);
444 else 444 else
445 return; 445 return;
446 } 446 }
@@ -460,17 +460,17 @@ static void aircable_read_bulk_callback(struct urb *urb)
460 unsigned char *temp; 460 unsigned char *temp;
461 int status = urb->status; 461 int status = urb->status;
462 462
463 dbg("%s - port %d", __FUNCTION__, port->number); 463 dbg("%s - port %d", __func__, port->number);
464 464
465 if (status) { 465 if (status) {
466 dbg("%s - urb status = %d", __FUNCTION__, status); 466 dbg("%s - urb status = %d", __func__, status);
467 if (!port->open_count) { 467 if (!port->open_count) {
468 dbg("%s - port is closed, exiting.", __FUNCTION__); 468 dbg("%s - port is closed, exiting.", __func__);
469 return; 469 return;
470 } 470 }
471 if (status == -EPROTO) { 471 if (status == -EPROTO) {
472 dbg("%s - caught -EPROTO, resubmitting the urb", 472 dbg("%s - caught -EPROTO, resubmitting the urb",
473 __FUNCTION__); 473 __func__);
474 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 474 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
475 usb_rcvbulkpipe(port->serial->dev, 475 usb_rcvbulkpipe(port->serial->dev,
476 port->bulk_in_endpointAddress), 476 port->bulk_in_endpointAddress),
@@ -482,14 +482,14 @@ static void aircable_read_bulk_callback(struct urb *urb)
482 if (result) 482 if (result)
483 dev_err(&urb->dev->dev, 483 dev_err(&urb->dev->dev,
484 "%s - failed resubmitting read urb, error %d\n", 484 "%s - failed resubmitting read urb, error %d\n",
485 __FUNCTION__, result); 485 __func__, result);
486 return; 486 return;
487 } 487 }
488 dbg("%s - unable to handle the error, exiting.", __FUNCTION__); 488 dbg("%s - unable to handle the error, exiting.", __func__);
489 return; 489 return;
490 } 490 }
491 491
492 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 492 usb_serial_debug_data(debug, &port->dev, __func__,
493 urb->actual_length,urb->transfer_buffer); 493 urb->actual_length,urb->transfer_buffer);
494 494
495 tty = port->tty; 495 tty = port->tty;
@@ -538,7 +538,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
538 if (result) 538 if (result)
539 dev_err(&urb->dev->dev, 539 dev_err(&urb->dev->dev,
540 "%s - failed resubmitting read urb, error %d\n", 540 "%s - failed resubmitting read urb, error %d\n",
541 __FUNCTION__, result); 541 __func__, result);
542 } 542 }
543 543
544 return; 544 return;
@@ -550,7 +550,7 @@ static void aircable_throttle(struct usb_serial_port *port)
550 struct aircable_private *priv = usb_get_serial_port_data(port); 550 struct aircable_private *priv = usb_get_serial_port_data(port);
551 unsigned long flags; 551 unsigned long flags;
552 552
553 dbg("%s - port %d", __FUNCTION__, port->number); 553 dbg("%s - port %d", __func__, port->number);
554 554
555 spin_lock_irqsave(&priv->rx_lock, flags); 555 spin_lock_irqsave(&priv->rx_lock, flags);
556 priv->rx_flags |= THROTTLED; 556 priv->rx_flags |= THROTTLED;
@@ -564,7 +564,7 @@ static void aircable_unthrottle(struct usb_serial_port *port)
564 int actually_throttled; 564 int actually_throttled;
565 unsigned long flags; 565 unsigned long flags;
566 566
567 dbg("%s - port %d", __FUNCTION__, port->number); 567 dbg("%s - port %d", __func__, port->number);
568 568
569 spin_lock_irqsave(&priv->rx_lock, flags); 569 spin_lock_irqsave(&priv->rx_lock, flags);
570 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; 570 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index f156dba0300f..725b6b94c274 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -53,7 +53,7 @@ static int airprime_send_setup(struct usb_serial_port *port)
53 struct usb_serial *serial = port->serial; 53 struct usb_serial *serial = port->serial;
54 struct airprime_private *priv; 54 struct airprime_private *priv;
55 55
56 dbg("%s", __FUNCTION__); 56 dbg("%s", __func__);
57 57
58 if (port->number != 0) 58 if (port->number != 0)
59 return 0; 59 return 0;
@@ -83,14 +83,14 @@ static void airprime_read_bulk_callback(struct urb *urb)
83 int result; 83 int result;
84 int status = urb->status; 84 int status = urb->status;
85 85
86 dbg("%s - port %d", __FUNCTION__, port->number); 86 dbg("%s - port %d", __func__, port->number);
87 87
88 if (status) { 88 if (status) {
89 dbg("%s - nonzero read bulk status received: %d", 89 dbg("%s - nonzero read bulk status received: %d",
90 __FUNCTION__, status); 90 __func__, status);
91 return; 91 return;
92 } 92 }
93 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 93 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
94 94
95 tty = port->tty; 95 tty = port->tty;
96 if (tty && urb->actual_length) { 96 if (tty && urb->actual_length) {
@@ -101,7 +101,7 @@ static void airprime_read_bulk_callback(struct urb *urb)
101 result = usb_submit_urb (urb, GFP_ATOMIC); 101 result = usb_submit_urb (urb, GFP_ATOMIC);
102 if (result) 102 if (result)
103 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", 103 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
104 __FUNCTION__, result); 104 __func__, result);
105 return; 105 return;
106} 106}
107 107
@@ -112,14 +112,14 @@ static void airprime_write_bulk_callback(struct urb *urb)
112 int status = urb->status; 112 int status = urb->status;
113 unsigned long flags; 113 unsigned long flags;
114 114
115 dbg("%s - port %d", __FUNCTION__, port->number); 115 dbg("%s - port %d", __func__, port->number);
116 116
117 /* free up the transfer buffer, as usb_free_urb() does not do this */ 117 /* free up the transfer buffer, as usb_free_urb() does not do this */
118 kfree (urb->transfer_buffer); 118 kfree (urb->transfer_buffer);
119 119
120 if (status) 120 if (status)
121 dbg("%s - nonzero write bulk status received: %d", 121 dbg("%s - nonzero write bulk status received: %d",
122 __FUNCTION__, status); 122 __func__, status);
123 spin_lock_irqsave(&priv->lock, flags); 123 spin_lock_irqsave(&priv->lock, flags);
124 --priv->outstanding_urbs; 124 --priv->outstanding_urbs;
125 spin_unlock_irqrestore(&priv->lock, flags); 125 spin_unlock_irqrestore(&priv->lock, flags);
@@ -136,7 +136,7 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
136 int i; 136 int i;
137 int result = 0; 137 int result = 0;
138 138
139 dbg("%s - port %d", __FUNCTION__, port->number); 139 dbg("%s - port %d", __func__, port->number);
140 140
141 /* initialize our private data structure if it isn't already created */ 141 /* initialize our private data structure if it isn't already created */
142 if (!priv) { 142 if (!priv) {
@@ -157,7 +157,7 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
157 buffer = kmalloc(buffer_size, GFP_KERNEL); 157 buffer = kmalloc(buffer_size, GFP_KERNEL);
158 if (!buffer) { 158 if (!buffer) {
159 dev_err(&port->dev, "%s - out of memory.\n", 159 dev_err(&port->dev, "%s - out of memory.\n",
160 __FUNCTION__); 160 __func__);
161 result = -ENOMEM; 161 result = -ENOMEM;
162 goto errout; 162 goto errout;
163 } 163 }
@@ -165,7 +165,7 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
165 if (!urb) { 165 if (!urb) {
166 kfree(buffer); 166 kfree(buffer);
167 dev_err(&port->dev, "%s - no more urbs?\n", 167 dev_err(&port->dev, "%s - no more urbs?\n",
168 __FUNCTION__); 168 __func__);
169 result = -ENOMEM; 169 result = -ENOMEM;
170 goto errout; 170 goto errout;
171 } 171 }
@@ -180,7 +180,7 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
180 kfree(buffer); 180 kfree(buffer);
181 dev_err(&port->dev, 181 dev_err(&port->dev,
182 "%s - failed submitting read urb %d for port %d, error %d\n", 182 "%s - failed submitting read urb %d for port %d, error %d\n",
183 __FUNCTION__, i, port->number, result); 183 __func__, i, port->number, result);
184 goto errout; 184 goto errout;
185 } 185 }
186 /* remember this urb so we can kill it when the port is closed */ 186 /* remember this urb so we can kill it when the port is closed */
@@ -212,7 +212,7 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
212 struct airprime_private *priv = usb_get_serial_port_data(port); 212 struct airprime_private *priv = usb_get_serial_port_data(port);
213 int i; 213 int i;
214 214
215 dbg("%s - port %d", __FUNCTION__, port->number); 215 dbg("%s - port %d", __func__, port->number);
216 216
217 priv->rts_state = 0; 217 priv->rts_state = 0;
218 priv->dtr_state = 0; 218 priv->dtr_state = 0;
@@ -242,12 +242,12 @@ static int airprime_write(struct usb_serial_port *port,
242 unsigned char *buffer; 242 unsigned char *buffer;
243 unsigned long flags; 243 unsigned long flags;
244 int status; 244 int status;
245 dbg("%s - port %d", __FUNCTION__, port->number); 245 dbg("%s - port %d", __func__, port->number);
246 246
247 spin_lock_irqsave(&priv->lock, flags); 247 spin_lock_irqsave(&priv->lock, flags);
248 if (priv->outstanding_urbs > NUM_WRITE_URBS) { 248 if (priv->outstanding_urbs > NUM_WRITE_URBS) {
249 spin_unlock_irqrestore(&priv->lock, flags); 249 spin_unlock_irqrestore(&priv->lock, flags);
250 dbg("%s - write limit hit\n", __FUNCTION__); 250 dbg("%s - write limit hit\n", __func__);
251 return 0; 251 return 0;
252 } 252 }
253 spin_unlock_irqrestore(&priv->lock, flags); 253 spin_unlock_irqrestore(&priv->lock, flags);
@@ -264,7 +264,7 @@ static int airprime_write(struct usb_serial_port *port,
264 } 264 }
265 memcpy (buffer, buf, count); 265 memcpy (buffer, buf, count);
266 266
267 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer); 267 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
268 268
269 usb_fill_bulk_urb(urb, serial->dev, 269 usb_fill_bulk_urb(urb, serial->dev,
270 usb_sndbulkpipe(serial->dev, 270 usb_sndbulkpipe(serial->dev,
@@ -277,7 +277,7 @@ static int airprime_write(struct usb_serial_port *port,
277 if (status) { 277 if (status) {
278 dev_err(&port->dev, 278 dev_err(&port->dev,
279 "%s - usb_submit_urb(write bulk) failed with status = %d\n", 279 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
280 __FUNCTION__, status); 280 __func__, status);
281 count = status; 281 count = status;
282 kfree (buffer); 282 kfree (buffer);
283 } else { 283 } else {
@@ -306,9 +306,6 @@ static struct usb_serial_driver airprime_device = {
306 }, 306 },
307 .usb_driver = &airprime_driver, 307 .usb_driver = &airprime_driver,
308 .id_table = id_table, 308 .id_table = id_table,
309 .num_interrupt_in = NUM_DONT_CARE,
310 .num_bulk_in = NUM_DONT_CARE,
311 .num_bulk_out = NUM_DONT_CARE,
312 .open = airprime_open, 309 .open = airprime_open,
313 .close = airprime_close, 310 .close = airprime_close,
314 .write = airprime_write, 311 .write = airprime_write,
@@ -331,7 +328,7 @@ static int __init airprime_init(void)
331 328
332static void __exit airprime_exit(void) 329static void __exit airprime_exit(void)
333{ 330{
334 dbg("%s", __FUNCTION__); 331 dbg("%s", __func__);
335 332
336 usb_deregister(&airprime_driver); 333 usb_deregister(&airprime_driver);
337 usb_serial_deregister(&airprime_device); 334 usb_serial_deregister(&airprime_device);
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index fe2bfd67ba8e..599ab2e548a7 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -173,7 +173,7 @@ static void ark3116_set_termios(struct usb_serial_port *port,
173 173
174 config = 0; 174 config = 0;
175 175
176 dbg("%s - port %d", __FUNCTION__, port->number); 176 dbg("%s - port %d", __func__, port->number);
177 177
178 spin_lock_irqsave(&priv->lock, flags); 178 spin_lock_irqsave(&priv->lock, flags);
179 if (!priv->termios_initialized) { 179 if (!priv->termios_initialized) {
@@ -192,6 +192,7 @@ static void ark3116_set_termios(struct usb_serial_port *port,
192 buf = kmalloc(1, GFP_KERNEL); 192 buf = kmalloc(1, GFP_KERNEL);
193 if (!buf) { 193 if (!buf) {
194 dbg("error kmalloc"); 194 dbg("error kmalloc");
195 *port->tty->termios = *old_termios;
195 return; 196 return;
196 } 197 }
197 198
@@ -323,7 +324,7 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp)
323 char *buf; 324 char *buf;
324 int result = 0; 325 int result = 0;
325 326
326 dbg("%s - port %d", __FUNCTION__, port->number); 327 dbg("%s - port %d", __func__, port->number);
327 328
328 buf = kmalloc(1, GFP_KERNEL); 329 buf = kmalloc(1, GFP_KERNEL);
329 if (!buf) { 330 if (!buf) {
@@ -395,7 +396,7 @@ static int ark3116_ioctl(struct usb_serial_port *port, struct file *file,
395 return -EFAULT; 396 return -EFAULT;
396 return 0; 397 return 0;
397 default: 398 default:
398 dbg("%s cmd 0x%04x not supported", __FUNCTION__, cmd); 399 dbg("%s cmd 0x%04x not supported", __func__, cmd);
399 break; 400 break;
400 } 401 }
401 402
@@ -447,9 +448,6 @@ static struct usb_serial_driver ark3116_device = {
447 }, 448 },
448 .id_table = id_table, 449 .id_table = id_table,
449 .usb_driver = &ark3116_driver, 450 .usb_driver = &ark3116_driver,
450 .num_interrupt_in = 1,
451 .num_bulk_in = 1,
452 .num_bulk_out = 1,
453 .num_ports = 1, 451 .num_ports = 1,
454 .attach = ark3116_attach, 452 .attach = ark3116_attach,
455 .set_termios = ark3116_set_termios, 453 .set_termios = ark3116_set_termios,
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index df0a2b3b0294..0a322fc53d6e 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -128,9 +128,6 @@ static struct usb_serial_driver belkin_device = {
128 .description = "Belkin / Peracom / GoHubs USB Serial Adapter", 128 .description = "Belkin / Peracom / GoHubs USB Serial Adapter",
129 .usb_driver = &belkin_driver, 129 .usb_driver = &belkin_driver,
130 .id_table = id_table_combined, 130 .id_table = id_table_combined,
131 .num_interrupt_in = 1,
132 .num_bulk_in = 1,
133 .num_bulk_out = 1,
134 .num_ports = 1, 131 .num_ports = 1,
135 .open = belkin_sa_open, 132 .open = belkin_sa_open,
136 .close = belkin_sa_close, 133 .close = belkin_sa_close,
@@ -198,7 +195,7 @@ static void belkin_sa_shutdown (struct usb_serial *serial)
198 struct belkin_sa_private *priv; 195 struct belkin_sa_private *priv;
199 int i; 196 int i;
200 197
201 dbg ("%s", __FUNCTION__); 198 dbg ("%s", __func__);
202 199
203 /* stop reads and writes on all ports */ 200 /* stop reads and writes on all ports */
204 for (i=0; i < serial->num_ports; ++i) { 201 for (i=0; i < serial->num_ports; ++i) {
@@ -213,7 +210,7 @@ static int belkin_sa_open (struct usb_serial_port *port, struct file *filp)
213{ 210{
214 int retval = 0; 211 int retval = 0;
215 212
216 dbg("%s port %d", __FUNCTION__, port->number); 213 dbg("%s port %d", __func__, port->number);
217 214
218 /*Start reading from the device*/ 215 /*Start reading from the device*/
219 /* TODO: Look at possibility of submitting multiple URBs to device to 216 /* TODO: Look at possibility of submitting multiple URBs to device to
@@ -240,7 +237,7 @@ exit:
240 237
241static void belkin_sa_close (struct usb_serial_port *port, struct file *filp) 238static void belkin_sa_close (struct usb_serial_port *port, struct file *filp)
242{ 239{
243 dbg("%s port %d", __FUNCTION__, port->number); 240 dbg("%s port %d", __func__, port->number);
244 241
245 /* shutdown our bulk reads and writes */ 242 /* shutdown our bulk reads and writes */
246 usb_kill_urb(port->write_urb); 243 usb_kill_urb(port->write_urb);
@@ -251,7 +248,7 @@ static void belkin_sa_close (struct usb_serial_port *port, struct file *filp)
251 248
252static void belkin_sa_read_int_callback (struct urb *urb) 249static void belkin_sa_read_int_callback (struct urb *urb)
253{ 250{
254 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 251 struct usb_serial_port *port = urb->context;
255 struct belkin_sa_private *priv; 252 struct belkin_sa_private *priv;
256 unsigned char *data = urb->transfer_buffer; 253 unsigned char *data = urb->transfer_buffer;
257 int retval; 254 int retval;
@@ -267,15 +264,15 @@ static void belkin_sa_read_int_callback (struct urb *urb)
267 case -ESHUTDOWN: 264 case -ESHUTDOWN:
268 /* this urb is terminated, clean up */ 265 /* this urb is terminated, clean up */
269 dbg("%s - urb shutting down with status: %d", 266 dbg("%s - urb shutting down with status: %d",
270 __FUNCTION__, status); 267 __func__, status);
271 return; 268 return;
272 default: 269 default:
273 dbg("%s - nonzero urb status received: %d", 270 dbg("%s - nonzero urb status received: %d",
274 __FUNCTION__, status); 271 __func__, status);
275 goto exit; 272 goto exit;
276 } 273 }
277 274
278 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 275 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
279 276
280 /* Handle known interrupt data */ 277 /* Handle known interrupt data */
281 /* ignore data[0] and data[1] */ 278 /* ignore data[0] and data[1] */
@@ -334,7 +331,7 @@ exit:
334 retval = usb_submit_urb (urb, GFP_ATOMIC); 331 retval = usb_submit_urb (urb, GFP_ATOMIC);
335 if (retval) 332 if (retval)
336 err ("%s - usb_submit_urb failed with result %d", 333 err ("%s - usb_submit_urb failed with result %d",
337 __FUNCTION__, retval); 334 __func__, retval);
338} 335}
339 336
340static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 337static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
@@ -481,7 +478,7 @@ static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file)
481 unsigned long control_state; 478 unsigned long control_state;
482 unsigned long flags; 479 unsigned long flags;
483 480
484 dbg("%s", __FUNCTION__); 481 dbg("%s", __func__);
485 482
486 spin_lock_irqsave(&priv->lock, flags); 483 spin_lock_irqsave(&priv->lock, flags);
487 control_state = priv->control_state; 484 control_state = priv->control_state;
@@ -502,7 +499,7 @@ static int belkin_sa_tiocmset (struct usb_serial_port *port, struct file *file,
502 int rts = 0; 499 int rts = 0;
503 int dtr = 0; 500 int dtr = 0;
504 501
505 dbg("%s", __FUNCTION__); 502 dbg("%s", __func__);
506 503
507 spin_lock_irqsave(&priv->lock, flags); 504 spin_lock_irqsave(&priv->lock, flags);
508 control_state = priv->control_state; 505 control_state = priv->control_state;
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 42582d49b69c..d947d955bceb 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -318,9 +318,6 @@ static struct usb_serial_driver ch341_device = {
318 }, 318 },
319 .id_table = id_table, 319 .id_table = id_table,
320 .usb_driver = &ch341_driver, 320 .usb_driver = &ch341_driver,
321 .num_interrupt_in = NUM_DONT_CARE,
322 .num_bulk_in = 1,
323 .num_bulk_out = 1,
324 .num_ports = 1, 321 .num_ports = 1,
325 .open = ch341_open, 322 .open = ch341_open,
326 .set_termios = ch341_set_termios, 323 .set_termios = ch341_set_termios,
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 66ce30c1b75b..201184c3fb87 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -67,7 +67,7 @@ static int usb_console_setup(struct console *co, char *options)
67 struct tty_struct *tty = NULL; 67 struct tty_struct *tty = NULL;
68 struct ktermios *termios = NULL, dummy; 68 struct ktermios *termios = NULL, dummy;
69 69
70 dbg ("%s", __FUNCTION__); 70 dbg ("%s", __func__);
71 71
72 if (options) { 72 if (options) {
73 baud = simple_strtoul(options, NULL, 10); 73 baud = simple_strtoul(options, NULL, 10);
@@ -225,10 +225,10 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
225 if (count == 0) 225 if (count == 0)
226 return; 226 return;
227 227
228 dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count); 228 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
229 229
230 if (!port->open_count) { 230 if (!port->open_count) {
231 dbg ("%s - port not opened", __FUNCTION__); 231 dbg ("%s - port not opened", __func__);
232 return; 232 return;
233 } 233 }
234 234
@@ -248,7 +248,7 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
248 retval = serial->type->write(port, buf, i); 248 retval = serial->type->write(port, buf, i);
249 else 249 else
250 retval = usb_serial_generic_write(port, buf, i); 250 retval = usb_serial_generic_write(port, buf, i);
251 dbg("%s - return value : %d", __FUNCTION__, retval); 251 dbg("%s - return value : %d", __func__, retval);
252 if (lf) { 252 if (lf) {
253 /* append CR after LF */ 253 /* append CR after LF */
254 unsigned char cr = 13; 254 unsigned char cr = 13;
@@ -256,7 +256,7 @@ static void usb_console_write(struct console *co, const char *buf, unsigned coun
256 retval = serial->type->write(port, &cr, 1); 256 retval = serial->type->write(port, &cr, 1);
257 else 257 else
258 retval = usb_serial_generic_write(port, &cr, 1); 258 retval = usb_serial_generic_write(port, &cr, 1);
259 dbg("%s - return value : %d", __FUNCTION__, retval); 259 dbg("%s - return value : %d", __func__, retval);
260 } 260 }
261 buf += i; 261 buf += i;
262 count -= i; 262 count -= i;
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 324bb61d68ff..dc0ea08ed231 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -53,9 +53,11 @@ static void cp2101_shutdown(struct usb_serial*);
53static int debug; 53static int debug;
54 54
55static struct usb_device_id id_table [] = { 55static struct usb_device_id id_table [] = {
56 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
56 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ 57 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
57 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ 58 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
58 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ 59 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */
60 { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */
59 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ 61 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
60 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ 62 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
61 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ 63 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
@@ -71,6 +73,7 @@ static struct usb_device_id id_table [] = {
71 { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */ 73 { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */
72 { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */ 74 { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */
73 { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */ 75 { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */
76 { USB_DEVICE(0x10C4, 0x81AC) }, /* MSD Dash Hawk */
74 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ 77 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
75 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ 78 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
76 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ 79 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
@@ -106,9 +109,6 @@ static struct usb_serial_driver cp2101_device = {
106 }, 109 },
107 .usb_driver = &cp2101_driver, 110 .usb_driver = &cp2101_driver,
108 .id_table = id_table, 111 .id_table = id_table,
109 .num_interrupt_in = 0,
110 .num_bulk_in = NUM_DONT_CARE,
111 .num_bulk_out = NUM_DONT_CARE,
112 .num_ports = 1, 112 .num_ports = 1,
113 .open = cp2101_open, 113 .open = cp2101_open,
114 .close = cp2101_close, 114 .close = cp2101_close,
@@ -193,7 +193,7 @@ static int cp2101_get_config(struct usb_serial_port* port, u8 request,
193 193
194 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL); 194 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
195 if (!buf) { 195 if (!buf) {
196 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); 196 dev_err(&port->dev, "%s - out of memory.\n", __func__);
197 return -ENOMEM; 197 return -ENOMEM;
198 } 198 }
199 199
@@ -214,7 +214,7 @@ static int cp2101_get_config(struct usb_serial_port* port, u8 request,
214 if (result != size) { 214 if (result != size) {
215 dev_err(&port->dev, "%s - Unable to send config request, " 215 dev_err(&port->dev, "%s - Unable to send config request, "
216 "request=0x%x size=%d result=%d\n", 216 "request=0x%x size=%d result=%d\n",
217 __FUNCTION__, request, size, result); 217 __func__, request, size, result);
218 return -EPROTO; 218 return -EPROTO;
219 } 219 }
220 220
@@ -240,7 +240,7 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
240 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); 240 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL);
241 if (!buf) { 241 if (!buf) {
242 dev_err(&port->dev, "%s - out of memory.\n", 242 dev_err(&port->dev, "%s - out of memory.\n",
243 __FUNCTION__); 243 __func__);
244 return -ENOMEM; 244 return -ENOMEM;
245 } 245 }
246 246
@@ -265,7 +265,7 @@ static int cp2101_set_config(struct usb_serial_port* port, u8 request,
265 if ((size > 2 && result != size) || result < 0) { 265 if ((size > 2 && result != size) || result < 0) {
266 dev_err(&port->dev, "%s - Unable to send request, " 266 dev_err(&port->dev, "%s - Unable to send request, "
267 "request=0x%x size=%d result=%d\n", 267 "request=0x%x size=%d result=%d\n",
268 __FUNCTION__, request, size, result); 268 __func__, request, size, result);
269 return -EPROTO; 269 return -EPROTO;
270 } 270 }
271 271
@@ -293,11 +293,11 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
293 struct usb_serial *serial = port->serial; 293 struct usb_serial *serial = port->serial;
294 int result; 294 int result;
295 295
296 dbg("%s - port %d", __FUNCTION__, port->number); 296 dbg("%s - port %d", __func__, port->number);
297 297
298 if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) { 298 if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) {
299 dev_err(&port->dev, "%s - Unable to enable UART\n", 299 dev_err(&port->dev, "%s - Unable to enable UART\n",
300 __FUNCTION__); 300 __func__);
301 return -EPROTO; 301 return -EPROTO;
302 } 302 }
303 303
@@ -312,7 +312,7 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
312 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 312 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
313 if (result) { 313 if (result) {
314 dev_err(&port->dev, "%s - failed resubmitting read urb, " 314 dev_err(&port->dev, "%s - failed resubmitting read urb, "
315 "error %d\n", __FUNCTION__, result); 315 "error %d\n", __func__, result);
316 return result; 316 return result;
317 } 317 }
318 318
@@ -329,7 +329,7 @@ static void cp2101_cleanup (struct usb_serial_port *port)
329{ 329{
330 struct usb_serial *serial = port->serial; 330 struct usb_serial *serial = port->serial;
331 331
332 dbg("%s - port %d", __FUNCTION__, port->number); 332 dbg("%s - port %d", __func__, port->number);
333 333
334 if (serial->dev) { 334 if (serial->dev) {
335 /* shutdown any bulk reads that might be going on */ 335 /* shutdown any bulk reads that might be going on */
@@ -342,10 +342,10 @@ static void cp2101_cleanup (struct usb_serial_port *port)
342 342
343static void cp2101_close (struct usb_serial_port *port, struct file * filp) 343static void cp2101_close (struct usb_serial_port *port, struct file * filp)
344{ 344{
345 dbg("%s - port %d", __FUNCTION__, port->number); 345 dbg("%s - port %d", __func__, port->number);
346 346
347 /* shutdown our urbs */ 347 /* shutdown our urbs */
348 dbg("%s - shutting down urbs", __FUNCTION__); 348 dbg("%s - shutting down urbs", __func__);
349 usb_kill_urb(port->write_urb); 349 usb_kill_urb(port->write_urb);
350 usb_kill_urb(port->read_urb); 350 usb_kill_urb(port->read_urb);
351 351
@@ -367,10 +367,10 @@ static void cp2101_get_termios (struct usb_serial_port *port)
367 int baud; 367 int baud;
368 int bits; 368 int bits;
369 369
370 dbg("%s - port %d", __FUNCTION__, port->number); 370 dbg("%s - port %d", __func__, port->number);
371 371
372 if (!port->tty || !port->tty->termios) { 372 if (!port->tty || !port->tty->termios) {
373 dbg("%s - no tty structures", __FUNCTION__); 373 dbg("%s - no tty structures", __func__);
374 return; 374 return;
375 } 375 }
376 376
@@ -379,7 +379,7 @@ static void cp2101_get_termios (struct usb_serial_port *port)
379 if (baud) 379 if (baud)
380 baud = BAUD_RATE_GEN_FREQ / baud; 380 baud = BAUD_RATE_GEN_FREQ / baud;
381 381
382 dbg("%s - baud rate = %d", __FUNCTION__, baud); 382 dbg("%s - baud rate = %d", __func__, baud);
383 383
384 tty_encode_baud_rate(port->tty, baud, baud); 384 tty_encode_baud_rate(port->tty, baud, baud);
385 cflag = port->tty->termios->c_cflag; 385 cflag = port->tty->termios->c_cflag;
@@ -388,24 +388,24 @@ static void cp2101_get_termios (struct usb_serial_port *port)
388 cflag &= ~CSIZE; 388 cflag &= ~CSIZE;
389 switch(bits & BITS_DATA_MASK) { 389 switch(bits & BITS_DATA_MASK) {
390 case BITS_DATA_5: 390 case BITS_DATA_5:
391 dbg("%s - data bits = 5", __FUNCTION__); 391 dbg("%s - data bits = 5", __func__);
392 cflag |= CS5; 392 cflag |= CS5;
393 break; 393 break;
394 case BITS_DATA_6: 394 case BITS_DATA_6:
395 dbg("%s - data bits = 6", __FUNCTION__); 395 dbg("%s - data bits = 6", __func__);
396 cflag |= CS6; 396 cflag |= CS6;
397 break; 397 break;
398 case BITS_DATA_7: 398 case BITS_DATA_7:
399 dbg("%s - data bits = 7", __FUNCTION__); 399 dbg("%s - data bits = 7", __func__);
400 cflag |= CS7; 400 cflag |= CS7;
401 break; 401 break;
402 case BITS_DATA_8: 402 case BITS_DATA_8:
403 dbg("%s - data bits = 8", __FUNCTION__); 403 dbg("%s - data bits = 8", __func__);
404 cflag |= CS8; 404 cflag |= CS8;
405 break; 405 break;
406 case BITS_DATA_9: 406 case BITS_DATA_9:
407 dbg("%s - data bits = 9 (not supported, " 407 dbg("%s - data bits = 9 (not supported, "
408 "using 8 data bits)", __FUNCTION__); 408 "using 8 data bits)", __func__);
409 cflag |= CS8; 409 cflag |= CS8;
410 bits &= ~BITS_DATA_MASK; 410 bits &= ~BITS_DATA_MASK;
411 bits |= BITS_DATA_8; 411 bits |= BITS_DATA_8;
@@ -413,7 +413,7 @@ static void cp2101_get_termios (struct usb_serial_port *port)
413 break; 413 break;
414 default: 414 default:
415 dbg("%s - Unknown number of data bits, " 415 dbg("%s - Unknown number of data bits, "
416 "using 8", __FUNCTION__); 416 "using 8", __func__);
417 cflag |= CS8; 417 cflag |= CS8;
418 bits &= ~BITS_DATA_MASK; 418 bits &= ~BITS_DATA_MASK;
419 bits |= BITS_DATA_8; 419 bits |= BITS_DATA_8;
@@ -423,35 +423,35 @@ static void cp2101_get_termios (struct usb_serial_port *port)
423 423
424 switch(bits & BITS_PARITY_MASK) { 424 switch(bits & BITS_PARITY_MASK) {
425 case BITS_PARITY_NONE: 425 case BITS_PARITY_NONE:
426 dbg("%s - parity = NONE", __FUNCTION__); 426 dbg("%s - parity = NONE", __func__);
427 cflag &= ~PARENB; 427 cflag &= ~PARENB;
428 break; 428 break;
429 case BITS_PARITY_ODD: 429 case BITS_PARITY_ODD:
430 dbg("%s - parity = ODD", __FUNCTION__); 430 dbg("%s - parity = ODD", __func__);
431 cflag |= (PARENB|PARODD); 431 cflag |= (PARENB|PARODD);
432 break; 432 break;
433 case BITS_PARITY_EVEN: 433 case BITS_PARITY_EVEN:
434 dbg("%s - parity = EVEN", __FUNCTION__); 434 dbg("%s - parity = EVEN", __func__);
435 cflag &= ~PARODD; 435 cflag &= ~PARODD;
436 cflag |= PARENB; 436 cflag |= PARENB;
437 break; 437 break;
438 case BITS_PARITY_MARK: 438 case BITS_PARITY_MARK:
439 dbg("%s - parity = MARK (not supported, " 439 dbg("%s - parity = MARK (not supported, "
440 "disabling parity)", __FUNCTION__); 440 "disabling parity)", __func__);
441 cflag &= ~PARENB; 441 cflag &= ~PARENB;
442 bits &= ~BITS_PARITY_MASK; 442 bits &= ~BITS_PARITY_MASK;
443 cp2101_set_config(port, CP2101_BITS, &bits, 2); 443 cp2101_set_config(port, CP2101_BITS, &bits, 2);
444 break; 444 break;
445 case BITS_PARITY_SPACE: 445 case BITS_PARITY_SPACE:
446 dbg("%s - parity = SPACE (not supported, " 446 dbg("%s - parity = SPACE (not supported, "
447 "disabling parity)", __FUNCTION__); 447 "disabling parity)", __func__);
448 cflag &= ~PARENB; 448 cflag &= ~PARENB;
449 bits &= ~BITS_PARITY_MASK; 449 bits &= ~BITS_PARITY_MASK;
450 cp2101_set_config(port, CP2101_BITS, &bits, 2); 450 cp2101_set_config(port, CP2101_BITS, &bits, 2);
451 break; 451 break;
452 default: 452 default:
453 dbg("%s - Unknown parity mode, " 453 dbg("%s - Unknown parity mode, "
454 "disabling parity", __FUNCTION__); 454 "disabling parity", __func__);
455 cflag &= ~PARENB; 455 cflag &= ~PARENB;
456 bits &= ~BITS_PARITY_MASK; 456 bits &= ~BITS_PARITY_MASK;
457 cp2101_set_config(port, CP2101_BITS, &bits, 2); 457 cp2101_set_config(port, CP2101_BITS, &bits, 2);
@@ -461,21 +461,21 @@ static void cp2101_get_termios (struct usb_serial_port *port)
461 cflag &= ~CSTOPB; 461 cflag &= ~CSTOPB;
462 switch(bits & BITS_STOP_MASK) { 462 switch(bits & BITS_STOP_MASK) {
463 case BITS_STOP_1: 463 case BITS_STOP_1:
464 dbg("%s - stop bits = 1", __FUNCTION__); 464 dbg("%s - stop bits = 1", __func__);
465 break; 465 break;
466 case BITS_STOP_1_5: 466 case BITS_STOP_1_5:
467 dbg("%s - stop bits = 1.5 (not supported, " 467 dbg("%s - stop bits = 1.5 (not supported, "
468 "using 1 stop bit)", __FUNCTION__); 468 "using 1 stop bit)", __func__);
469 bits &= ~BITS_STOP_MASK; 469 bits &= ~BITS_STOP_MASK;
470 cp2101_set_config(port, CP2101_BITS, &bits, 2); 470 cp2101_set_config(port, CP2101_BITS, &bits, 2);
471 break; 471 break;
472 case BITS_STOP_2: 472 case BITS_STOP_2:
473 dbg("%s - stop bits = 2", __FUNCTION__); 473 dbg("%s - stop bits = 2", __func__);
474 cflag |= CSTOPB; 474 cflag |= CSTOPB;
475 break; 475 break;
476 default: 476 default:
477 dbg("%s - Unknown number of stop bits, " 477 dbg("%s - Unknown number of stop bits, "
478 "using 1 stop bit", __FUNCTION__); 478 "using 1 stop bit", __func__);
479 bits &= ~BITS_STOP_MASK; 479 bits &= ~BITS_STOP_MASK;
480 cp2101_set_config(port, CP2101_BITS, &bits, 2); 480 cp2101_set_config(port, CP2101_BITS, &bits, 2);
481 break; 481 break;
@@ -483,10 +483,10 @@ static void cp2101_get_termios (struct usb_serial_port *port)
483 483
484 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 484 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
485 if (modem_ctl[0] & 0x0008) { 485 if (modem_ctl[0] & 0x0008) {
486 dbg("%s - flow control = CRTSCTS", __FUNCTION__); 486 dbg("%s - flow control = CRTSCTS", __func__);
487 cflag |= CRTSCTS; 487 cflag |= CRTSCTS;
488 } else { 488 } else {
489 dbg("%s - flow control = NONE", __FUNCTION__); 489 dbg("%s - flow control = NONE", __func__);
490 cflag &= ~CRTSCTS; 490 cflag &= ~CRTSCTS;
491 } 491 }
492 492
@@ -500,10 +500,10 @@ static void cp2101_set_termios (struct usb_serial_port *port,
500 int baud=0, bits; 500 int baud=0, bits;
501 unsigned int modem_ctl[4]; 501 unsigned int modem_ctl[4];
502 502
503 dbg("%s - port %d", __FUNCTION__, port->number); 503 dbg("%s - port %d", __func__, port->number);
504 504
505 if (!port->tty || !port->tty->termios) { 505 if (!port->tty || !port->tty->termios) {
506 dbg("%s - no tty structures", __FUNCTION__); 506 dbg("%s - no tty structures", __func__);
507 return; 507 return;
508 } 508 }
509 port->tty->termios->c_cflag &= ~CMSPAR; 509 port->tty->termios->c_cflag &= ~CMSPAR;
@@ -542,7 +542,7 @@ static void cp2101_set_termios (struct usb_serial_port *port,
542 } 542 }
543 543
544 if (baud) { 544 if (baud) {
545 dbg("%s - Setting baud rate to %d baud", __FUNCTION__, 545 dbg("%s - Setting baud rate to %d baud", __func__,
546 baud); 546 baud);
547 if (cp2101_set_config_single(port, CP2101_BAUDRATE, 547 if (cp2101_set_config_single(port, CP2101_BAUDRATE,
548 (BAUD_RATE_GEN_FREQ / baud))) { 548 (BAUD_RATE_GEN_FREQ / baud))) {
@@ -562,23 +562,23 @@ static void cp2101_set_termios (struct usb_serial_port *port,
562 switch (cflag & CSIZE) { 562 switch (cflag & CSIZE) {
563 case CS5: 563 case CS5:
564 bits |= BITS_DATA_5; 564 bits |= BITS_DATA_5;
565 dbg("%s - data bits = 5", __FUNCTION__); 565 dbg("%s - data bits = 5", __func__);
566 break; 566 break;
567 case CS6: 567 case CS6:
568 bits |= BITS_DATA_6; 568 bits |= BITS_DATA_6;
569 dbg("%s - data bits = 6", __FUNCTION__); 569 dbg("%s - data bits = 6", __func__);
570 break; 570 break;
571 case CS7: 571 case CS7:
572 bits |= BITS_DATA_7; 572 bits |= BITS_DATA_7;
573 dbg("%s - data bits = 7", __FUNCTION__); 573 dbg("%s - data bits = 7", __func__);
574 break; 574 break;
575 case CS8: 575 case CS8:
576 bits |= BITS_DATA_8; 576 bits |= BITS_DATA_8;
577 dbg("%s - data bits = 8", __FUNCTION__); 577 dbg("%s - data bits = 8", __func__);
578 break; 578 break;
579 /*case CS9: 579 /*case CS9:
580 bits |= BITS_DATA_9; 580 bits |= BITS_DATA_9;
581 dbg("%s - data bits = 9", __FUNCTION__); 581 dbg("%s - data bits = 9", __func__);
582 break;*/ 582 break;*/
583 default: 583 default:
584 dev_err(&port->dev, "cp2101 driver does not " 584 dev_err(&port->dev, "cp2101 driver does not "
@@ -598,10 +598,10 @@ static void cp2101_set_termios (struct usb_serial_port *port,
598 if (cflag & PARENB) { 598 if (cflag & PARENB) {
599 if (cflag & PARODD) { 599 if (cflag & PARODD) {
600 bits |= BITS_PARITY_ODD; 600 bits |= BITS_PARITY_ODD;
601 dbg("%s - parity = ODD", __FUNCTION__); 601 dbg("%s - parity = ODD", __func__);
602 } else { 602 } else {
603 bits |= BITS_PARITY_EVEN; 603 bits |= BITS_PARITY_EVEN;
604 dbg("%s - parity = EVEN", __FUNCTION__); 604 dbg("%s - parity = EVEN", __func__);
605 } 605 }
606 } 606 }
607 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 607 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
@@ -614,10 +614,10 @@ static void cp2101_set_termios (struct usb_serial_port *port,
614 bits &= ~BITS_STOP_MASK; 614 bits &= ~BITS_STOP_MASK;
615 if (cflag & CSTOPB) { 615 if (cflag & CSTOPB) {
616 bits |= BITS_STOP_2; 616 bits |= BITS_STOP_2;
617 dbg("%s - stop bits = 2", __FUNCTION__); 617 dbg("%s - stop bits = 2", __func__);
618 } else { 618 } else {
619 bits |= BITS_STOP_1; 619 bits |= BITS_STOP_1;
620 dbg("%s - stop bits = 1", __FUNCTION__); 620 dbg("%s - stop bits = 1", __func__);
621 } 621 }
622 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 622 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
623 dev_err(&port->dev, "Number of stop bits requested " 623 dev_err(&port->dev, "Number of stop bits requested "
@@ -627,23 +627,23 @@ static void cp2101_set_termios (struct usb_serial_port *port,
627 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { 627 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
628 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 628 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
629 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 629 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
630 __FUNCTION__, modem_ctl[0], modem_ctl[1], 630 __func__, modem_ctl[0], modem_ctl[1],
631 modem_ctl[2], modem_ctl[3]); 631 modem_ctl[2], modem_ctl[3]);
632 632
633 if (cflag & CRTSCTS) { 633 if (cflag & CRTSCTS) {
634 modem_ctl[0] &= ~0x7B; 634 modem_ctl[0] &= ~0x7B;
635 modem_ctl[0] |= 0x09; 635 modem_ctl[0] |= 0x09;
636 modem_ctl[1] = 0x80; 636 modem_ctl[1] = 0x80;
637 dbg("%s - flow control = CRTSCTS", __FUNCTION__); 637 dbg("%s - flow control = CRTSCTS", __func__);
638 } else { 638 } else {
639 modem_ctl[0] &= ~0x7B; 639 modem_ctl[0] &= ~0x7B;
640 modem_ctl[0] |= 0x01; 640 modem_ctl[0] |= 0x01;
641 modem_ctl[1] |= 0x40; 641 modem_ctl[1] |= 0x40;
642 dbg("%s - flow control = NONE", __FUNCTION__); 642 dbg("%s - flow control = NONE", __func__);
643 } 643 }
644 644
645 dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 645 dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
646 __FUNCTION__, modem_ctl[0], modem_ctl[1], 646 __func__, modem_ctl[0], modem_ctl[1],
647 modem_ctl[2], modem_ctl[3]); 647 modem_ctl[2], modem_ctl[3]);
648 cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16); 648 cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16);
649 } 649 }
@@ -655,7 +655,7 @@ static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file,
655{ 655{
656 int control = 0; 656 int control = 0;
657 657
658 dbg("%s - port %d", __FUNCTION__, port->number); 658 dbg("%s - port %d", __func__, port->number);
659 659
660 if (set & TIOCM_RTS) { 660 if (set & TIOCM_RTS) {
661 control |= CONTROL_RTS; 661 control |= CONTROL_RTS;
@@ -674,7 +674,7 @@ static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file,
674 control |= CONTROL_WRITE_DTR; 674 control |= CONTROL_WRITE_DTR;
675 } 675 }
676 676
677 dbg("%s - control = 0x%.4x", __FUNCTION__, control); 677 dbg("%s - control = 0x%.4x", __func__, control);
678 678
679 return cp2101_set_config(port, CP2101_CONTROL, &control, 2); 679 return cp2101_set_config(port, CP2101_CONTROL, &control, 2);
680 680
@@ -684,7 +684,7 @@ static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file)
684{ 684{
685 int control, result; 685 int control, result;
686 686
687 dbg("%s - port %d", __FUNCTION__, port->number); 687 dbg("%s - port %d", __func__, port->number);
688 688
689 cp2101_get_config(port, CP2101_CONTROL, &control, 1); 689 cp2101_get_config(port, CP2101_CONTROL, &control, 1);
690 690
@@ -695,7 +695,7 @@ static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file)
695 |((control & CONTROL_RING)? TIOCM_RI : 0) 695 |((control & CONTROL_RING)? TIOCM_RI : 0)
696 |((control & CONTROL_DCD) ? TIOCM_CD : 0); 696 |((control & CONTROL_DCD) ? TIOCM_CD : 0);
697 697
698 dbg("%s - control = 0x%.2x", __FUNCTION__, control); 698 dbg("%s - control = 0x%.2x", __func__, control);
699 699
700 return result; 700 return result;
701} 701}
@@ -704,12 +704,12 @@ static void cp2101_break_ctl (struct usb_serial_port *port, int break_state)
704{ 704{
705 int state; 705 int state;
706 706
707 dbg("%s - port %d", __FUNCTION__, port->number); 707 dbg("%s - port %d", __func__, port->number);
708 if (break_state == 0) 708 if (break_state == 0)
709 state = BREAK_OFF; 709 state = BREAK_OFF;
710 else 710 else
711 state = BREAK_ON; 711 state = BREAK_ON;
712 dbg("%s - turning break %s", __FUNCTION__, 712 dbg("%s - turning break %s", __func__,
713 state==BREAK_OFF ? "off" : "on"); 713 state==BREAK_OFF ? "off" : "on");
714 cp2101_set_config(port, CP2101_BREAK, &state, 2); 714 cp2101_set_config(port, CP2101_BREAK, &state, 2);
715} 715}
@@ -725,7 +725,7 @@ static void cp2101_shutdown (struct usb_serial *serial)
725{ 725{
726 int i; 726 int i;
727 727
728 dbg("%s", __FUNCTION__); 728 dbg("%s", __func__);
729 729
730 /* Stop reads and writes on all ports */ 730 /* Stop reads and writes on all ports */
731 for (i=0; i < serial->num_ports; ++i) { 731 for (i=0; i < serial->num_ports; ++i) {
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 8d9b045aa7e8..c164e2cf2752 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -90,9 +90,6 @@ static struct usb_serial_driver cyberjack_device = {
90 .description = "Reiner SCT Cyberjack USB card reader", 90 .description = "Reiner SCT Cyberjack USB card reader",
91 .usb_driver = &cyberjack_driver, 91 .usb_driver = &cyberjack_driver,
92 .id_table = id_table, 92 .id_table = id_table,
93 .num_interrupt_in = 1,
94 .num_bulk_in = 1,
95 .num_bulk_out = 1,
96 .num_ports = 1, 93 .num_ports = 1,
97 .attach = cyberjack_startup, 94 .attach = cyberjack_startup,
98 .shutdown = cyberjack_shutdown, 95 .shutdown = cyberjack_shutdown,
@@ -119,7 +116,7 @@ static int cyberjack_startup (struct usb_serial *serial)
119 struct cyberjack_private *priv; 116 struct cyberjack_private *priv;
120 int i; 117 int i;
121 118
122 dbg("%s", __FUNCTION__); 119 dbg("%s", __func__);
123 120
124 /* allocate the private data structure */ 121 /* allocate the private data structure */
125 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL); 122 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL);
@@ -142,7 +139,7 @@ static int cyberjack_startup (struct usb_serial *serial)
142 GFP_KERNEL); 139 GFP_KERNEL);
143 if (result) 140 if (result)
144 err(" usb_submit_urb(read int) failed"); 141 err(" usb_submit_urb(read int) failed");
145 dbg("%s - usb_submit_urb(int urb)", __FUNCTION__); 142 dbg("%s - usb_submit_urb(int urb)", __func__);
146 } 143 }
147 144
148 return( 0 ); 145 return( 0 );
@@ -152,9 +149,9 @@ static void cyberjack_shutdown (struct usb_serial *serial)
152{ 149{
153 int i; 150 int i;
154 151
155 dbg("%s", __FUNCTION__); 152 dbg("%s", __func__);
156 153
157 for (i=0; i < serial->num_ports; ++i) { 154 for (i = 0; i < serial->num_ports; ++i) {
158 usb_kill_urb(serial->port[i]->interrupt_in_urb); 155 usb_kill_urb(serial->port[i]->interrupt_in_urb);
159 /* My special items, the standard routines free my urbs */ 156 /* My special items, the standard routines free my urbs */
160 kfree(usb_get_serial_port_data(serial->port[i])); 157 kfree(usb_get_serial_port_data(serial->port[i]));
@@ -168,9 +165,9 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
168 unsigned long flags; 165 unsigned long flags;
169 int result = 0; 166 int result = 0;
170 167
171 dbg("%s - port %d", __FUNCTION__, port->number); 168 dbg("%s - port %d", __func__, port->number);
172 169
173 dbg("%s - usb_clear_halt", __FUNCTION__ ); 170 dbg("%s - usb_clear_halt", __func__ );
174 usb_clear_halt(port->serial->dev, port->write_urb->pipe); 171 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
175 172
176 /* force low_latency on so that our tty_push actually forces 173 /* force low_latency on so that our tty_push actually forces
@@ -191,7 +188,7 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
191 188
192static void cyberjack_close (struct usb_serial_port *port, struct file *filp) 189static void cyberjack_close (struct usb_serial_port *port, struct file *filp)
193{ 190{
194 dbg("%s - port %d", __FUNCTION__, port->number); 191 dbg("%s - port %d", __func__, port->number);
195 192
196 if (port->serial->dev) { 193 if (port->serial->dev) {
197 /* shutdown any bulk reads that might be going on */ 194 /* shutdown any bulk reads that might be going on */
@@ -208,17 +205,17 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
208 int result; 205 int result;
209 int wrexpected; 206 int wrexpected;
210 207
211 dbg("%s - port %d", __FUNCTION__, port->number); 208 dbg("%s - port %d", __func__, port->number);
212 209
213 if (count == 0) { 210 if (count == 0) {
214 dbg("%s - write request of 0 bytes", __FUNCTION__); 211 dbg("%s - write request of 0 bytes", __func__);
215 return (0); 212 return 0;
216 } 213 }
217 214
218 spin_lock_bh(&port->lock); 215 spin_lock_bh(&port->lock);
219 if (port->write_urb_busy) { 216 if (port->write_urb_busy) {
220 spin_unlock_bh(&port->lock); 217 spin_unlock_bh(&port->lock);
221 dbg("%s - already writing", __FUNCTION__); 218 dbg("%s - already writing", __func__);
222 return 0; 219 return 0;
223 } 220 }
224 port->write_urb_busy = 1; 221 port->write_urb_busy = 1;
@@ -226,24 +223,24 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
226 223
227 spin_lock_irqsave(&priv->lock, flags); 224 spin_lock_irqsave(&priv->lock, flags);
228 225
229 if( (count+priv->wrfilled)>sizeof(priv->wrbuf) ) { 226 if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) {
230 /* To much data for buffer. Reset buffer. */ 227 /* To much data for buffer. Reset buffer. */
231 priv->wrfilled=0; 228 priv->wrfilled = 0;
232 spin_unlock_irqrestore(&priv->lock, flags);
233 port->write_urb_busy = 0; 229 port->write_urb_busy = 0;
234 return (0); 230 spin_unlock_irqrestore(&priv->lock, flags);
231 return 0;
235 } 232 }
236 233
237 /* Copy data */ 234 /* Copy data */
238 memcpy (priv->wrbuf+priv->wrfilled, buf, count); 235 memcpy (priv->wrbuf+priv->wrfilled, buf, count);
239 236
240 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, 237 usb_serial_debug_data(debug, &port->dev, __func__, count,
241 priv->wrbuf+priv->wrfilled); 238 priv->wrbuf+priv->wrfilled);
242 priv->wrfilled += count; 239 priv->wrfilled += count;
243 240
244 if( priv->wrfilled >= 3 ) { 241 if( priv->wrfilled >= 3 ) {
245 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 242 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
246 dbg("%s - expected data: %d", __FUNCTION__, wrexpected); 243 dbg("%s - expected data: %d", __func__, wrexpected);
247 } else { 244 } else {
248 wrexpected = sizeof(priv->wrbuf); 245 wrexpected = sizeof(priv->wrbuf);
249 } 246 }
@@ -252,7 +249,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
252 /* We have enough data to begin transmission */ 249 /* We have enough data to begin transmission */
253 int length; 250 int length;
254 251
255 dbg("%s - transmitting data (frame 1)", __FUNCTION__); 252 dbg("%s - transmitting data (frame 1)", __func__);
256 length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected; 253 length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected;
257 254
258 memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length ); 255 memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length );
@@ -270,23 +267,23 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
270 /* send the data out the bulk port */ 267 /* send the data out the bulk port */
271 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 268 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
272 if (result) { 269 if (result) {
273 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 270 err("%s - failed submitting write urb, error %d", __func__, result);
274 /* Throw away data. No better idea what to do with it. */ 271 /* Throw away data. No better idea what to do with it. */
275 priv->wrfilled=0; 272 priv->wrfilled = 0;
276 priv->wrsent=0; 273 priv->wrsent = 0;
277 spin_unlock_irqrestore(&priv->lock, flags); 274 spin_unlock_irqrestore(&priv->lock, flags);
278 port->write_urb_busy = 0; 275 port->write_urb_busy = 0;
279 return 0; 276 return 0;
280 } 277 }
281 278
282 dbg("%s - priv->wrsent=%d", __FUNCTION__,priv->wrsent); 279 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
283 dbg("%s - priv->wrfilled=%d", __FUNCTION__,priv->wrfilled); 280 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
284 281
285 if( priv->wrsent>=priv->wrfilled ) { 282 if( priv->wrsent>=priv->wrfilled ) {
286 dbg("%s - buffer cleaned", __FUNCTION__); 283 dbg("%s - buffer cleaned", __func__);
287 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 284 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
288 priv->wrfilled=0; 285 priv->wrfilled = 0;
289 priv->wrsent=0; 286 priv->wrsent = 0;
290 } 287 }
291 } 288 }
292 289
@@ -297,27 +294,28 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
297 294
298static int cyberjack_write_room( struct usb_serial_port *port ) 295static int cyberjack_write_room( struct usb_serial_port *port )
299{ 296{
297 /* FIXME: .... */
300 return CYBERJACK_LOCAL_BUF_SIZE; 298 return CYBERJACK_LOCAL_BUF_SIZE;
301} 299}
302 300
303static void cyberjack_read_int_callback( struct urb *urb ) 301static void cyberjack_read_int_callback( struct urb *urb )
304{ 302{
305 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 303 struct usb_serial_port *port = urb->context;
306 struct cyberjack_private *priv = usb_get_serial_port_data(port); 304 struct cyberjack_private *priv = usb_get_serial_port_data(port);
307 unsigned char *data = urb->transfer_buffer; 305 unsigned char *data = urb->transfer_buffer;
308 int status = urb->status; 306 int status = urb->status;
309 int result; 307 int result;
310 308
311 dbg("%s - port %d", __FUNCTION__, port->number); 309 dbg("%s - port %d", __func__, port->number);
312 310
313 /* the urb might have been killed. */ 311 /* the urb might have been killed. */
314 if (status) 312 if (status)
315 return; 313 return;
316 314
317 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 315 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
318 316
319 /* React only to interrupts signaling a bulk_in transfer */ 317 /* React only to interrupts signaling a bulk_in transfer */
320 if( (urb->actual_length==4) && (data[0]==0x01) ) { 318 if( (urb->actual_length == 4) && (data[0] == 0x01) ) {
321 short old_rdtodo; 319 short old_rdtodo;
322 320
323 /* This is a announcement of coming bulk_ins. */ 321 /* This is a announcement of coming bulk_ins. */
@@ -336,7 +334,7 @@ static void cyberjack_read_int_callback( struct urb *urb )
336 /* "+=" is probably more fault tollerant than "=" */ 334 /* "+=" is probably more fault tollerant than "=" */
337 priv->rdtodo += size; 335 priv->rdtodo += size;
338 336
339 dbg("%s - rdtodo: %d", __FUNCTION__, priv->rdtodo); 337 dbg("%s - rdtodo: %d", __func__, priv->rdtodo);
340 338
341 spin_unlock(&priv->lock); 339 spin_unlock(&priv->lock);
342 340
@@ -344,8 +342,8 @@ static void cyberjack_read_int_callback( struct urb *urb )
344 port->read_urb->dev = port->serial->dev; 342 port->read_urb->dev = port->serial->dev;
345 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 343 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
346 if( result ) 344 if( result )
347 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 345 err("%s - failed resubmitting read urb, error %d", __func__, result);
348 dbg("%s - usb_submit_urb(read urb)", __FUNCTION__); 346 dbg("%s - usb_submit_urb(read urb)", __func__);
349 } 347 }
350 } 348 }
351 349
@@ -354,12 +352,12 @@ resubmit:
354 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 352 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
355 if (result) 353 if (result)
356 err(" usb_submit_urb(read int) failed"); 354 err(" usb_submit_urb(read int) failed");
357 dbg("%s - usb_submit_urb(int urb)", __FUNCTION__); 355 dbg("%s - usb_submit_urb(int urb)", __func__);
358} 356}
359 357
360static void cyberjack_read_bulk_callback (struct urb *urb) 358static void cyberjack_read_bulk_callback (struct urb *urb)
361{ 359{
362 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 360 struct usb_serial_port *port = urb->context;
363 struct cyberjack_private *priv = usb_get_serial_port_data(port); 361 struct cyberjack_private *priv = usb_get_serial_port_data(port);
364 struct tty_struct *tty; 362 struct tty_struct *tty;
365 unsigned char *data = urb->transfer_buffer; 363 unsigned char *data = urb->transfer_buffer;
@@ -367,18 +365,18 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
367 int result; 365 int result;
368 int status = urb->status; 366 int status = urb->status;
369 367
370 dbg("%s - port %d", __FUNCTION__, port->number); 368 dbg("%s - port %d", __func__, port->number);
371 369
372 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 370 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
373 if (status) { 371 if (status) {
374 dbg("%s - nonzero read bulk status received: %d", 372 dbg("%s - nonzero read bulk status received: %d",
375 __FUNCTION__, status); 373 __func__, status);
376 return; 374 return;
377 } 375 }
378 376
379 tty = port->tty; 377 tty = port->tty;
380 if (!tty) { 378 if (!tty) {
381 dbg("%s - ignoring since device not open\n", __FUNCTION__); 379 dbg("%s - ignoring since device not open\n", __func__);
382 return; 380 return;
383 } 381 }
384 if (urb->actual_length) { 382 if (urb->actual_length) {
@@ -397,30 +395,30 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
397 395
398 spin_unlock(&priv->lock); 396 spin_unlock(&priv->lock);
399 397
400 dbg("%s - rdtodo: %d", __FUNCTION__, todo); 398 dbg("%s - rdtodo: %d", __func__, todo);
401 399
402 /* Continue to read if we have still urbs to do. */ 400 /* Continue to read if we have still urbs to do. */
403 if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) { 401 if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) {
404 port->read_urb->dev = port->serial->dev; 402 port->read_urb->dev = port->serial->dev;
405 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 403 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
406 if (result) 404 if (result)
407 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 405 err("%s - failed resubmitting read urb, error %d", __func__, result);
408 dbg("%s - usb_submit_urb(read urb)", __FUNCTION__); 406 dbg("%s - usb_submit_urb(read urb)", __func__);
409 } 407 }
410} 408}
411 409
412static void cyberjack_write_bulk_callback (struct urb *urb) 410static void cyberjack_write_bulk_callback (struct urb *urb)
413{ 411{
414 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 412 struct usb_serial_port *port = urb->context;
415 struct cyberjack_private *priv = usb_get_serial_port_data(port); 413 struct cyberjack_private *priv = usb_get_serial_port_data(port);
416 int status = urb->status; 414 int status = urb->status;
417 415
418 dbg("%s - port %d", __FUNCTION__, port->number); 416 dbg("%s - port %d", __func__, port->number);
419 417
420 port->write_urb_busy = 0; 418 port->write_urb_busy = 0;
421 if (status) { 419 if (status) {
422 dbg("%s - nonzero write bulk status received: %d", 420 dbg("%s - nonzero write bulk status received: %d",
423 __FUNCTION__, status); 421 __func__, status);
424 return; 422 return;
425 } 423 }
426 424
@@ -430,7 +428,7 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
430 if( priv->wrfilled ) { 428 if( priv->wrfilled ) {
431 int length, blksize, result; 429 int length, blksize, result;
432 430
433 dbg("%s - transmitting data (frame n)", __FUNCTION__); 431 dbg("%s - transmitting data (frame n)", __func__);
434 432
435 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? 433 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
436 port->bulk_out_size : (priv->wrfilled - priv->wrsent); 434 port->bulk_out_size : (priv->wrfilled - priv->wrsent);
@@ -451,23 +449,23 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
451 /* send the data out the bulk port */ 449 /* send the data out the bulk port */
452 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 450 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
453 if (result) { 451 if (result) {
454 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 452 err("%s - failed submitting write urb, error %d", __func__, result);
455 /* Throw away data. No better idea what to do with it. */ 453 /* Throw away data. No better idea what to do with it. */
456 priv->wrfilled=0; 454 priv->wrfilled = 0;
457 priv->wrsent=0; 455 priv->wrsent = 0;
458 goto exit; 456 goto exit;
459 } 457 }
460 458
461 dbg("%s - priv->wrsent=%d", __FUNCTION__,priv->wrsent); 459 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
462 dbg("%s - priv->wrfilled=%d", __FUNCTION__,priv->wrfilled); 460 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
463 461
464 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 462 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
465 463
466 if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) { 464 if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) {
467 dbg("%s - buffer cleaned", __FUNCTION__); 465 dbg("%s - buffer cleaned", __func__);
468 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 466 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
469 priv->wrfilled=0; 467 priv->wrfilled = 0;
470 priv->wrsent=0; 468 priv->wrsent = 0;
471 } 469 }
472 } 470 }
473 471
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 779d07851a4d..32121794808d 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -122,6 +122,11 @@ static struct usb_driver cypress_driver = {
122 .no_dynamic_id = 1, 122 .no_dynamic_id = 1,
123}; 123};
124 124
125enum packet_format {
126 packet_format_1, /* b0:status, b1:payload count */
127 packet_format_2 /* b0[7:3]:status, b0[2:0]:payload count */
128};
129
125struct cypress_private { 130struct cypress_private {
126 spinlock_t lock; /* private lock */ 131 spinlock_t lock; /* private lock */
127 int chiptype; /* identifier of device, for quirks/etc */ 132 int chiptype; /* identifier of device, for quirks/etc */
@@ -139,8 +144,9 @@ struct cypress_private {
139 __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */ 144 __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */
140 __u8 current_config; /* stores the current configuration byte */ 145 __u8 current_config; /* stores the current configuration byte */
141 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */ 146 __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
147 enum packet_format pkt_fmt; /* format to use for packet send / receive */
148 int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */
142 int baud_rate; /* stores current baud rate in integer form */ 149 int baud_rate; /* stores current baud rate in integer form */
143 int cbr_mask; /* stores current baud rate in masked form */
144 int isthrottled; /* if throttled, discard reads */ 150 int isthrottled; /* if throttled, discard reads */
145 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ 151 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
146 char prev_status, diff_status; /* used for TIOCMIWAIT */ 152 char prev_status, diff_status; /* used for TIOCMIWAIT */
@@ -176,9 +182,6 @@ static void cypress_unthrottle (struct usb_serial_port *port);
176static void cypress_set_dead (struct usb_serial_port *port); 182static void cypress_set_dead (struct usb_serial_port *port);
177static void cypress_read_int_callback (struct urb *urb); 183static void cypress_read_int_callback (struct urb *urb);
178static void cypress_write_int_callback (struct urb *urb); 184static void cypress_write_int_callback (struct urb *urb);
179/* baud helper functions */
180static int mask_to_rate (unsigned mask);
181static unsigned rate_to_mask (int rate);
182/* write buffer functions */ 185/* write buffer functions */
183static struct cypress_buf *cypress_buf_alloc(unsigned int size); 186static struct cypress_buf *cypress_buf_alloc(unsigned int size);
184static void cypress_buf_free(struct cypress_buf *cb); 187static void cypress_buf_free(struct cypress_buf *cb);
@@ -197,10 +200,6 @@ static struct usb_serial_driver cypress_earthmate_device = {
197 .description = "DeLorme Earthmate USB", 200 .description = "DeLorme Earthmate USB",
198 .usb_driver = &cypress_driver, 201 .usb_driver = &cypress_driver,
199 .id_table = id_table_earthmate, 202 .id_table = id_table_earthmate,
200 .num_interrupt_in = 1,
201 .num_interrupt_out = 1,
202 .num_bulk_in = NUM_DONT_CARE,
203 .num_bulk_out = NUM_DONT_CARE,
204 .num_ports = 1, 203 .num_ports = 1,
205 .attach = cypress_earthmate_startup, 204 .attach = cypress_earthmate_startup,
206 .shutdown = cypress_shutdown, 205 .shutdown = cypress_shutdown,
@@ -227,10 +226,6 @@ static struct usb_serial_driver cypress_hidcom_device = {
227 .description = "HID->COM RS232 Adapter", 226 .description = "HID->COM RS232 Adapter",
228 .usb_driver = &cypress_driver, 227 .usb_driver = &cypress_driver,
229 .id_table = id_table_cyphidcomrs232, 228 .id_table = id_table_cyphidcomrs232,
230 .num_interrupt_in = 1,
231 .num_interrupt_out = 1,
232 .num_bulk_in = NUM_DONT_CARE,
233 .num_bulk_out = NUM_DONT_CARE,
234 .num_ports = 1, 229 .num_ports = 1,
235 .attach = cypress_hidcom_startup, 230 .attach = cypress_hidcom_startup,
236 .shutdown = cypress_shutdown, 231 .shutdown = cypress_shutdown,
@@ -257,10 +252,6 @@ static struct usb_serial_driver cypress_ca42v2_device = {
257 .description = "Nokia CA-42 V2 Adapter", 252 .description = "Nokia CA-42 V2 Adapter",
258 .usb_driver = &cypress_driver, 253 .usb_driver = &cypress_driver,
259 .id_table = id_table_nokiaca42v2, 254 .id_table = id_table_nokiaca42v2,
260 .num_interrupt_in = 1,
261 .num_interrupt_out = 1,
262 .num_bulk_in = NUM_DONT_CARE,
263 .num_bulk_out = NUM_DONT_CARE,
264 .num_ports = 1, 255 .num_ports = 1,
265 .attach = cypress_ca42v2_startup, 256 .attach = cypress_ca42v2_startup,
266 .shutdown = cypress_shutdown, 257 .shutdown = cypress_shutdown,
@@ -284,16 +275,62 @@ static struct usb_serial_driver cypress_ca42v2_device = {
284 *****************************************************************************/ 275 *****************************************************************************/
285 276
286 277
278static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
279{
280 struct cypress_private *priv;
281 priv = usb_get_serial_port_data(port);
282
283 /*
284 * The general purpose firmware for the Cypress M8 allows for
285 * a maximum speed of 57600bps (I have no idea whether DeLorme
286 * chose to use the general purpose firmware or not), if you
287 * need to modify this speed setting for your own project
288 * please add your own chiptype and modify the code likewise.
289 * The Cypress HID->COM device will work successfully up to
290 * 115200bps (but the actual throughput is around 3kBps).
291 */
292 if (port->serial->dev->speed == USB_SPEED_LOW) {
293 /*
294 * Mike Isely <isely@pobox.com> 2-Feb-2008: The
295 * Cypress app note that describes this mechanism
296 * states the the low-speed part can't handle more
297 * than 800 bytes/sec, in which case 4800 baud is the
298 * safest speed for a part like that.
299 */
300 if (new_rate > 4800) {
301 dbg("%s - failed setting baud rate, device incapable "
302 "speed %d", __func__, new_rate);
303 return -1;
304 }
305 }
306 switch (priv->chiptype) {
307 case CT_EARTHMATE:
308 if (new_rate <= 600) {
309 /* 300 and 600 baud rates are supported under
310 * the generic firmware, but are not used with
311 * NMEA and SiRF protocols */
312 dbg("%s - failed setting baud rate, unsupported speed "
313 "of %d on Earthmate GPS", __func__, new_rate);
314 return -1;
315 }
316 break;
317 default:
318 break;
319 }
320 return new_rate;
321}
322
323
287/* This function can either set or retrieve the current serial line settings */ 324/* This function can either set or retrieve the current serial line settings */
288static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_mask, int data_bits, int stop_bits, 325static int cypress_serial_control (struct usb_serial_port *port, speed_t baud_rate, int data_bits, int stop_bits,
289 int parity_enable, int parity_type, int reset, int cypress_request_type) 326 int parity_enable, int parity_type, int reset, int cypress_request_type)
290{ 327{
291 int new_baudrate = 0, retval = 0, tries = 0; 328 int new_baudrate = 0, retval = 0, tries = 0;
292 struct cypress_private *priv; 329 struct cypress_private *priv;
293 __u8 feature_buffer[8]; 330 __u8 feature_buffer[5];
294 unsigned long flags; 331 unsigned long flags;
295 332
296 dbg("%s", __FUNCTION__); 333 dbg("%s", __func__);
297 334
298 priv = usb_get_serial_port_data(port); 335 priv = usb_get_serial_port_data(port);
299 336
@@ -302,58 +339,23 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
302 339
303 switch(cypress_request_type) { 340 switch(cypress_request_type) {
304 case CYPRESS_SET_CONFIG: 341 case CYPRESS_SET_CONFIG:
305 342 new_baudrate = priv->baud_rate;
306 /* 343 /* 0 means 'Hang up' so doesn't change the true bit rate */
307 * The general purpose firmware for the Cypress M8 allows for a maximum speed 344 if (baud_rate == 0)
308 * of 57600bps (I have no idea whether DeLorme chose to use the general purpose
309 * firmware or not), if you need to modify this speed setting for your own
310 * project please add your own chiptype and modify the code likewise. The
311 * Cypress HID->COM device will work successfully up to 115200bps (but the
312 * actual throughput is around 3kBps).
313 */
314 if (baud_mask != priv->cbr_mask) {
315 dbg("%s - baud rate is changing", __FUNCTION__);
316 if ( priv->chiptype == CT_EARTHMATE ) {
317 /* 300 and 600 baud rates are supported under the generic firmware,
318 * but are not used with NMEA and SiRF protocols */
319
320 if ( (baud_mask == B300) || (baud_mask == B600) ) {
321 err("%s - failed setting baud rate, unsupported speed",
322 __FUNCTION__);
323 new_baudrate = priv->baud_rate;
324 } else if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
325 err("%s - failed setting baud rate, unsupported speed",
326 __FUNCTION__);
327 new_baudrate = priv->baud_rate;
328 }
329 } else if (priv->chiptype == CT_CYPHIDCOM) {
330 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
331 err("%s - failed setting baud rate, unsupported speed",
332 __FUNCTION__);
333 new_baudrate = priv->baud_rate;
334 }
335 } else if (priv->chiptype == CT_CA42V2) {
336 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
337 err("%s - failed setting baud rate, unsupported speed",
338 __FUNCTION__);
339 new_baudrate = priv->baud_rate;
340 }
341 } else if (priv->chiptype == CT_GENERIC) {
342 if ( (new_baudrate = mask_to_rate(baud_mask)) == -1) {
343 err("%s - failed setting baud rate, unsupported speed",
344 __FUNCTION__);
345 new_baudrate = priv->baud_rate;
346 }
347 } else {
348 info("%s - please define your chiptype", __FUNCTION__);
349 new_baudrate = priv->baud_rate;
350 }
351 } else { /* baud rate not changing, keep the old */
352 new_baudrate = priv->baud_rate; 345 new_baudrate = priv->baud_rate;
346 /* Change of speed ? */
347 else if (baud_rate != priv->baud_rate) {
348 dbg("%s - baud rate is changing", __func__);
349 retval = analyze_baud_rate(port, baud_rate);
350 if (retval >= 0) {
351 new_baudrate = retval;
352 dbg("%s - New baud rate set to %d",
353 __func__, new_baudrate);
354 }
353 } 355 }
354 dbg("%s - baud rate is being sent as %d", __FUNCTION__, new_baudrate); 356 dbg("%s - baud rate is being sent as %d", __func__, new_baudrate);
355 357
356 memset(feature_buffer, 0, 8); 358 memset(feature_buffer, 0, sizeof(feature_buffer));
357 /* fill the feature_buffer with new configuration */ 359 /* fill the feature_buffer with new configuration */
358 *((u_int32_t *)feature_buffer) = new_baudrate; 360 *((u_int32_t *)feature_buffer) = new_baudrate;
359 361
@@ -365,48 +367,65 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
365 /* 1 bit gap */ 367 /* 1 bit gap */
366 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */ 368 feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
367 369
368 dbg("%s - device is being sent this feature report:", __FUNCTION__); 370 dbg("%s - device is being sent this feature report:", __func__);
369 dbg("%s - %02X - %02X - %02X - %02X - %02X", __FUNCTION__, feature_buffer[0], feature_buffer[1], 371 dbg("%s - %02X - %02X - %02X - %02X - %02X", __func__, feature_buffer[0], feature_buffer[1],
370 feature_buffer[2], feature_buffer[3], feature_buffer[4]); 372 feature_buffer[2], feature_buffer[3], feature_buffer[4]);
371 373
372 do { 374 do {
373 retval = usb_control_msg (port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), 375 retval = usb_control_msg(port->serial->dev,
374 HID_REQ_SET_REPORT, USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, 376 usb_sndctrlpipe(port->serial->dev, 0),
375 0x0300, 0, feature_buffer, 8, 500); 377 HID_REQ_SET_REPORT,
378 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
379 0x0300, 0, feature_buffer,
380 sizeof(feature_buffer), 500);
376 381
377 if (tries++ >= 3) 382 if (tries++ >= 3)
378 break; 383 break;
379 384
380 } while (retval != 8 && retval != -ENODEV); 385 } while (retval != sizeof(feature_buffer) &&
386 retval != -ENODEV);
381 387
382 if (retval != 8) { 388 if (retval != sizeof(feature_buffer)) {
383 err("%s - failed sending serial line settings - %d", __FUNCTION__, retval); 389 err("%s - failed sending serial line settings - %d", __func__, retval);
384 cypress_set_dead(port); 390 cypress_set_dead(port);
385 } else { 391 } else {
386 spin_lock_irqsave(&priv->lock, flags); 392 spin_lock_irqsave(&priv->lock, flags);
387 priv->baud_rate = new_baudrate; 393 priv->baud_rate = new_baudrate;
388 priv->cbr_mask = baud_mask;
389 priv->current_config = feature_buffer[4]; 394 priv->current_config = feature_buffer[4];
390 spin_unlock_irqrestore(&priv->lock, flags); 395 spin_unlock_irqrestore(&priv->lock, flags);
396 /* If we asked for a speed change encode it */
397 if (baud_rate)
398 tty_encode_baud_rate(port->tty,
399 new_baudrate, new_baudrate);
391 } 400 }
392 break; 401 break;
393 case CYPRESS_GET_CONFIG: 402 case CYPRESS_GET_CONFIG:
394 dbg("%s - retreiving serial line settings", __FUNCTION__); 403 if (priv->get_cfg_unsafe) {
404 /* Not implemented for this device,
405 and if we try to do it we're likely
406 to crash the hardware. */
407 return -ENOTTY;
408 }
409 dbg("%s - retreiving serial line settings", __func__);
395 /* set initial values in feature buffer */ 410 /* set initial values in feature buffer */
396 memset(feature_buffer, 0, 8); 411 memset(feature_buffer, 0, sizeof(feature_buffer));
397 412
398 do { 413 do {
399 retval = usb_control_msg (port->serial->dev, usb_rcvctrlpipe(port->serial->dev, 0), 414 retval = usb_control_msg(port->serial->dev,
400 HID_REQ_GET_REPORT, USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS, 415 usb_rcvctrlpipe(port->serial->dev, 0),
401 0x0300, 0, feature_buffer, 8, 500); 416 HID_REQ_GET_REPORT,
402 417 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
418 0x0300, 0, feature_buffer,
419 sizeof(feature_buffer), 500);
420
403 if (tries++ >= 3) 421 if (tries++ >= 3)
404 break; 422 break;
405 423
406 } while (retval != 5 && retval != -ENODEV); 424 } while (retval != sizeof(feature_buffer) &&
425 retval != -ENODEV);
407 426
408 if (retval != 5) { 427 if (retval != sizeof(feature_buffer)) {
409 err("%s - failed to retrieve serial line settings - %d", __FUNCTION__, retval); 428 err("%s - failed to retrieve serial line settings - %d", __func__, retval);
410 cypress_set_dead(port); 429 cypress_set_dead(port);
411 return retval; 430 return retval;
412 } else { 431 } else {
@@ -415,9 +434,6 @@ static int cypress_serial_control (struct usb_serial_port *port, unsigned baud_m
415 /* store the config in one byte, and later use bit masks to check values */ 434 /* store the config in one byte, and later use bit masks to check values */
416 priv->current_config = feature_buffer[4]; 435 priv->current_config = feature_buffer[4];
417 priv->baud_rate = *((u_int32_t *)feature_buffer); 436 priv->baud_rate = *((u_int32_t *)feature_buffer);
418
419 if ( (priv->cbr_mask = rate_to_mask(priv->baud_rate)) == 0x40)
420 dbg("%s - failed setting the baud mask (not defined)", __FUNCTION__);
421 spin_unlock_irqrestore(&priv->lock, flags); 437 spin_unlock_irqrestore(&priv->lock, flags);
422 } 438 }
423 } 439 }
@@ -447,51 +463,6 @@ static void cypress_set_dead(struct usb_serial_port *port)
447} 463}
448 464
449 465
450/* given a baud mask, it will return integer baud on success */
451static int mask_to_rate (unsigned mask)
452{
453 int rate;
454
455 switch (mask) {
456 case B0: rate = 0; break;
457 case B300: rate = 300; break;
458 case B600: rate = 600; break;
459 case B1200: rate = 1200; break;
460 case B2400: rate = 2400; break;
461 case B4800: rate = 4800; break;
462 case B9600: rate = 9600; break;
463 case B19200: rate = 19200; break;
464 case B38400: rate = 38400; break;
465 case B57600: rate = 57600; break;
466 case B115200: rate = 115200; break;
467 default: rate = -1;
468 }
469
470 return rate;
471}
472
473
474static unsigned rate_to_mask (int rate)
475{
476 unsigned mask;
477
478 switch (rate) {
479 case 0: mask = B0; break;
480 case 300: mask = B300; break;
481 case 600: mask = B600; break;
482 case 1200: mask = B1200; break;
483 case 2400: mask = B2400; break;
484 case 4800: mask = B4800; break;
485 case 9600: mask = B9600; break;
486 case 19200: mask = B19200; break;
487 case 38400: mask = B38400; break;
488 case 57600: mask = B57600; break;
489 case 115200: mask = B115200; break;
490 default: mask = 0x40;
491 }
492
493 return mask;
494}
495/***************************************************************************** 466/*****************************************************************************
496 * Cypress serial driver functions 467 * Cypress serial driver functions
497 *****************************************************************************/ 468 *****************************************************************************/
@@ -502,7 +473,7 @@ static int generic_startup (struct usb_serial *serial)
502 struct cypress_private *priv; 473 struct cypress_private *priv;
503 struct usb_serial_port *port = serial->port[0]; 474 struct usb_serial_port *port = serial->port[0];
504 475
505 dbg("%s - port %d", __FUNCTION__, port->number); 476 dbg("%s - port %d", __func__, port->number);
506 477
507 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL); 478 priv = kzalloc(sizeof (struct cypress_private), GFP_KERNEL);
508 if (!priv) 479 if (!priv)
@@ -523,17 +494,27 @@ static int generic_startup (struct usb_serial *serial)
523 priv->line_control = 0; 494 priv->line_control = 0;
524 priv->termios_initialized = 0; 495 priv->termios_initialized = 0;
525 priv->rx_flags = 0; 496 priv->rx_flags = 0;
526 priv->cbr_mask = B300; 497 /* Default packet format setting is determined by packet size.
498 Anything with a size larger then 9 must have a separate
499 count field since the 3 bit count field is otherwise too
500 small. Otherwise we can use the slightly more compact
501 format. This is in accordance with the cypress_m8 serial
502 converter app note. */
503 if (port->interrupt_out_size > 9) {
504 priv->pkt_fmt = packet_format_1;
505 } else {
506 priv->pkt_fmt = packet_format_2;
507 }
527 if (interval > 0) { 508 if (interval > 0) {
528 priv->write_urb_interval = interval; 509 priv->write_urb_interval = interval;
529 priv->read_urb_interval = interval; 510 priv->read_urb_interval = interval;
530 dbg("%s - port %d read & write intervals forced to %d", 511 dbg("%s - port %d read & write intervals forced to %d",
531 __FUNCTION__,port->number,interval); 512 __func__,port->number,interval);
532 } else { 513 } else {
533 priv->write_urb_interval = port->interrupt_out_urb->interval; 514 priv->write_urb_interval = port->interrupt_out_urb->interval;
534 priv->read_urb_interval = port->interrupt_in_urb->interval; 515 priv->read_urb_interval = port->interrupt_in_urb->interval;
535 dbg("%s - port %d intervals: read=%d write=%d", 516 dbg("%s - port %d intervals: read=%d write=%d",
536 __FUNCTION__,port->number, 517 __func__,port->number,
537 priv->read_urb_interval,priv->write_urb_interval); 518 priv->read_urb_interval,priv->write_urb_interval);
538 } 519 }
539 usb_set_serial_port_data(port, priv); 520 usb_set_serial_port_data(port, priv);
@@ -545,17 +526,30 @@ static int generic_startup (struct usb_serial *serial)
545static int cypress_earthmate_startup (struct usb_serial *serial) 526static int cypress_earthmate_startup (struct usb_serial *serial)
546{ 527{
547 struct cypress_private *priv; 528 struct cypress_private *priv;
529 struct usb_serial_port *port = serial->port[0];
548 530
549 dbg("%s", __FUNCTION__); 531 dbg("%s", __func__);
550 532
551 if (generic_startup(serial)) { 533 if (generic_startup(serial)) {
552 dbg("%s - Failed setting up port %d", __FUNCTION__, 534 dbg("%s - Failed setting up port %d", __func__,
553 serial->port[0]->number); 535 port->number);
554 return 1; 536 return 1;
555 } 537 }
556 538
557 priv = usb_get_serial_port_data(serial->port[0]); 539 priv = usb_get_serial_port_data(port);
558 priv->chiptype = CT_EARTHMATE; 540 priv->chiptype = CT_EARTHMATE;
541 /* All Earthmate devices use the separated-count packet
542 format! Idiotic. */
543 priv->pkt_fmt = packet_format_1;
544 if (serial->dev->descriptor.idProduct != PRODUCT_ID_EARTHMATEUSB) {
545 /* The old original USB Earthmate seemed able to
546 handle GET_CONFIG requests; everything they've
547 produced since that time crashes if this command is
548 attempted :-( */
549 dbg("%s - Marking this device as unsafe for GET_CONFIG "
550 "commands", __func__);
551 priv->get_cfg_unsafe = !0;
552 }
559 553
560 return 0; 554 return 0;
561} /* cypress_earthmate_startup */ 555} /* cypress_earthmate_startup */
@@ -565,10 +559,10 @@ static int cypress_hidcom_startup (struct usb_serial *serial)
565{ 559{
566 struct cypress_private *priv; 560 struct cypress_private *priv;
567 561
568 dbg("%s", __FUNCTION__); 562 dbg("%s", __func__);
569 563
570 if (generic_startup(serial)) { 564 if (generic_startup(serial)) {
571 dbg("%s - Failed setting up port %d", __FUNCTION__, 565 dbg("%s - Failed setting up port %d", __func__,
572 serial->port[0]->number); 566 serial->port[0]->number);
573 return 1; 567 return 1;
574 } 568 }
@@ -584,10 +578,10 @@ static int cypress_ca42v2_startup (struct usb_serial *serial)
584{ 578{
585 struct cypress_private *priv; 579 struct cypress_private *priv;
586 580
587 dbg("%s", __FUNCTION__); 581 dbg("%s", __func__);
588 582
589 if (generic_startup(serial)) { 583 if (generic_startup(serial)) {
590 dbg("%s - Failed setting up port %d", __FUNCTION__, 584 dbg("%s - Failed setting up port %d", __func__,
591 serial->port[0]->number); 585 serial->port[0]->number);
592 return 1; 586 return 1;
593 } 587 }
@@ -603,7 +597,7 @@ static void cypress_shutdown (struct usb_serial *serial)
603{ 597{
604 struct cypress_private *priv; 598 struct cypress_private *priv;
605 599
606 dbg ("%s - port %d", __FUNCTION__, serial->port[0]->number); 600 dbg ("%s - port %d", __func__, serial->port[0]->number);
607 601
608 /* all open ports are closed at this point */ 602 /* all open ports are closed at this point */
609 603
@@ -624,7 +618,7 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
624 unsigned long flags; 618 unsigned long flags;
625 int result = 0; 619 int result = 0;
626 620
627 dbg("%s - port %d", __FUNCTION__, port->number); 621 dbg("%s - port %d", __func__, port->number);
628 622
629 if (!priv->comm_is_ok) 623 if (!priv->comm_is_ok)
630 return -EIO; 624 return -EIO;
@@ -652,16 +646,16 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
652 result = cypress_write(port, NULL, 0); 646 result = cypress_write(port, NULL, 0);
653 647
654 if (result) { 648 if (result) {
655 dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __FUNCTION__, result); 649 dev_err(&port->dev, "%s - failed setting the control lines - error %d\n", __func__, result);
656 return result; 650 return result;
657 } else 651 } else
658 dbg("%s - success setting the control lines", __FUNCTION__); 652 dbg("%s - success setting the control lines", __func__);
659 653
660 cypress_set_termios(port, &priv->tmp_termios); 654 cypress_set_termios(port, &priv->tmp_termios);
661 655
662 /* setup the port and start reading from the device */ 656 /* setup the port and start reading from the device */
663 if(!port->interrupt_in_urb){ 657 if(!port->interrupt_in_urb){
664 err("%s - interrupt_in_urb is empty!", __FUNCTION__); 658 err("%s - interrupt_in_urb is empty!", __func__);
665 return(-1); 659 return(-1);
666 } 660 }
667 661
@@ -672,7 +666,7 @@ static int cypress_open (struct usb_serial_port *port, struct file *filp)
672 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 666 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
673 667
674 if (result){ 668 if (result){
675 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 669 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result);
676 cypress_set_dead(port); 670 cypress_set_dead(port);
677 } 671 }
678 672
@@ -688,7 +682,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
688 long timeout; 682 long timeout;
689 wait_queue_t wait; 683 wait_queue_t wait;
690 684
691 dbg("%s - port %d", __FUNCTION__, port->number); 685 dbg("%s - port %d", __func__, port->number);
692 686
693 /* wait for data to drain from buffer */ 687 /* wait for data to drain from buffer */
694 spin_lock_irq(&priv->lock); 688 spin_lock_irq(&priv->lock);
@@ -726,7 +720,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
726 timeout = 2*HZ; 720 timeout = 2*HZ;
727 schedule_timeout_interruptible(timeout); 721 schedule_timeout_interruptible(timeout);
728 722
729 dbg("%s - stopping urbs", __FUNCTION__); 723 dbg("%s - stopping urbs", __func__);
730 usb_kill_urb (port->interrupt_in_urb); 724 usb_kill_urb (port->interrupt_in_urb);
731 usb_kill_urb (port->interrupt_out_urb); 725 usb_kill_urb (port->interrupt_out_urb);
732 726
@@ -755,7 +749,7 @@ static int cypress_write(struct usb_serial_port *port, const unsigned char *buf,
755 struct cypress_private *priv = usb_get_serial_port_data(port); 749 struct cypress_private *priv = usb_get_serial_port_data(port);
756 unsigned long flags; 750 unsigned long flags;
757 751
758 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); 752 dbg("%s - port %d, %d bytes", __func__, port->number, count);
759 753
760 /* line control commands, which need to be executed immediately, 754 /* line control commands, which need to be executed immediately,
761 are not put into the buffer for obvious reasons. 755 are not put into the buffer for obvious reasons.
@@ -788,12 +782,12 @@ static void cypress_send(struct usb_serial_port *port)
788 if (!priv->comm_is_ok) 782 if (!priv->comm_is_ok)
789 return; 783 return;
790 784
791 dbg("%s - port %d", __FUNCTION__, port->number); 785 dbg("%s - port %d", __func__, port->number);
792 dbg("%s - interrupt out size is %d", __FUNCTION__, port->interrupt_out_size); 786 dbg("%s - interrupt out size is %d", __func__, port->interrupt_out_size);
793 787
794 spin_lock_irqsave(&priv->lock, flags); 788 spin_lock_irqsave(&priv->lock, flags);
795 if (priv->write_urb_in_use) { 789 if (priv->write_urb_in_use) {
796 dbg("%s - can't write, urb in use", __FUNCTION__); 790 dbg("%s - can't write, urb in use", __func__);
797 spin_unlock_irqrestore(&priv->lock, flags); 791 spin_unlock_irqrestore(&priv->lock, flags);
798 return; 792 return;
799 } 793 }
@@ -803,21 +797,18 @@ static void cypress_send(struct usb_serial_port *port)
803 memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size); 797 memset(port->interrupt_out_urb->transfer_buffer, 0, port->interrupt_out_size);
804 798
805 spin_lock_irqsave(&priv->lock, flags); 799 spin_lock_irqsave(&priv->lock, flags);
806 switch (port->interrupt_out_size) { 800 switch (priv->pkt_fmt) {
807 case 32: 801 default:
808 /* this is for the CY7C64013... */ 802 case packet_format_1:
809 offset = 2; 803 /* this is for the CY7C64013... */
810 port->interrupt_out_buffer[0] = priv->line_control; 804 offset = 2;
811 break; 805 port->interrupt_out_buffer[0] = priv->line_control;
812 case 8: 806 break;
813 /* this is for the CY7C63743... */ 807 case packet_format_2:
814 offset = 1; 808 /* this is for the CY7C63743... */
815 port->interrupt_out_buffer[0] = priv->line_control; 809 offset = 1;
816 break; 810 port->interrupt_out_buffer[0] = priv->line_control;
817 default: 811 break;
818 dbg("%s - wrong packet size", __FUNCTION__);
819 spin_unlock_irqrestore(&priv->lock, flags);
820 return;
821 } 812 }
822 813
823 if (priv->line_control & CONTROL_RESET) 814 if (priv->line_control & CONTROL_RESET)
@@ -825,7 +816,7 @@ static void cypress_send(struct usb_serial_port *port)
825 816
826 if (priv->cmd_ctrl) { 817 if (priv->cmd_ctrl) {
827 priv->cmd_count++; 818 priv->cmd_count++;
828 dbg("%s - line control command being issued", __FUNCTION__); 819 dbg("%s - line control command being issued", __func__);
829 spin_unlock_irqrestore(&priv->lock, flags); 820 spin_unlock_irqrestore(&priv->lock, flags);
830 goto send; 821 goto send;
831 } else 822 } else
@@ -838,15 +829,16 @@ static void cypress_send(struct usb_serial_port *port)
838 return; 829 return;
839 } 830 }
840 831
841 switch (port->interrupt_out_size) { 832 switch (priv->pkt_fmt) {
842 case 32: 833 default:
843 port->interrupt_out_buffer[1] = count; 834 case packet_format_1:
844 break; 835 port->interrupt_out_buffer[1] = count;
845 case 8: 836 break;
846 port->interrupt_out_buffer[0] |= count; 837 case packet_format_2:
838 port->interrupt_out_buffer[0] |= count;
847 } 839 }
848 840
849 dbg("%s - count is %d", __FUNCTION__, count); 841 dbg("%s - count is %d", __func__, count);
850 842
851send: 843send:
852 spin_lock_irqsave(&priv->lock, flags); 844 spin_lock_irqsave(&priv->lock, flags);
@@ -856,9 +848,10 @@ send:
856 if (priv->cmd_ctrl) 848 if (priv->cmd_ctrl)
857 actual_size = 1; 849 actual_size = 1;
858 else 850 else
859 actual_size = count + (port->interrupt_out_size == 32 ? 2 : 1); 851 actual_size = count +
860 852 (priv->pkt_fmt == packet_format_1 ? 2 : 1);
861 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, port->interrupt_out_size, 853
854 usb_serial_debug_data(debug, &port->dev, __func__, port->interrupt_out_size,
862 port->interrupt_out_urb->transfer_buffer); 855 port->interrupt_out_urb->transfer_buffer);
863 856
864 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev, 857 usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
@@ -867,7 +860,7 @@ send:
867 cypress_write_int_callback, port, priv->write_urb_interval); 860 cypress_write_int_callback, port, priv->write_urb_interval);
868 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC); 861 result = usb_submit_urb (port->interrupt_out_urb, GFP_ATOMIC);
869 if (result) { 862 if (result) {
870 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, 863 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__,
871 result); 864 result);
872 priv->write_urb_in_use = 0; 865 priv->write_urb_in_use = 0;
873 cypress_set_dead(port); 866 cypress_set_dead(port);
@@ -891,13 +884,13 @@ static int cypress_write_room(struct usb_serial_port *port)
891 int room = 0; 884 int room = 0;
892 unsigned long flags; 885 unsigned long flags;
893 886
894 dbg("%s - port %d", __FUNCTION__, port->number); 887 dbg("%s - port %d", __func__, port->number);
895 888
896 spin_lock_irqsave(&priv->lock, flags); 889 spin_lock_irqsave(&priv->lock, flags);
897 room = cypress_buf_space_avail(priv->buf); 890 room = cypress_buf_space_avail(priv->buf);
898 spin_unlock_irqrestore(&priv->lock, flags); 891 spin_unlock_irqrestore(&priv->lock, flags);
899 892
900 dbg("%s - returns %d", __FUNCTION__, room); 893 dbg("%s - returns %d", __func__, room);
901 return room; 894 return room;
902} 895}
903 896
@@ -909,7 +902,7 @@ static int cypress_tiocmget (struct usb_serial_port *port, struct file *file)
909 unsigned int result = 0; 902 unsigned int result = 0;
910 unsigned long flags; 903 unsigned long flags;
911 904
912 dbg("%s - port %d", __FUNCTION__, port->number); 905 dbg("%s - port %d", __func__, port->number);
913 906
914 spin_lock_irqsave(&priv->lock, flags); 907 spin_lock_irqsave(&priv->lock, flags);
915 control = priv->line_control; 908 control = priv->line_control;
@@ -923,7 +916,7 @@ static int cypress_tiocmget (struct usb_serial_port *port, struct file *file)
923 | ((status & UART_RI) ? TIOCM_RI : 0) 916 | ((status & UART_RI) ? TIOCM_RI : 0)
924 | ((status & UART_CD) ? TIOCM_CD : 0); 917 | ((status & UART_CD) ? TIOCM_CD : 0);
925 918
926 dbg("%s - result = %x", __FUNCTION__, result); 919 dbg("%s - result = %x", __func__, result);
927 920
928 return result; 921 return result;
929} 922}
@@ -935,7 +928,7 @@ static int cypress_tiocmset (struct usb_serial_port *port, struct file *file,
935 struct cypress_private *priv = usb_get_serial_port_data(port); 928 struct cypress_private *priv = usb_get_serial_port_data(port);
936 unsigned long flags; 929 unsigned long flags;
937 930
938 dbg("%s - port %d", __FUNCTION__, port->number); 931 dbg("%s - port %d", __func__, port->number);
939 932
940 spin_lock_irqsave(&priv->lock, flags); 933 spin_lock_irqsave(&priv->lock, flags);
941 if (set & TIOCM_RTS) 934 if (set & TIOCM_RTS)
@@ -946,9 +939,9 @@ static int cypress_tiocmset (struct usb_serial_port *port, struct file *file,
946 priv->line_control &= ~CONTROL_RTS; 939 priv->line_control &= ~CONTROL_RTS;
947 if (clear & TIOCM_DTR) 940 if (clear & TIOCM_DTR)
948 priv->line_control &= ~CONTROL_DTR; 941 priv->line_control &= ~CONTROL_DTR;
942 priv->cmd_ctrl = 1;
949 spin_unlock_irqrestore(&priv->lock, flags); 943 spin_unlock_irqrestore(&priv->lock, flags);
950 944
951 priv->cmd_ctrl = 1;
952 return cypress_write(port, NULL, 0); 945 return cypress_write(port, NULL, 0);
953} 946}
954 947
@@ -957,23 +950,9 @@ static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsi
957{ 950{
958 struct cypress_private *priv = usb_get_serial_port_data(port); 951 struct cypress_private *priv = usb_get_serial_port_data(port);
959 952
960 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); 953 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
961 954
962 switch (cmd) { 955 switch (cmd) {
963 case TIOCGSERIAL:
964 if (copy_to_user((void __user *)arg, port->tty->termios, sizeof(struct ktermios))) {
965 return -EFAULT;
966 }
967 return (0);
968 break;
969 case TIOCSSERIAL:
970 if (copy_from_user(port->tty->termios, (void __user *)arg, sizeof(struct ktermios))) {
971 return -EFAULT;
972 }
973 /* here we need to call cypress_set_termios to invoke the new settings */
974 cypress_set_termios(port, &priv->tmp_termios);
975 return (0);
976 break;
977 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 956 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
978 case TIOCMIWAIT: 957 case TIOCMIWAIT:
979 while (priv != NULL) { 958 while (priv != NULL) {
@@ -1009,7 +988,7 @@ static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsi
1009 break; 988 break;
1010 } 989 }
1011 990
1012 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __FUNCTION__, cmd); 991 dbg("%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h", __func__, cmd);
1013 992
1014 return -ENOIOCTLCMD; 993 return -ENOIOCTLCMD;
1015} /* cypress_ioctl */ 994} /* cypress_ioctl */
@@ -1021,18 +1000,14 @@ static void cypress_set_termios (struct usb_serial_port *port,
1021 struct cypress_private *priv = usb_get_serial_port_data(port); 1000 struct cypress_private *priv = usb_get_serial_port_data(port);
1022 struct tty_struct *tty; 1001 struct tty_struct *tty;
1023 int data_bits, stop_bits, parity_type, parity_enable; 1002 int data_bits, stop_bits, parity_type, parity_enable;
1024 unsigned cflag, iflag, baud_mask; 1003 unsigned cflag, iflag;
1025 unsigned long flags; 1004 unsigned long flags;
1026 __u8 oldlines; 1005 __u8 oldlines;
1027 int linechange = 0; 1006 int linechange = 0;
1028 1007
1029 dbg("%s - port %d", __FUNCTION__, port->number); 1008 dbg("%s - port %d", __func__, port->number);
1030 1009
1031 tty = port->tty; 1010 tty = port->tty;
1032 if ((!tty) || (!tty->termios)) {
1033 dbg("%s - no tty structures", __FUNCTION__);
1034 return;
1035 }
1036 1011
1037 spin_lock_irqsave(&priv->lock, flags); 1012 spin_lock_irqsave(&priv->lock, flags);
1038 if (!priv->termios_initialized) { 1013 if (!priv->termios_initialized) {
@@ -1040,40 +1015,37 @@ static void cypress_set_termios (struct usb_serial_port *port,
1040 *(tty->termios) = tty_std_termios; 1015 *(tty->termios) = tty_std_termios;
1041 tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL | 1016 tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL |
1042 CLOCAL; 1017 CLOCAL;
1018 tty->termios->c_ispeed = 4800;
1019 tty->termios->c_ospeed = 4800;
1043 } else if (priv->chiptype == CT_CYPHIDCOM) { 1020 } else if (priv->chiptype == CT_CYPHIDCOM) {
1044 *(tty->termios) = tty_std_termios; 1021 *(tty->termios) = tty_std_termios;
1045 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | 1022 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1046 CLOCAL; 1023 CLOCAL;
1024 tty->termios->c_ispeed = 9600;
1025 tty->termios->c_ospeed = 9600;
1047 } else if (priv->chiptype == CT_CA42V2) { 1026 } else if (priv->chiptype == CT_CA42V2) {
1048 *(tty->termios) = tty_std_termios; 1027 *(tty->termios) = tty_std_termios;
1049 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | 1028 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
1050 CLOCAL; 1029 CLOCAL;
1030 tty->termios->c_ispeed = 9600;
1031 tty->termios->c_ospeed = 9600;
1051 } 1032 }
1052 priv->termios_initialized = 1; 1033 priv->termios_initialized = 1;
1053 } 1034 }
1054 spin_unlock_irqrestore(&priv->lock, flags); 1035 spin_unlock_irqrestore(&priv->lock, flags);
1055 1036
1037 /* Unsupported features need clearing */
1038 tty->termios->c_cflag &= ~(CMSPAR|CRTSCTS);
1039
1056 cflag = tty->termios->c_cflag; 1040 cflag = tty->termios->c_cflag;
1057 iflag = tty->termios->c_iflag; 1041 iflag = tty->termios->c_iflag;
1058 1042
1059 /* check if there are new settings */ 1043 /* check if there are new settings */
1060 if (old_termios) { 1044 if (old_termios) {
1061 if ((cflag != old_termios->c_cflag) || 1045 spin_lock_irqsave(&priv->lock, flags);
1062 (RELEVANT_IFLAG(iflag) != 1046 priv->tmp_termios = *(tty->termios);
1063 RELEVANT_IFLAG(old_termios->c_iflag))) { 1047 spin_unlock_irqrestore(&priv->lock, flags);
1064 dbg("%s - attempting to set new termios settings", 1048 }
1065 __FUNCTION__);
1066 /* should make a copy of this in case something goes
1067 * wrong in the function, we can restore it */
1068 spin_lock_irqsave(&priv->lock, flags);
1069 priv->tmp_termios = *(tty->termios);
1070 spin_unlock_irqrestore(&priv->lock, flags);
1071 } else {
1072 dbg("%s - nothing to do, exiting", __FUNCTION__);
1073 return;
1074 }
1075 } else
1076 return;
1077 1049
1078 /* set number of data bits, parity, stop bits */ 1050 /* set number of data bits, parity, stop bits */
1079 /* when parity is disabled the parity type bit is ignored */ 1051 /* when parity is disabled the parity type bit is ignored */
@@ -1104,7 +1076,7 @@ static void cypress_set_termios (struct usb_serial_port *port,
1104 break; 1076 break;
1105 default: 1077 default:
1106 err("%s - CSIZE was set, but not CS5-CS8", 1078 err("%s - CSIZE was set, but not CS5-CS8",
1107 __FUNCTION__); 1079 __func__);
1108 data_bits = 3; 1080 data_bits = 3;
1109 } 1081 }
1110 } else 1082 } else
@@ -1114,54 +1086,17 @@ static void cypress_set_termios (struct usb_serial_port *port,
1114 oldlines = priv->line_control; 1086 oldlines = priv->line_control;
1115 if ((cflag & CBAUD) == B0) { 1087 if ((cflag & CBAUD) == B0) {
1116 /* drop dtr and rts */ 1088 /* drop dtr and rts */
1117 dbg("%s - dropping the lines, baud rate 0bps", __FUNCTION__); 1089 dbg("%s - dropping the lines, baud rate 0bps", __func__);
1118 baud_mask = B0;
1119 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 1090 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
1120 } else { 1091 } else
1121 baud_mask = (cflag & CBAUD);
1122 switch(baud_mask) {
1123 case B300:
1124 dbg("%s - setting baud 300bps", __FUNCTION__);
1125 break;
1126 case B600:
1127 dbg("%s - setting baud 600bps", __FUNCTION__);
1128 break;
1129 case B1200:
1130 dbg("%s - setting baud 1200bps", __FUNCTION__);
1131 break;
1132 case B2400:
1133 dbg("%s - setting baud 2400bps", __FUNCTION__);
1134 break;
1135 case B4800:
1136 dbg("%s - setting baud 4800bps", __FUNCTION__);
1137 break;
1138 case B9600:
1139 dbg("%s - setting baud 9600bps", __FUNCTION__);
1140 break;
1141 case B19200:
1142 dbg("%s - setting baud 19200bps", __FUNCTION__);
1143 break;
1144 case B38400:
1145 dbg("%s - setting baud 38400bps", __FUNCTION__);
1146 break;
1147 case B57600:
1148 dbg("%s - setting baud 57600bps", __FUNCTION__);
1149 break;
1150 case B115200:
1151 dbg("%s - setting baud 115200bps", __FUNCTION__);
1152 break;
1153 default:
1154 dbg("%s - unknown masked baud rate", __FUNCTION__);
1155 }
1156 priv->line_control = (CONTROL_DTR | CONTROL_RTS); 1092 priv->line_control = (CONTROL_DTR | CONTROL_RTS);
1157 }
1158 spin_unlock_irqrestore(&priv->lock, flags); 1093 spin_unlock_irqrestore(&priv->lock, flags);
1159 1094
1160 dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, " 1095 dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, "
1161 "%d data_bits (+5)", __FUNCTION__, stop_bits, 1096 "%d data_bits (+5)", __func__, stop_bits,
1162 parity_enable, parity_type, data_bits); 1097 parity_enable, parity_type, data_bits);
1163 1098
1164 cypress_serial_control(port, baud_mask, data_bits, stop_bits, 1099 cypress_serial_control(port, tty_get_baud_rate(tty), data_bits, stop_bits,
1165 parity_enable, parity_type, 0, CYPRESS_SET_CONFIG); 1100 parity_enable, parity_type, 0, CYPRESS_SET_CONFIG);
1166 1101
1167 /* we perform a CYPRESS_GET_CONFIG so that the current settings are 1102 /* we perform a CYPRESS_GET_CONFIG so that the current settings are
@@ -1219,13 +1154,13 @@ static int cypress_chars_in_buffer(struct usb_serial_port *port)
1219 int chars = 0; 1154 int chars = 0;
1220 unsigned long flags; 1155 unsigned long flags;
1221 1156
1222 dbg("%s - port %d", __FUNCTION__, port->number); 1157 dbg("%s - port %d", __func__, port->number);
1223 1158
1224 spin_lock_irqsave(&priv->lock, flags); 1159 spin_lock_irqsave(&priv->lock, flags);
1225 chars = cypress_buf_data_avail(priv->buf); 1160 chars = cypress_buf_data_avail(priv->buf);
1226 spin_unlock_irqrestore(&priv->lock, flags); 1161 spin_unlock_irqrestore(&priv->lock, flags);
1227 1162
1228 dbg("%s - returns %d", __FUNCTION__, chars); 1163 dbg("%s - returns %d", __func__, chars);
1229 return chars; 1164 return chars;
1230} 1165}
1231 1166
@@ -1235,7 +1170,7 @@ static void cypress_throttle (struct usb_serial_port *port)
1235 struct cypress_private *priv = usb_get_serial_port_data(port); 1170 struct cypress_private *priv = usb_get_serial_port_data(port);
1236 unsigned long flags; 1171 unsigned long flags;
1237 1172
1238 dbg("%s - port %d", __FUNCTION__, port->number); 1173 dbg("%s - port %d", __func__, port->number);
1239 1174
1240 spin_lock_irqsave(&priv->lock, flags); 1175 spin_lock_irqsave(&priv->lock, flags);
1241 priv->rx_flags = THROTTLED; 1176 priv->rx_flags = THROTTLED;
@@ -1249,7 +1184,7 @@ static void cypress_unthrottle (struct usb_serial_port *port)
1249 int actually_throttled, result; 1184 int actually_throttled, result;
1250 unsigned long flags; 1185 unsigned long flags;
1251 1186
1252 dbg("%s - port %d", __FUNCTION__, port->number); 1187 dbg("%s - port %d", __func__, port->number);
1253 1188
1254 spin_lock_irqsave(&priv->lock, flags); 1189 spin_lock_irqsave(&priv->lock, flags);
1255 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; 1190 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
@@ -1265,7 +1200,7 @@ static void cypress_unthrottle (struct usb_serial_port *port)
1265 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1200 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1266 if (result) { 1201 if (result) {
1267 dev_err(&port->dev, "%s - failed submitting read urb, " 1202 dev_err(&port->dev, "%s - failed submitting read urb, "
1268 "error %d\n", __FUNCTION__, result); 1203 "error %d\n", __func__, result);
1269 cypress_set_dead(port); 1204 cypress_set_dead(port);
1270 } 1205 }
1271 } 1206 }
@@ -1274,7 +1209,7 @@ static void cypress_unthrottle (struct usb_serial_port *port)
1274 1209
1275static void cypress_read_int_callback(struct urb *urb) 1210static void cypress_read_int_callback(struct urb *urb)
1276{ 1211{
1277 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1212 struct usb_serial_port *port = urb->context;
1278 struct cypress_private *priv = usb_get_serial_port_data(port); 1213 struct cypress_private *priv = usb_get_serial_port_data(port);
1279 struct tty_struct *tty; 1214 struct tty_struct *tty;
1280 unsigned char *data = urb->transfer_buffer; 1215 unsigned char *data = urb->transfer_buffer;
@@ -1286,7 +1221,7 @@ static void cypress_read_int_callback(struct urb *urb)
1286 int i = 0; 1221 int i = 0;
1287 int status = urb->status; 1222 int status = urb->status;
1288 1223
1289 dbg("%s - port %d", __FUNCTION__, port->number); 1224 dbg("%s - port %d", __func__, port->number);
1290 1225
1291 switch (status) { 1226 switch (status) {
1292 case 0: /* success */ 1227 case 0: /* success */
@@ -1302,14 +1237,14 @@ static void cypress_read_int_callback(struct urb *urb)
1302 default: 1237 default:
1303 /* something ugly is going on... */ 1238 /* something ugly is going on... */
1304 dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n", 1239 dev_err(&urb->dev->dev,"%s - unexpected nonzero read status received: %d\n",
1305 __FUNCTION__, status); 1240 __func__, status);
1306 cypress_set_dead(port); 1241 cypress_set_dead(port);
1307 return; 1242 return;
1308 } 1243 }
1309 1244
1310 spin_lock_irqsave(&priv->lock, flags); 1245 spin_lock_irqsave(&priv->lock, flags);
1311 if (priv->rx_flags & THROTTLED) { 1246 if (priv->rx_flags & THROTTLED) {
1312 dbg("%s - now throttling", __FUNCTION__); 1247 dbg("%s - now throttling", __func__);
1313 priv->rx_flags |= ACTUALLY_THROTTLED; 1248 priv->rx_flags |= ACTUALLY_THROTTLED;
1314 spin_unlock_irqrestore(&priv->lock, flags); 1249 spin_unlock_irqrestore(&priv->lock, flags);
1315 return; 1250 return;
@@ -1318,48 +1253,48 @@ static void cypress_read_int_callback(struct urb *urb)
1318 1253
1319 tty = port->tty; 1254 tty = port->tty;
1320 if (!tty) { 1255 if (!tty) {
1321 dbg("%s - bad tty pointer - exiting", __FUNCTION__); 1256 dbg("%s - bad tty pointer - exiting", __func__);
1322 return; 1257 return;
1323 } 1258 }
1324 1259
1325 spin_lock_irqsave(&priv->lock, flags); 1260 spin_lock_irqsave(&priv->lock, flags);
1326 switch(urb->actual_length) { 1261 result = urb->actual_length;
1327 case 32: 1262 switch (priv->pkt_fmt) {
1328 /* This is for the CY7C64013... */ 1263 default:
1329 priv->current_status = data[0] & 0xF8; 1264 case packet_format_1:
1330 bytes = data[1] + 2; 1265 /* This is for the CY7C64013... */
1331 i = 2; 1266 priv->current_status = data[0] & 0xF8;
1332 if (bytes > 2) 1267 bytes = data[1] + 2;
1333 havedata = 1; 1268 i = 2;
1334 break; 1269 if (bytes > 2)
1335 case 8: 1270 havedata = 1;
1336 /* This is for the CY7C63743... */ 1271 break;
1337 priv->current_status = data[0] & 0xF8; 1272 case packet_format_2:
1338 bytes = (data[0] & 0x07) + 1; 1273 /* This is for the CY7C63743... */
1339 i = 1; 1274 priv->current_status = data[0] & 0xF8;
1340 if (bytes > 1) 1275 bytes = (data[0] & 0x07) + 1;
1341 havedata = 1; 1276 i = 1;
1342 break; 1277 if (bytes > 1)
1343 default: 1278 havedata = 1;
1344 dbg("%s - wrong packet size - received %d bytes", 1279 break;
1345 __FUNCTION__, urb->actual_length);
1346 spin_unlock_irqrestore(&priv->lock, flags);
1347 goto continue_read;
1348 } 1280 }
1349 spin_unlock_irqrestore(&priv->lock, flags); 1281 spin_unlock_irqrestore(&priv->lock, flags);
1282 if (result < bytes) {
1283 dbg("%s - wrong packet size - received %d bytes but packet "
1284 "said %d bytes", __func__, result, bytes);
1285 goto continue_read;
1286 }
1350 1287
1351 usb_serial_debug_data (debug, &port->dev, __FUNCTION__, 1288 usb_serial_debug_data (debug, &port->dev, __func__,
1352 urb->actual_length, data); 1289 urb->actual_length, data);
1353 1290
1354 spin_lock_irqsave(&priv->lock, flags); 1291 spin_lock_irqsave(&priv->lock, flags);
1355 /* check to see if status has changed */ 1292 /* check to see if status has changed */
1356 if (priv != NULL) { 1293 if (priv->current_status != priv->prev_status) {
1357 if (priv->current_status != priv->prev_status) { 1294 priv->diff_status |= priv->current_status ^
1358 priv->diff_status |= priv->current_status ^ 1295 priv->prev_status;
1359 priv->prev_status; 1296 wake_up_interruptible(&priv->delta_msr_wait);
1360 wake_up_interruptible(&priv->delta_msr_wait); 1297 priv->prev_status = priv->current_status;
1361 priv->prev_status = priv->current_status;
1362 }
1363 } 1298 }
1364 spin_unlock_irqrestore(&priv->lock, flags); 1299 spin_unlock_irqrestore(&priv->lock, flags);
1365 1300
@@ -1367,7 +1302,7 @@ static void cypress_read_int_callback(struct urb *urb)
1367 * though */ 1302 * though */
1368 if (tty && !(tty->termios->c_cflag & CLOCAL) && 1303 if (tty && !(tty->termios->c_cflag & CLOCAL) &&
1369 !(priv->current_status & UART_CD)) { 1304 !(priv->current_status & UART_CD)) {
1370 dbg("%s - calling hangup", __FUNCTION__); 1305 dbg("%s - calling hangup", __func__);
1371 tty_hangup(tty); 1306 tty_hangup(tty);
1372 goto continue_read; 1307 goto continue_read;
1373 } 1308 }
@@ -1380,7 +1315,7 @@ static void cypress_read_int_callback(struct urb *urb)
1380 if (priv->current_status & CYP_ERROR) { 1315 if (priv->current_status & CYP_ERROR) {
1381 spin_unlock_irqrestore(&priv->lock, flags); 1316 spin_unlock_irqrestore(&priv->lock, flags);
1382 tty_flag = TTY_PARITY; 1317 tty_flag = TTY_PARITY;
1383 dbg("%s - Parity Error detected", __FUNCTION__); 1318 dbg("%s - Parity Error detected", __func__);
1384 } else 1319 } else
1385 spin_unlock_irqrestore(&priv->lock, flags); 1320 spin_unlock_irqrestore(&priv->lock, flags);
1386 1321
@@ -1414,7 +1349,7 @@ continue_read:
1414 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1349 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1415 if (result) { 1350 if (result) {
1416 dev_err(&urb->dev->dev, "%s - failed resubmitting " 1351 dev_err(&urb->dev->dev, "%s - failed resubmitting "
1417 "read urb, error %d\n", __FUNCTION__, 1352 "read urb, error %d\n", __func__,
1418 result); 1353 result);
1419 cypress_set_dead(port); 1354 cypress_set_dead(port);
1420 } 1355 }
@@ -1426,12 +1361,12 @@ continue_read:
1426 1361
1427static void cypress_write_int_callback(struct urb *urb) 1362static void cypress_write_int_callback(struct urb *urb)
1428{ 1363{
1429 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1364 struct usb_serial_port *port = urb->context;
1430 struct cypress_private *priv = usb_get_serial_port_data(port); 1365 struct cypress_private *priv = usb_get_serial_port_data(port);
1431 int result; 1366 int result;
1432 int status = urb->status; 1367 int status = urb->status;
1433 1368
1434 dbg("%s - port %d", __FUNCTION__, port->number); 1369 dbg("%s - port %d", __func__, port->number);
1435 1370
1436 switch (status) { 1371 switch (status) {
1437 case 0: 1372 case 0:
@@ -1442,7 +1377,7 @@ static void cypress_write_int_callback(struct urb *urb)
1442 case -ESHUTDOWN: 1377 case -ESHUTDOWN:
1443 /* this urb is terminated, clean up */ 1378 /* this urb is terminated, clean up */
1444 dbg("%s - urb shutting down with status: %d", 1379 dbg("%s - urb shutting down with status: %d",
1445 __FUNCTION__, status); 1380 __func__, status);
1446 priv->write_urb_in_use = 0; 1381 priv->write_urb_in_use = 0;
1447 return; 1382 return;
1448 case -EPIPE: /* no break needed; clear halt and resubmit */ 1383 case -EPIPE: /* no break needed; clear halt and resubmit */
@@ -1451,19 +1386,19 @@ static void cypress_write_int_callback(struct urb *urb)
1451 usb_clear_halt(port->serial->dev, 0x02); 1386 usb_clear_halt(port->serial->dev, 0x02);
1452 /* error in the urb, so we have to resubmit it */ 1387 /* error in the urb, so we have to resubmit it */
1453 dbg("%s - nonzero write bulk status received: %d", 1388 dbg("%s - nonzero write bulk status received: %d",
1454 __FUNCTION__, status); 1389 __func__, status);
1455 port->interrupt_out_urb->transfer_buffer_length = 1; 1390 port->interrupt_out_urb->transfer_buffer_length = 1;
1456 port->interrupt_out_urb->dev = port->serial->dev; 1391 port->interrupt_out_urb->dev = port->serial->dev;
1457 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC); 1392 result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
1458 if (!result) 1393 if (!result)
1459 return; 1394 return;
1460 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", 1395 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n",
1461 __FUNCTION__, result); 1396 __func__, result);
1462 cypress_set_dead(port); 1397 cypress_set_dead(port);
1463 break; 1398 break;
1464 default: 1399 default:
1465 dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n", 1400 dev_err(&urb->dev->dev,"%s - unexpected nonzero write status received: %d\n",
1466 __FUNCTION__, status); 1401 __func__, status);
1467 cypress_set_dead(port); 1402 cypress_set_dead(port);
1468 break; 1403 break;
1469 } 1404 }
@@ -1668,7 +1603,7 @@ static int __init cypress_init(void)
1668{ 1603{
1669 int retval; 1604 int retval;
1670 1605
1671 dbg("%s", __FUNCTION__); 1606 dbg("%s", __func__);
1672 1607
1673 retval = usb_serial_register(&cypress_earthmate_device); 1608 retval = usb_serial_register(&cypress_earthmate_device);
1674 if (retval) 1609 if (retval)
@@ -1699,7 +1634,7 @@ failed_em_register:
1699 1634
1700static void __exit cypress_exit (void) 1635static void __exit cypress_exit (void)
1701{ 1636{
1702 dbg("%s", __FUNCTION__); 1637 dbg("%s", __func__);
1703 1638
1704 usb_deregister (&cypress_driver); 1639 usb_deregister (&cypress_driver);
1705 usb_serial_deregister (&cypress_earthmate_device); 1640 usb_serial_deregister (&cypress_earthmate_device);
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 5f9c6e46bee5..d17d1645714f 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -508,9 +508,6 @@ static struct usb_serial_driver digi_acceleport_2_device = {
508 .description = "Digi 2 port USB adapter", 508 .description = "Digi 2 port USB adapter",
509 .usb_driver = &digi_driver, 509 .usb_driver = &digi_driver,
510 .id_table = id_table_2, 510 .id_table = id_table_2,
511 .num_interrupt_in = 0,
512 .num_bulk_in = 4,
513 .num_bulk_out = 4,
514 .num_ports = 3, 511 .num_ports = 3,
515 .open = digi_open, 512 .open = digi_open,
516 .close = digi_close, 513 .close = digi_close,
@@ -538,9 +535,6 @@ static struct usb_serial_driver digi_acceleport_4_device = {
538 .description = "Digi 4 port USB adapter", 535 .description = "Digi 4 port USB adapter",
539 .usb_driver = &digi_driver, 536 .usb_driver = &digi_driver,
540 .id_table = id_table_4, 537 .id_table = id_table_4,
541 .num_interrupt_in = 0,
542 .num_bulk_in = 5,
543 .num_bulk_out = 5,
544 .num_ports = 4, 538 .num_ports = 4,
545 .open = digi_open, 539 .open = digi_open,
546 .close = digi_close, 540 .close = digi_close,
@@ -665,7 +659,7 @@ static int digi_write_oob_command(struct usb_serial_port *port,
665 } 659 }
666 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags); 660 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
667 if (ret) 661 if (ret)
668 err("%s: usb_submit_urb failed, ret=%d", __FUNCTION__, ret); 662 err("%s: usb_submit_urb failed, ret=%d", __func__, ret);
669 return ret; 663 return ret;
670 664
671} 665}
@@ -746,7 +740,7 @@ static int digi_write_inb_command(struct usb_serial_port *port,
746 740
747 if (ret) 741 if (ret)
748 err("%s: usb_submit_urb failed, ret=%d, port=%d", 742 err("%s: usb_submit_urb failed, ret=%d, port=%d",
749 __FUNCTION__, ret, priv->dp_port_num); 743 __func__, ret, priv->dp_port_num);
750 return ret; 744 return ret;
751} 745}
752 746
@@ -810,7 +804,7 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
810 spin_unlock(&port_priv->dp_port_lock); 804 spin_unlock(&port_priv->dp_port_lock);
811 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags); 805 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
812 if (ret) 806 if (ret)
813 err("%s: usb_submit_urb failed, ret=%d", __FUNCTION__, ret); 807 err("%s: usb_submit_urb failed, ret=%d", __func__, ret);
814 return ret; 808 return ret;
815} 809}
816 810
@@ -903,7 +897,7 @@ static void digi_rx_unthrottle(struct usb_serial_port *port)
903 897
904 if (ret) 898 if (ret)
905 err("%s: usb_submit_urb failed, ret=%d, port=%d", 899 err("%s: usb_submit_urb failed, ret=%d, port=%d",
906 __FUNCTION__, ret, priv->dp_port_num); 900 __func__, ret, priv->dp_port_num);
907} 901}
908 902
909 903
@@ -1113,7 +1107,7 @@ static int digi_tiocmget(struct usb_serial_port *port, struct file *file)
1113 unsigned int val; 1107 unsigned int val;
1114 unsigned long flags; 1108 unsigned long flags;
1115 1109
1116 dbg("%s: TOP: port=%d", __FUNCTION__, priv->dp_port_num); 1110 dbg("%s: TOP: port=%d", __func__, priv->dp_port_num);
1117 1111
1118 spin_lock_irqsave(&priv->dp_port_lock, flags); 1112 spin_lock_irqsave(&priv->dp_port_lock, flags);
1119 val = priv->dp_modem_signals; 1113 val = priv->dp_modem_signals;
@@ -1129,7 +1123,7 @@ static int digi_tiocmset(struct usb_serial_port *port, struct file *file,
1129 unsigned int val; 1123 unsigned int val;
1130 unsigned long flags; 1124 unsigned long flags;
1131 1125
1132 dbg("%s: TOP: port=%d", __FUNCTION__, priv->dp_port_num); 1126 dbg("%s: TOP: port=%d", __func__, priv->dp_port_num);
1133 1127
1134 spin_lock_irqsave(&priv->dp_port_lock, flags); 1128 spin_lock_irqsave(&priv->dp_port_lock, flags);
1135 val = (priv->dp_modem_signals & ~clear) | set; 1129 val = (priv->dp_modem_signals & ~clear) | set;
@@ -1224,7 +1218,7 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1224 spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1218 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1225 if (ret < 0) 1219 if (ret < 0)
1226 err("%s: usb_submit_urb failed, ret=%d, port=%d", 1220 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1227 __FUNCTION__, ret, priv->dp_port_num); 1221 __func__, ret, priv->dp_port_num);
1228 dbg("digi_write: returning %d", ret); 1222 dbg("digi_write: returning %d", ret);
1229 return ret; 1223 return ret;
1230 1224
@@ -1233,7 +1227,7 @@ static int digi_write(struct usb_serial_port *port, const unsigned char *buf, in
1233static void digi_write_bulk_callback(struct urb *urb) 1227static void digi_write_bulk_callback(struct urb *urb)
1234{ 1228{
1235 1229
1236 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1230 struct usb_serial_port *port = urb->context;
1237 struct usb_serial *serial; 1231 struct usb_serial *serial;
1238 struct digi_port *priv; 1232 struct digi_port *priv;
1239 struct digi_serial *serial_priv; 1233 struct digi_serial *serial_priv;
@@ -1245,13 +1239,13 @@ static void digi_write_bulk_callback(struct urb *urb)
1245 /* port and serial sanity check */ 1239 /* port and serial sanity check */
1246 if (port == NULL || (priv=usb_get_serial_port_data(port)) == NULL) { 1240 if (port == NULL || (priv=usb_get_serial_port_data(port)) == NULL) {
1247 err("%s: port or port->private is NULL, status=%d", 1241 err("%s: port or port->private is NULL, status=%d",
1248 __FUNCTION__, status); 1242 __func__, status);
1249 return; 1243 return;
1250 } 1244 }
1251 serial = port->serial; 1245 serial = port->serial;
1252 if (serial == NULL || (serial_priv=usb_get_serial_data(serial)) == NULL) { 1246 if (serial == NULL || (serial_priv=usb_get_serial_data(serial)) == NULL) {
1253 err("%s: serial or serial->private is NULL, status=%d", 1247 err("%s: serial or serial->private is NULL, status=%d",
1254 __FUNCTION__, status); 1248 __func__, status);
1255 return; 1249 return;
1256 } 1250 }
1257 1251
@@ -1292,7 +1286,7 @@ static void digi_write_bulk_callback(struct urb *urb)
1292 spin_unlock(&priv->dp_port_lock); 1286 spin_unlock(&priv->dp_port_lock);
1293 if (ret) 1287 if (ret)
1294 err("%s: usb_submit_urb failed, ret=%d, port=%d", 1288 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1295 __FUNCTION__, ret, priv->dp_port_num); 1289 __func__, ret, priv->dp_port_num);
1296} 1290}
1297 1291
1298static int digi_write_room(struct usb_serial_port *port) 1292static int digi_write_room(struct usb_serial_port *port)
@@ -1521,7 +1515,7 @@ static int digi_startup_device(struct usb_serial *serial)
1521 port->write_urb->dev = port->serial->dev; 1515 port->write_urb->dev = port->serial->dev;
1522 if ((ret = usb_submit_urb(port->read_urb, GFP_KERNEL)) != 0) { 1516 if ((ret = usb_submit_urb(port->read_urb, GFP_KERNEL)) != 0) {
1523 err("%s: usb_submit_urb failed, ret=%d, port=%d", 1517 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1524 __FUNCTION__, ret, i); 1518 __func__, ret, i);
1525 break; 1519 break;
1526 } 1520 }
1527 } 1521 }
@@ -1611,7 +1605,7 @@ static void digi_shutdown(struct usb_serial *serial)
1611 1605
1612static void digi_read_bulk_callback(struct urb *urb) 1606static void digi_read_bulk_callback(struct urb *urb)
1613{ 1607{
1614 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1608 struct usb_serial_port *port = urb->context;
1615 struct digi_port *priv; 1609 struct digi_port *priv;
1616 struct digi_serial *serial_priv; 1610 struct digi_serial *serial_priv;
1617 int ret; 1611 int ret;
@@ -1622,20 +1616,20 @@ static void digi_read_bulk_callback(struct urb *urb)
1622 /* port sanity check, do not resubmit if port is not valid */ 1616 /* port sanity check, do not resubmit if port is not valid */
1623 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) { 1617 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
1624 err("%s: port or port->private is NULL, status=%d", 1618 err("%s: port or port->private is NULL, status=%d",
1625 __FUNCTION__, status); 1619 __func__, status);
1626 return; 1620 return;
1627 } 1621 }
1628 if (port->serial == NULL || 1622 if (port->serial == NULL ||
1629 (serial_priv=usb_get_serial_data(port->serial)) == NULL) { 1623 (serial_priv=usb_get_serial_data(port->serial)) == NULL) {
1630 err("%s: serial is bad or serial->private is NULL, status=%d", 1624 err("%s: serial is bad or serial->private is NULL, status=%d",
1631 __FUNCTION__, status); 1625 __func__, status);
1632 return; 1626 return;
1633 } 1627 }
1634 1628
1635 /* do not resubmit urb if it has any status error */ 1629 /* do not resubmit urb if it has any status error */
1636 if (status) { 1630 if (status) {
1637 err("%s: nonzero read bulk status: status=%d, port=%d", 1631 err("%s: nonzero read bulk status: status=%d, port=%d",
1638 __FUNCTION__, status, priv->dp_port_num); 1632 __func__, status, priv->dp_port_num);
1639 return; 1633 return;
1640 } 1634 }
1641 1635
@@ -1652,7 +1646,7 @@ static void digi_read_bulk_callback(struct urb *urb)
1652 urb->dev = port->serial->dev; 1646 urb->dev = port->serial->dev;
1653 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1647 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
1654 err("%s: failed resubmitting urb, ret=%d, port=%d", 1648 err("%s: failed resubmitting urb, ret=%d, port=%d",
1655 __FUNCTION__, ret, priv->dp_port_num); 1649 __func__, ret, priv->dp_port_num);
1656 } 1650 }
1657 1651
1658} 1652}
@@ -1670,7 +1664,7 @@ static void digi_read_bulk_callback(struct urb *urb)
1670static int digi_read_inb_callback(struct urb *urb) 1664static int digi_read_inb_callback(struct urb *urb)
1671{ 1665{
1672 1666
1673 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1667 struct usb_serial_port *port = urb->context;
1674 struct tty_struct *tty = port->tty; 1668 struct tty_struct *tty = port->tty;
1675 struct digi_port *priv = usb_get_serial_port_data(port); 1669 struct digi_port *priv = usb_get_serial_port_data(port);
1676 int opcode = ((unsigned char *)urb->transfer_buffer)[0]; 1670 int opcode = ((unsigned char *)urb->transfer_buffer)[0];
@@ -1690,7 +1684,7 @@ static int digi_read_inb_callback(struct urb *urb)
1690 if (urb->actual_length != len + 2) { 1684 if (urb->actual_length != len + 2) {
1691 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, " 1685 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, "
1692 "port=%d, opcode=%d, len=%d, actual_length=%d, " 1686 "port=%d, opcode=%d, len=%d, actual_length=%d, "
1693 "status=%d", __FUNCTION__, status, priv->dp_port_num, 1687 "status=%d", __func__, status, priv->dp_port_num,
1694 opcode, len, urb->actual_length, port_status); 1688 opcode, len, urb->actual_length, port_status);
1695 return -1; 1689 return -1;
1696 } 1690 }
@@ -1739,9 +1733,9 @@ static int digi_read_inb_callback(struct urb *urb)
1739 spin_unlock(&priv->dp_port_lock); 1733 spin_unlock(&priv->dp_port_lock);
1740 1734
1741 if (opcode == DIGI_CMD_RECEIVE_DISABLE) 1735 if (opcode == DIGI_CMD_RECEIVE_DISABLE)
1742 dbg("%s: got RECEIVE_DISABLE", __FUNCTION__); 1736 dbg("%s: got RECEIVE_DISABLE", __func__);
1743 else if (opcode != DIGI_CMD_RECEIVE_DATA) 1737 else if (opcode != DIGI_CMD_RECEIVE_DATA)
1744 dbg("%s: unknown opcode: %d", __FUNCTION__, opcode); 1738 dbg("%s: unknown opcode: %d", __func__, opcode);
1745 1739
1746 return(throttled ? 1 : 0); 1740 return(throttled ? 1 : 0);
1747 1741
@@ -1760,7 +1754,7 @@ static int digi_read_inb_callback(struct urb *urb)
1760static int digi_read_oob_callback(struct urb *urb) 1754static int digi_read_oob_callback(struct urb *urb)
1761{ 1755{
1762 1756
1763 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1757 struct usb_serial_port *port = urb->context;
1764 struct usb_serial *serial = port->serial; 1758 struct usb_serial *serial = port->serial;
1765 struct digi_port *priv = usb_get_serial_port_data(port); 1759 struct digi_port *priv = usb_get_serial_port_data(port);
1766 int opcode, line, status, val; 1760 int opcode, line, status, val;
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index a5c8e1e17ea5..c5ec309a3cb1 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -118,9 +118,6 @@ static struct usb_serial_driver empeg_device = {
118 }, 118 },
119 .id_table = id_table, 119 .id_table = id_table,
120 .usb_driver = &empeg_driver, 120 .usb_driver = &empeg_driver,
121 .num_interrupt_in = 0,
122 .num_bulk_in = 1,
123 .num_bulk_out = 1,
124 .num_ports = 1, 121 .num_ports = 1,
125 .open = empeg_open, 122 .open = empeg_open,
126 .close = empeg_close, 123 .close = empeg_close,
@@ -153,7 +150,7 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
153 struct usb_serial *serial = port->serial; 150 struct usb_serial *serial = port->serial;
154 int result = 0; 151 int result = 0;
155 152
156 dbg("%s - port %d", __FUNCTION__, port->number); 153 dbg("%s - port %d", __func__, port->number);
157 154
158 /* Force default termio settings */ 155 /* Force default termio settings */
159 empeg_set_termios (port, NULL) ; 156 empeg_set_termios (port, NULL) ;
@@ -175,7 +172,7 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
175 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 172 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
176 173
177 if (result) 174 if (result)
178 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 175 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result);
179 176
180 return result; 177 return result;
181} 178}
@@ -183,7 +180,7 @@ static int empeg_open (struct usb_serial_port *port, struct file *filp)
183 180
184static void empeg_close (struct usb_serial_port *port, struct file * filp) 181static void empeg_close (struct usb_serial_port *port, struct file * filp)
185{ 182{
186 dbg("%s - port %d", __FUNCTION__, port->number); 183 dbg("%s - port %d", __func__, port->number);
187 184
188 /* shutdown our bulk read */ 185 /* shutdown our bulk read */
189 usb_kill_urb(port->read_urb); 186 usb_kill_urb(port->read_urb);
@@ -203,7 +200,7 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
203 int bytes_sent = 0; 200 int bytes_sent = 0;
204 int transfer_size; 201 int transfer_size;
205 202
206 dbg("%s - port %d", __FUNCTION__, port->number); 203 dbg("%s - port %d", __func__, port->number);
207 204
208 while (count > 0) { 205 while (count > 0) {
209 206
@@ -222,14 +219,14 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
222 spin_unlock_irqrestore (&write_urb_pool_lock, flags); 219 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
223 220
224 if (urb == NULL) { 221 if (urb == NULL) {
225 dbg("%s - no more free urbs", __FUNCTION__); 222 dbg("%s - no more free urbs", __func__);
226 goto exit; 223 goto exit;
227 } 224 }
228 225
229 if (urb->transfer_buffer == NULL) { 226 if (urb->transfer_buffer == NULL) {
230 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 227 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
231 if (urb->transfer_buffer == NULL) { 228 if (urb->transfer_buffer == NULL) {
232 dev_err(&port->dev, "%s no more kernel memory...\n", __FUNCTION__); 229 dev_err(&port->dev, "%s no more kernel memory...\n", __func__);
233 goto exit; 230 goto exit;
234 } 231 }
235 } 232 }
@@ -238,7 +235,7 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
238 235
239 memcpy (urb->transfer_buffer, current_position, transfer_size); 236 memcpy (urb->transfer_buffer, current_position, transfer_size);
240 237
241 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, transfer_size, urb->transfer_buffer); 238 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer);
242 239
243 /* build up our urb */ 240 /* build up our urb */
244 usb_fill_bulk_urb ( 241 usb_fill_bulk_urb (
@@ -254,7 +251,7 @@ static int empeg_write (struct usb_serial_port *port, const unsigned char *buf,
254 /* send it down the pipe */ 251 /* send it down the pipe */
255 status = usb_submit_urb(urb, GFP_ATOMIC); 252 status = usb_submit_urb(urb, GFP_ATOMIC);
256 if (status) { 253 if (status) {
257 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __FUNCTION__, status); 254 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status);
258 bytes_sent = status; 255 bytes_sent = status;
259 break; 256 break;
260 } 257 }
@@ -278,7 +275,7 @@ static int empeg_write_room (struct usb_serial_port *port)
278 int i; 275 int i;
279 int room = 0; 276 int room = 0;
280 277
281 dbg("%s - port %d", __FUNCTION__, port->number); 278 dbg("%s - port %d", __func__, port->number);
282 279
283 spin_lock_irqsave (&write_urb_pool_lock, flags); 280 spin_lock_irqsave (&write_urb_pool_lock, flags);
284 281
@@ -291,7 +288,7 @@ static int empeg_write_room (struct usb_serial_port *port)
291 288
292 spin_unlock_irqrestore (&write_urb_pool_lock, flags); 289 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
293 290
294 dbg("%s - returns %d", __FUNCTION__, room); 291 dbg("%s - returns %d", __func__, room);
295 292
296 return (room); 293 return (room);
297 294
@@ -304,7 +301,7 @@ static int empeg_chars_in_buffer (struct usb_serial_port *port)
304 int i; 301 int i;
305 int chars = 0; 302 int chars = 0;
306 303
307 dbg("%s - port %d", __FUNCTION__, port->number); 304 dbg("%s - port %d", __func__, port->number);
308 305
309 spin_lock_irqsave (&write_urb_pool_lock, flags); 306 spin_lock_irqsave (&write_urb_pool_lock, flags);
310 307
@@ -317,7 +314,7 @@ static int empeg_chars_in_buffer (struct usb_serial_port *port)
317 314
318 spin_unlock_irqrestore (&write_urb_pool_lock, flags); 315 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
319 316
320 dbg("%s - returns %d", __FUNCTION__, chars); 317 dbg("%s - returns %d", __func__, chars);
321 318
322 return (chars); 319 return (chars);
323 320
@@ -329,11 +326,11 @@ static void empeg_write_bulk_callback (struct urb *urb)
329 struct usb_serial_port *port = urb->context; 326 struct usb_serial_port *port = urb->context;
330 int status = urb->status; 327 int status = urb->status;
331 328
332 dbg("%s - port %d", __FUNCTION__, port->number); 329 dbg("%s - port %d", __func__, port->number);
333 330
334 if (status) { 331 if (status) {
335 dbg("%s - nonzero write bulk status received: %d", 332 dbg("%s - nonzero write bulk status received: %d",
336 __FUNCTION__, status); 333 __func__, status);
337 return; 334 return;
338 } 335 }
339 336
@@ -343,21 +340,21 @@ static void empeg_write_bulk_callback (struct urb *urb)
343 340
344static void empeg_read_bulk_callback (struct urb *urb) 341static void empeg_read_bulk_callback (struct urb *urb)
345{ 342{
346 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 343 struct usb_serial_port *port = urb->context;
347 struct tty_struct *tty; 344 struct tty_struct *tty;
348 unsigned char *data = urb->transfer_buffer; 345 unsigned char *data = urb->transfer_buffer;
349 int result; 346 int result;
350 int status = urb->status; 347 int status = urb->status;
351 348
352 dbg("%s - port %d", __FUNCTION__, port->number); 349 dbg("%s - port %d", __func__, port->number);
353 350
354 if (status) { 351 if (status) {
355 dbg("%s - nonzero read bulk status received: %d", 352 dbg("%s - nonzero read bulk status received: %d",
356 __FUNCTION__, status); 353 __func__, status);
357 return; 354 return;
358 } 355 }
359 356
360 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 357 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
361 358
362 tty = port->tty; 359 tty = port->tty;
363 360
@@ -382,7 +379,7 @@ static void empeg_read_bulk_callback (struct urb *urb)
382 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 379 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
383 380
384 if (result) 381 if (result)
385 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 382 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
386 383
387 return; 384 return;
388 385
@@ -391,7 +388,7 @@ static void empeg_read_bulk_callback (struct urb *urb)
391 388
392static void empeg_throttle (struct usb_serial_port *port) 389static void empeg_throttle (struct usb_serial_port *port)
393{ 390{
394 dbg("%s - port %d", __FUNCTION__, port->number); 391 dbg("%s - port %d", __func__, port->number);
395 usb_kill_urb(port->read_urb); 392 usb_kill_urb(port->read_urb);
396} 393}
397 394
@@ -400,14 +397,14 @@ static void empeg_unthrottle (struct usb_serial_port *port)
400{ 397{
401 int result; 398 int result;
402 399
403 dbg("%s - port %d", __FUNCTION__, port->number); 400 dbg("%s - port %d", __func__, port->number);
404 401
405 port->read_urb->dev = port->serial->dev; 402 port->read_urb->dev = port->serial->dev;
406 403
407 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 404 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
408 405
409 if (result) 406 if (result)
410 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 407 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result);
411 408
412 return; 409 return;
413} 410}
@@ -417,14 +414,14 @@ static int empeg_startup (struct usb_serial *serial)
417{ 414{
418 int r; 415 int r;
419 416
420 dbg("%s", __FUNCTION__); 417 dbg("%s", __func__);
421 418
422 if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 419 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
423 err("active config #%d != 1 ??", 420 err("active config #%d != 1 ??",
424 serial->dev->actconfig->desc.bConfigurationValue); 421 serial->dev->actconfig->desc.bConfigurationValue);
425 return -ENODEV; 422 return -ENODEV;
426 } 423 }
427 dbg("%s - reset config", __FUNCTION__); 424 dbg("%s - reset config", __func__);
428 r = usb_reset_configuration (serial->dev); 425 r = usb_reset_configuration (serial->dev);
429 426
430 /* continue on with initialization */ 427 /* continue on with initialization */
@@ -435,13 +432,13 @@ static int empeg_startup (struct usb_serial *serial)
435 432
436static void empeg_shutdown (struct usb_serial *serial) 433static void empeg_shutdown (struct usb_serial *serial)
437{ 434{
438 dbg ("%s", __FUNCTION__); 435 dbg ("%s", __func__);
439} 436}
440 437
441 438
442static int empeg_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 439static int empeg_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
443{ 440{
444 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); 441 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
445 442
446 return -ENOIOCTLCMD; 443 return -ENOIOCTLCMD;
447} 444}
@@ -450,7 +447,7 @@ static int empeg_ioctl (struct usb_serial_port *port, struct file * file, unsign
450static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 447static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
451{ 448{
452 struct ktermios *termios = port->tty->termios; 449 struct ktermios *termios = port->tty->termios;
453 dbg("%s - port %d", __FUNCTION__, port->number); 450 dbg("%s - port %d", __func__, port->number);
454 451
455 /* 452 /*
456 * The empeg-car player wants these particular tty settings. 453 * The empeg-car player wants these particular tty settings.
@@ -517,7 +514,7 @@ static int __init empeg_init (void)
517 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 514 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
518 if (!urb->transfer_buffer) { 515 if (!urb->transfer_buffer) {
519 err("%s - out of memory for urb buffers.", 516 err("%s - out of memory for urb buffers.",
520 __FUNCTION__); 517 __func__);
521 continue; 518 continue;
522 } 519 }
523 } 520 }
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index 3f698baa0abb..cc4fbd9d60be 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -27,13 +27,13 @@ int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *da
27 27
28 /* dbg("ezusb_writememory %x, %d", address, length); */ 28 /* dbg("ezusb_writememory %x, %d", address, length); */
29 if (!serial->dev) { 29 if (!serial->dev) {
30 err("%s - no physical device present, failing.", __FUNCTION__); 30 err("%s - no physical device present, failing.", __func__);
31 return -ENODEV; 31 return -ENODEV;
32 } 32 }
33 33
34 transfer_buffer = kmemdup(data, length, GFP_KERNEL); 34 transfer_buffer = kmemdup(data, length, GFP_KERNEL);
35 if (!transfer_buffer) { 35 if (!transfer_buffer) {
36 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __FUNCTION__, length); 36 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, length);
37 return -ENOMEM; 37 return -ENOMEM;
38 } 38 }
39 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), bRequest, 0x40, address, 0, transfer_buffer, length, 3000); 39 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), bRequest, 0x40, address, 0, transfer_buffer, length, 3000);
@@ -45,10 +45,10 @@ int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit)
45{ 45{
46 int response; 46 int response;
47 47
48 /* dbg("%s - %d", __FUNCTION__, reset_bit); */ 48 /* dbg("%s - %d", __func__, reset_bit); */
49 response = ezusb_writememory (serial, CPUCS_REG, &reset_bit, 1, 0xa0); 49 response = ezusb_writememory (serial, CPUCS_REG, &reset_bit, 1, 0xa0);
50 if (response < 0) 50 if (response < 0)
51 dev_err(&serial->dev->dev, "%s- %d failed\n", __FUNCTION__, reset_bit); 51 dev_err(&serial->dev->dev, "%s- %d failed\n", __func__, reset_bit);
52 return response; 52 return response;
53} 53}
54 54
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 3abb3c863647..23f51a41093e 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -439,9 +439,6 @@ static struct usb_serial_driver ftdi_sio_device = {
439 .description = "FTDI USB Serial Device", 439 .description = "FTDI USB Serial Device",
440 .usb_driver = &ftdi_driver , 440 .usb_driver = &ftdi_driver ,
441 .id_table = id_table_combined, 441 .id_table = id_table_combined,
442 .num_interrupt_in = 0,
443 .num_bulk_in = 1,
444 .num_bulk_out = 1,
445 .num_ports = 1, 442 .num_ports = 1,
446 .probe = ftdi_sio_probe, 443 .probe = ftdi_sio_probe,
447 .port_probe = ftdi_sio_port_probe, 444 .port_probe = ftdi_sio_port_probe,
@@ -528,14 +525,13 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned
528 int rv; 525 int rv;
529 526
530 if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) { 527 if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) {
531 dbg("%s - DTR|RTS not being set|cleared", __FUNCTION__); 528 dbg("%s - DTR|RTS not being set|cleared", __func__);
532 return 0; /* no change */ 529 return 0; /* no change */
533 } 530 }
534 531
535 buf = kmalloc(1, GFP_NOIO); 532 buf = kmalloc(1, GFP_NOIO);
536 if (!buf) { 533 if (!buf)
537 return -ENOMEM; 534 return -ENOMEM;
538 }
539 535
540 clear &= ~set; /* 'set' takes precedence over 'clear' */ 536 clear &= ~set; /* 'set' takes precedence over 'clear' */
541 urb_value = 0; 537 urb_value = 0;
@@ -557,17 +553,18 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned
557 kfree(buf); 553 kfree(buf);
558 if (rv < 0) { 554 if (rv < 0) {
559 err("%s Error from MODEM_CTRL urb: DTR %s, RTS %s", 555 err("%s Error from MODEM_CTRL urb: DTR %s, RTS %s",
560 __FUNCTION__, 556 __func__,
561 (set & TIOCM_DTR) ? "HIGH" : 557 (set & TIOCM_DTR) ? "HIGH" :
562 (clear & TIOCM_DTR) ? "LOW" : "unchanged", 558 (clear & TIOCM_DTR) ? "LOW" : "unchanged",
563 (set & TIOCM_RTS) ? "HIGH" : 559 (set & TIOCM_RTS) ? "HIGH" :
564 (clear & TIOCM_RTS) ? "LOW" : "unchanged"); 560 (clear & TIOCM_RTS) ? "LOW" : "unchanged");
565 } else { 561 } else {
566 dbg("%s - DTR %s, RTS %s", __FUNCTION__, 562 dbg("%s - DTR %s, RTS %s", __func__,
567 (set & TIOCM_DTR) ? "HIGH" : 563 (set & TIOCM_DTR) ? "HIGH" :
568 (clear & TIOCM_DTR) ? "LOW" : "unchanged", 564 (clear & TIOCM_DTR) ? "LOW" : "unchanged",
569 (set & TIOCM_RTS) ? "HIGH" : 565 (set & TIOCM_RTS) ? "HIGH" :
570 (clear & TIOCM_RTS) ? "LOW" : "unchanged"); 566 (clear & TIOCM_RTS) ? "LOW" : "unchanged");
567 /* FIXME: locking on last_dtr_rts */
571 priv->last_dtr_rts = (priv->last_dtr_rts & ~clear) | set; 568 priv->last_dtr_rts = (priv->last_dtr_rts & ~clear) | set;
572 } 569 }
573 return rv; 570 return rv;
@@ -642,7 +639,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
642 /* 1. Get the baud rate from the tty settings, this observes alt_speed hack */ 639 /* 1. Get the baud rate from the tty settings, this observes alt_speed hack */
643 640
644 baud = tty_get_baud_rate(port->tty); 641 baud = tty_get_baud_rate(port->tty);
645 dbg("%s - tty_get_baud_rate reports speed %d", __FUNCTION__, baud); 642 dbg("%s - tty_get_baud_rate reports speed %d", __func__, baud);
646 643
647 /* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */ 644 /* 2. Observe async-compatible custom_divisor hack, update baudrate if needed */
648 645
@@ -650,7 +647,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
650 ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 647 ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
651 (priv->custom_divisor)) { 648 (priv->custom_divisor)) {
652 baud = priv->baud_base / priv->custom_divisor; 649 baud = priv->baud_base / priv->custom_divisor;
653 dbg("%s - custom divisor %d sets baud rate to %d", __FUNCTION__, priv->custom_divisor, baud); 650 dbg("%s - custom divisor %d sets baud rate to %d", __func__, priv->custom_divisor, baud);
654 } 651 }
655 652
656 /* 3. Convert baudrate to device-specific divisor */ 653 /* 3. Convert baudrate to device-specific divisor */
@@ -671,7 +668,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
671 case 115200: div_value = ftdi_sio_b115200; break; 668 case 115200: div_value = ftdi_sio_b115200; break;
672 } /* baud */ 669 } /* baud */
673 if (div_value == 0) { 670 if (div_value == 0) {
674 dbg("%s - Baudrate (%d) requested is not supported", __FUNCTION__, baud); 671 dbg("%s - Baudrate (%d) requested is not supported", __func__, baud);
675 div_value = ftdi_sio_b9600; 672 div_value = ftdi_sio_b9600;
676 baud = 9600; 673 baud = 9600;
677 div_okay = 0; 674 div_okay = 0;
@@ -681,7 +678,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
681 if (baud <= 3000000) { 678 if (baud <= 3000000) {
682 div_value = ftdi_232am_baud_to_divisor(baud); 679 div_value = ftdi_232am_baud_to_divisor(baud);
683 } else { 680 } else {
684 dbg("%s - Baud rate too high!", __FUNCTION__); 681 dbg("%s - Baud rate too high!", __func__);
685 baud = 9600; 682 baud = 9600;
686 div_value = ftdi_232am_baud_to_divisor(9600); 683 div_value = ftdi_232am_baud_to_divisor(9600);
687 div_okay = 0; 684 div_okay = 0;
@@ -693,7 +690,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
693 if (baud <= 3000000) { 690 if (baud <= 3000000) {
694 div_value = ftdi_232bm_baud_to_divisor(baud); 691 div_value = ftdi_232bm_baud_to_divisor(baud);
695 } else { 692 } else {
696 dbg("%s - Baud rate too high!", __FUNCTION__); 693 dbg("%s - Baud rate too high!", __func__);
697 div_value = ftdi_232bm_baud_to_divisor(9600); 694 div_value = ftdi_232bm_baud_to_divisor(9600);
698 div_okay = 0; 695 div_okay = 0;
699 baud = 9600; 696 baud = 9600;
@@ -703,7 +700,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port)
703 700
704 if (div_okay) { 701 if (div_okay) {
705 dbg("%s - Baud rate set to %d (divisor 0x%lX) on chip %s", 702 dbg("%s - Baud rate set to %d (divisor 0x%lX) on chip %s",
706 __FUNCTION__, baud, (unsigned long)div_value, 703 __func__, baud, (unsigned long)div_value,
707 ftdi_chip_name[priv->chip_type]); 704 ftdi_chip_name[priv->chip_type]);
708 } 705 }
709 706
@@ -804,7 +801,7 @@ static void ftdi_determine_type(struct usb_serial_port *port)
804 801
805 version = le16_to_cpu(udev->descriptor.bcdDevice); 802 version = le16_to_cpu(udev->descriptor.bcdDevice);
806 interfaces = udev->actconfig->desc.bNumInterfaces; 803 interfaces = udev->actconfig->desc.bNumInterfaces;
807 dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __FUNCTION__, 804 dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __func__,
808 version, interfaces); 805 version, interfaces);
809 if (interfaces > 1) { 806 if (interfaces > 1) {
810 int inter; 807 int inter;
@@ -822,7 +819,7 @@ static void ftdi_determine_type(struct usb_serial_port *port)
822 * to 0x200 when iSerialNumber is 0. */ 819 * to 0x200 when iSerialNumber is 0. */
823 if (version < 0x500) { 820 if (version < 0x500) {
824 dbg("%s: something fishy - bcdDevice too low for multi-interface device", 821 dbg("%s: something fishy - bcdDevice too low for multi-interface device",
825 __FUNCTION__); 822 __func__);
826 } 823 }
827 } else if (version < 0x200) { 824 } else if (version < 0x200) {
828 /* Old device. Assume its the original SIO. */ 825 /* Old device. Assume its the original SIO. */
@@ -860,7 +857,7 @@ static ssize_t show_latency_timer(struct device *dev, struct device_attribute *a
860 int rv = 0; 857 int rv = 0;
861 858
862 859
863 dbg("%s",__FUNCTION__); 860 dbg("%s",__func__);
864 861
865 rv = usb_control_msg(udev, 862 rv = usb_control_msg(udev,
866 usb_rcvctrlpipe(udev, 0), 863 usb_rcvctrlpipe(udev, 0),
@@ -887,7 +884,7 @@ static ssize_t store_latency_timer(struct device *dev, struct device_attribute *
887 int v = simple_strtoul(valbuf, NULL, 10); 884 int v = simple_strtoul(valbuf, NULL, 10);
888 int rv = 0; 885 int rv = 0;
889 886
890 dbg("%s: setting latency timer = %i", __FUNCTION__, v); 887 dbg("%s: setting latency timer = %i", __func__, v);
891 888
892 rv = usb_control_msg(udev, 889 rv = usb_control_msg(udev,
893 usb_sndctrlpipe(udev, 0), 890 usb_sndctrlpipe(udev, 0),
@@ -916,7 +913,7 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att
916 int v = simple_strtoul(valbuf, NULL, 10); 913 int v = simple_strtoul(valbuf, NULL, 10);
917 int rv = 0; 914 int rv = 0;
918 915
919 dbg("%s: setting event char = %i", __FUNCTION__, v); 916 dbg("%s: setting event char = %i", __func__, v);
920 917
921 rv = usb_control_msg(udev, 918 rv = usb_control_msg(udev,
922 usb_sndctrlpipe(udev, 0), 919 usb_sndctrlpipe(udev, 0),
@@ -941,7 +938,7 @@ static int create_sysfs_attrs(struct usb_serial_port *port)
941 struct ftdi_private *priv = usb_get_serial_port_data(port); 938 struct ftdi_private *priv = usb_get_serial_port_data(port);
942 int retval = 0; 939 int retval = 0;
943 940
944 dbg("%s",__FUNCTION__); 941 dbg("%s",__func__);
945 942
946 /* XXX I've no idea if the original SIO supports the event_char 943 /* XXX I've no idea if the original SIO supports the event_char
947 * sysfs parameter, so I'm playing it safe. */ 944 * sysfs parameter, so I'm playing it safe. */
@@ -963,7 +960,7 @@ static void remove_sysfs_attrs(struct usb_serial_port *port)
963{ 960{
964 struct ftdi_private *priv = usb_get_serial_port_data(port); 961 struct ftdi_private *priv = usb_get_serial_port_data(port);
965 962
966 dbg("%s",__FUNCTION__); 963 dbg("%s",__func__);
967 964
968 /* XXX see create_sysfs_attrs */ 965 /* XXX see create_sysfs_attrs */
969 if (priv->chip_type != SIO) { 966 if (priv->chip_type != SIO) {
@@ -1005,11 +1002,11 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1005 struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial); 1002 struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial);
1006 1003
1007 1004
1008 dbg("%s",__FUNCTION__); 1005 dbg("%s",__func__);
1009 1006
1010 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); 1007 priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
1011 if (!priv){ 1008 if (!priv){
1012 err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct ftdi_private)); 1009 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct ftdi_private));
1013 return -ENOMEM; 1010 return -ENOMEM;
1014 } 1011 }
1015 1012
@@ -1058,7 +1055,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1058/* Called from usbserial:serial_probe */ 1055/* Called from usbserial:serial_probe */
1059static void ftdi_USB_UIRT_setup (struct ftdi_private *priv) 1056static void ftdi_USB_UIRT_setup (struct ftdi_private *priv)
1060{ 1057{
1061 dbg("%s",__FUNCTION__); 1058 dbg("%s",__func__);
1062 1059
1063 priv->flags |= ASYNC_SPD_CUST; 1060 priv->flags |= ASYNC_SPD_CUST;
1064 priv->custom_divisor = 77; 1061 priv->custom_divisor = 77;
@@ -1069,7 +1066,7 @@ static void ftdi_USB_UIRT_setup (struct ftdi_private *priv)
1069 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */ 1066 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
1070static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv) 1067static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv)
1071{ 1068{
1072 dbg("%s",__FUNCTION__); 1069 dbg("%s",__func__);
1073 1070
1074 priv->flags |= ASYNC_SPD_CUST; 1071 priv->flags |= ASYNC_SPD_CUST;
1075 priv->custom_divisor = 240; 1072 priv->custom_divisor = 240;
@@ -1087,7 +1084,7 @@ static int ftdi_jtag_probe(struct usb_serial *serial)
1087 struct usb_device *udev = serial->dev; 1084 struct usb_device *udev = serial->dev;
1088 struct usb_interface *interface = serial->interface; 1085 struct usb_interface *interface = serial->interface;
1089 1086
1090 dbg("%s",__FUNCTION__); 1087 dbg("%s",__func__);
1091 1088
1092 if (interface == udev->actconfig->interface[0]) { 1089 if (interface == udev->actconfig->interface[0]) {
1093 info("Ignoring serial port reserved for JTAG"); 1090 info("Ignoring serial port reserved for JTAG");
@@ -1123,14 +1120,14 @@ static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
1123 */ 1120 */
1124static void ftdi_shutdown (struct usb_serial *serial) 1121static void ftdi_shutdown (struct usb_serial *serial)
1125{ 1122{
1126 dbg("%s", __FUNCTION__); 1123 dbg("%s", __func__);
1127} 1124}
1128 1125
1129static int ftdi_sio_port_remove(struct usb_serial_port *port) 1126static int ftdi_sio_port_remove(struct usb_serial_port *port)
1130{ 1127{
1131 struct ftdi_private *priv = usb_get_serial_port_data(port); 1128 struct ftdi_private *priv = usb_get_serial_port_data(port);
1132 1129
1133 dbg("%s", __FUNCTION__); 1130 dbg("%s", __func__);
1134 1131
1135 remove_sysfs_attrs(port); 1132 remove_sysfs_attrs(port);
1136 1133
@@ -1155,7 +1152,7 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1155 int result = 0; 1152 int result = 0;
1156 char buf[1]; /* Needed for the usb_control_msg I think */ 1153 char buf[1]; /* Needed for the usb_control_msg I think */
1157 1154
1158 dbg("%s", __FUNCTION__); 1155 dbg("%s", __func__);
1159 1156
1160 spin_lock_irqsave(&priv->tx_lock, flags); 1157 spin_lock_irqsave(&priv->tx_lock, flags);
1161 priv->tx_bytes = 0; 1158 priv->tx_bytes = 0;
@@ -1200,7 +1197,7 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1200 ftdi_read_bulk_callback, port); 1197 ftdi_read_bulk_callback, port);
1201 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 1198 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
1202 if (result) 1199 if (result)
1203 err("%s - failed submitting read urb, error %d", __FUNCTION__, result); 1200 err("%s - failed submitting read urb, error %d", __func__, result);
1204 1201
1205 1202
1206 return result; 1203 return result;
@@ -1222,7 +1219,7 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1222 struct ftdi_private *priv = usb_get_serial_port_data(port); 1219 struct ftdi_private *priv = usb_get_serial_port_data(port);
1223 char buf[1]; 1220 char buf[1];
1224 1221
1225 dbg("%s", __FUNCTION__); 1222 dbg("%s", __func__);
1226 1223
1227 mutex_lock(&port->serial->disc_mutex); 1224 mutex_lock(&port->serial->disc_mutex);
1228 if (c_cflag & HUPCL && !port->serial->disconnected){ 1225 if (c_cflag & HUPCL && !port->serial->disconnected){
@@ -1269,7 +1266,7 @@ static int ftdi_write (struct usb_serial_port *port,
1269 int transfer_size; 1266 int transfer_size;
1270 unsigned long flags; 1267 unsigned long flags;
1271 1268
1272 dbg("%s port %d, %d bytes", __FUNCTION__, port->number, count); 1269 dbg("%s port %d, %d bytes", __func__, port->number, count);
1273 1270
1274 if (count == 0) { 1271 if (count == 0) {
1275 dbg("write request of 0 bytes"); 1272 dbg("write request of 0 bytes");
@@ -1278,7 +1275,7 @@ static int ftdi_write (struct usb_serial_port *port,
1278 spin_lock_irqsave(&priv->tx_lock, flags); 1275 spin_lock_irqsave(&priv->tx_lock, flags);
1279 if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) { 1276 if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) {
1280 spin_unlock_irqrestore(&priv->tx_lock, flags); 1277 spin_unlock_irqrestore(&priv->tx_lock, flags);
1281 dbg("%s - write limit hit\n", __FUNCTION__); 1278 dbg("%s - write limit hit\n", __func__);
1282 return 0; 1279 return 0;
1283 } 1280 }
1284 priv->tx_outstanding_urbs++; 1281 priv->tx_outstanding_urbs++;
@@ -1298,14 +1295,14 @@ static int ftdi_write (struct usb_serial_port *port,
1298 1295
1299 buffer = kmalloc (transfer_size, GFP_ATOMIC); 1296 buffer = kmalloc (transfer_size, GFP_ATOMIC);
1300 if (!buffer) { 1297 if (!buffer) {
1301 err("%s ran out of kernel memory for urb ...", __FUNCTION__); 1298 err("%s ran out of kernel memory for urb ...", __func__);
1302 count = -ENOMEM; 1299 count = -ENOMEM;
1303 goto error_no_buffer; 1300 goto error_no_buffer;
1304 } 1301 }
1305 1302
1306 urb = usb_alloc_urb(0, GFP_ATOMIC); 1303 urb = usb_alloc_urb(0, GFP_ATOMIC);
1307 if (!urb) { 1304 if (!urb) {
1308 err("%s - no more free urbs", __FUNCTION__); 1305 err("%s - no more free urbs", __func__);
1309 count = -ENOMEM; 1306 count = -ENOMEM;
1310 goto error_no_urb; 1307 goto error_no_urb;
1311 } 1308 }
@@ -1337,7 +1334,7 @@ static int ftdi_write (struct usb_serial_port *port,
1337 memcpy (buffer, buf, count); 1334 memcpy (buffer, buf, count);
1338 } 1335 }
1339 1336
1340 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, transfer_size, buffer); 1337 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, buffer);
1341 1338
1342 /* fill the buffer and send it */ 1339 /* fill the buffer and send it */
1343 usb_fill_bulk_urb(urb, port->serial->dev, 1340 usb_fill_bulk_urb(urb, port->serial->dev,
@@ -1347,7 +1344,7 @@ static int ftdi_write (struct usb_serial_port *port,
1347 1344
1348 status = usb_submit_urb(urb, GFP_ATOMIC); 1345 status = usb_submit_urb(urb, GFP_ATOMIC);
1349 if (status) { 1346 if (status) {
1350 err("%s - failed submitting write urb, error %d", __FUNCTION__, status); 1347 err("%s - failed submitting write urb, error %d", __func__, status);
1351 count = status; 1348 count = status;
1352 goto error; 1349 goto error;
1353 } else { 1350 } else {
@@ -1361,7 +1358,7 @@ static int ftdi_write (struct usb_serial_port *port,
1361 * really free it when it is finished with it */ 1358 * really free it when it is finished with it */
1362 usb_free_urb(urb); 1359 usb_free_urb(urb);
1363 1360
1364 dbg("%s write returning: %d", __FUNCTION__, count); 1361 dbg("%s write returning: %d", __func__, count);
1365 return count; 1362 return count;
1366error: 1363error:
1367 usb_free_urb(urb); 1364 usb_free_urb(urb);
@@ -1380,7 +1377,7 @@ error_no_buffer:
1380static void ftdi_write_bulk_callback (struct urb *urb) 1377static void ftdi_write_bulk_callback (struct urb *urb)
1381{ 1378{
1382 unsigned long flags; 1379 unsigned long flags;
1383 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1380 struct usb_serial_port *port = urb->context;
1384 struct ftdi_private *priv; 1381 struct ftdi_private *priv;
1385 int data_offset; /* will be 1 for the SIO and 0 otherwise */ 1382 int data_offset; /* will be 1 for the SIO and 0 otherwise */
1386 unsigned long countback; 1383 unsigned long countback;
@@ -1389,7 +1386,7 @@ static void ftdi_write_bulk_callback (struct urb *urb)
1389 /* free up the transfer buffer, as usb_free_urb() does not do this */ 1386 /* free up the transfer buffer, as usb_free_urb() does not do this */
1390 kfree (urb->transfer_buffer); 1387 kfree (urb->transfer_buffer);
1391 1388
1392 dbg("%s - port %d", __FUNCTION__, port->number); 1389 dbg("%s - port %d", __func__, port->number);
1393 1390
1394 if (status) { 1391 if (status) {
1395 dbg("nonzero write bulk status received: %d", status); 1392 dbg("nonzero write bulk status received: %d", status);
@@ -1398,7 +1395,7 @@ static void ftdi_write_bulk_callback (struct urb *urb)
1398 1395
1399 priv = usb_get_serial_port_data(port); 1396 priv = usb_get_serial_port_data(port);
1400 if (!priv) { 1397 if (!priv) {
1401 dbg("%s - bad port private data pointer - exiting", __FUNCTION__); 1398 dbg("%s - bad port private data pointer - exiting", __func__);
1402 return; 1399 return;
1403 } 1400 }
1404 /* account for transferred data */ 1401 /* account for transferred data */
@@ -1406,7 +1403,7 @@ static void ftdi_write_bulk_callback (struct urb *urb)
1406 data_offset = priv->write_offset; 1403 data_offset = priv->write_offset;
1407 if (data_offset > 0) { 1404 if (data_offset > 0) {
1408 /* Subtract the control bytes */ 1405 /* Subtract the control bytes */
1409 countback -= (data_offset * ((countback + (PKTSZ - 1)) / PKTSZ)); 1406 countback -= (data_offset * DIV_ROUND_UP(countback, PKTSZ));
1410 } 1407 }
1411 spin_lock_irqsave(&priv->tx_lock, flags); 1408 spin_lock_irqsave(&priv->tx_lock, flags);
1412 --priv->tx_outstanding_urbs; 1409 --priv->tx_outstanding_urbs;
@@ -1423,7 +1420,7 @@ static int ftdi_write_room( struct usb_serial_port *port )
1423 int room; 1420 int room;
1424 unsigned long flags; 1421 unsigned long flags;
1425 1422
1426 dbg("%s - port %d", __FUNCTION__, port->number); 1423 dbg("%s - port %d", __func__, port->number);
1427 1424
1428 spin_lock_irqsave(&priv->tx_lock, flags); 1425 spin_lock_irqsave(&priv->tx_lock, flags);
1429 if (priv->tx_outstanding_urbs < URB_UPPER_LIMIT) { 1426 if (priv->tx_outstanding_urbs < URB_UPPER_LIMIT) {
@@ -1447,13 +1444,13 @@ static int ftdi_chars_in_buffer (struct usb_serial_port *port)
1447 int buffered; 1444 int buffered;
1448 unsigned long flags; 1445 unsigned long flags;
1449 1446
1450 dbg("%s - port %d", __FUNCTION__, port->number); 1447 dbg("%s - port %d", __func__, port->number);
1451 1448
1452 spin_lock_irqsave(&priv->tx_lock, flags); 1449 spin_lock_irqsave(&priv->tx_lock, flags);
1453 buffered = (int)priv->tx_outstanding_bytes; 1450 buffered = (int)priv->tx_outstanding_bytes;
1454 spin_unlock_irqrestore(&priv->tx_lock, flags); 1451 spin_unlock_irqrestore(&priv->tx_lock, flags);
1455 if (buffered < 0) { 1452 if (buffered < 0) {
1456 err("%s outstanding tx bytes is negative!", __FUNCTION__); 1453 err("%s outstanding tx bytes is negative!", __func__);
1457 buffered = 0; 1454 buffered = 0;
1458 } 1455 }
1459 return buffered; 1456 return buffered;
@@ -1463,7 +1460,7 @@ static int ftdi_chars_in_buffer (struct usb_serial_port *port)
1463 1460
1464static void ftdi_read_bulk_callback (struct urb *urb) 1461static void ftdi_read_bulk_callback (struct urb *urb)
1465{ /* ftdi_read_bulk_callback */ 1462{ /* ftdi_read_bulk_callback */
1466 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1463 struct usb_serial_port *port = urb->context;
1467 struct tty_struct *tty; 1464 struct tty_struct *tty;
1468 struct ftdi_private *priv; 1465 struct ftdi_private *priv;
1469 unsigned long countread; 1466 unsigned long countread;
@@ -1471,30 +1468,30 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1471 int status = urb->status; 1468 int status = urb->status;
1472 1469
1473 if (urb->number_of_packets > 0) { 1470 if (urb->number_of_packets > 0) {
1474 err("%s transfer_buffer_length %d actual_length %d number of packets %d",__FUNCTION__, 1471 err("%s transfer_buffer_length %d actual_length %d number of packets %d",__func__,
1475 urb->transfer_buffer_length, urb->actual_length, urb->number_of_packets ); 1472 urb->transfer_buffer_length, urb->actual_length, urb->number_of_packets );
1476 err("%s transfer_flags %x ", __FUNCTION__,urb->transfer_flags ); 1473 err("%s transfer_flags %x ", __func__,urb->transfer_flags );
1477 } 1474 }
1478 1475
1479 dbg("%s - port %d", __FUNCTION__, port->number); 1476 dbg("%s - port %d", __func__, port->number);
1480 1477
1481 if (port->open_count <= 0) 1478 if (port->open_count <= 0)
1482 return; 1479 return;
1483 1480
1484 tty = port->tty; 1481 tty = port->tty;
1485 if (!tty) { 1482 if (!tty) {
1486 dbg("%s - bad tty pointer - exiting",__FUNCTION__); 1483 dbg("%s - bad tty pointer - exiting",__func__);
1487 return; 1484 return;
1488 } 1485 }
1489 1486
1490 priv = usb_get_serial_port_data(port); 1487 priv = usb_get_serial_port_data(port);
1491 if (!priv) { 1488 if (!priv) {
1492 dbg("%s - bad port private data pointer - exiting", __FUNCTION__); 1489 dbg("%s - bad port private data pointer - exiting", __func__);
1493 return; 1490 return;
1494 } 1491 }
1495 1492
1496 if (urb != port->read_urb) { 1493 if (urb != port->read_urb) {
1497 err("%s - Not my urb!", __FUNCTION__); 1494 err("%s - Not my urb!", __func__);
1498 } 1495 }
1499 1496
1500 if (status) { 1497 if (status) {
@@ -1506,7 +1503,7 @@ static void ftdi_read_bulk_callback (struct urb *urb)
1506 1503
1507 /* count data bytes, but not status bytes */ 1504 /* count data bytes, but not status bytes */
1508 countread = urb->actual_length; 1505 countread = urb->actual_length;
1509 countread -= 2 * ((countread + (PKTSZ - 1)) / PKTSZ); 1506 countread -= 2 * DIV_ROUND_UP(countread, PKTSZ);
1510 spin_lock_irqsave(&priv->rx_lock, flags); 1507 spin_lock_irqsave(&priv->rx_lock, flags);
1511 priv->rx_bytes += countread; 1508 priv->rx_bytes += countread;
1512 spin_unlock_irqrestore(&priv->rx_lock, flags); 1509 spin_unlock_irqrestore(&priv->rx_lock, flags);
@@ -1532,39 +1529,39 @@ static void ftdi_process_read (struct work_struct *work)
1532 int packet_offset; 1529 int packet_offset;
1533 unsigned long flags; 1530 unsigned long flags;
1534 1531
1535 dbg("%s - port %d", __FUNCTION__, port->number); 1532 dbg("%s - port %d", __func__, port->number);
1536 1533
1537 if (port->open_count <= 0) 1534 if (port->open_count <= 0)
1538 return; 1535 return;
1539 1536
1540 tty = port->tty; 1537 tty = port->tty;
1541 if (!tty) { 1538 if (!tty) {
1542 dbg("%s - bad tty pointer - exiting",__FUNCTION__); 1539 dbg("%s - bad tty pointer - exiting",__func__);
1543 return; 1540 return;
1544 } 1541 }
1545 1542
1546 priv = usb_get_serial_port_data(port); 1543 priv = usb_get_serial_port_data(port);
1547 if (!priv) { 1544 if (!priv) {
1548 dbg("%s - bad port private data pointer - exiting", __FUNCTION__); 1545 dbg("%s - bad port private data pointer - exiting", __func__);
1549 return; 1546 return;
1550 } 1547 }
1551 1548
1552 urb = port->read_urb; 1549 urb = port->read_urb;
1553 if (!urb) { 1550 if (!urb) {
1554 dbg("%s - bad read_urb pointer - exiting", __FUNCTION__); 1551 dbg("%s - bad read_urb pointer - exiting", __func__);
1555 return; 1552 return;
1556 } 1553 }
1557 1554
1558 data = urb->transfer_buffer; 1555 data = urb->transfer_buffer;
1559 1556
1560 if (priv->rx_processed) { 1557 if (priv->rx_processed) {
1561 dbg("%s - already processed: %d bytes, %d remain", __FUNCTION__, 1558 dbg("%s - already processed: %d bytes, %d remain", __func__,
1562 priv->rx_processed, 1559 priv->rx_processed,
1563 urb->actual_length - priv->rx_processed); 1560 urb->actual_length - priv->rx_processed);
1564 } else { 1561 } else {
1565 /* The first two bytes of every read packet are status */ 1562 /* The first two bytes of every read packet are status */
1566 if (urb->actual_length > 2) { 1563 if (urb->actual_length > 2) {
1567 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 1564 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
1568 } else { 1565 } else {
1569 dbg("Status only: %03oo %03oo",data[0],data[1]); 1566 dbg("Status only: %03oo %03oo",data[0],data[1]);
1570 } 1567 }
@@ -1594,17 +1591,17 @@ static void ftdi_process_read (struct work_struct *work)
1594 1591
1595 length = min(PKTSZ, urb->actual_length-packet_offset)-2; 1592 length = min(PKTSZ, urb->actual_length-packet_offset)-2;
1596 if (length < 0) { 1593 if (length < 0) {
1597 err("%s - bad packet length: %d", __FUNCTION__, length+2); 1594 err("%s - bad packet length: %d", __func__, length+2);
1598 length = 0; 1595 length = 0;
1599 } 1596 }
1600 1597
1601 if (priv->rx_flags & THROTTLED) { 1598 if (priv->rx_flags & THROTTLED) {
1602 dbg("%s - throttled", __FUNCTION__); 1599 dbg("%s - throttled", __func__);
1603 break; 1600 break;
1604 } 1601 }
1605 if (tty_buffer_request_room(tty, length) < length) { 1602 if (tty_buffer_request_room(tty, length) < length) {
1606 /* break out & wait for throttling/unthrottling to happen */ 1603 /* break out & wait for throttling/unthrottling to happen */
1607 dbg("%s - receive room low", __FUNCTION__); 1604 dbg("%s - receive room low", __func__);
1608 break; 1605 break;
1609 } 1606 }
1610 1607
@@ -1672,7 +1669,7 @@ static void ftdi_process_read (struct work_struct *work)
1672 /* not completely processed - record progress */ 1669 /* not completely processed - record progress */
1673 priv->rx_processed = packet_offset; 1670 priv->rx_processed = packet_offset;
1674 dbg("%s - incomplete, %d bytes processed, %d remain", 1671 dbg("%s - incomplete, %d bytes processed, %d remain",
1675 __FUNCTION__, packet_offset, 1672 __func__, packet_offset,
1676 urb->actual_length - packet_offset); 1673 urb->actual_length - packet_offset);
1677 /* check if we were throttled while processing */ 1674 /* check if we were throttled while processing */
1678 spin_lock_irqsave(&priv->rx_lock, flags); 1675 spin_lock_irqsave(&priv->rx_lock, flags);
@@ -1680,7 +1677,7 @@ static void ftdi_process_read (struct work_struct *work)
1680 priv->rx_flags |= ACTUALLY_THROTTLED; 1677 priv->rx_flags |= ACTUALLY_THROTTLED;
1681 spin_unlock_irqrestore(&priv->rx_lock, flags); 1678 spin_unlock_irqrestore(&priv->rx_lock, flags);
1682 dbg("%s - deferring remainder until unthrottled", 1679 dbg("%s - deferring remainder until unthrottled",
1683 __FUNCTION__); 1680 __func__);
1684 return; 1681 return;
1685 } 1682 }
1686 spin_unlock_irqrestore(&priv->rx_lock, flags); 1683 spin_unlock_irqrestore(&priv->rx_lock, flags);
@@ -1689,7 +1686,7 @@ static void ftdi_process_read (struct work_struct *work)
1689 /* delay processing of remainder */ 1686 /* delay processing of remainder */
1690 schedule_delayed_work(&priv->rx_work, 1); 1687 schedule_delayed_work(&priv->rx_work, 1);
1691 } else { 1688 } else {
1692 dbg("%s - port is closed", __FUNCTION__); 1689 dbg("%s - port is closed", __func__);
1693 } 1690 }
1694 return; 1691 return;
1695 } 1692 }
@@ -1707,7 +1704,7 @@ static void ftdi_process_read (struct work_struct *work)
1707 1704
1708 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 1705 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1709 if (result) 1706 if (result)
1710 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 1707 err("%s - failed resubmitting read urb, error %d", __func__, result);
1711 } 1708 }
1712 1709
1713 return; 1710 return;
@@ -1736,10 +1733,10 @@ static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
1736 FTDI_SIO_SET_DATA_REQUEST_TYPE, 1733 FTDI_SIO_SET_DATA_REQUEST_TYPE,
1737 urb_value , priv->interface, 1734 urb_value , priv->interface,
1738 buf, 0, WDR_TIMEOUT) < 0) { 1735 buf, 0, WDR_TIMEOUT) < 0) {
1739 err("%s FAILED to enable/disable break state (state was %d)", __FUNCTION__,break_state); 1736 err("%s FAILED to enable/disable break state (state was %d)", __func__,break_state);
1740 } 1737 }
1741 1738
1742 dbg("%s break state is %d - urb is %d", __FUNCTION__,break_state, urb_value); 1739 dbg("%s break state is %d - urb is %d", __func__,break_state, urb_value);
1743 1740
1744} 1741}
1745 1742
@@ -1763,18 +1760,18 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
1763 unsigned char vstop; 1760 unsigned char vstop;
1764 unsigned char vstart; 1761 unsigned char vstart;
1765 1762
1766 dbg("%s", __FUNCTION__); 1763 dbg("%s", __func__);
1767 1764
1768 /* Force baud rate if this device requires it, unless it is set to B0. */ 1765 /* Force baud rate if this device requires it, unless it is set to B0. */
1769 if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) { 1766 if (priv->force_baud && ((termios->c_cflag & CBAUD) != B0)) {
1770 dbg("%s: forcing baud rate for this device", __FUNCTION__); 1767 dbg("%s: forcing baud rate for this device", __func__);
1771 tty_encode_baud_rate(port->tty, priv->force_baud, 1768 tty_encode_baud_rate(port->tty, priv->force_baud,
1772 priv->force_baud); 1769 priv->force_baud);
1773 } 1770 }
1774 1771
1775 /* Force RTS-CTS if this device requires it. */ 1772 /* Force RTS-CTS if this device requires it. */
1776 if (priv->force_rtscts) { 1773 if (priv->force_rtscts) {
1777 dbg("%s: forcing rtscts for this device", __FUNCTION__); 1774 dbg("%s: forcing rtscts for this device", __func__);
1778 termios->c_cflag |= CRTSCTS; 1775 termios->c_cflag |= CRTSCTS;
1779 } 1776 }
1780 1777
@@ -1818,7 +1815,7 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
1818 FTDI_SIO_SET_DATA_REQUEST_TYPE, 1815 FTDI_SIO_SET_DATA_REQUEST_TYPE,
1819 urb_value , priv->interface, 1816 urb_value , priv->interface,
1820 buf, 0, WDR_SHORT_TIMEOUT) < 0) { 1817 buf, 0, WDR_SHORT_TIMEOUT) < 0) {
1821 err("%s FAILED to set databits/stopbits/parity", __FUNCTION__); 1818 err("%s FAILED to set databits/stopbits/parity", __func__);
1822 } 1819 }
1823 1820
1824 /* Now do the baudrate */ 1821 /* Now do the baudrate */
@@ -1829,14 +1826,14 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
1829 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 1826 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
1830 0, priv->interface, 1827 0, priv->interface,
1831 buf, 0, WDR_TIMEOUT) < 0) { 1828 buf, 0, WDR_TIMEOUT) < 0) {
1832 err("%s error from disable flowcontrol urb", __FUNCTION__); 1829 err("%s error from disable flowcontrol urb", __func__);
1833 } 1830 }
1834 /* Drop RTS and DTR */ 1831 /* Drop RTS and DTR */
1835 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1832 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1836 } else { 1833 } else {
1837 /* set the baudrate determined before */ 1834 /* set the baudrate determined before */
1838 if (change_speed(port)) { 1835 if (change_speed(port)) {
1839 err("%s urb failed to set baudrate", __FUNCTION__); 1836 err("%s urb failed to set baudrate", __func__);
1840 } 1837 }
1841 /* Ensure RTS and DTR are raised when baudrate changed from 0 */ 1838 /* Ensure RTS and DTR are raised when baudrate changed from 0 */
1842 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) { 1839 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) {
@@ -1847,7 +1844,7 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
1847 /* Set flow control */ 1844 /* Set flow control */
1848 /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */ 1845 /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */
1849 if (cflag & CRTSCTS) { 1846 if (cflag & CRTSCTS) {
1850 dbg("%s Setting to CRTSCTS flow control", __FUNCTION__); 1847 dbg("%s Setting to CRTSCTS flow control", __func__);
1851 if (usb_control_msg(dev, 1848 if (usb_control_msg(dev,
1852 usb_sndctrlpipe(dev, 0), 1849 usb_sndctrlpipe(dev, 0),
1853 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 1850 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
@@ -1865,7 +1862,7 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
1865 * if IXOFF is not set, the pre-xon/xoff code is executed. 1862 * if IXOFF is not set, the pre-xon/xoff code is executed.
1866 */ 1863 */
1867 if (iflag & IXOFF) { 1864 if (iflag & IXOFF) {
1868 dbg("%s request to enable xonxoff iflag=%04x",__FUNCTION__,iflag); 1865 dbg("%s request to enable xonxoff iflag=%04x",__func__,iflag);
1869 // Try to enable the XON/XOFF on the ftdi_sio 1866 // Try to enable the XON/XOFF on the ftdi_sio
1870 // Set the vstart and vstop -- could have been done up above where 1867 // Set the vstart and vstop -- could have been done up above where
1871 // a lot of other dereferencing is done but that would be very 1868 // a lot of other dereferencing is done but that would be very
@@ -1886,7 +1883,7 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old
1886 } else { 1883 } else {
1887 /* else clause to only run if cfag ! CRTSCTS and iflag ! XOFF */ 1884 /* else clause to only run if cfag ! CRTSCTS and iflag ! XOFF */
1888 /* CHECKME Assuming XON/XOFF handled by tty stack - not by device */ 1885 /* CHECKME Assuming XON/XOFF handled by tty stack - not by device */
1889 dbg("%s Turning off hardware flow control", __FUNCTION__); 1886 dbg("%s Turning off hardware flow control", __func__);
1890 if (usb_control_msg(dev, 1887 if (usb_control_msg(dev,
1891 usb_sndctrlpipe(dev, 0), 1888 usb_sndctrlpipe(dev, 0),
1892 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 1889 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
@@ -1908,7 +1905,7 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
1908 unsigned char buf[2]; 1905 unsigned char buf[2];
1909 int ret; 1906 int ret;
1910 1907
1911 dbg("%s TIOCMGET", __FUNCTION__); 1908 dbg("%s TIOCMGET", __func__);
1912 switch (priv->chip_type) { 1909 switch (priv->chip_type) {
1913 case SIO: 1910 case SIO:
1914 /* Request the status from the device */ 1911 /* Request the status from the device */
@@ -1918,7 +1915,7 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
1918 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 1915 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
1919 0, 0, 1916 0, 0,
1920 buf, 1, WDR_TIMEOUT)) < 0 ) { 1917 buf, 1, WDR_TIMEOUT)) < 0 ) {
1921 err("%s Could not get modem status of device - err: %d", __FUNCTION__, 1918 err("%s Could not get modem status of device - err: %d", __func__,
1922 ret); 1919 ret);
1923 return(ret); 1920 return(ret);
1924 } 1921 }
@@ -1935,7 +1932,7 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
1935 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 1932 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
1936 0, priv->interface, 1933 0, priv->interface,
1937 buf, 2, WDR_TIMEOUT)) < 0 ) { 1934 buf, 2, WDR_TIMEOUT)) < 0 ) {
1938 err("%s Could not get modem status of device - err: %d", __FUNCTION__, 1935 err("%s Could not get modem status of device - err: %d", __func__,
1939 ret); 1936 ret);
1940 return(ret); 1937 return(ret);
1941 } 1938 }
@@ -1954,7 +1951,7 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
1954 1951
1955static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear) 1952static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear)
1956{ 1953{
1957 dbg("%s TIOCMSET", __FUNCTION__); 1954 dbg("%s TIOCMSET", __func__);
1958 return update_mctrl(port, set, clear); 1955 return update_mctrl(port, set, clear);
1959} 1956}
1960 1957
@@ -1963,7 +1960,7 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
1963{ 1960{
1964 struct ftdi_private *priv = usb_get_serial_port_data(port); 1961 struct ftdi_private *priv = usb_get_serial_port_data(port);
1965 1962
1966 dbg("%s cmd 0x%04x", __FUNCTION__, cmd); 1963 dbg("%s cmd 0x%04x", __func__, cmd);
1967 1964
1968 /* Based on code from acm.c and others */ 1965 /* Based on code from acm.c and others */
1969 switch (cmd) { 1966 switch (cmd) {
@@ -2022,7 +2019,7 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
2022 /* This is not necessarily an error - turns out the higher layers will do 2019 /* This is not necessarily an error - turns out the higher layers will do
2023 * some ioctls itself (see comment above) 2020 * some ioctls itself (see comment above)
2024 */ 2021 */
2025 dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __FUNCTION__, cmd); 2022 dbg("%s arg not supported - it was 0x%04x - check /usr/include/asm/ioctls.h", __func__, cmd);
2026 2023
2027 return(-ENOIOCTLCMD); 2024 return(-ENOIOCTLCMD);
2028} /* ftdi_ioctl */ 2025} /* ftdi_ioctl */
@@ -2033,7 +2030,7 @@ static void ftdi_throttle (struct usb_serial_port *port)
2033 struct ftdi_private *priv = usb_get_serial_port_data(port); 2030 struct ftdi_private *priv = usb_get_serial_port_data(port);
2034 unsigned long flags; 2031 unsigned long flags;
2035 2032
2036 dbg("%s - port %d", __FUNCTION__, port->number); 2033 dbg("%s - port %d", __func__, port->number);
2037 2034
2038 spin_lock_irqsave(&priv->rx_lock, flags); 2035 spin_lock_irqsave(&priv->rx_lock, flags);
2039 priv->rx_flags |= THROTTLED; 2036 priv->rx_flags |= THROTTLED;
@@ -2047,7 +2044,7 @@ static void ftdi_unthrottle (struct usb_serial_port *port)
2047 int actually_throttled; 2044 int actually_throttled;
2048 unsigned long flags; 2045 unsigned long flags;
2049 2046
2050 dbg("%s - port %d", __FUNCTION__, port->number); 2047 dbg("%s - port %d", __func__, port->number);
2051 2048
2052 spin_lock_irqsave(&priv->rx_lock, flags); 2049 spin_lock_irqsave(&priv->rx_lock, flags);
2053 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; 2050 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
@@ -2062,7 +2059,7 @@ static int __init ftdi_init (void)
2062{ 2059{
2063 int retval; 2060 int retval;
2064 2061
2065 dbg("%s", __FUNCTION__); 2062 dbg("%s", __func__);
2066 if (vendor > 0 && product > 0) { 2063 if (vendor > 0 && product > 0) {
2067 /* Add user specified VID/PID to reserved element of table. */ 2064 /* Add user specified VID/PID to reserved element of table. */
2068 int i; 2065 int i;
@@ -2091,7 +2088,7 @@ failed_sio_register:
2091static void __exit ftdi_exit (void) 2088static void __exit ftdi_exit (void)
2092{ 2089{
2093 2090
2094 dbg("%s", __FUNCTION__); 2091 dbg("%s", __func__);
2095 2092
2096 usb_deregister (&ftdi_driver); 2093 usb_deregister (&ftdi_driver);
2097 usb_serial_deregister (&ftdi_sio_device); 2094 usb_serial_deregister (&ftdi_sio_device);
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index b5194dc7d3bb..e8ba2cb5995d 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -39,9 +39,6 @@ static struct usb_serial_driver funsoft_device = {
39 }, 39 },
40 .id_table = id_table, 40 .id_table = id_table,
41 .usb_driver = &funsoft_driver, 41 .usb_driver = &funsoft_driver,
42 .num_interrupt_in = NUM_DONT_CARE,
43 .num_bulk_in = NUM_DONT_CARE,
44 .num_bulk_out = NUM_DONT_CARE,
45 .num_ports = 1, 42 .num_ports = 1,
46}; 43};
47 44
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index d74e43d69230..8ce5a56a48e3 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -280,7 +280,7 @@ static void send_to_tty(struct usb_serial_port *port,
280 if (tty && actual_length) { 280 if (tty && actual_length) {
281 281
282 usb_serial_debug_data(debug, &port->dev, 282 usb_serial_debug_data(debug, &port->dev,
283 __FUNCTION__, actual_length, data); 283 __func__, actual_length, data);
284 284
285 tty_buffer_request_room(tty, actual_length); 285 tty_buffer_request_room(tty, actual_length);
286 tty_insert_flip_string(tty, data, actual_length); 286 tty_insert_flip_string(tty, data, actual_length);
@@ -355,7 +355,7 @@ static void pkt_clear(struct garmin_data * garmin_data_p)
355 unsigned long flags; 355 unsigned long flags;
356 struct garmin_packet *result = NULL; 356 struct garmin_packet *result = NULL;
357 357
358 dbg("%s", __FUNCTION__); 358 dbg("%s", __func__);
359 359
360 spin_lock_irqsave(&garmin_data_p->lock, flags); 360 spin_lock_irqsave(&garmin_data_p->lock, flags);
361 while (!list_empty(&garmin_data_p->pktlist)) { 361 while (!list_empty(&garmin_data_p->pktlist)) {
@@ -379,7 +379,7 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id)
379 __u8 *ptr = pkt; 379 __u8 *ptr = pkt;
380 unsigned l = 0; 380 unsigned l = 0;
381 381
382 dbg("%s - pkt-id: 0x%X.", __FUNCTION__, 0xFF & pkt_id); 382 dbg("%s - pkt-id: 0x%X.", __func__, 0xFF & pkt_id);
383 383
384 *ptr++ = DLE; 384 *ptr++ = DLE;
385 *ptr++ = ACK; 385 *ptr++ = ACK;
@@ -429,11 +429,11 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
429 int size = recpkt[1]; 429 int size = recpkt[1];
430 430
431 usb_serial_debug_data(debug, &garmin_data_p->port->dev, 431 usb_serial_debug_data(debug, &garmin_data_p->port->dev,
432 __FUNCTION__, count-GSP_INITIAL_OFFSET, recpkt); 432 __func__, count-GSP_INITIAL_OFFSET, recpkt);
433 433
434 if (size != (count-GSP_INITIAL_OFFSET-3)) { 434 if (size != (count-GSP_INITIAL_OFFSET-3)) {
435 dbg("%s - invalid size, expected %d bytes, got %d", 435 dbg("%s - invalid size, expected %d bytes, got %d",
436 __FUNCTION__, size, (count-GSP_INITIAL_OFFSET-3)); 436 __func__, size, (count-GSP_INITIAL_OFFSET-3));
437 return -EINVPKT; 437 return -EINVPKT;
438 } 438 }
439 439
@@ -443,7 +443,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
443 // sanity check, remove after test ... 443 // sanity check, remove after test ...
444 if ((__u8*)&(usbdata[3]) != recpkt) { 444 if ((__u8*)&(usbdata[3]) != recpkt) {
445 dbg("%s - ptr mismatch %p - %p", 445 dbg("%s - ptr mismatch %p - %p",
446 __FUNCTION__, &(usbdata[4]), recpkt); 446 __func__, &(usbdata[4]), recpkt);
447 return -EINVPKT; 447 return -EINVPKT;
448 } 448 }
449 449
@@ -454,7 +454,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count)
454 454
455 if ((0xff & (cksum + *recpkt)) != 0) { 455 if ((0xff & (cksum + *recpkt)) != 0) {
456 dbg("%s - invalid checksum, expected %02x, got %02x", 456 dbg("%s - invalid checksum, expected %02x, got %02x",
457 __FUNCTION__, 0xff & -cksum, 0xff & *recpkt); 457 __func__, 0xff & -cksum, 0xff & *recpkt);
458 return -EINVPKT; 458 return -EINVPKT;
459 } 459 }
460 460
@@ -519,7 +519,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
519 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 519 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
520 520
521 dbg("%s - dle=%d skip=%d size=%d count=%d", 521 dbg("%s - dle=%d skip=%d size=%d count=%d",
522 __FUNCTION__, dleSeen, skip, size, count); 522 __func__, dleSeen, skip, size, count);
523 523
524 if (size == 0) { 524 if (size == 0) {
525 size = GSP_INITIAL_OFFSET; 525 size = GSP_INITIAL_OFFSET;
@@ -578,7 +578,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p,
578 } 578 }
579 579
580 if (size >= GPS_IN_BUFSIZ) { 580 if (size >= GPS_IN_BUFSIZ) {
581 dbg("%s - packet too large.", __FUNCTION__); 581 dbg("%s - packet too large.", __func__);
582 skip = 1; 582 skip = 1;
583 size = GSP_INITIAL_OFFSET; 583 size = GSP_INITIAL_OFFSET;
584 dleSeen = 0; 584 dleSeen = 0;
@@ -634,7 +634,7 @@ static int gsp_send(struct garmin_data * garmin_data_p,
634 int i=0; 634 int i=0;
635 int k; 635 int k;
636 636
637 dbg("%s - state %d - %d bytes.", __FUNCTION__, 637 dbg("%s - state %d - %d bytes.", __func__,
638 garmin_data_p->state, count); 638 garmin_data_p->state, count);
639 639
640 k = garmin_data_p->outsize; 640 k = garmin_data_p->outsize;
@@ -658,13 +658,13 @@ static int gsp_send(struct garmin_data * garmin_data_p,
658 return 0; 658 return 0;
659 } 659 }
660 660
661 dbg("%s - %d bytes in buffer, %d bytes in pkt.", __FUNCTION__, 661 dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__,
662 k, i); 662 k, i);
663 663
664 /* garmin_data_p->outbuffer now contains a complete packet */ 664 /* garmin_data_p->outbuffer now contains a complete packet */
665 665
666 usb_serial_debug_data(debug, &garmin_data_p->port->dev, 666 usb_serial_debug_data(debug, &garmin_data_p->port->dev,
667 __FUNCTION__, k, garmin_data_p->outbuffer); 667 __func__, k, garmin_data_p->outbuffer);
668 668
669 garmin_data_p->outsize = 0; 669 garmin_data_p->outsize = 0;
670 670
@@ -749,7 +749,7 @@ static void gsp_next_packet(struct garmin_data * garmin_data_p)
749 struct garmin_packet *pkt = NULL; 749 struct garmin_packet *pkt = NULL;
750 750
751 while ((pkt = pkt_pop(garmin_data_p)) != NULL) { 751 while ((pkt = pkt_pop(garmin_data_p)) != NULL) {
752 dbg("%s - next pkt: %d", __FUNCTION__, pkt->seq); 752 dbg("%s - next pkt: %d", __func__, pkt->seq);
753 if (gsp_send(garmin_data_p, pkt->data, pkt->size) > 0) { 753 if (gsp_send(garmin_data_p, pkt->data, pkt->size) > 0) {
754 kfree(pkt); 754 kfree(pkt);
755 return; 755 return;
@@ -794,7 +794,7 @@ static int nat_receive(struct garmin_data * garmin_data_p,
794 if (len >= GPS_IN_BUFSIZ) { 794 if (len >= GPS_IN_BUFSIZ) {
795 /* seem to be an invalid packet, ignore rest of input */ 795 /* seem to be an invalid packet, ignore rest of input */
796 dbg("%s - packet size too large: %d", 796 dbg("%s - packet size too large: %d",
797 __FUNCTION__, len); 797 __func__, len);
798 garmin_data_p->insize = 0; 798 garmin_data_p->insize = 0;
799 count = 0; 799 count = 0;
800 result = -EINVPKT; 800 result = -EINVPKT;
@@ -873,11 +873,11 @@ static int process_resetdev_request(struct usb_serial_port *port)
873 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 873 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
874 874
875 usb_kill_urb (port->interrupt_in_urb); 875 usb_kill_urb (port->interrupt_in_urb);
876 dbg("%s - usb_reset_device", __FUNCTION__ ); 876 dbg("%s - usb_reset_device", __func__ );
877 status = usb_reset_device(port->serial->dev); 877 status = usb_reset_device(port->serial->dev);
878 if (status) 878 if (status)
879 dbg("%s - usb_reset_device failed: %d", 879 dbg("%s - usb_reset_device failed: %d",
880 __FUNCTION__, status); 880 __func__, status);
881 return status; 881 return status;
882} 882}
883 883
@@ -926,18 +926,18 @@ static int garmin_init_session(struct usb_serial_port *port)
926 if (status == 0) { 926 if (status == 0) {
927 usb_kill_urb (port->interrupt_in_urb); 927 usb_kill_urb (port->interrupt_in_urb);
928 928
929 dbg("%s - adding interrupt input", __FUNCTION__); 929 dbg("%s - adding interrupt input", __func__);
930 port->interrupt_in_urb->dev = serial->dev; 930 port->interrupt_in_urb->dev = serial->dev;
931 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 931 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
932 if (status) 932 if (status)
933 dev_err(&serial->dev->dev, 933 dev_err(&serial->dev->dev,
934 "%s - failed submitting interrupt urb," 934 "%s - failed submitting interrupt urb,"
935 " error %d\n", 935 " error %d\n",
936 __FUNCTION__, status); 936 __func__, status);
937 } 937 }
938 938
939 if (status == 0) { 939 if (status == 0) {
940 dbg("%s - starting session ...", __FUNCTION__); 940 dbg("%s - starting session ...", __func__);
941 garmin_data_p->state = STATE_ACTIVE; 941 garmin_data_p->state = STATE_ACTIVE;
942 status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ, 942 status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ,
943 sizeof(GARMIN_START_SESSION_REQ), 943 sizeof(GARMIN_START_SESSION_REQ),
@@ -976,7 +976,7 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp)
976 int status = 0; 976 int status = 0;
977 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 977 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
978 978
979 dbg("%s - port %d", __FUNCTION__, port->number); 979 dbg("%s - port %d", __func__, port->number);
980 980
981 /* 981 /*
982 * Force low_latency on so that our tty_push actually forces the data 982 * Force low_latency on so that our tty_push actually forces the data
@@ -1013,7 +1013,7 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
1013 struct usb_serial *serial = port->serial; 1013 struct usb_serial *serial = port->serial;
1014 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1014 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1015 1015
1016 dbg("%s - port %d - mode=%d state=%d flags=0x%X", __FUNCTION__, 1016 dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__,
1017 port->number, garmin_data_p->mode, 1017 port->number, garmin_data_p->mode,
1018 garmin_data_p->state, garmin_data_p->flags); 1018 garmin_data_p->state, garmin_data_p->flags);
1019 1019
@@ -1046,13 +1046,13 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
1046static void garmin_write_bulk_callback (struct urb *urb) 1046static void garmin_write_bulk_callback (struct urb *urb)
1047{ 1047{
1048 unsigned long flags; 1048 unsigned long flags;
1049 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1049 struct usb_serial_port *port = urb->context;
1050 int status = urb->status; 1050 int status = urb->status;
1051 1051
1052 if (port) { 1052 if (port) {
1053 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1053 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1054 1054
1055 dbg("%s - port %d", __FUNCTION__, port->number); 1055 dbg("%s - port %d", __func__, port->number);
1056 1056
1057 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer) 1057 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)
1058 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) { 1058 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) {
@@ -1061,7 +1061,7 @@ static void garmin_write_bulk_callback (struct urb *urb)
1061 1061
1062 if (status) { 1062 if (status) {
1063 dbg("%s - nonzero write bulk status received: %d", 1063 dbg("%s - nonzero write bulk status received: %d",
1064 __FUNCTION__, urb->status); 1064 __func__, urb->status);
1065 spin_lock_irqsave(&garmin_data_p->lock, flags); 1065 spin_lock_irqsave(&garmin_data_p->lock, flags);
1066 garmin_data_p->flags |= CLEAR_HALT_REQUIRED; 1066 garmin_data_p->flags |= CLEAR_HALT_REQUIRED;
1067 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1067 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
@@ -1088,7 +1088,7 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1088 unsigned char *buffer; 1088 unsigned char *buffer;
1089 int status; 1089 int status;
1090 1090
1091 dbg("%s - port %d, state %d", __FUNCTION__, port->number, 1091 dbg("%s - port %d, state %d", __func__, port->number,
1092 garmin_data_p->state); 1092 garmin_data_p->state);
1093 1093
1094 spin_lock_irqsave(&garmin_data_p->lock, flags); 1094 spin_lock_irqsave(&garmin_data_p->lock, flags);
@@ -1110,7 +1110,7 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1110 1110
1111 memcpy (buffer, buf, count); 1111 memcpy (buffer, buf, count);
1112 1112
1113 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer); 1113 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
1114 1114
1115 usb_fill_bulk_urb (urb, serial->dev, 1115 usb_fill_bulk_urb (urb, serial->dev,
1116 usb_sndbulkpipe (serial->dev, 1116 usb_sndbulkpipe (serial->dev,
@@ -1134,7 +1134,7 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1134 dev_err(&port->dev, 1134 dev_err(&port->dev,
1135 "%s - usb_submit_urb(write bulk) " 1135 "%s - usb_submit_urb(write bulk) "
1136 "failed with status = %d\n", 1136 "failed with status = %d\n",
1137 __FUNCTION__, status); 1137 __func__, status);
1138 count = status; 1138 count = status;
1139 } 1139 }
1140 1140
@@ -1154,7 +1154,7 @@ static int garmin_write (struct usb_serial_port *port,
1154 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1154 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1155 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; 1155 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt;
1156 1156
1157 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buf); 1157 usb_serial_debug_data(debug, &port->dev, __func__, count, buf);
1158 1158
1159 /* check for our private packets */ 1159 /* check for our private packets */
1160 if (count >= GARMIN_PKTHDR_LENGTH) { 1160 if (count >= GARMIN_PKTHDR_LENGTH) {
@@ -1172,7 +1172,7 @@ static int garmin_write (struct usb_serial_port *port,
1172 && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { 1172 && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) {
1173 1173
1174 dbg("%s - processing private request %d", 1174 dbg("%s - processing private request %d",
1175 __FUNCTION__, pktid); 1175 __func__, pktid);
1176 1176
1177 // drop all unfinished transfers 1177 // drop all unfinished transfers
1178 garmin_clear(garmin_data_p); 1178 garmin_clear(garmin_data_p);
@@ -1184,7 +1184,7 @@ static int garmin_write (struct usb_serial_port *port,
1184 return -EINVPKT; 1184 return -EINVPKT;
1185 debug = __le32_to_cpu(privpkt[3]); 1185 debug = __le32_to_cpu(privpkt[3]);
1186 dbg("%s - debug level set to 0x%X", 1186 dbg("%s - debug level set to 0x%X",
1187 __FUNCTION__, debug); 1187 __func__, debug);
1188 break; 1188 break;
1189 1189
1190 case PRIV_PKTID_SET_MODE: 1190 case PRIV_PKTID_SET_MODE:
@@ -1192,7 +1192,7 @@ static int garmin_write (struct usb_serial_port *port,
1192 return -EINVPKT; 1192 return -EINVPKT;
1193 garmin_data_p->mode = __le32_to_cpu(privpkt[3]); 1193 garmin_data_p->mode = __le32_to_cpu(privpkt[3]);
1194 dbg("%s - mode set to %d", 1194 dbg("%s - mode set to %d",
1195 __FUNCTION__, garmin_data_p->mode); 1195 __func__, garmin_data_p->mode);
1196 break; 1196 break;
1197 1197
1198 case PRIV_PKTID_INFO_REQ: 1198 case PRIV_PKTID_INFO_REQ:
@@ -1208,7 +1208,7 @@ static int garmin_write (struct usb_serial_port *port,
1208 return -EINVPKT; 1208 return -EINVPKT;
1209 initial_mode = __le32_to_cpu(privpkt[3]); 1209 initial_mode = __le32_to_cpu(privpkt[3]);
1210 dbg("%s - initial_mode set to %d", 1210 dbg("%s - initial_mode set to %d",
1211 __FUNCTION__, 1211 __func__,
1212 garmin_data_p->mode); 1212 garmin_data_p->mode);
1213 break; 1213 break;
1214 } 1214 }
@@ -1255,7 +1255,7 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1255{ 1255{
1256 if (garmin_data_p->flags & FLAGS_DROP_DATA) { 1256 if (garmin_data_p->flags & FLAGS_DROP_DATA) {
1257 /* abort-transfer cmd is actice */ 1257 /* abort-transfer cmd is actice */
1258 dbg("%s - pkt dropped", __FUNCTION__); 1258 dbg("%s - pkt dropped", __func__);
1259 } else if (garmin_data_p->state != STATE_DISCONNECTED && 1259 } else if (garmin_data_p->state != STATE_DISCONNECTED &&
1260 garmin_data_p->state != STATE_RESET ) { 1260 garmin_data_p->state != STATE_RESET ) {
1261 1261
@@ -1286,28 +1286,28 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1286static void garmin_read_bulk_callback (struct urb *urb) 1286static void garmin_read_bulk_callback (struct urb *urb)
1287{ 1287{
1288 unsigned long flags; 1288 unsigned long flags;
1289 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1289 struct usb_serial_port *port = urb->context;
1290 struct usb_serial *serial = port->serial; 1290 struct usb_serial *serial = port->serial;
1291 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1291 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1292 unsigned char *data = urb->transfer_buffer; 1292 unsigned char *data = urb->transfer_buffer;
1293 int status = urb->status; 1293 int status = urb->status;
1294 int retval; 1294 int retval;
1295 1295
1296 dbg("%s - port %d", __FUNCTION__, port->number); 1296 dbg("%s - port %d", __func__, port->number);
1297 1297
1298 if (!serial) { 1298 if (!serial) {
1299 dbg("%s - bad serial pointer, exiting", __FUNCTION__); 1299 dbg("%s - bad serial pointer, exiting", __func__);
1300 return; 1300 return;
1301 } 1301 }
1302 1302
1303 if (status) { 1303 if (status) {
1304 dbg("%s - nonzero read bulk status received: %d", 1304 dbg("%s - nonzero read bulk status received: %d",
1305 __FUNCTION__, status); 1305 __func__, status);
1306 return; 1306 return;
1307 } 1307 }
1308 1308
1309 usb_serial_debug_data(debug, &port->dev, 1309 usb_serial_debug_data(debug, &port->dev,
1310 __FUNCTION__, urb->actual_length, data); 1310 __func__, urb->actual_length, data);
1311 1311
1312 garmin_read_process(garmin_data_p, data, urb->actual_length); 1312 garmin_read_process(garmin_data_p, data, urb->actual_length);
1313 1313
@@ -1320,7 +1320,7 @@ static void garmin_read_bulk_callback (struct urb *urb)
1320 if (retval) 1320 if (retval)
1321 dev_err(&port->dev, 1321 dev_err(&port->dev,
1322 "%s - failed resubmitting read urb, error %d\n", 1322 "%s - failed resubmitting read urb, error %d\n",
1323 __FUNCTION__, retval); 1323 __func__, retval);
1324 } else if (urb->actual_length > 0) { 1324 } else if (urb->actual_length > 0) {
1325 /* Continue trying to read until nothing more is received */ 1325 /* Continue trying to read until nothing more is received */
1326 if (0 == (garmin_data_p->flags & FLAGS_THROTTLED)) { 1326 if (0 == (garmin_data_p->flags & FLAGS_THROTTLED)) {
@@ -1328,10 +1328,10 @@ static void garmin_read_bulk_callback (struct urb *urb)
1328 if (retval) 1328 if (retval)
1329 dev_err(&port->dev, 1329 dev_err(&port->dev,
1330 "%s - failed resubmitting read urb, " 1330 "%s - failed resubmitting read urb, "
1331 "error %d\n", __FUNCTION__, retval); 1331 "error %d\n", __func__, retval);
1332 } 1332 }
1333 } else { 1333 } else {
1334 dbg("%s - end of bulk data", __FUNCTION__); 1334 dbg("%s - end of bulk data", __func__);
1335 spin_lock_irqsave(&garmin_data_p->lock, flags); 1335 spin_lock_irqsave(&garmin_data_p->lock, flags);
1336 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE; 1336 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE;
1337 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1337 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
@@ -1344,7 +1344,7 @@ static void garmin_read_int_callback (struct urb *urb)
1344{ 1344{
1345 unsigned long flags; 1345 unsigned long flags;
1346 int retval; 1346 int retval;
1347 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1347 struct usb_serial_port *port = urb->context;
1348 struct usb_serial *serial = port->serial; 1348 struct usb_serial *serial = port->serial;
1349 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1349 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1350 unsigned char *data = urb->transfer_buffer; 1350 unsigned char *data = urb->transfer_buffer;
@@ -1359,22 +1359,22 @@ static void garmin_read_int_callback (struct urb *urb)
1359 case -ESHUTDOWN: 1359 case -ESHUTDOWN:
1360 /* this urb is terminated, clean up */ 1360 /* this urb is terminated, clean up */
1361 dbg("%s - urb shutting down with status: %d", 1361 dbg("%s - urb shutting down with status: %d",
1362 __FUNCTION__, status); 1362 __func__, status);
1363 return; 1363 return;
1364 default: 1364 default:
1365 dbg("%s - nonzero urb status received: %d", 1365 dbg("%s - nonzero urb status received: %d",
1366 __FUNCTION__, status); 1366 __func__, status);
1367 return; 1367 return;
1368 } 1368 }
1369 1369
1370 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 1370 usb_serial_debug_data(debug, &port->dev, __func__,
1371 urb->actual_length, urb->transfer_buffer); 1371 urb->actual_length, urb->transfer_buffer);
1372 1372
1373 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && 1373 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) &&
1374 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, 1374 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
1375 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { 1375 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) {
1376 1376
1377 dbg("%s - bulk data available.", __FUNCTION__); 1377 dbg("%s - bulk data available.", __func__);
1378 1378
1379 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { 1379 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1380 1380
@@ -1389,7 +1389,7 @@ static void garmin_read_int_callback (struct urb *urb)
1389 if (retval) { 1389 if (retval) {
1390 dev_err(&port->dev, 1390 dev_err(&port->dev,
1391 "%s - failed submitting read urb, error %d\n", 1391 "%s - failed submitting read urb, error %d\n",
1392 __FUNCTION__, retval); 1392 __func__, retval);
1393 } else { 1393 } else {
1394 spin_lock_irqsave(&garmin_data_p->lock, flags); 1394 spin_lock_irqsave(&garmin_data_p->lock, flags);
1395 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; 1395 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
@@ -1417,14 +1417,14 @@ static void garmin_read_int_callback (struct urb *urb)
1417 = __le32_to_cpup((__le32*)(data+GARMIN_PKTHDR_LENGTH)); 1417 = __le32_to_cpup((__le32*)(data+GARMIN_PKTHDR_LENGTH));
1418 1418
1419 dbg("%s - start-of-session reply seen - serial %u.", 1419 dbg("%s - start-of-session reply seen - serial %u.",
1420 __FUNCTION__, garmin_data_p->serial_num); 1420 __func__, garmin_data_p->serial_num);
1421 } 1421 }
1422 1422
1423 if (garmin_data_p->ignorePkts) { 1423 if (garmin_data_p->ignorePkts) {
1424 /* this reply belongs to a request generated by the driver, 1424 /* this reply belongs to a request generated by the driver,
1425 ignore it. */ 1425 ignore it. */
1426 dbg("%s - pkt ignored (%d)", 1426 dbg("%s - pkt ignored (%d)",
1427 __FUNCTION__, garmin_data_p->ignorePkts); 1427 __func__, garmin_data_p->ignorePkts);
1428 spin_lock_irqsave(&garmin_data_p->lock, flags); 1428 spin_lock_irqsave(&garmin_data_p->lock, flags);
1429 garmin_data_p->ignorePkts--; 1429 garmin_data_p->ignorePkts--;
1430 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1430 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
@@ -1437,7 +1437,7 @@ static void garmin_read_int_callback (struct urb *urb)
1437 if (retval) 1437 if (retval)
1438 dev_err(&urb->dev->dev, 1438 dev_err(&urb->dev->dev,
1439 "%s - Error %d submitting interrupt urb\n", 1439 "%s - Error %d submitting interrupt urb\n",
1440 __FUNCTION__, retval); 1440 __func__, retval);
1441} 1441}
1442 1442
1443 1443
@@ -1473,7 +1473,7 @@ static void garmin_throttle (struct usb_serial_port *port)
1473 unsigned long flags; 1473 unsigned long flags;
1474 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1474 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1475 1475
1476 dbg("%s - port %d", __FUNCTION__, port->number); 1476 dbg("%s - port %d", __func__, port->number);
1477 /* set flag, data received will be put into a queue 1477 /* set flag, data received will be put into a queue
1478 for later processing */ 1478 for later processing */
1479 spin_lock_irqsave(&garmin_data_p->lock, flags); 1479 spin_lock_irqsave(&garmin_data_p->lock, flags);
@@ -1488,7 +1488,7 @@ static void garmin_unthrottle (struct usb_serial_port *port)
1488 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1488 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1489 int status; 1489 int status;
1490 1490
1491 dbg("%s - port %d", __FUNCTION__, port->number); 1491 dbg("%s - port %d", __func__, port->number);
1492 spin_lock_irqsave(&garmin_data_p->lock, flags); 1492 spin_lock_irqsave(&garmin_data_p->lock, flags);
1493 garmin_data_p->flags &= ~FLAGS_THROTTLED; 1493 garmin_data_p->flags &= ~FLAGS_THROTTLED;
1494 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1494 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
@@ -1503,7 +1503,7 @@ static void garmin_unthrottle (struct usb_serial_port *port)
1503 if (status) 1503 if (status)
1504 dev_err(&port->dev, 1504 dev_err(&port->dev,
1505 "%s - failed resubmitting read urb, error %d\n", 1505 "%s - failed resubmitting read urb, error %d\n",
1506 __FUNCTION__, status); 1506 __func__, status);
1507 } 1507 }
1508} 1508}
1509 1509
@@ -1532,11 +1532,11 @@ static int garmin_attach (struct usb_serial *serial)
1532 struct usb_serial_port *port = serial->port[0]; 1532 struct usb_serial_port *port = serial->port[0];
1533 struct garmin_data * garmin_data_p = NULL; 1533 struct garmin_data * garmin_data_p = NULL;
1534 1534
1535 dbg("%s", __FUNCTION__); 1535 dbg("%s", __func__);
1536 1536
1537 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); 1537 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL);
1538 if (garmin_data_p == NULL) { 1538 if (garmin_data_p == NULL) {
1539 dev_err(&port->dev, "%s - Out of memory\n", __FUNCTION__); 1539 dev_err(&port->dev, "%s - Out of memory\n", __func__);
1540 return -ENOMEM; 1540 return -ENOMEM;
1541 } 1541 }
1542 init_timer(&garmin_data_p->timer); 1542 init_timer(&garmin_data_p->timer);
@@ -1561,7 +1561,7 @@ static void garmin_shutdown (struct usb_serial *serial)
1561 struct usb_serial_port *port = serial->port[0]; 1561 struct usb_serial_port *port = serial->port[0];
1562 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1562 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port);
1563 1563
1564 dbg("%s", __FUNCTION__); 1564 dbg("%s", __func__);
1565 1565
1566 usb_kill_urb (port->interrupt_in_urb); 1566 usb_kill_urb (port->interrupt_in_urb);
1567 del_timer_sync(&garmin_data_p->timer); 1567 del_timer_sync(&garmin_data_p->timer);
@@ -1579,9 +1579,6 @@ static struct usb_serial_driver garmin_device = {
1579 .description = "Garmin GPS usb/tty", 1579 .description = "Garmin GPS usb/tty",
1580 .usb_driver = &garmin_driver, 1580 .usb_driver = &garmin_driver,
1581 .id_table = id_table, 1581 .id_table = id_table,
1582 .num_interrupt_in = 1,
1583 .num_bulk_in = 1,
1584 .num_bulk_out = 1,
1585 .num_ports = 1, 1582 .num_ports = 1,
1586 .open = garmin_open, 1583 .open = garmin_open,
1587 .close = garmin_close, 1584 .close = garmin_close,
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 7cfce9dabb90..537f12a027c2 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -62,9 +62,6 @@ struct usb_serial_driver usb_serial_generic_device = {
62 }, 62 },
63 .id_table = generic_device_ids, 63 .id_table = generic_device_ids,
64 .usb_driver = &generic_driver, 64 .usb_driver = &generic_driver,
65 .num_interrupt_in = NUM_DONT_CARE,
66 .num_bulk_in = NUM_DONT_CARE,
67 .num_bulk_out = NUM_DONT_CARE,
68 .num_ports = 1, 65 .num_ports = 1,
69 .shutdown = usb_serial_generic_shutdown, 66 .shutdown = usb_serial_generic_shutdown,
70 .throttle = usb_serial_generic_throttle, 67 .throttle = usb_serial_generic_throttle,
@@ -121,7 +118,7 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
121 int result = 0; 118 int result = 0;
122 unsigned long flags; 119 unsigned long flags;
123 120
124 dbg("%s - port %d", __FUNCTION__, port->number); 121 dbg("%s - port %d", __func__, port->number);
125 122
126 /* force low_latency on so that our tty_push actually forces the data through, 123 /* force low_latency on so that our tty_push actually forces the data through,
127 otherwise it is scheduled, and with high data rates (like with OHCI) data 124 otherwise it is scheduled, and with high data rates (like with OHCI) data
@@ -148,7 +145,7 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
148 port); 145 port);
149 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 146 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
150 if (result) 147 if (result)
151 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 148 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
152 } 149 }
153 150
154 return result; 151 return result;
@@ -159,7 +156,7 @@ static void generic_cleanup (struct usb_serial_port *port)
159{ 156{
160 struct usb_serial *serial = port->serial; 157 struct usb_serial *serial = port->serial;
161 158
162 dbg("%s - port %d", __FUNCTION__, port->number); 159 dbg("%s - port %d", __func__, port->number);
163 160
164 if (serial->dev) { 161 if (serial->dev) {
165 /* shutdown any bulk reads that might be going on */ 162 /* shutdown any bulk reads that might be going on */
@@ -197,7 +194,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
197 194
198void usb_serial_generic_close (struct usb_serial_port *port, struct file * filp) 195void usb_serial_generic_close (struct usb_serial_port *port, struct file * filp)
199{ 196{
200 dbg("%s - port %d", __FUNCTION__, port->number); 197 dbg("%s - port %d", __func__, port->number);
201 generic_cleanup (port); 198 generic_cleanup (port);
202} 199}
203 200
@@ -207,10 +204,10 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
207 int result; 204 int result;
208 unsigned char *data; 205 unsigned char *data;
209 206
210 dbg("%s - port %d", __FUNCTION__, port->number); 207 dbg("%s - port %d", __func__, port->number);
211 208
212 if (count == 0) { 209 if (count == 0) {
213 dbg("%s - write request of 0 bytes", __FUNCTION__); 210 dbg("%s - write request of 0 bytes", __func__);
214 return (0); 211 return (0);
215 } 212 }
216 213
@@ -220,7 +217,7 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
220 spin_lock_irqsave(&port->lock, flags); 217 spin_lock_irqsave(&port->lock, flags);
221 if (port->write_urb_busy) { 218 if (port->write_urb_busy) {
222 spin_unlock_irqrestore(&port->lock, flags); 219 spin_unlock_irqrestore(&port->lock, flags);
223 dbg("%s - already writing", __FUNCTION__); 220 dbg("%s - already writing", __func__);
224 return 0; 221 return 0;
225 } 222 }
226 port->write_urb_busy = 1; 223 port->write_urb_busy = 1;
@@ -230,7 +227,7 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
230 227
231 memcpy (port->write_urb->transfer_buffer, buf, count); 228 memcpy (port->write_urb->transfer_buffer, buf, count);
232 data = port->write_urb->transfer_buffer; 229 data = port->write_urb->transfer_buffer;
233 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, data); 230 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
234 231
235 /* set up our urb */ 232 /* set up our urb */
236 usb_fill_bulk_urb (port->write_urb, serial->dev, 233 usb_fill_bulk_urb (port->write_urb, serial->dev,
@@ -245,7 +242,7 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
245 port->write_urb_busy = 1; 242 port->write_urb_busy = 1;
246 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 243 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
247 if (result) { 244 if (result) {
248 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 245 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result);
249 /* don't have to grab the lock here, as we will retry if != 0 */ 246 /* don't have to grab the lock here, as we will retry if != 0 */
250 port->write_urb_busy = 0; 247 port->write_urb_busy = 0;
251 } else 248 } else
@@ -263,15 +260,16 @@ int usb_serial_generic_write_room (struct usb_serial_port *port)
263 struct usb_serial *serial = port->serial; 260 struct usb_serial *serial = port->serial;
264 int room = 0; 261 int room = 0;
265 262
266 dbg("%s - port %d", __FUNCTION__, port->number); 263 dbg("%s - port %d", __func__, port->number);
267 264
265 /* FIXME: Locking */
268 if (serial->num_bulk_out) { 266 if (serial->num_bulk_out) {
269 if (!(port->write_urb_busy)) 267 if (!(port->write_urb_busy))
270 room = port->bulk_out_size; 268 room = port->bulk_out_size;
271 } 269 }
272 270
273 dbg("%s - returns %d", __FUNCTION__, room); 271 dbg("%s - returns %d", __func__, room);
274 return (room); 272 return room;
275} 273}
276 274
277int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port) 275int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
@@ -279,14 +277,15 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
279 struct usb_serial *serial = port->serial; 277 struct usb_serial *serial = port->serial;
280 int chars = 0; 278 int chars = 0;
281 279
282 dbg("%s - port %d", __FUNCTION__, port->number); 280 dbg("%s - port %d", __func__, port->number);
283 281
282 /* FIXME: Locking */
284 if (serial->num_bulk_out) { 283 if (serial->num_bulk_out) {
285 if (port->write_urb_busy) 284 if (port->write_urb_busy)
286 chars = port->write_urb->transfer_buffer_length; 285 chars = port->write_urb->transfer_buffer_length;
287 } 286 }
288 287
289 dbg("%s - returns %d", __FUNCTION__, chars); 288 dbg("%s - returns %d", __func__, chars);
290 return (chars); 289 return (chars);
291} 290}
292 291
@@ -308,7 +307,7 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
308 usb_serial_generic_read_bulk_callback), port); 307 usb_serial_generic_read_bulk_callback), port);
309 result = usb_submit_urb(urb, mem_flags); 308 result = usb_submit_urb(urb, mem_flags);
310 if (result) 309 if (result)
311 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 310 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
312} 311}
313 312
314/* Push data to tty layer and resubmit the bulk read URB */ 313/* Push data to tty layer and resubmit the bulk read URB */
@@ -332,20 +331,20 @@ static void flush_and_resubmit_read_urb (struct usb_serial_port *port)
332 331
333void usb_serial_generic_read_bulk_callback (struct urb *urb) 332void usb_serial_generic_read_bulk_callback (struct urb *urb)
334{ 333{
335 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 334 struct usb_serial_port *port = urb->context;
336 unsigned char *data = urb->transfer_buffer; 335 unsigned char *data = urb->transfer_buffer;
337 int status = urb->status; 336 int status = urb->status;
338 unsigned long flags; 337 unsigned long flags;
339 338
340 dbg("%s - port %d", __FUNCTION__, port->number); 339 dbg("%s - port %d", __func__, port->number);
341 340
342 if (unlikely(status != 0)) { 341 if (unlikely(status != 0)) {
343 dbg("%s - nonzero read bulk status received: %d", 342 dbg("%s - nonzero read bulk status received: %d",
344 __FUNCTION__, status); 343 __func__, status);
345 return; 344 return;
346 } 345 }
347 346
348 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 347 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
349 348
350 /* Throttle the device if requested by tty */ 349 /* Throttle the device if requested by tty */
351 spin_lock_irqsave(&port->lock, flags); 350 spin_lock_irqsave(&port->lock, flags);
@@ -360,18 +359,17 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
360 359
361void usb_serial_generic_write_bulk_callback (struct urb *urb) 360void usb_serial_generic_write_bulk_callback (struct urb *urb)
362{ 361{
363 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 362 struct usb_serial_port *port = urb->context;
364 int status = urb->status; 363 int status = urb->status;
365 364
366 dbg("%s - port %d", __FUNCTION__, port->number); 365 dbg("%s - port %d", __func__, port->number);
367 366
368 port->write_urb_busy = 0; 367 port->write_urb_busy = 0;
369 if (status) { 368 if (status) {
370 dbg("%s - nonzero write bulk status received: %d", 369 dbg("%s - nonzero write bulk status received: %d",
371 __FUNCTION__, status); 370 __func__, status);
372 return; 371 return;
373 } 372 }
374
375 usb_serial_port_softint(port); 373 usb_serial_port_softint(port);
376} 374}
377EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 375EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
@@ -380,7 +378,7 @@ void usb_serial_generic_throttle (struct usb_serial_port *port)
380{ 378{
381 unsigned long flags; 379 unsigned long flags;
382 380
383 dbg("%s - port %d", __FUNCTION__, port->number); 381 dbg("%s - port %d", __func__, port->number);
384 382
385 /* Set the throttle request flag. It will be picked up 383 /* Set the throttle request flag. It will be picked up
386 * by usb_serial_generic_read_bulk_callback(). */ 384 * by usb_serial_generic_read_bulk_callback(). */
@@ -394,7 +392,7 @@ void usb_serial_generic_unthrottle (struct usb_serial_port *port)
394 int was_throttled; 392 int was_throttled;
395 unsigned long flags; 393 unsigned long flags;
396 394
397 dbg("%s - port %d", __FUNCTION__, port->number); 395 dbg("%s - port %d", __func__, port->number);
398 396
399 /* Clear the throttle flags */ 397 /* Clear the throttle flags */
400 spin_lock_irqsave(&port->lock, flags); 398 spin_lock_irqsave(&port->lock, flags);
@@ -412,7 +410,7 @@ void usb_serial_generic_shutdown (struct usb_serial *serial)
412{ 410{
413 int i; 411 int i;
414 412
415 dbg("%s", __FUNCTION__); 413 dbg("%s", __func__);
416 414
417 /* stop reads and writes on all ports */ 415 /* stop reads and writes on all ports */
418 for (i=0; i < serial->num_ports; ++i) { 416 for (i=0; i < serial->num_ports; ++i) {
diff --git a/drivers/usb/serial/hp4x.c b/drivers/usb/serial/hp4x.c
index 6c6ebae741c9..75b88b356ebc 100644
--- a/drivers/usb/serial/hp4x.c
+++ b/drivers/usb/serial/hp4x.c
@@ -50,9 +50,6 @@ static struct usb_serial_driver hp49gp_device = {
50 }, 50 },
51 .id_table = id_table, 51 .id_table = id_table,
52 .usb_driver = &hp49gp_driver, 52 .usb_driver = &hp49gp_driver,
53 .num_interrupt_in = NUM_DONT_CARE,
54 .num_bulk_in = NUM_DONT_CARE,
55 .num_bulk_out = NUM_DONT_CARE,
56 .num_ports = 1, 53 .num_ports = 1,
57}; 54};
58 55
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 3428ccc28da7..ce2e487f3240 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -371,7 +371,7 @@ static int get_string (struct usb_device *dev, int Id, char *string, int buflen)
371 struct usb_string_descriptor StringDesc; 371 struct usb_string_descriptor StringDesc;
372 struct usb_string_descriptor *pStringDesc; 372 struct usb_string_descriptor *pStringDesc;
373 373
374 dbg("%s - USB String ID = %d", __FUNCTION__, Id ); 374 dbg("%s - USB String ID = %d", __func__, Id );
375 375
376 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { 376 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) {
377 return 0; 377 return 0;
@@ -391,7 +391,7 @@ static int get_string (struct usb_device *dev, int Id, char *string, int buflen)
391 unicode_to_ascii(string, buflen, pStringDesc->wData, pStringDesc->bLength/2); 391 unicode_to_ascii(string, buflen, pStringDesc->wData, pStringDesc->bLength/2);
392 392
393 kfree(pStringDesc); 393 kfree(pStringDesc);
394 dbg("%s - USB String %s", __FUNCTION__, string); 394 dbg("%s - USB String %s", __func__, string);
395 return strlen(string); 395 return strlen(string);
396} 396}
397 397
@@ -407,7 +407,7 @@ static int get_string_desc (struct usb_device *dev, int Id, struct usb_string_de
407 struct usb_string_descriptor StringDesc; 407 struct usb_string_descriptor StringDesc;
408 struct usb_string_descriptor *pStringDesc; 408 struct usb_string_descriptor *pStringDesc;
409 409
410 dbg("%s - USB String ID = %d", __FUNCTION__, Id ); 410 dbg("%s - USB String ID = %d", __func__, Id );
411 411
412 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { 412 if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) {
413 return 0; 413 return 0;
@@ -537,7 +537,7 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
537 sizeof(struct edge_compatibility_descriptor), 537 sizeof(struct edge_compatibility_descriptor),
538 300); 538 300);
539 539
540 dbg("%s result = %d", __FUNCTION__, result); 540 dbg("%s result = %d", __func__, result);
541 541
542 if (result > 0) { 542 if (result > 0) {
543 ep->is_epic = 1; 543 ep->is_epic = 1;
@@ -589,7 +589,7 @@ static int get_epic_descriptor(struct edgeport_serial *ep)
589 *****************************************************************************/ 589 *****************************************************************************/
590static void edge_interrupt_callback (struct urb *urb) 590static void edge_interrupt_callback (struct urb *urb)
591{ 591{
592 struct edgeport_serial *edge_serial = (struct edgeport_serial *)urb->context; 592 struct edgeport_serial *edge_serial = urb->context;
593 struct edgeport_port *edge_port; 593 struct edgeport_port *edge_port;
594 struct usb_serial_port *port; 594 struct usb_serial_port *port;
595 unsigned char *data = urb->transfer_buffer; 595 unsigned char *data = urb->transfer_buffer;
@@ -601,7 +601,7 @@ static void edge_interrupt_callback (struct urb *urb)
601 int result; 601 int result;
602 int status = urb->status; 602 int status = urb->status;
603 603
604 dbg("%s", __FUNCTION__); 604 dbg("%s", __func__);
605 605
606 switch (status) { 606 switch (status) {
607 case 0: 607 case 0:
@@ -612,35 +612,35 @@ static void edge_interrupt_callback (struct urb *urb)
612 case -ESHUTDOWN: 612 case -ESHUTDOWN:
613 /* this urb is terminated, clean up */ 613 /* this urb is terminated, clean up */
614 dbg("%s - urb shutting down with status: %d", 614 dbg("%s - urb shutting down with status: %d",
615 __FUNCTION__, status); 615 __func__, status);
616 return; 616 return;
617 default: 617 default:
618 dbg("%s - nonzero urb status received: %d", 618 dbg("%s - nonzero urb status received: %d",
619 __FUNCTION__, status); 619 __func__, status);
620 goto exit; 620 goto exit;
621 } 621 }
622 622
623 // process this interrupt-read even if there are no ports open 623 // process this interrupt-read even if there are no ports open
624 if (length) { 624 if (length) {
625 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __FUNCTION__, length, data); 625 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data);
626 626
627 if (length > 1) { 627 if (length > 1) {
628 bytes_avail = data[0] | (data[1] << 8); 628 bytes_avail = data[0] | (data[1] << 8);
629 if (bytes_avail) { 629 if (bytes_avail) {
630 spin_lock(&edge_serial->es_lock); 630 spin_lock(&edge_serial->es_lock);
631 edge_serial->rxBytesAvail += bytes_avail; 631 edge_serial->rxBytesAvail += bytes_avail;
632 dbg("%s - bytes_avail=%d, rxBytesAvail=%d, read_in_progress=%d", __FUNCTION__, bytes_avail, edge_serial->rxBytesAvail, edge_serial->read_in_progress); 632 dbg("%s - bytes_avail=%d, rxBytesAvail=%d, read_in_progress=%d", __func__, bytes_avail, edge_serial->rxBytesAvail, edge_serial->read_in_progress);
633 633
634 if (edge_serial->rxBytesAvail > 0 && 634 if (edge_serial->rxBytesAvail > 0 &&
635 !edge_serial->read_in_progress) { 635 !edge_serial->read_in_progress) {
636 dbg("%s - posting a read", __FUNCTION__); 636 dbg("%s - posting a read", __func__);
637 edge_serial->read_in_progress = true; 637 edge_serial->read_in_progress = true;
638 638
639 /* we have pending bytes on the bulk in pipe, send a request */ 639 /* we have pending bytes on the bulk in pipe, send a request */
640 edge_serial->read_urb->dev = edge_serial->serial->dev; 640 edge_serial->read_urb->dev = edge_serial->serial->dev;
641 result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); 641 result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
642 if (result) { 642 if (result) {
643 dev_err(&edge_serial->serial->dev->dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n", __FUNCTION__, result); 643 dev_err(&edge_serial->serial->dev->dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n", __func__, result);
644 edge_serial->read_in_progress = false; 644 edge_serial->read_in_progress = false;
645 } 645 }
646 } 646 }
@@ -659,7 +659,7 @@ static void edge_interrupt_callback (struct urb *urb)
659 spin_lock(&edge_port->ep_lock); 659 spin_lock(&edge_port->ep_lock);
660 edge_port->txCredits += txCredits; 660 edge_port->txCredits += txCredits;
661 spin_unlock(&edge_port->ep_lock); 661 spin_unlock(&edge_port->ep_lock);
662 dbg("%s - txcredits for port%d = %d", __FUNCTION__, portNumber, edge_port->txCredits); 662 dbg("%s - txcredits for port%d = %d", __func__, portNumber, edge_port->txCredits);
663 663
664 /* tell the tty driver that something has changed */ 664 /* tell the tty driver that something has changed */
665 if (edge_port->port->tty) 665 if (edge_port->port->tty)
@@ -677,7 +677,7 @@ static void edge_interrupt_callback (struct urb *urb)
677exit: 677exit:
678 result = usb_submit_urb (urb, GFP_ATOMIC); 678 result = usb_submit_urb (urb, GFP_ATOMIC);
679 if (result) { 679 if (result) {
680 dev_err(&urb->dev->dev, "%s - Error %d submitting control urb\n", __FUNCTION__, result); 680 dev_err(&urb->dev->dev, "%s - Error %d submitting control urb\n", __func__, result);
681 } 681 }
682} 682}
683 683
@@ -689,49 +689,49 @@ exit:
689 *****************************************************************************/ 689 *****************************************************************************/
690static void edge_bulk_in_callback (struct urb *urb) 690static void edge_bulk_in_callback (struct urb *urb)
691{ 691{
692 struct edgeport_serial *edge_serial = (struct edgeport_serial *)urb->context; 692 struct edgeport_serial *edge_serial = urb->context;
693 unsigned char *data = urb->transfer_buffer; 693 unsigned char *data = urb->transfer_buffer;
694 int retval; 694 int retval;
695 __u16 raw_data_length; 695 __u16 raw_data_length;
696 int status = urb->status; 696 int status = urb->status;
697 697
698 dbg("%s", __FUNCTION__); 698 dbg("%s", __func__);
699 699
700 if (status) { 700 if (status) {
701 dbg("%s - nonzero read bulk status received: %d", 701 dbg("%s - nonzero read bulk status received: %d",
702 __FUNCTION__, status); 702 __func__, status);
703 edge_serial->read_in_progress = false; 703 edge_serial->read_in_progress = false;
704 return; 704 return;
705 } 705 }
706 706
707 if (urb->actual_length == 0) { 707 if (urb->actual_length == 0) {
708 dbg("%s - read bulk callback with no data", __FUNCTION__); 708 dbg("%s - read bulk callback with no data", __func__);
709 edge_serial->read_in_progress = false; 709 edge_serial->read_in_progress = false;
710 return; 710 return;
711 } 711 }
712 712
713 raw_data_length = urb->actual_length; 713 raw_data_length = urb->actual_length;
714 714
715 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __FUNCTION__, raw_data_length, data); 715 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, raw_data_length, data);
716 716
717 spin_lock(&edge_serial->es_lock); 717 spin_lock(&edge_serial->es_lock);
718 718
719 /* decrement our rxBytes available by the number that we just got */ 719 /* decrement our rxBytes available by the number that we just got */
720 edge_serial->rxBytesAvail -= raw_data_length; 720 edge_serial->rxBytesAvail -= raw_data_length;
721 721
722 dbg("%s - Received = %d, rxBytesAvail %d", __FUNCTION__, raw_data_length, edge_serial->rxBytesAvail); 722 dbg("%s - Received = %d, rxBytesAvail %d", __func__, raw_data_length, edge_serial->rxBytesAvail);
723 723
724 process_rcvd_data (edge_serial, data, urb->actual_length); 724 process_rcvd_data (edge_serial, data, urb->actual_length);
725 725
726 /* check to see if there's any more data for us to read */ 726 /* check to see if there's any more data for us to read */
727 if (edge_serial->rxBytesAvail > 0) { 727 if (edge_serial->rxBytesAvail > 0) {
728 dbg("%s - posting a read", __FUNCTION__); 728 dbg("%s - posting a read", __func__);
729 edge_serial->read_urb->dev = edge_serial->serial->dev; 729 edge_serial->read_urb->dev = edge_serial->serial->dev;
730 retval = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); 730 retval = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
731 if (retval) { 731 if (retval) {
732 dev_err(&urb->dev->dev, 732 dev_err(&urb->dev->dev,
733 "%s - usb_submit_urb(read bulk) failed, " 733 "%s - usb_submit_urb(read bulk) failed, "
734 "retval = %d\n", __FUNCTION__, retval); 734 "retval = %d\n", __func__, retval);
735 edge_serial->read_in_progress = false; 735 edge_serial->read_in_progress = false;
736 } 736 }
737 } else { 737 } else {
@@ -749,15 +749,15 @@ static void edge_bulk_in_callback (struct urb *urb)
749 *****************************************************************************/ 749 *****************************************************************************/
750static void edge_bulk_out_data_callback (struct urb *urb) 750static void edge_bulk_out_data_callback (struct urb *urb)
751{ 751{
752 struct edgeport_port *edge_port = (struct edgeport_port *)urb->context; 752 struct edgeport_port *edge_port = urb->context;
753 struct tty_struct *tty; 753 struct tty_struct *tty;
754 int status = urb->status; 754 int status = urb->status;
755 755
756 dbg("%s", __FUNCTION__); 756 dbg("%s", __func__);
757 757
758 if (status) { 758 if (status) {
759 dbg("%s - nonzero write bulk status received: %d", 759 dbg("%s - nonzero write bulk status received: %d",
760 __FUNCTION__, status); 760 __func__, status);
761 } 761 }
762 762
763 tty = edge_port->port->tty; 763 tty = edge_port->port->tty;
@@ -782,14 +782,14 @@ static void edge_bulk_out_data_callback (struct urb *urb)
782 *****************************************************************************/ 782 *****************************************************************************/
783static void edge_bulk_out_cmd_callback (struct urb *urb) 783static void edge_bulk_out_cmd_callback (struct urb *urb)
784{ 784{
785 struct edgeport_port *edge_port = (struct edgeport_port *)urb->context; 785 struct edgeport_port *edge_port = urb->context;
786 struct tty_struct *tty; 786 struct tty_struct *tty;
787 int status = urb->status; 787 int status = urb->status;
788 788
789 dbg("%s", __FUNCTION__); 789 dbg("%s", __func__);
790 790
791 atomic_dec(&CmdUrbs); 791 atomic_dec(&CmdUrbs);
792 dbg("%s - FREE URB %p (outstanding %d)", __FUNCTION__, urb, atomic_read(&CmdUrbs)); 792 dbg("%s - FREE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs));
793 793
794 794
795 /* clean up the transfer buffer */ 795 /* clean up the transfer buffer */
@@ -799,7 +799,7 @@ static void edge_bulk_out_cmd_callback (struct urb *urb)
799 usb_free_urb (urb); 799 usb_free_urb (urb);
800 800
801 if (status) { 801 if (status) {
802 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, status); 802 dbg("%s - nonzero write bulk status received: %d", __func__, status);
803 return; 803 return;
804 } 804 }
805 805
@@ -833,7 +833,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
833 struct edgeport_serial *edge_serial; 833 struct edgeport_serial *edge_serial;
834 int response; 834 int response;
835 835
836 dbg("%s - port %d", __FUNCTION__, port->number); 836 dbg("%s - port %d", __func__, port->number);
837 837
838 if (edge_port == NULL) 838 if (edge_port == NULL)
839 return -ENODEV; 839 return -ENODEV;
@@ -883,7 +883,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
883 * this interrupt will continue as long as the edgeport is connected */ 883 * this interrupt will continue as long as the edgeport is connected */
884 response = usb_submit_urb (edge_serial->interrupt_read_urb, GFP_KERNEL); 884 response = usb_submit_urb (edge_serial->interrupt_read_urb, GFP_KERNEL);
885 if (response) { 885 if (response) {
886 dev_err(&port->dev, "%s - Error %d submitting control urb\n", __FUNCTION__, response); 886 dev_err(&port->dev, "%s - Error %d submitting control urb\n", __func__, response);
887 } 887 }
888 } 888 }
889 889
@@ -907,7 +907,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
907 response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); 907 response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0);
908 908
909 if (response < 0) { 909 if (response < 0) {
910 dev_err(&port->dev, "%s - error sending open port command\n", __FUNCTION__); 910 dev_err(&port->dev, "%s - error sending open port command\n", __func__);
911 edge_port->openPending = false; 911 edge_port->openPending = false;
912 return -ENODEV; 912 return -ENODEV;
913 } 913 }
@@ -917,7 +917,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
917 917
918 if (!edge_port->open) { 918 if (!edge_port->open) {
919 /* open timed out */ 919 /* open timed out */
920 dbg("%s - open timedout", __FUNCTION__); 920 dbg("%s - open timedout", __func__);
921 edge_port->openPending = false; 921 edge_port->openPending = false;
922 return -ENODEV; 922 return -ENODEV;
923 } 923 }
@@ -930,7 +930,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
930 edge_port->txfifo.fifo = kmalloc (edge_port->maxTxCredits, GFP_KERNEL); 930 edge_port->txfifo.fifo = kmalloc (edge_port->maxTxCredits, GFP_KERNEL);
931 931
932 if (!edge_port->txfifo.fifo) { 932 if (!edge_port->txfifo.fifo) {
933 dbg("%s - no memory", __FUNCTION__); 933 dbg("%s - no memory", __func__);
934 edge_close (port, filp); 934 edge_close (port, filp);
935 return -ENOMEM; 935 return -ENOMEM;
936 } 936 }
@@ -940,14 +940,14 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
940 edge_port->write_in_progress = false; 940 edge_port->write_in_progress = false;
941 941
942 if (!edge_port->write_urb) { 942 if (!edge_port->write_urb) {
943 dbg("%s - no memory", __FUNCTION__); 943 dbg("%s - no memory", __func__);
944 edge_close (port, filp); 944 edge_close (port, filp);
945 return -ENOMEM; 945 return -ENOMEM;
946 } 946 }
947 947
948 dbg("%s(%d) - Initialize TX fifo to %d bytes", __FUNCTION__, port->number, edge_port->maxTxCredits); 948 dbg("%s(%d) - Initialize TX fifo to %d bytes", __func__, port->number, edge_port->maxTxCredits);
949 949
950 dbg("%s exited", __FUNCTION__); 950 dbg("%s exited", __func__);
951 951
952 return 0; 952 return 0;
953} 953}
@@ -976,11 +976,11 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
976 976
977 // Did we get our Chase response 977 // Did we get our Chase response
978 if (!edge_port->chaseResponsePending) { 978 if (!edge_port->chaseResponsePending) {
979 dbg("%s - Got Chase Response", __FUNCTION__); 979 dbg("%s - Got Chase Response", __func__);
980 980
981 // did we get all of our credit back? 981 // did we get all of our credit back?
982 if (edge_port->txCredits == edge_port->maxTxCredits ) { 982 if (edge_port->txCredits == edge_port->maxTxCredits ) {
983 dbg("%s - Got all credits", __FUNCTION__); 983 dbg("%s - Got all credits", __func__);
984 return; 984 return;
985 } 985 }
986 } 986 }
@@ -995,12 +995,12 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
995 loop--; 995 loop--;
996 if (loop == 0) { 996 if (loop == 0) {
997 edge_port->chaseResponsePending = false; 997 edge_port->chaseResponsePending = false;
998 dbg("%s - Chase TIMEOUT", __FUNCTION__); 998 dbg("%s - Chase TIMEOUT", __func__);
999 return; 999 return;
1000 } 1000 }
1001 } else { 1001 } else {
1002 // Reset timeout value back to 10 seconds 1002 // Reset timeout value back to 10 seconds
1003 dbg("%s - Last %d, Current %d", __FUNCTION__, lastCredits, edge_port->txCredits); 1003 dbg("%s - Last %d, Current %d", __func__, lastCredits, edge_port->txCredits);
1004 loop = 10; 1004 loop = 10;
1005 } 1005 }
1006 } 1006 }
@@ -1031,7 +1031,7 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
1031 1031
1032 // Is the Edgeport Buffer empty? 1032 // Is the Edgeport Buffer empty?
1033 if (lastCount == 0) { 1033 if (lastCount == 0) {
1034 dbg("%s - TX Buffer Empty", __FUNCTION__); 1034 dbg("%s - TX Buffer Empty", __func__);
1035 return; 1035 return;
1036 } 1036 }
1037 1037
@@ -1040,13 +1040,13 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
1040 schedule_timeout(timeout); 1040 schedule_timeout(timeout);
1041 finish_wait(&edge_port->wait_chase, &wait); 1041 finish_wait(&edge_port->wait_chase, &wait);
1042 1042
1043 dbg("%s wait", __FUNCTION__); 1043 dbg("%s wait", __func__);
1044 1044
1045 if (lastCount == fifo->count) { 1045 if (lastCount == fifo->count) {
1046 // No activity.. count down. 1046 // No activity.. count down.
1047 loop--; 1047 loop--;
1048 if (loop == 0) { 1048 if (loop == 0) {
1049 dbg("%s - TIMEOUT", __FUNCTION__); 1049 dbg("%s - TIMEOUT", __func__);
1050 return; 1050 return;
1051 } 1051 }
1052 } else { 1052 } else {
@@ -1067,7 +1067,7 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1067 struct edgeport_port *edge_port; 1067 struct edgeport_port *edge_port;
1068 int status; 1068 int status;
1069 1069
1070 dbg("%s - port %d", __FUNCTION__, port->number); 1070 dbg("%s - port %d", __func__, port->number);
1071 1071
1072 edge_serial = usb_get_serial_data(port->serial); 1072 edge_serial = usb_get_serial_data(port->serial);
1073 edge_port = usb_get_serial_port_data(port); 1073 edge_port = usb_get_serial_port_data(port);
@@ -1085,7 +1085,7 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1085 /* flush and chase */ 1085 /* flush and chase */
1086 edge_port->chaseResponsePending = true; 1086 edge_port->chaseResponsePending = true;
1087 1087
1088 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __FUNCTION__); 1088 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
1089 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); 1089 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0);
1090 if (status == 0) { 1090 if (status == 0) {
1091 // block until chase finished 1091 // block until chase finished
@@ -1099,7 +1099,7 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1099 ((edge_serial->is_epic) && 1099 ((edge_serial->is_epic) &&
1100 (edge_serial->epic_descriptor.Supports.IOSPClose))) { 1100 (edge_serial->epic_descriptor.Supports.IOSPClose))) {
1101 /* close the port */ 1101 /* close the port */
1102 dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __FUNCTION__); 1102 dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__);
1103 send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); 1103 send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0);
1104 } 1104 }
1105 1105
@@ -1119,7 +1119,7 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
1119 kfree(edge_port->txfifo.fifo); 1119 kfree(edge_port->txfifo.fifo);
1120 edge_port->txfifo.fifo = NULL; 1120 edge_port->txfifo.fifo = NULL;
1121 1121
1122 dbg("%s exited", __FUNCTION__); 1122 dbg("%s exited", __func__);
1123} 1123}
1124 1124
1125/***************************************************************************** 1125/*****************************************************************************
@@ -1139,7 +1139,7 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
1139 int secondhalf; 1139 int secondhalf;
1140 unsigned long flags; 1140 unsigned long flags;
1141 1141
1142 dbg("%s - port %d", __FUNCTION__, port->number); 1142 dbg("%s - port %d", __func__, port->number);
1143 1143
1144 if (edge_port == NULL) 1144 if (edge_port == NULL)
1145 return -ENODEV; 1145 return -ENODEV;
@@ -1152,12 +1152,12 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
1152 // calculate number of bytes to put in fifo 1152 // calculate number of bytes to put in fifo
1153 copySize = min ((unsigned int)count, (edge_port->txCredits - fifo->count)); 1153 copySize = min ((unsigned int)count, (edge_port->txCredits - fifo->count));
1154 1154
1155 dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes", __FUNCTION__, 1155 dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes", __func__,
1156 port->number, count, edge_port->txCredits - fifo->count, copySize); 1156 port->number, count, edge_port->txCredits - fifo->count, copySize);
1157 1157
1158 /* catch writes of 0 bytes which the tty driver likes to give us, and when txCredits is empty */ 1158 /* catch writes of 0 bytes which the tty driver likes to give us, and when txCredits is empty */
1159 if (copySize == 0) { 1159 if (copySize == 0) {
1160 dbg("%s - copySize = Zero", __FUNCTION__); 1160 dbg("%s - copySize = Zero", __func__);
1161 goto finish_write; 1161 goto finish_write;
1162 } 1162 }
1163 1163
@@ -1169,11 +1169,11 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
1169 1169
1170 bytesleft = fifo->size - fifo->head; 1170 bytesleft = fifo->size - fifo->head;
1171 firsthalf = min (bytesleft, copySize); 1171 firsthalf = min (bytesleft, copySize);
1172 dbg("%s - copy %d bytes of %d into fifo ", __FUNCTION__, firsthalf, bytesleft); 1172 dbg("%s - copy %d bytes of %d into fifo ", __func__, firsthalf, bytesleft);
1173 1173
1174 /* now copy our data */ 1174 /* now copy our data */
1175 memcpy(&fifo->fifo[fifo->head], data, firsthalf); 1175 memcpy(&fifo->fifo[fifo->head], data, firsthalf);
1176 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, firsthalf, &fifo->fifo[fifo->head]); 1176 usb_serial_debug_data(debug, &port->dev, __func__, firsthalf, &fifo->fifo[fifo->head]);
1177 1177
1178 // update the index and size 1178 // update the index and size
1179 fifo->head += firsthalf; 1179 fifo->head += firsthalf;
@@ -1187,9 +1187,9 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
1187 secondhalf = copySize-firsthalf; 1187 secondhalf = copySize-firsthalf;
1188 1188
1189 if (secondhalf) { 1189 if (secondhalf) {
1190 dbg("%s - copy rest of data %d", __FUNCTION__, secondhalf); 1190 dbg("%s - copy rest of data %d", __func__, secondhalf);
1191 memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf); 1191 memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf);
1192 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, secondhalf, &fifo->fifo[fifo->head]); 1192 usb_serial_debug_data(debug, &port->dev, __func__, secondhalf, &fifo->fifo[fifo->head]);
1193 // update the index and size 1193 // update the index and size
1194 fifo->count += secondhalf; 1194 fifo->count += secondhalf;
1195 fifo->head += secondhalf; 1195 fifo->head += secondhalf;
@@ -1201,7 +1201,7 @@ finish_write:
1201 1201
1202 send_more_port_data((struct edgeport_serial *)usb_get_serial_data(port->serial), edge_port); 1202 send_more_port_data((struct edgeport_serial *)usb_get_serial_data(port->serial), edge_port);
1203 1203
1204 dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __FUNCTION__, copySize, edge_port->txCredits, fifo->count); 1204 dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__, copySize, edge_port->txCredits, fifo->count);
1205 1205
1206 return copySize; 1206 return copySize;
1207} 1207}
@@ -1232,14 +1232,14 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1232 int secondhalf; 1232 int secondhalf;
1233 unsigned long flags; 1233 unsigned long flags;
1234 1234
1235 dbg("%s(%d)", __FUNCTION__, edge_port->port->number); 1235 dbg("%s(%d)", __func__, edge_port->port->number);
1236 1236
1237 spin_lock_irqsave(&edge_port->ep_lock, flags); 1237 spin_lock_irqsave(&edge_port->ep_lock, flags);
1238 1238
1239 if (edge_port->write_in_progress || 1239 if (edge_port->write_in_progress ||
1240 !edge_port->open || 1240 !edge_port->open ||
1241 (fifo->count == 0)) { 1241 (fifo->count == 0)) {
1242 dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", __FUNCTION__, edge_port->port->number, fifo->count, edge_port->write_in_progress); 1242 dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", __func__, edge_port->port->number, fifo->count, edge_port->write_in_progress);
1243 goto exit_send; 1243 goto exit_send;
1244 } 1244 }
1245 1245
@@ -1251,7 +1251,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1251 // it's better to wait for more credits so we can do a larger 1251 // it's better to wait for more credits so we can do a larger
1252 // write. 1252 // write.
1253 if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits,EDGE_FW_BULK_MAX_PACKET_SIZE)) { 1253 if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits,EDGE_FW_BULK_MAX_PACKET_SIZE)) {
1254 dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", __FUNCTION__, edge_port->port->number, fifo->count, edge_port->txCredits ); 1254 dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", __func__, edge_port->port->number, fifo->count, edge_port->txCredits );
1255 goto exit_send; 1255 goto exit_send;
1256 } 1256 }
1257 1257
@@ -1269,7 +1269,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1269 count = fifo->count; 1269 count = fifo->count;
1270 buffer = kmalloc (count+2, GFP_ATOMIC); 1270 buffer = kmalloc (count+2, GFP_ATOMIC);
1271 if (buffer == NULL) { 1271 if (buffer == NULL) {
1272 dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __FUNCTION__); 1272 dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __func__);
1273 edge_port->write_in_progress = false; 1273 edge_port->write_in_progress = false;
1274 goto exit_send; 1274 goto exit_send;
1275 } 1275 }
@@ -1294,7 +1294,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1294 } 1294 }
1295 1295
1296 if (count) 1296 if (count)
1297 usb_serial_debug_data(debug, &edge_port->port->dev, __FUNCTION__, count, &buffer[2]); 1297 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, count, &buffer[2]);
1298 1298
1299 /* fill up the urb with all of our data and submit it */ 1299 /* fill up the urb with all of our data and submit it */
1300 usb_fill_bulk_urb (urb, edge_serial->serial->dev, 1300 usb_fill_bulk_urb (urb, edge_serial->serial->dev,
@@ -1309,14 +1309,14 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
1309 status = usb_submit_urb(urb, GFP_ATOMIC); 1309 status = usb_submit_urb(urb, GFP_ATOMIC);
1310 if (status) { 1310 if (status) {
1311 /* something went wrong */ 1311 /* something went wrong */
1312 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __FUNCTION__, status); 1312 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __func__, status);
1313 edge_port->write_in_progress = false; 1313 edge_port->write_in_progress = false;
1314 1314
1315 /* revert the credits as something bad happened. */ 1315 /* revert the credits as something bad happened. */
1316 edge_port->txCredits += count; 1316 edge_port->txCredits += count;
1317 edge_port->icount.tx -= count; 1317 edge_port->icount.tx -= count;
1318 } 1318 }
1319 dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", __FUNCTION__, count, edge_port->txCredits, fifo->count); 1319 dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", __func__, count, edge_port->txCredits, fifo->count);
1320 1320
1321exit_send: 1321exit_send:
1322 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1322 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
@@ -1337,17 +1337,17 @@ static int edge_write_room (struct usb_serial_port *port)
1337 int room; 1337 int room;
1338 unsigned long flags; 1338 unsigned long flags;
1339 1339
1340 dbg("%s", __FUNCTION__); 1340 dbg("%s", __func__);
1341 1341
1342 if (edge_port == NULL) 1342 if (edge_port == NULL)
1343 return -ENODEV; 1343 return -ENODEV;
1344 if (edge_port->closePending) 1344 if (edge_port->closePending)
1345 return -ENODEV; 1345 return -ENODEV;
1346 1346
1347 dbg("%s - port %d", __FUNCTION__, port->number); 1347 dbg("%s - port %d", __func__, port->number);
1348 1348
1349 if (!edge_port->open) { 1349 if (!edge_port->open) {
1350 dbg("%s - port not opened", __FUNCTION__); 1350 dbg("%s - port not opened", __func__);
1351 return -EINVAL; 1351 return -EINVAL;
1352 } 1352 }
1353 1353
@@ -1356,7 +1356,7 @@ static int edge_write_room (struct usb_serial_port *port)
1356 room = edge_port->txCredits - edge_port->txfifo.count; 1356 room = edge_port->txCredits - edge_port->txfifo.count;
1357 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1357 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1358 1358
1359 dbg("%s - returns %d", __FUNCTION__, room); 1359 dbg("%s - returns %d", __func__, room);
1360 return room; 1360 return room;
1361} 1361}
1362 1362
@@ -1376,7 +1376,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
1376 int num_chars; 1376 int num_chars;
1377 unsigned long flags; 1377 unsigned long flags;
1378 1378
1379 dbg("%s", __FUNCTION__); 1379 dbg("%s", __func__);
1380 1380
1381 if (edge_port == NULL) 1381 if (edge_port == NULL)
1382 return -ENODEV; 1382 return -ENODEV;
@@ -1384,7 +1384,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
1384 return -ENODEV; 1384 return -ENODEV;
1385 1385
1386 if (!edge_port->open) { 1386 if (!edge_port->open) {
1387 dbg("%s - port not opened", __FUNCTION__); 1387 dbg("%s - port not opened", __func__);
1388 return -EINVAL; 1388 return -EINVAL;
1389 } 1389 }
1390 1390
@@ -1392,7 +1392,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
1392 num_chars = edge_port->maxTxCredits - edge_port->txCredits + edge_port->txfifo.count; 1392 num_chars = edge_port->maxTxCredits - edge_port->txCredits + edge_port->txfifo.count;
1393 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1393 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1394 if (num_chars) { 1394 if (num_chars) {
1395 dbg("%s(port %d) - returns %d", __FUNCTION__, port->number, num_chars); 1395 dbg("%s(port %d) - returns %d", __func__, port->number, num_chars);
1396 } 1396 }
1397 1397
1398 return num_chars; 1398 return num_chars;
@@ -1410,19 +1410,19 @@ static void edge_throttle (struct usb_serial_port *port)
1410 struct tty_struct *tty; 1410 struct tty_struct *tty;
1411 int status; 1411 int status;
1412 1412
1413 dbg("%s - port %d", __FUNCTION__, port->number); 1413 dbg("%s - port %d", __func__, port->number);
1414 1414
1415 if (edge_port == NULL) 1415 if (edge_port == NULL)
1416 return; 1416 return;
1417 1417
1418 if (!edge_port->open) { 1418 if (!edge_port->open) {
1419 dbg("%s - port not opened", __FUNCTION__); 1419 dbg("%s - port not opened", __func__);
1420 return; 1420 return;
1421 } 1421 }
1422 1422
1423 tty = port->tty; 1423 tty = port->tty;
1424 if (!tty) { 1424 if (!tty) {
1425 dbg ("%s - no tty available", __FUNCTION__); 1425 dbg ("%s - no tty available", __func__);
1426 return; 1426 return;
1427 } 1427 }
1428 1428
@@ -1459,19 +1459,19 @@ static void edge_unthrottle (struct usb_serial_port *port)
1459 struct tty_struct *tty; 1459 struct tty_struct *tty;
1460 int status; 1460 int status;
1461 1461
1462 dbg("%s - port %d", __FUNCTION__, port->number); 1462 dbg("%s - port %d", __func__, port->number);
1463 1463
1464 if (edge_port == NULL) 1464 if (edge_port == NULL)
1465 return; 1465 return;
1466 1466
1467 if (!edge_port->open) { 1467 if (!edge_port->open) {
1468 dbg("%s - port not opened", __FUNCTION__); 1468 dbg("%s - port not opened", __func__);
1469 return; 1469 return;
1470 } 1470 }
1471 1471
1472 tty = port->tty; 1472 tty = port->tty;
1473 if (!tty) { 1473 if (!tty) {
1474 dbg ("%s - no tty available", __FUNCTION__); 1474 dbg ("%s - no tty available", __func__);
1475 return; 1475 return;
1476 } 1476 }
1477 1477
@@ -1509,18 +1509,18 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
1509 unsigned int cflag; 1509 unsigned int cflag;
1510 1510
1511 cflag = tty->termios->c_cflag; 1511 cflag = tty->termios->c_cflag;
1512 dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 1512 dbg("%s - clfag %08x iflag %08x", __func__,
1513 tty->termios->c_cflag, tty->termios->c_iflag); 1513 tty->termios->c_cflag, tty->termios->c_iflag);
1514 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, 1514 dbg("%s - old clfag %08x old iflag %08x", __func__,
1515 old_termios->c_cflag, old_termios->c_iflag); 1515 old_termios->c_cflag, old_termios->c_iflag);
1516 1516
1517 dbg("%s - port %d", __FUNCTION__, port->number); 1517 dbg("%s - port %d", __func__, port->number);
1518 1518
1519 if (edge_port == NULL) 1519 if (edge_port == NULL)
1520 return; 1520 return;
1521 1521
1522 if (!edge_port->open) { 1522 if (!edge_port->open) {
1523 dbg("%s - port not opened", __FUNCTION__); 1523 dbg("%s - port not opened", __func__);
1524 return; 1524 return;
1525 } 1525 }
1526 1526
@@ -1549,7 +1549,7 @@ static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *va
1549 spin_lock_irqsave(&edge_port->ep_lock, flags); 1549 spin_lock_irqsave(&edge_port->ep_lock, flags);
1550 if (edge_port->maxTxCredits == edge_port->txCredits && 1550 if (edge_port->maxTxCredits == edge_port->txCredits &&
1551 edge_port->txfifo.count == 0) { 1551 edge_port->txfifo.count == 0) {
1552 dbg("%s -- Empty", __FUNCTION__); 1552 dbg("%s -- Empty", __func__);
1553 result = TIOCSER_TEMT; 1553 result = TIOCSER_TEMT;
1554 } 1554 }
1555 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1555 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
@@ -1569,7 +1569,7 @@ static int get_number_bytes_avail(struct edgeport_port *edge_port, unsigned int
1569 1569
1570 result = tty->read_cnt; 1570 result = tty->read_cnt;
1571 1571
1572 dbg("%s(%d) = %d", __FUNCTION__, edge_port->port->number, result); 1572 dbg("%s(%d) = %d", __func__, edge_port->port->number, result);
1573 if (copy_to_user(value, &result, sizeof(int))) 1573 if (copy_to_user(value, &result, sizeof(int)))
1574 return -EFAULT; 1574 return -EFAULT;
1575 //return 0; 1575 //return 0;
@@ -1581,7 +1581,7 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
1581 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1581 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1582 unsigned int mcr; 1582 unsigned int mcr;
1583 1583
1584 dbg("%s - port %d", __FUNCTION__, port->number); 1584 dbg("%s - port %d", __func__, port->number);
1585 1585
1586 mcr = edge_port->shadowMCR; 1586 mcr = edge_port->shadowMCR;
1587 if (set & TIOCM_RTS) 1587 if (set & TIOCM_RTS)
@@ -1612,7 +1612,7 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
1612 unsigned int msr; 1612 unsigned int msr;
1613 unsigned int mcr; 1613 unsigned int mcr;
1614 1614
1615 dbg("%s - port %d", __FUNCTION__, port->number); 1615 dbg("%s - port %d", __func__, port->number);
1616 1616
1617 msr = edge_port->shadowMSR; 1617 msr = edge_port->shadowMSR;
1618 mcr = edge_port->shadowMCR; 1618 mcr = edge_port->shadowMCR;
@@ -1624,7 +1624,7 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
1624 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */ 1624 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
1625 1625
1626 1626
1627 dbg("%s -- %x", __FUNCTION__, result); 1627 dbg("%s -- %x", __func__, result);
1628 1628
1629 return result; 1629 return result;
1630} 1630}
@@ -1670,30 +1670,30 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
1670 struct async_icount cprev; 1670 struct async_icount cprev;
1671 struct serial_icounter_struct icount; 1671 struct serial_icounter_struct icount;
1672 1672
1673 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd); 1673 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1674 1674
1675 switch (cmd) { 1675 switch (cmd) {
1676 // return number of bytes available 1676 // return number of bytes available
1677 case TIOCINQ: 1677 case TIOCINQ:
1678 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number); 1678 dbg("%s (%d) TIOCINQ", __func__, port->number);
1679 return get_number_bytes_avail(edge_port, (unsigned int __user *) arg); 1679 return get_number_bytes_avail(edge_port, (unsigned int __user *) arg);
1680 break; 1680 break;
1681 1681
1682 case TIOCSERGETLSR: 1682 case TIOCSERGETLSR:
1683 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number); 1683 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1684 return get_lsr_info(edge_port, (unsigned int __user *) arg); 1684 return get_lsr_info(edge_port, (unsigned int __user *) arg);
1685 return 0; 1685 return 0;
1686 1686
1687 case TIOCGSERIAL: 1687 case TIOCGSERIAL:
1688 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number); 1688 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1689 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 1689 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
1690 1690
1691 case TIOCSSERIAL: 1691 case TIOCSSERIAL:
1692 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number); 1692 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
1693 break; 1693 break;
1694 1694
1695 case TIOCMIWAIT: 1695 case TIOCMIWAIT:
1696 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number); 1696 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1697 cprev = edge_port->icount; 1697 cprev = edge_port->icount;
1698 while (1) { 1698 while (1) {
1699 prepare_to_wait(&edge_port->delta_msr_wait, &wait, TASK_INTERRUPTIBLE); 1699 prepare_to_wait(&edge_port->delta_msr_wait, &wait, TASK_INTERRUPTIBLE);
@@ -1732,7 +1732,7 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
1732 icount.brk = cnow.brk; 1732 icount.brk = cnow.brk;
1733 icount.buf_overrun = cnow.buf_overrun; 1733 icount.buf_overrun = cnow.buf_overrun;
1734 1734
1735 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__, port->number, icount.rx, icount.tx ); 1735 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, port->number, icount.rx, icount.tx );
1736 if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) 1736 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1737 return -EFAULT; 1737 return -EFAULT;
1738 return 0; 1738 return 0;
@@ -1758,7 +1758,7 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1758 /* flush and chase */ 1758 /* flush and chase */
1759 edge_port->chaseResponsePending = true; 1759 edge_port->chaseResponsePending = true;
1760 1760
1761 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __FUNCTION__); 1761 dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__);
1762 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); 1762 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0);
1763 if (status == 0) { 1763 if (status == 0) {
1764 // block until chase finished 1764 // block until chase finished
@@ -1772,14 +1772,14 @@ static void edge_break (struct usb_serial_port *port, int break_state)
1772 ((edge_serial->is_epic) && 1772 ((edge_serial->is_epic) &&
1773 (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) { 1773 (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) {
1774 if (break_state == -1) { 1774 if (break_state == -1) {
1775 dbg("%s - Sending IOSP_CMD_SET_BREAK", __FUNCTION__); 1775 dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__);
1776 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_SET_BREAK, 0); 1776 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_SET_BREAK, 0);
1777 } else { 1777 } else {
1778 dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __FUNCTION__); 1778 dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__);
1779 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CLEAR_BREAK, 0); 1779 status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CLEAR_BREAK, 0);
1780 } 1780 }
1781 if (status) { 1781 if (status) {
1782 dbg("%s - error sending break set/clear command.", __FUNCTION__); 1782 dbg("%s - error sending break set/clear command.", __func__);
1783 } 1783 }
1784 } 1784 }
1785 1785
@@ -1799,14 +1799,14 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1799 __u16 lastBufferLength; 1799 __u16 lastBufferLength;
1800 __u16 rxLen; 1800 __u16 rxLen;
1801 1801
1802 dbg("%s", __FUNCTION__); 1802 dbg("%s", __func__);
1803 1803
1804 lastBufferLength = bufferLength + 1; 1804 lastBufferLength = bufferLength + 1;
1805 1805
1806 while (bufferLength > 0) { 1806 while (bufferLength > 0) {
1807 /* failsafe incase we get a message that we don't understand */ 1807 /* failsafe incase we get a message that we don't understand */
1808 if (lastBufferLength == bufferLength) { 1808 if (lastBufferLength == bufferLength) {
1809 dbg("%s - stuck in loop, exiting it.", __FUNCTION__); 1809 dbg("%s - stuck in loop, exiting it.", __func__);
1810 break; 1810 break;
1811 } 1811 }
1812 lastBufferLength = bufferLength; 1812 lastBufferLength = bufferLength;
@@ -1828,7 +1828,7 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1828 ++buffer; 1828 ++buffer;
1829 --bufferLength; 1829 --bufferLength;
1830 1830
1831 dbg("%s - Hdr1=%02X Hdr2=%02X", __FUNCTION__, edge_serial->rxHeader1, edge_serial->rxHeader2); 1831 dbg("%s - Hdr1=%02X Hdr2=%02X", __func__, edge_serial->rxHeader1, edge_serial->rxHeader2);
1832 1832
1833 // Process depending on whether this header is 1833 // Process depending on whether this header is
1834 // data or status 1834 // data or status
@@ -1858,7 +1858,7 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1858 edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1); 1858 edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1);
1859 edge_serial->rxBytesRemaining = IOSP_GET_HDR_DATA_LEN(edge_serial->rxHeader1, edge_serial->rxHeader2); 1859 edge_serial->rxBytesRemaining = IOSP_GET_HDR_DATA_LEN(edge_serial->rxHeader1, edge_serial->rxHeader2);
1860 1860
1861 dbg("%s - Data for Port %u Len %u", __FUNCTION__, edge_serial->rxPort, edge_serial->rxBytesRemaining); 1861 dbg("%s - Data for Port %u Len %u", __func__, edge_serial->rxPort, edge_serial->rxBytesRemaining);
1862 1862
1863 //ASSERT( DevExt->RxPort < DevExt->NumPorts ); 1863 //ASSERT( DevExt->RxPort < DevExt->NumPorts );
1864 //ASSERT( DevExt->RxBytesRemaining < IOSP_MAX_DATA_LENGTH ); 1864 //ASSERT( DevExt->RxBytesRemaining < IOSP_MAX_DATA_LENGTH );
@@ -1891,7 +1891,7 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
1891 if (edge_port->open) { 1891 if (edge_port->open) {
1892 tty = edge_port->port->tty; 1892 tty = edge_port->port->tty;
1893 if (tty) { 1893 if (tty) {
1894 dbg("%s - Sending %d bytes to TTY for port %d", __FUNCTION__, rxLen, edge_serial->rxPort); 1894 dbg("%s - Sending %d bytes to TTY for port %d", __func__, rxLen, edge_serial->rxPort);
1895 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen); 1895 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen);
1896 } 1896 }
1897 edge_port->icount.rx += rxLen; 1897 edge_port->icount.rx += rxLen;
@@ -1930,17 +1930,17 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1930 port = edge_serial->serial->port[edge_serial->rxPort]; 1930 port = edge_serial->serial->port[edge_serial->rxPort];
1931 edge_port = usb_get_serial_port_data(port); 1931 edge_port = usb_get_serial_port_data(port);
1932 if (edge_port == NULL) { 1932 if (edge_port == NULL) {
1933 dev_err(&edge_serial->serial->dev->dev, "%s - edge_port == NULL for port %d\n", __FUNCTION__, edge_serial->rxPort); 1933 dev_err(&edge_serial->serial->dev->dev, "%s - edge_port == NULL for port %d\n", __func__, edge_serial->rxPort);
1934 return; 1934 return;
1935 } 1935 }
1936 1936
1937 dbg("%s - port %d", __FUNCTION__, edge_serial->rxPort); 1937 dbg("%s - port %d", __func__, edge_serial->rxPort);
1938 1938
1939 if (code == IOSP_EXT_STATUS) { 1939 if (code == IOSP_EXT_STATUS) {
1940 switch (byte2) { 1940 switch (byte2) {
1941 case IOSP_EXT_STATUS_CHASE_RSP: 1941 case IOSP_EXT_STATUS_CHASE_RSP:
1942 // we want to do EXT status regardless of port open/closed 1942 // we want to do EXT status regardless of port open/closed
1943 dbg("%s - Port %u EXT CHASE_RSP Data = %02x", __FUNCTION__, edge_serial->rxPort, byte3 ); 1943 dbg("%s - Port %u EXT CHASE_RSP Data = %02x", __func__, edge_serial->rxPort, byte3 );
1944 // Currently, the only EXT_STATUS is Chase, so process here instead of one more call 1944 // Currently, the only EXT_STATUS is Chase, so process here instead of one more call
1945 // to one more subroutine. If/when more EXT_STATUS, there'll be more work to do. 1945 // to one more subroutine. If/when more EXT_STATUS, there'll be more work to do.
1946 // Also, we currently clear flag and close the port regardless of content of above's Byte3. 1946 // Also, we currently clear flag and close the port regardless of content of above's Byte3.
@@ -1951,7 +1951,7 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1951 return; 1951 return;
1952 1952
1953 case IOSP_EXT_STATUS_RX_CHECK_RSP: 1953 case IOSP_EXT_STATUS_RX_CHECK_RSP:
1954 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __FUNCTION__, edge_serial->rxPort, byte3 ); 1954 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3 );
1955 //Port->RxCheckRsp = true; 1955 //Port->RxCheckRsp = true;
1956 return; 1956 return;
1957 } 1957 }
@@ -1960,7 +1960,7 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1960 if (code == IOSP_STATUS_OPEN_RSP) { 1960 if (code == IOSP_STATUS_OPEN_RSP) {
1961 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); 1961 edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3);
1962 edge_port->maxTxCredits = edge_port->txCredits; 1962 edge_port->maxTxCredits = edge_port->txCredits;
1963 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __FUNCTION__, edge_serial->rxPort, byte2, edge_port->txCredits); 1963 dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits);
1964 handle_new_msr (edge_port, byte2); 1964 handle_new_msr (edge_port, byte2);
1965 1965
1966 /* send the current line settings to the port so we are in sync with any further termios calls */ 1966 /* send the current line settings to the port so we are in sync with any further termios calls */
@@ -1984,23 +1984,23 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
1984 switch (code) { 1984 switch (code) {
1985 // Not currently sent by Edgeport 1985 // Not currently sent by Edgeport
1986 case IOSP_STATUS_LSR: 1986 case IOSP_STATUS_LSR:
1987 dbg("%s - Port %u LSR Status = %02x", __FUNCTION__, edge_serial->rxPort, byte2); 1987 dbg("%s - Port %u LSR Status = %02x", __func__, edge_serial->rxPort, byte2);
1988 handle_new_lsr(edge_port, false, byte2, 0); 1988 handle_new_lsr(edge_port, false, byte2, 0);
1989 break; 1989 break;
1990 1990
1991 case IOSP_STATUS_LSR_DATA: 1991 case IOSP_STATUS_LSR_DATA:
1992 dbg("%s - Port %u LSR Status = %02x, Data = %02x", __FUNCTION__, edge_serial->rxPort, byte2, byte3); 1992 dbg("%s - Port %u LSR Status = %02x, Data = %02x", __func__, edge_serial->rxPort, byte2, byte3);
1993 // byte2 is LSR Register 1993 // byte2 is LSR Register
1994 // byte3 is broken data byte 1994 // byte3 is broken data byte
1995 handle_new_lsr(edge_port, true, byte2, byte3); 1995 handle_new_lsr(edge_port, true, byte2, byte3);
1996 break; 1996 break;
1997 // 1997 //
1998 // case IOSP_EXT_4_STATUS: 1998 // case IOSP_EXT_4_STATUS:
1999 // dbg("%s - Port %u LSR Status = %02x Data = %02x", __FUNCTION__, edge_serial->rxPort, byte2, byte3); 1999 // dbg("%s - Port %u LSR Status = %02x Data = %02x", __func__, edge_serial->rxPort, byte2, byte3);
2000 // break; 2000 // break;
2001 // 2001 //
2002 case IOSP_STATUS_MSR: 2002 case IOSP_STATUS_MSR:
2003 dbg("%s - Port %u MSR Status = %02x", __FUNCTION__, edge_serial->rxPort, byte2); 2003 dbg("%s - Port %u MSR Status = %02x", __func__, edge_serial->rxPort, byte2);
2004 2004
2005 // Process this new modem status and generate appropriate 2005 // Process this new modem status and generate appropriate
2006 // events, etc, based on the new status. This routine 2006 // events, etc, based on the new status. This routine
@@ -2009,7 +2009,7 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
2009 break; 2009 break;
2010 2010
2011 default: 2011 default:
2012 dbg("%s - Unrecognized IOSP status code %u\n", __FUNCTION__, code); 2012 dbg("%s - Unrecognized IOSP status code %u\n", __func__, code);
2013 break; 2013 break;
2014 } 2014 }
2015 2015
@@ -2029,7 +2029,7 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c
2029 cnt = tty_buffer_request_room(tty, length); 2029 cnt = tty_buffer_request_room(tty, length);
2030 if (cnt < length) { 2030 if (cnt < length) {
2031 dev_err(dev, "%s - dropping data, %d bytes lost\n", 2031 dev_err(dev, "%s - dropping data, %d bytes lost\n",
2032 __FUNCTION__, length - cnt); 2032 __func__, length - cnt);
2033 if(cnt == 0) 2033 if(cnt == 0)
2034 break; 2034 break;
2035 } 2035 }
@@ -2050,7 +2050,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2050{ 2050{
2051 struct async_icount *icount; 2051 struct async_icount *icount;
2052 2052
2053 dbg("%s %02x", __FUNCTION__, newMsr); 2053 dbg("%s %02x", __func__, newMsr);
2054 2054
2055 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 2055 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
2056 icount = &edge_port->icount; 2056 icount = &edge_port->icount;
@@ -2087,7 +2087,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 l
2087 __u8 newLsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); 2087 __u8 newLsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
2088 struct async_icount *icount; 2088 struct async_icount *icount;
2089 2089
2090 dbg("%s - %02x", __FUNCTION__, newLsr); 2090 dbg("%s - %02x", __func__, newLsr);
2091 2091
2092 edge_port->shadowLSR = lsr; 2092 edge_port->shadowLSR = lsr;
2093 2093
@@ -2136,11 +2136,11 @@ static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u
2136 __u16 current_length; 2136 __u16 current_length;
2137 unsigned char *transfer_buffer; 2137 unsigned char *transfer_buffer;
2138 2138
2139 dbg("%s - %x, %x, %d", __FUNCTION__, extAddr, addr, length); 2139 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
2140 2140
2141 transfer_buffer = kmalloc (64, GFP_KERNEL); 2141 transfer_buffer = kmalloc (64, GFP_KERNEL);
2142 if (!transfer_buffer) { 2142 if (!transfer_buffer) {
2143 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __FUNCTION__, 64); 2143 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64);
2144 return -ENOMEM; 2144 return -ENOMEM;
2145 } 2145 }
2146 2146
@@ -2152,7 +2152,7 @@ static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u
2152 } else { 2152 } else {
2153 current_length = length; 2153 current_length = length;
2154 } 2154 }
2155// dbg("%s - writing %x, %x, %d", __FUNCTION__, extAddr, addr, current_length); 2155// dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length);
2156 memcpy (transfer_buffer, data, current_length); 2156 memcpy (transfer_buffer, data, current_length);
2157 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_RAM, 2157 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_RAM,
2158 0x40, addr, extAddr, transfer_buffer, current_length, 300); 2158 0x40, addr, extAddr, transfer_buffer, current_length, 300);
@@ -2181,11 +2181,11 @@ static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1
2181 __u16 current_length; 2181 __u16 current_length;
2182 unsigned char *transfer_buffer; 2182 unsigned char *transfer_buffer;
2183 2183
2184// dbg("%s - %x, %x, %d", __FUNCTION__, extAddr, addr, length); 2184// dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
2185 2185
2186 transfer_buffer = kmalloc (64, GFP_KERNEL); 2186 transfer_buffer = kmalloc (64, GFP_KERNEL);
2187 if (!transfer_buffer) { 2187 if (!transfer_buffer) {
2188 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __FUNCTION__, 64); 2188 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64);
2189 return -ENOMEM; 2189 return -ENOMEM;
2190 } 2190 }
2191 2191
@@ -2197,7 +2197,7 @@ static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1
2197 } else { 2197 } else {
2198 current_length = length; 2198 current_length = length;
2199 } 2199 }
2200// dbg("%s - writing %x, %x, %d", __FUNCTION__, extAddr, addr, current_length); 2200// dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length);
2201 memcpy (transfer_buffer, data, current_length); 2201 memcpy (transfer_buffer, data, current_length);
2202 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_ROM, 2202 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_ROM,
2203 0x40, addr, extAddr, transfer_buffer, current_length, 300); 2203 0x40, addr, extAddr, transfer_buffer, current_length, 300);
@@ -2226,11 +2226,11 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2226 __u16 current_length; 2226 __u16 current_length;
2227 unsigned char *transfer_buffer; 2227 unsigned char *transfer_buffer;
2228 2228
2229 dbg("%s - %x, %x, %d", __FUNCTION__, extAddr, addr, length); 2229 dbg("%s - %x, %x, %d", __func__, extAddr, addr, length);
2230 2230
2231 transfer_buffer = kmalloc (64, GFP_KERNEL); 2231 transfer_buffer = kmalloc (64, GFP_KERNEL);
2232 if (!transfer_buffer) { 2232 if (!transfer_buffer) {
2233 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __FUNCTION__, 64); 2233 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64);
2234 return -ENOMEM; 2234 return -ENOMEM;
2235 } 2235 }
2236 2236
@@ -2242,7 +2242,7 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16
2242 } else { 2242 } else {
2243 current_length = length; 2243 current_length = length;
2244 } 2244 }
2245// dbg("%s - %x, %x, %d", __FUNCTION__, extAddr, addr, current_length); 2245// dbg("%s - %x, %x, %d", __func__, extAddr, addr, current_length);
2246 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), USB_REQUEST_ION_READ_ROM, 2246 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), USB_REQUEST_ION_READ_ROM,
2247 0xC0, addr, extAddr, transfer_buffer, current_length, 300); 2247 0xC0, addr, extAddr, transfer_buffer, current_length, 300);
2248 if (result < 0) 2248 if (result < 0)
@@ -2269,11 +2269,11 @@ static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u
2269 int length = 0; 2269 int length = 0;
2270 int status = 0; 2270 int status = 0;
2271 2271
2272 dbg("%s - %d, %d", __FUNCTION__, command, param); 2272 dbg("%s - %d, %d", __func__, command, param);
2273 2273
2274 buffer = kmalloc (10, GFP_ATOMIC); 2274 buffer = kmalloc (10, GFP_ATOMIC);
2275 if (!buffer) { 2275 if (!buffer) {
2276 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __FUNCTION__, 10); 2276 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 10);
2277 return -ENOMEM; 2277 return -ENOMEM;
2278 } 2278 }
2279 2279
@@ -2304,7 +2304,7 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer
2304 struct urb *urb; 2304 struct urb *urb;
2305 int timeout; 2305 int timeout;
2306 2306
2307 usb_serial_debug_data(debug, &edge_port->port->dev, __FUNCTION__, length, buffer); 2307 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, length, buffer);
2308 2308
2309 /* Allocate our next urb */ 2309 /* Allocate our next urb */
2310 urb = usb_alloc_urb (0, GFP_ATOMIC); 2310 urb = usb_alloc_urb (0, GFP_ATOMIC);
@@ -2312,7 +2312,7 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer
2312 return -ENOMEM; 2312 return -ENOMEM;
2313 2313
2314 atomic_inc(&CmdUrbs); 2314 atomic_inc(&CmdUrbs);
2315 dbg("%s - ALLOCATE URB %p (outstanding %d)", __FUNCTION__, urb, atomic_read(&CmdUrbs)); 2315 dbg("%s - ALLOCATE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs));
2316 2316
2317 usb_fill_bulk_urb (urb, edge_serial->serial->dev, 2317 usb_fill_bulk_urb (urb, edge_serial->serial->dev,
2318 usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), 2318 usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint),
@@ -2323,7 +2323,7 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer
2323 2323
2324 if (status) { 2324 if (status) {
2325 /* something went wrong */ 2325 /* something went wrong */
2326 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __FUNCTION__, status); 2326 dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __func__, status);
2327 usb_kill_urb(urb); 2327 usb_kill_urb(urb);
2328 usb_free_urb(urb); 2328 usb_free_urb(urb);
2329 atomic_dec(&CmdUrbs); 2329 atomic_dec(&CmdUrbs);
@@ -2337,7 +2337,7 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer
2337 2337
2338 if (edge_port->commandPending) { 2338 if (edge_port->commandPending) {
2339 /* command timed out */ 2339 /* command timed out */
2340 dbg("%s - command timed out", __FUNCTION__); 2340 dbg("%s - command timed out", __func__);
2341 status = -EINVAL; 2341 status = -EINVAL;
2342 } 2342 }
2343#endif 2343#endif
@@ -2367,18 +2367,18 @@ static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRa
2367 return 0; 2367 return 0;
2368 } 2368 }
2369 2369
2370 dbg("%s - port = %d, baud = %d", __FUNCTION__, edge_port->port->number, baudRate); 2370 dbg("%s - port = %d, baud = %d", __func__, edge_port->port->number, baudRate);
2371 2371
2372 status = calc_baud_rate_divisor (baudRate, &divisor); 2372 status = calc_baud_rate_divisor (baudRate, &divisor);
2373 if (status) { 2373 if (status) {
2374 dev_err(&edge_port->port->dev, "%s - bad baud rate\n", __FUNCTION__); 2374 dev_err(&edge_port->port->dev, "%s - bad baud rate\n", __func__);
2375 return status; 2375 return status;
2376 } 2376 }
2377 2377
2378 // Alloc memory for the string of commands. 2378 // Alloc memory for the string of commands.
2379 cmdBuffer = kmalloc (0x100, GFP_ATOMIC); 2379 cmdBuffer = kmalloc (0x100, GFP_ATOMIC);
2380 if (!cmdBuffer) { 2380 if (!cmdBuffer) {
2381 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __FUNCTION__, 0x100); 2381 dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 0x100);
2382 return -ENOMEM; 2382 return -ENOMEM;
2383 } 2383 }
2384 currCmd = cmdBuffer; 2384 currCmd = cmdBuffer;
@@ -2414,7 +2414,7 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
2414 __u16 custom; 2414 __u16 custom;
2415 2415
2416 2416
2417 dbg("%s - %d", __FUNCTION__, baudrate); 2417 dbg("%s - %d", __func__, baudrate);
2418 2418
2419 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { 2419 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
2420 if ( divisor_table[i].BaudRate == baudrate ) { 2420 if ( divisor_table[i].BaudRate == baudrate ) {
@@ -2432,7 +2432,7 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
2432 2432
2433 *divisor = custom; 2433 *divisor = custom;
2434 2434
2435 dbg("%s - Baud %d = %d\n", __FUNCTION__, baudrate, custom); 2435 dbg("%s - Baud %d = %d\n", __func__, baudrate, custom);
2436 return 0; 2436 return 0;
2437 } 2437 }
2438 2438
@@ -2452,7 +2452,7 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2452 unsigned long cmdLen = 0; 2452 unsigned long cmdLen = 0;
2453 int status; 2453 int status;
2454 2454
2455 dbg("%s - write to %s register 0x%02x", (regNum == MCR) ? "MCR" : "LCR", __FUNCTION__, regValue); 2455 dbg("%s - write to %s register 0x%02x", (regNum == MCR) ? "MCR" : "LCR", __func__, regValue);
2456 2456
2457 if (edge_serial->is_epic && 2457 if (edge_serial->is_epic &&
2458 !edge_serial->epic_descriptor.Supports.IOSPWriteMCR && 2458 !edge_serial->epic_descriptor.Supports.IOSPWriteMCR &&
@@ -2513,29 +2513,29 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2513 __u8 txFlow; 2513 __u8 txFlow;
2514 int status; 2514 int status;
2515 2515
2516 dbg("%s - port %d", __FUNCTION__, edge_port->port->number); 2516 dbg("%s - port %d", __func__, edge_port->port->number);
2517 2517
2518 if (!edge_port->open && 2518 if (!edge_port->open &&
2519 !edge_port->openPending) { 2519 !edge_port->openPending) {
2520 dbg("%s - port not opened", __FUNCTION__); 2520 dbg("%s - port not opened", __func__);
2521 return; 2521 return;
2522 } 2522 }
2523 2523
2524 tty = edge_port->port->tty; 2524 tty = edge_port->port->tty;
2525 if ((!tty) || 2525 if ((!tty) ||
2526 (!tty->termios)) { 2526 (!tty->termios)) {
2527 dbg("%s - no tty structures", __FUNCTION__); 2527 dbg("%s - no tty structures", __func__);
2528 return; 2528 return;
2529 } 2529 }
2530 2530
2531 cflag = tty->termios->c_cflag; 2531 cflag = tty->termios->c_cflag;
2532 2532
2533 switch (cflag & CSIZE) { 2533 switch (cflag & CSIZE) {
2534 case CS5: lData = LCR_BITS_5; mask = 0x1f; dbg("%s - data bits = 5", __FUNCTION__); break; 2534 case CS5: lData = LCR_BITS_5; mask = 0x1f; dbg("%s - data bits = 5", __func__); break;
2535 case CS6: lData = LCR_BITS_6; mask = 0x3f; dbg("%s - data bits = 6", __FUNCTION__); break; 2535 case CS6: lData = LCR_BITS_6; mask = 0x3f; dbg("%s - data bits = 6", __func__); break;
2536 case CS7: lData = LCR_BITS_7; mask = 0x7f; dbg("%s - data bits = 7", __FUNCTION__); break; 2536 case CS7: lData = LCR_BITS_7; mask = 0x7f; dbg("%s - data bits = 7", __func__); break;
2537 default: 2537 default:
2538 case CS8: lData = LCR_BITS_8; dbg("%s - data bits = 8", __FUNCTION__); break; 2538 case CS8: lData = LCR_BITS_8; dbg("%s - data bits = 8", __func__); break;
2539 } 2539 }
2540 2540
2541 lParity = LCR_PAR_NONE; 2541 lParity = LCR_PAR_NONE;
@@ -2543,28 +2543,28 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2543 if (cflag & CMSPAR) { 2543 if (cflag & CMSPAR) {
2544 if (cflag & PARODD) { 2544 if (cflag & PARODD) {
2545 lParity = LCR_PAR_MARK; 2545 lParity = LCR_PAR_MARK;
2546 dbg("%s - parity = mark", __FUNCTION__); 2546 dbg("%s - parity = mark", __func__);
2547 } else { 2547 } else {
2548 lParity = LCR_PAR_SPACE; 2548 lParity = LCR_PAR_SPACE;
2549 dbg("%s - parity = space", __FUNCTION__); 2549 dbg("%s - parity = space", __func__);
2550 } 2550 }
2551 } else if (cflag & PARODD) { 2551 } else if (cflag & PARODD) {
2552 lParity = LCR_PAR_ODD; 2552 lParity = LCR_PAR_ODD;
2553 dbg("%s - parity = odd", __FUNCTION__); 2553 dbg("%s - parity = odd", __func__);
2554 } else { 2554 } else {
2555 lParity = LCR_PAR_EVEN; 2555 lParity = LCR_PAR_EVEN;
2556 dbg("%s - parity = even", __FUNCTION__); 2556 dbg("%s - parity = even", __func__);
2557 } 2557 }
2558 } else { 2558 } else {
2559 dbg("%s - parity = none", __FUNCTION__); 2559 dbg("%s - parity = none", __func__);
2560 } 2560 }
2561 2561
2562 if (cflag & CSTOPB) { 2562 if (cflag & CSTOPB) {
2563 lStop = LCR_STOP_2; 2563 lStop = LCR_STOP_2;
2564 dbg("%s - stop bits = 2", __FUNCTION__); 2564 dbg("%s - stop bits = 2", __func__);
2565 } else { 2565 } else {
2566 lStop = LCR_STOP_1; 2566 lStop = LCR_STOP_1;
2567 dbg("%s - stop bits = 1", __FUNCTION__); 2567 dbg("%s - stop bits = 1", __func__);
2568 } 2568 }
2569 2569
2570 /* figure out the flow control settings */ 2570 /* figure out the flow control settings */
@@ -2572,9 +2572,9 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2572 if (cflag & CRTSCTS) { 2572 if (cflag & CRTSCTS) {
2573 rxFlow |= IOSP_RX_FLOW_RTS; 2573 rxFlow |= IOSP_RX_FLOW_RTS;
2574 txFlow |= IOSP_TX_FLOW_CTS; 2574 txFlow |= IOSP_TX_FLOW_CTS;
2575 dbg("%s - RTS/CTS is enabled", __FUNCTION__); 2575 dbg("%s - RTS/CTS is enabled", __func__);
2576 } else { 2576 } else {
2577 dbg("%s - RTS/CTS is disabled", __FUNCTION__); 2577 dbg("%s - RTS/CTS is disabled", __func__);
2578 } 2578 }
2579 2579
2580 /* if we are implementing XON/XOFF, set the start and stop character in the device */ 2580 /* if we are implementing XON/XOFF, set the start and stop character in the device */
@@ -2592,17 +2592,17 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2592 /* if we are implementing INBOUND XON/XOFF */ 2592 /* if we are implementing INBOUND XON/XOFF */
2593 if (I_IXOFF(tty)) { 2593 if (I_IXOFF(tty)) {
2594 rxFlow |= IOSP_RX_FLOW_XON_XOFF; 2594 rxFlow |= IOSP_RX_FLOW_XON_XOFF;
2595 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __FUNCTION__, start_char, stop_char); 2595 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char);
2596 } else { 2596 } else {
2597 dbg("%s - INBOUND XON/XOFF is disabled", __FUNCTION__); 2597 dbg("%s - INBOUND XON/XOFF is disabled", __func__);
2598 } 2598 }
2599 2599
2600 /* if we are implementing OUTBOUND XON/XOFF */ 2600 /* if we are implementing OUTBOUND XON/XOFF */
2601 if (I_IXON(tty)) { 2601 if (I_IXON(tty)) {
2602 txFlow |= IOSP_TX_FLOW_XON_XOFF; 2602 txFlow |= IOSP_TX_FLOW_XON_XOFF;
2603 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __FUNCTION__, start_char, stop_char); 2603 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char);
2604 } else { 2604 } else {
2605 dbg("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__); 2605 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
2606 } 2606 }
2607 } 2607 }
2608 2608
@@ -2645,7 +2645,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2645 baud = 9600; 2645 baud = 9600;
2646 } 2646 }
2647 2647
2648 dbg("%s - baud rate = %d", __FUNCTION__, baud); 2648 dbg("%s - baud rate = %d", __func__, baud);
2649 status = send_cmd_write_baud_rate (edge_port, baud); 2649 status = send_cmd_write_baud_rate (edge_port, baud);
2650 if (status == -1) { 2650 if (status == -1) {
2651 /* Speed change was not possible - put back the old speed */ 2651 /* Speed change was not possible - put back the old speed */
@@ -2843,7 +2843,7 @@ static int edge_startup (struct usb_serial *serial)
2843 /* create our private serial structure */ 2843 /* create our private serial structure */
2844 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); 2844 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
2845 if (edge_serial == NULL) { 2845 if (edge_serial == NULL) {
2846 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2846 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
2847 return -ENOMEM; 2847 return -ENOMEM;
2848 } 2848 }
2849 spin_lock_init(&edge_serial->es_lock); 2849 spin_lock_init(&edge_serial->es_lock);
@@ -2885,19 +2885,19 @@ static int edge_startup (struct usb_serial *serial)
2885 serial->num_ports); 2885 serial->num_ports);
2886 } 2886 }
2887 2887
2888 dbg("%s - time 1 %ld", __FUNCTION__, jiffies); 2888 dbg("%s - time 1 %ld", __func__, jiffies);
2889 2889
2890 /* If not an EPiC device */ 2890 /* If not an EPiC device */
2891 if (!edge_serial->is_epic) { 2891 if (!edge_serial->is_epic) {
2892 /* now load the application firmware into this device */ 2892 /* now load the application firmware into this device */
2893 load_application_firmware (edge_serial); 2893 load_application_firmware (edge_serial);
2894 2894
2895 dbg("%s - time 2 %ld", __FUNCTION__, jiffies); 2895 dbg("%s - time 2 %ld", __func__, jiffies);
2896 2896
2897 /* Check current Edgeport EEPROM and update if necessary */ 2897 /* Check current Edgeport EEPROM and update if necessary */
2898 update_edgeport_E2PROM (edge_serial); 2898 update_edgeport_E2PROM (edge_serial);
2899 2899
2900 dbg("%s - time 3 %ld", __FUNCTION__, jiffies); 2900 dbg("%s - time 3 %ld", __func__, jiffies);
2901 2901
2902 /* set the configuration to use #1 */ 2902 /* set the configuration to use #1 */
2903// dbg("set_configuration 1"); 2903// dbg("set_configuration 1");
@@ -2911,7 +2911,7 @@ static int edge_startup (struct usb_serial *serial)
2911 for (i = 0; i < serial->num_ports; ++i) { 2911 for (i = 0; i < serial->num_ports; ++i) {
2912 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL); 2912 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL);
2913 if (edge_port == NULL) { 2913 if (edge_port == NULL) {
2914 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2914 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
2915 for (j = 0; j < i; ++j) { 2915 for (j = 0; j < i; ++j) {
2916 kfree (usb_get_serial_port_data(serial->port[j])); 2916 kfree (usb_get_serial_port_data(serial->port[j]));
2917 usb_set_serial_port_data(serial->port[j], NULL); 2917 usb_set_serial_port_data(serial->port[j], NULL);
@@ -3017,7 +3017,7 @@ static int edge_startup (struct usb_serial *serial)
3017 * continue as long as the edgeport is connected */ 3017 * continue as long as the edgeport is connected */
3018 response = usb_submit_urb(edge_serial->interrupt_read_urb, GFP_KERNEL); 3018 response = usb_submit_urb(edge_serial->interrupt_read_urb, GFP_KERNEL);
3019 if (response) 3019 if (response)
3020 err("%s - Error %d submitting control urb", __FUNCTION__, response); 3020 err("%s - Error %d submitting control urb", __func__, response);
3021 } 3021 }
3022 return response; 3022 return response;
3023} 3023}
@@ -3032,7 +3032,7 @@ static void edge_shutdown (struct usb_serial *serial)
3032 struct edgeport_serial *edge_serial = usb_get_serial_data(serial); 3032 struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
3033 int i; 3033 int i;
3034 3034
3035 dbg("%s", __FUNCTION__); 3035 dbg("%s", __func__);
3036 3036
3037 /* stop reads and writes on all ports */ 3037 /* stop reads and writes on all ports */
3038 for (i=0; i < serial->num_ports; ++i) { 3038 for (i=0; i < serial->num_ports; ++i) {
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index 6d3008772540..2ec85893f27a 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -111,9 +111,6 @@ static struct usb_serial_driver edgeport_2port_device = {
111 .description = "Edgeport 2 port adapter", 111 .description = "Edgeport 2 port adapter",
112 .usb_driver = &io_driver, 112 .usb_driver = &io_driver,
113 .id_table = edgeport_2port_id_table, 113 .id_table = edgeport_2port_id_table,
114 .num_interrupt_in = 1,
115 .num_bulk_in = 1,
116 .num_bulk_out = 1,
117 .num_ports = 2, 114 .num_ports = 2,
118 .open = edge_open, 115 .open = edge_open,
119 .close = edge_close, 116 .close = edge_close,
@@ -142,9 +139,6 @@ static struct usb_serial_driver edgeport_4port_device = {
142 .description = "Edgeport 4 port adapter", 139 .description = "Edgeport 4 port adapter",
143 .usb_driver = &io_driver, 140 .usb_driver = &io_driver,
144 .id_table = edgeport_4port_id_table, 141 .id_table = edgeport_4port_id_table,
145 .num_interrupt_in = 1,
146 .num_bulk_in = 1,
147 .num_bulk_out = 1,
148 .num_ports = 4, 142 .num_ports = 4,
149 .open = edge_open, 143 .open = edge_open,
150 .close = edge_close, 144 .close = edge_close,
@@ -173,9 +167,6 @@ static struct usb_serial_driver edgeport_8port_device = {
173 .description = "Edgeport 8 port adapter", 167 .description = "Edgeport 8 port adapter",
174 .usb_driver = &io_driver, 168 .usb_driver = &io_driver,
175 .id_table = edgeport_8port_id_table, 169 .id_table = edgeport_8port_id_table,
176 .num_interrupt_in = 1,
177 .num_bulk_in = 1,
178 .num_bulk_out = 1,
179 .num_ports = 8, 170 .num_ports = 8,
180 .open = edge_open, 171 .open = edge_open,
181 .close = edge_close, 172 .close = edge_close,
@@ -203,9 +194,6 @@ static struct usb_serial_driver epic_device = {
203 }, 194 },
204 .description = "EPiC device", 195 .description = "EPiC device",
205 .id_table = Epic_port_id_table, 196 .id_table = Epic_port_id_table,
206 .num_interrupt_in = 1,
207 .num_bulk_in = 1,
208 .num_bulk_out = 1,
209 .num_ports = 1, 197 .num_ports = 1,
210 .open = edge_open, 198 .open = edge_open,
211 .close = edge_close, 199 .close = edge_close,
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index e5ea5ef6335d..05e4fa730730 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -290,7 +290,7 @@ static int TIReadVendorRequestSync (struct usb_device *dev,
290 return status; 290 return status;
291 if (status != size) { 291 if (status != size) {
292 dbg ("%s - wanted to write %d, but only wrote %d", 292 dbg ("%s - wanted to write %d, but only wrote %d",
293 __FUNCTION__, size, status); 293 __func__, size, status);
294 return -ECOMM; 294 return -ECOMM;
295 } 295 }
296 return 0; 296 return 0;
@@ -320,7 +320,7 @@ static int TISendVendorRequestSync (struct usb_device *dev,
320 return status; 320 return status;
321 if (status != size) { 321 if (status != size) {
322 dbg ("%s - wanted to write %d, but only wrote %d", 322 dbg ("%s - wanted to write %d, but only wrote %d",
323 __FUNCTION__, size, status); 323 __func__, size, status);
324 return -ECOMM; 324 return -ECOMM;
325 } 325 }
326 return 0; 326 return 0;
@@ -344,7 +344,7 @@ static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
344{ 344{
345 int port_number = port->number - port->serial->minor; 345 int port_number = port->number - port->serial->minor;
346 346
347 dbg ("%s - port %d, mask %x", __FUNCTION__, port_number, mask); 347 dbg ("%s - port %d, mask %x", __func__, port_number, mask);
348 348
349 return TIWriteCommandSync (port->serial->dev, 349 return TIWriteCommandSync (port->serial->dev,
350 UMPC_PURGE_PORT, 350 UMPC_PURGE_PORT,
@@ -369,7 +369,7 @@ static int TIReadDownloadMemory(struct usb_device *dev, int start_address,
369 __u8 read_length; 369 __u8 read_length;
370 __be16 be_start_address; 370 __be16 be_start_address;
371 371
372 dbg ("%s - @ %x for %d", __FUNCTION__, start_address, length); 372 dbg ("%s - @ %x for %d", __func__, start_address, length);
373 373
374 /* Read in blocks of 64 bytes 374 /* Read in blocks of 64 bytes
375 * (TI firmware can't handle more than 64 byte reads) 375 * (TI firmware can't handle more than 64 byte reads)
@@ -381,7 +381,7 @@ static int TIReadDownloadMemory(struct usb_device *dev, int start_address,
381 read_length = (__u8)length; 381 read_length = (__u8)length;
382 382
383 if (read_length > 1) { 383 if (read_length > 1) {
384 dbg ("%s - @ %x for %d", __FUNCTION__, 384 dbg ("%s - @ %x for %d", __func__,
385 start_address, read_length); 385 start_address, read_length);
386 } 386 }
387 be_start_address = cpu_to_be16 (start_address); 387 be_start_address = cpu_to_be16 (start_address);
@@ -393,12 +393,12 @@ static int TIReadDownloadMemory(struct usb_device *dev, int start_address,
393 read_length); // TransferBufferLength 393 read_length); // TransferBufferLength
394 394
395 if (status) { 395 if (status) {
396 dbg ("%s - ERROR %x", __FUNCTION__, status); 396 dbg ("%s - ERROR %x", __func__, status);
397 return status; 397 return status;
398 } 398 }
399 399
400 if (read_length > 1) { 400 if (read_length > 1) {
401 usb_serial_debug_data(debug, &dev->dev, __FUNCTION__, 401 usb_serial_debug_data(debug, &dev->dev, __func__,
402 read_length, buffer); 402 read_length, buffer);
403 } 403 }
404 404
@@ -434,13 +434,13 @@ static int TIReadBootMemory (struct edgeport_serial *serial, int start_address,
434 &buffer[i], // TransferBuffer 434 &buffer[i], // TransferBuffer
435 0x01); // TransferBufferLength 435 0x01); // TransferBufferLength
436 if (status) { 436 if (status) {
437 dbg ("%s - ERROR %x", __FUNCTION__, status); 437 dbg ("%s - ERROR %x", __func__, status);
438 return status; 438 return status;
439 } 439 }
440 } 440 }
441 441
442 dbg ("%s - start_address = %x, length = %d", __FUNCTION__, start_address, length); 442 dbg ("%s - start_address = %x, length = %d", __func__, start_address, length);
443 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, length, buffer); 443 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer);
444 444
445 serial->TiReadI2C = 1; 445 serial->TiReadI2C = 1;
446 446
@@ -472,8 +472,8 @@ static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address,
472 return status; 472 return status;
473 } 473 }
474 474
475 dbg ("%s - start_sddr = %x, length = %d", __FUNCTION__, start_address, length); 475 dbg ("%s - start_sddr = %x, length = %d", __func__, start_address, length);
476 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, length, buffer); 476 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer);
477 477
478 return status; 478 return status;
479} 479}
@@ -494,8 +494,8 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
494 if (write_length > length) 494 if (write_length > length)
495 write_length = length; 495 write_length = length;
496 496
497 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __FUNCTION__, start_address, write_length); 497 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __func__, start_address, write_length);
498 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, write_length, buffer); 498 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer);
499 499
500 /* Write first page */ 500 /* Write first page */
501 be_start_address = cpu_to_be16 (start_address); 501 be_start_address = cpu_to_be16 (start_address);
@@ -506,7 +506,7 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
506 buffer, // TransferBuffer 506 buffer, // TransferBuffer
507 write_length); 507 write_length);
508 if (status) { 508 if (status) {
509 dbg ("%s - ERROR %d", __FUNCTION__, status); 509 dbg ("%s - ERROR %d", __func__, status);
510 return status; 510 return status;
511 } 511 }
512 512
@@ -521,8 +521,8 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
521 else 521 else
522 write_length = length; 522 write_length = length;
523 523
524 dbg ("%s - Page Write Addr = %x, length = %d", __FUNCTION__, start_address, write_length); 524 dbg ("%s - Page Write Addr = %x, length = %d", __func__, start_address, write_length);
525 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, write_length, buffer); 525 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer);
526 526
527 /* Write next page */ 527 /* Write next page */
528 be_start_address = cpu_to_be16 (start_address); 528 be_start_address = cpu_to_be16 (start_address);
@@ -533,7 +533,7 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
533 buffer, // TransferBuffer 533 buffer, // TransferBuffer
534 write_length); // TransferBufferLength 534 write_length); // TransferBufferLength
535 if (status) { 535 if (status) {
536 dev_err (&serial->serial->dev->dev, "%s - ERROR %d\n", __FUNCTION__, status); 536 dev_err (&serial->serial->dev->dev, "%s - ERROR %d\n", __func__, status);
537 return status; 537 return status;
538 } 538 }
539 539
@@ -559,7 +559,7 @@ static int TIIsTxActive (struct edgeport_port *port)
559 559
560 oedb = kmalloc (sizeof (* oedb), GFP_KERNEL); 560 oedb = kmalloc (sizeof (* oedb), GFP_KERNEL);
561 if (!oedb) { 561 if (!oedb) {
562 dev_err (&port->port->dev, "%s - out of memory\n", __FUNCTION__); 562 dev_err (&port->port->dev, "%s - out of memory\n", __func__);
563 return -ENOMEM; 563 return -ENOMEM;
564 } 564 }
565 565
@@ -579,7 +579,7 @@ static int TIIsTxActive (struct edgeport_port *port)
579 if (status) 579 if (status)
580 goto exit_is_tx_active; 580 goto exit_is_tx_active;
581 581
582 dbg ("%s - XByteCount 0x%X", __FUNCTION__, oedb->XByteCount); 582 dbg ("%s - XByteCount 0x%X", __func__, oedb->XByteCount);
583 583
584 /* and the LSR */ 584 /* and the LSR */
585 status = TIReadRam (port->port->serial->dev, 585 status = TIReadRam (port->port->serial->dev,
@@ -589,7 +589,7 @@ static int TIIsTxActive (struct edgeport_port *port)
589 589
590 if (status) 590 if (status)
591 goto exit_is_tx_active; 591 goto exit_is_tx_active;
592 dbg ("%s - LSR = 0x%X", __FUNCTION__, *lsr); 592 dbg ("%s - LSR = 0x%X", __func__, *lsr);
593 593
594 /* If either buffer has data or we are transmitting then return TRUE */ 594 /* If either buffer has data or we are transmitting then return TRUE */
595 if ((oedb->XByteCount & 0x80 ) != 0 ) 595 if ((oedb->XByteCount & 0x80 ) != 0 )
@@ -600,7 +600,7 @@ static int TIIsTxActive (struct edgeport_port *port)
600 600
601 /* We return Not Active if we get any kind of error */ 601 /* We return Not Active if we get any kind of error */
602exit_is_tx_active: 602exit_is_tx_active:
603 dbg ("%s - return %d", __FUNCTION__, bytes_left ); 603 dbg ("%s - return %d", __func__, bytes_left );
604 604
605 kfree(lsr); 605 kfree(lsr);
606 kfree(oedb); 606 kfree(oedb);
@@ -654,7 +654,7 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
654 /* (TIIsTxActive doesn't seem to wait for the last byte) */ 654 /* (TIIsTxActive doesn't seem to wait for the last byte) */
655 if ((baud_rate=port->baud_rate) == 0) 655 if ((baud_rate=port->baud_rate) == 0)
656 baud_rate = 50; 656 baud_rate = 50;
657 msleep(max(1,(10000+baud_rate-1)/baud_rate)); 657 msleep(max(1, DIV_ROUND_UP(10000, baud_rate)));
658} 658}
659 659
660static int TIChooseConfiguration (struct usb_device *dev) 660static int TIChooseConfiguration (struct usb_device *dev)
@@ -664,11 +664,11 @@ static int TIChooseConfiguration (struct usb_device *dev)
664 // we want. However, we just support one config at this point, 664 // we want. However, we just support one config at this point,
665 // configuration # 1, which is Config Descriptor 0. 665 // configuration # 1, which is Config Descriptor 0.
666 666
667 dbg ("%s - Number of Interfaces = %d", __FUNCTION__, dev->config->desc.bNumInterfaces); 667 dbg ("%s - Number of Interfaces = %d", __func__, dev->config->desc.bNumInterfaces);
668 dbg ("%s - MAX Power = %d", __FUNCTION__, dev->config->desc.bMaxPower*2); 668 dbg ("%s - MAX Power = %d", __func__, dev->config->desc.bMaxPower*2);
669 669
670 if (dev->config->desc.bNumInterfaces != 1) { 670 if (dev->config->desc.bNumInterfaces != 1) {
671 dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __FUNCTION__); 671 dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__);
672 return -ENODEV; 672 return -ENODEV;
673 } 673 }
674 674
@@ -751,7 +751,7 @@ static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
751 cs = (__u8)(cs + buffer[i]); 751 cs = (__u8)(cs + buffer[i]);
752 } 752 }
753 if (cs != rom_desc->CheckSum) { 753 if (cs != rom_desc->CheckSum) {
754 dbg ("%s - Mismatch %x - %x", __FUNCTION__, rom_desc->CheckSum, cs); 754 dbg ("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
755 return -EINVAL; 755 return -EINVAL;
756 } 756 }
757 return 0; 757 return 0;
@@ -769,12 +769,12 @@ static int TiValidateI2cImage (struct edgeport_serial *serial)
769 769
770 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 770 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
771 if (!rom_desc) { 771 if (!rom_desc) {
772 dev_err (dev, "%s - out of memory\n", __FUNCTION__); 772 dev_err (dev, "%s - out of memory\n", __func__);
773 return -ENOMEM; 773 return -ENOMEM;
774 } 774 }
775 buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL); 775 buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL);
776 if (!buffer) { 776 if (!buffer) {
777 dev_err (dev, "%s - out of memory when allocating buffer\n", __FUNCTION__); 777 dev_err (dev, "%s - out of memory when allocating buffer\n", __func__);
778 kfree (rom_desc); 778 kfree (rom_desc);
779 return -ENOMEM; 779 return -ENOMEM;
780 } 780 }
@@ -785,7 +785,7 @@ static int TiValidateI2cImage (struct edgeport_serial *serial)
785 goto ExitTiValidateI2cImage; 785 goto ExitTiValidateI2cImage;
786 786
787 if (*buffer != UMP5152 && *buffer != UMP3410) { 787 if (*buffer != UMP5152 && *buffer != UMP3410) {
788 dev_err (dev, "%s - invalid buffer signature\n", __FUNCTION__); 788 dev_err (dev, "%s - invalid buffer signature\n", __func__);
789 status = -ENODEV; 789 status = -ENODEV;
790 goto ExitTiValidateI2cImage; 790 goto ExitTiValidateI2cImage;
791 } 791 }
@@ -801,11 +801,11 @@ static int TiValidateI2cImage (struct edgeport_serial *serial)
801 801
802 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) { 802 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) {
803 status = -ENODEV; 803 status = -ENODEV;
804 dbg ("%s - structure too big, erroring out.", __FUNCTION__); 804 dbg ("%s - structure too big, erroring out.", __func__);
805 break; 805 break;
806 } 806 }
807 807
808 dbg ("%s Type = 0x%x", __FUNCTION__, rom_desc->Type); 808 dbg ("%s Type = 0x%x", __func__, rom_desc->Type);
809 809
810 // Skip type 2 record 810 // Skip type 2 record
811 ttype = rom_desc->Type & 0x0f; 811 ttype = rom_desc->Type & 0x0f;
@@ -845,13 +845,13 @@ static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer)
845 845
846 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 846 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
847 if (!rom_desc) { 847 if (!rom_desc) {
848 dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __FUNCTION__); 848 dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __func__);
849 return -ENOMEM; 849 return -ENOMEM;
850 } 850 }
851 start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc); 851 start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc);
852 852
853 if (!start_address) { 853 if (!start_address) {
854 dbg ("%s - Edge Descriptor not found in I2C", __FUNCTION__); 854 dbg ("%s - Edge Descriptor not found in I2C", __func__);
855 status = -ENODEV; 855 status = -ENODEV;
856 goto exit; 856 goto exit;
857 } 857 }
@@ -867,12 +867,12 @@ static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer)
867 status = ValidChecksum(rom_desc, buffer); 867 status = ValidChecksum(rom_desc, buffer);
868 868
869 desc = (struct edge_ti_manuf_descriptor *)buffer; 869 desc = (struct edge_ti_manuf_descriptor *)buffer;
870 dbg ( "%s - IonConfig 0x%x", __FUNCTION__, desc->IonConfig ); 870 dbg ( "%s - IonConfig 0x%x", __func__, desc->IonConfig );
871 dbg ( "%s - Version %d", __FUNCTION__, desc->Version ); 871 dbg ( "%s - Version %d", __func__, desc->Version );
872 dbg ( "%s - Cpu/Board 0x%x", __FUNCTION__, desc->CpuRev_BoardRev ); 872 dbg ( "%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev );
873 dbg ( "%s - NumPorts %d", __FUNCTION__, desc->NumPorts ); 873 dbg ( "%s - NumPorts %d", __func__, desc->NumPorts );
874 dbg ( "%s - NumVirtualPorts %d", __FUNCTION__, desc->NumVirtualPorts ); 874 dbg ( "%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts );
875 dbg ( "%s - TotalPorts %d", __FUNCTION__, desc->TotalPorts ); 875 dbg ( "%s - TotalPorts %d", __func__, desc->TotalPorts );
876 876
877exit: 877exit:
878 kfree (rom_desc); 878 kfree (rom_desc);
@@ -902,7 +902,7 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
902 902
903 buffer = kmalloc (buffer_size, GFP_KERNEL); 903 buffer = kmalloc (buffer_size, GFP_KERNEL);
904 if (!buffer) { 904 if (!buffer) {
905 dev_err (dev, "%s - out of memory\n", __FUNCTION__); 905 dev_err (dev, "%s - out of memory\n", __func__);
906 return -ENOMEM; 906 return -ENOMEM;
907 } 907 }
908 908
@@ -955,11 +955,11 @@ static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial)
955 &data, // TransferBuffer 955 &data, // TransferBuffer
956 0x01); // TransferBufferLength 956 0x01); // TransferBufferLength
957 if (status) 957 if (status)
958 dbg ("%s - read 2 status error = %d", __FUNCTION__, status); 958 dbg ("%s - read 2 status error = %d", __func__, status);
959 else 959 else
960 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data); 960 dbg ("%s - read 2 data = 0x%x", __func__, data);
961 if ((!status) && (data == UMP5152 || data == UMP3410)) { 961 if ((!status) && (data == UMP5152 || data == UMP3410)) {
962 dbg ("%s - ROM_TYPE_II", __FUNCTION__); 962 dbg ("%s - ROM_TYPE_II", __func__);
963 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 963 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
964 return 0; 964 return 0;
965 } 965 }
@@ -972,16 +972,16 @@ static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial)
972 &data, // TransferBuffer 972 &data, // TransferBuffer
973 0x01); // TransferBufferLength 973 0x01); // TransferBufferLength
974 if (status) 974 if (status)
975 dbg ("%s - read 3 status error = %d", __FUNCTION__, status); 975 dbg ("%s - read 3 status error = %d", __func__, status);
976 else 976 else
977 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data); 977 dbg ("%s - read 2 data = 0x%x", __func__, data);
978 if ((!status) && (data == UMP5152 || data == UMP3410)) { 978 if ((!status) && (data == UMP5152 || data == UMP3410)) {
979 dbg ("%s - ROM_TYPE_III", __FUNCTION__); 979 dbg ("%s - ROM_TYPE_III", __func__);
980 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III; 980 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
981 return 0; 981 return 0;
982 } 982 }
983 983
984 dbg ("%s - Unknown", __FUNCTION__); 984 dbg ("%s - Unknown", __func__);
985 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 985 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
986 return -ENODEV; 986 return -ENODEV;
987} 987}
@@ -1063,7 +1063,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1063 1063
1064 interface = &serial->serial->interface->cur_altsetting->desc; 1064 interface = &serial->serial->interface->cur_altsetting->desc;
1065 if (!interface) { 1065 if (!interface) {
1066 dev_err (dev, "%s - no interface set, error!\n", __FUNCTION__); 1066 dev_err (dev, "%s - no interface set, error!\n", __func__);
1067 return -ENODEV; 1067 return -ENODEV;
1068 } 1068 }
1069 1069
@@ -1086,12 +1086,11 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1086 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) { 1086 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
1087 struct ti_i2c_desc *rom_desc; 1087 struct ti_i2c_desc *rom_desc;
1088 1088
1089 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN DOWNLOAD MODE>>>>>>>>>>", __FUNCTION__); 1089 dbg("%s - RUNNING IN DOWNLOAD MODE", __func__);
1090 1090
1091 status = TiValidateI2cImage (serial); 1091 status = TiValidateI2cImage (serial);
1092 if (status) { 1092 if (status) {
1093 dbg ("%s - <<<<<<<<<<<<<<<DOWNLOAD MODE -- BAD I2C >>>>>>>>>>", 1093 dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__);
1094 __FUNCTION__);
1095 return status; 1094 return status;
1096 } 1095 }
1097 1096
@@ -1100,7 +1099,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1100 */ 1099 */
1101 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); 1100 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1102 if (!ti_manuf_desc) { 1101 if (!ti_manuf_desc) {
1103 dev_err (dev, "%s - out of memory.\n", __FUNCTION__); 1102 dev_err (dev, "%s - out of memory.\n", __func__);
1104 return -ENOMEM; 1103 return -ENOMEM;
1105 } 1104 }
1106 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); 1105 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
@@ -1111,7 +1110,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1111 1110
1112 // Check version number of ION descriptor 1111 // Check version number of ION descriptor
1113 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { 1112 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1114 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__, 1113 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __func__,
1115 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); 1114 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1116 kfree (ti_manuf_desc); 1115 kfree (ti_manuf_desc);
1117 return -EINVAL; 1116 return -EINVAL;
@@ -1119,7 +1118,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1119 1118
1120 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 1119 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
1121 if (!rom_desc) { 1120 if (!rom_desc) {
1122 dev_err (dev, "%s - out of memory.\n", __FUNCTION__); 1121 dev_err (dev, "%s - out of memory.\n", __func__);
1123 kfree (ti_manuf_desc); 1122 kfree (ti_manuf_desc);
1124 return -ENOMEM; 1123 return -ENOMEM;
1125 } 1124 }
@@ -1129,11 +1128,11 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1129 struct ti_i2c_firmware_rec *firmware_version; 1128 struct ti_i2c_firmware_rec *firmware_version;
1130 __u8 record; 1129 __u8 record;
1131 1130
1132 dbg ("%s - Found Type FIRMWARE (Type 2) record", __FUNCTION__); 1131 dbg ("%s - Found Type FIRMWARE (Type 2) record", __func__);
1133 1132
1134 firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL); 1133 firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL);
1135 if (!firmware_version) { 1134 if (!firmware_version) {
1136 dev_err (dev, "%s - out of memory.\n", __FUNCTION__); 1135 dev_err (dev, "%s - out of memory.\n", __func__);
1137 kfree (rom_desc); 1136 kfree (rom_desc);
1138 kfree (ti_manuf_desc); 1137 kfree (ti_manuf_desc);
1139 return -ENOMEM; 1138 return -ENOMEM;
@@ -1159,7 +1158,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1159 (OperationalCodeImageVersion.MinorVersion); 1158 (OperationalCodeImageVersion.MinorVersion);
1160 1159
1161 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d", 1160 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d",
1162 __FUNCTION__, 1161 __func__,
1163 firmware_version->Ver_Major, 1162 firmware_version->Ver_Major,
1164 firmware_version->Ver_Minor, 1163 firmware_version->Ver_Minor,
1165 OperationalCodeImageVersion.MajorVersion, 1164 OperationalCodeImageVersion.MajorVersion,
@@ -1168,7 +1167,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1168 // Check if we have an old version in the I2C and update if necessary 1167 // Check if we have an old version in the I2C and update if necessary
1169 if (download_cur_ver != download_new_ver) { 1168 if (download_cur_ver != download_new_ver) {
1170 dbg ("%s - Update I2C Download from %d.%d to %d.%d", 1169 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1171 __FUNCTION__, 1170 __func__,
1172 firmware_version->Ver_Major, 1171 firmware_version->Ver_Major,
1173 firmware_version->Ver_Minor, 1172 firmware_version->Ver_Minor,
1174 OperationalCodeImageVersion.MajorVersion, 1173 OperationalCodeImageVersion.MajorVersion,
@@ -1210,14 +1209,14 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1210 } 1209 }
1211 1210
1212 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) { 1211 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1213 dev_err (dev, "%s - error resetting device\n", __FUNCTION__); 1212 dev_err (dev, "%s - error resetting device\n", __func__);
1214 kfree (firmware_version); 1213 kfree (firmware_version);
1215 kfree (rom_desc); 1214 kfree (rom_desc);
1216 kfree (ti_manuf_desc); 1215 kfree (ti_manuf_desc);
1217 return -ENODEV; 1216 return -ENODEV;
1218 } 1217 }
1219 1218
1220 dbg ("%s - HARDWARE RESET", __FUNCTION__); 1219 dbg ("%s - HARDWARE RESET", __func__);
1221 1220
1222 // Reset UMP -- Back to BOOT MODE 1221 // Reset UMP -- Back to BOOT MODE
1223 status = TISendVendorRequestSync (serial->serial->dev, 1222 status = TISendVendorRequestSync (serial->serial->dev,
@@ -1227,7 +1226,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1227 NULL, // TransferBuffer 1226 NULL, // TransferBuffer
1228 0); // TransferBufferLength 1227 0); // TransferBufferLength
1229 1228
1230 dbg ( "%s - HARDWARE RESET return %d", __FUNCTION__, status); 1229 dbg ( "%s - HARDWARE RESET return %d", __func__, status);
1231 1230
1232 /* return an error on purpose. */ 1231 /* return an error on purpose. */
1233 kfree (firmware_version); 1232 kfree (firmware_version);
@@ -1245,7 +1244,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1245 1244
1246 header = kmalloc (HEADER_SIZE, GFP_KERNEL); 1245 header = kmalloc (HEADER_SIZE, GFP_KERNEL);
1247 if (!header) { 1246 if (!header) {
1248 dev_err (dev, "%s - out of memory.\n", __FUNCTION__); 1247 dev_err (dev, "%s - out of memory.\n", __func__);
1249 kfree (rom_desc); 1248 kfree (rom_desc);
1250 kfree (ti_manuf_desc); 1249 kfree (ti_manuf_desc);
1251 return -ENOMEM; 1250 return -ENOMEM;
@@ -1253,14 +1252,14 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1253 1252
1254 vheader = kmalloc (HEADER_SIZE, GFP_KERNEL); 1253 vheader = kmalloc (HEADER_SIZE, GFP_KERNEL);
1255 if (!vheader) { 1254 if (!vheader) {
1256 dev_err (dev, "%s - out of memory.\n", __FUNCTION__); 1255 dev_err (dev, "%s - out of memory.\n", __func__);
1257 kfree (header); 1256 kfree (header);
1258 kfree (rom_desc); 1257 kfree (rom_desc);
1259 kfree (ti_manuf_desc); 1258 kfree (ti_manuf_desc);
1260 return -ENOMEM; 1259 return -ENOMEM;
1261 } 1260 }
1262 1261
1263 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __FUNCTION__); 1262 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __func__);
1264 1263
1265 // In order to update the I2C firmware we must change the type 2 record to type 0xF2. 1264 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1266 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver 1265 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
@@ -1298,7 +1297,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1298 vheader); 1297 vheader);
1299 1298
1300 if (status) { 1299 if (status) {
1301 dbg ("%s - can't read header back", __FUNCTION__); 1300 dbg ("%s - can't read header back", __func__);
1302 kfree (vheader); 1301 kfree (vheader);
1303 kfree (header); 1302 kfree (header);
1304 kfree (rom_desc); 1303 kfree (rom_desc);
@@ -1306,7 +1305,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1306 return status; 1305 return status;
1307 } 1306 }
1308 if (memcmp(vheader, header, HEADER_SIZE)) { 1307 if (memcmp(vheader, header, HEADER_SIZE)) {
1309 dbg ("%s - write download record failed", __FUNCTION__); 1308 dbg ("%s - write download record failed", __func__);
1310 kfree (vheader); 1309 kfree (vheader);
1311 kfree (header); 1310 kfree (header);
1312 kfree (rom_desc); 1311 kfree (rom_desc);
@@ -1317,7 +1316,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1317 kfree (vheader); 1316 kfree (vheader);
1318 kfree (header); 1317 kfree (header);
1319 1318
1320 dbg ("%s - Start firmware update", __FUNCTION__); 1319 dbg ("%s - Start firmware update", __func__);
1321 1320
1322 // Tell firmware to copy download image into I2C 1321 // Tell firmware to copy download image into I2C
1323 status = TISendVendorRequestSync (serial->serial->dev, 1322 status = TISendVendorRequestSync (serial->serial->dev,
@@ -1327,9 +1326,9 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1327 NULL, // TransferBuffer 1326 NULL, // TransferBuffer
1328 0); // TransferBufferLength 1327 0); // TransferBufferLength
1329 1328
1330 dbg ("%s - Update complete 0x%x", __FUNCTION__, status); 1329 dbg ("%s - Update complete 0x%x", __func__, status);
1331 if (status) { 1330 if (status) {
1332 dev_err (dev, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __FUNCTION__); 1331 dev_err (dev, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __func__);
1333 kfree (rom_desc); 1332 kfree (rom_desc);
1334 kfree (ti_manuf_desc); 1333 kfree (ti_manuf_desc);
1335 return status; 1334 return status;
@@ -1345,8 +1344,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1345 /********************************************************************/ 1344 /********************************************************************/
1346 /* Boot Mode */ 1345 /* Boot Mode */
1347 /********************************************************************/ 1346 /********************************************************************/
1348 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN BOOT MODE>>>>>>>>>>>>>>>", 1347 dbg("%s - RUNNING IN BOOT MODE", __func__);
1349 __FUNCTION__);
1350 1348
1351 // Configure the TI device so we can use the BULK pipes for download 1349 // Configure the TI device so we can use the BULK pipes for download
1352 status = TIConfigureBootDevice (serial->serial->dev); 1350 status = TIConfigureBootDevice (serial->serial->dev);
@@ -1354,7 +1352,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1354 return status; 1352 return status;
1355 1353
1356 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor) != USB_VENDOR_ID_ION) { 1354 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor) != USB_VENDOR_ID_ION) {
1357 dbg ("%s - VID = 0x%x", __FUNCTION__, 1355 dbg ("%s - VID = 0x%x", __func__,
1358 le16_to_cpu(serial->serial->dev->descriptor.idVendor)); 1356 le16_to_cpu(serial->serial->dev->descriptor.idVendor));
1359 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 1357 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1360 goto StayInBootMode; 1358 goto StayInBootMode;
@@ -1368,7 +1366,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1368 1366
1369 // Registry variable set? 1367 // Registry variable set?
1370 if (TIStayInBootMode) { 1368 if (TIStayInBootMode) {
1371 dbg ("%s - TIStayInBootMode", __FUNCTION__); 1369 dbg ("%s - TIStayInBootMode", __func__);
1372 goto StayInBootMode; 1370 goto StayInBootMode;
1373 } 1371 }
1374 1372
@@ -1385,7 +1383,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1385 */ 1383 */
1386 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); 1384 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1387 if (!ti_manuf_desc) { 1385 if (!ti_manuf_desc) {
1388 dev_err (dev, "%s - out of memory.\n", __FUNCTION__); 1386 dev_err (dev, "%s - out of memory.\n", __func__);
1389 return -ENOMEM; 1387 return -ENOMEM;
1390 } 1388 }
1391 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); 1389 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
@@ -1396,7 +1394,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1396 1394
1397 // Check for version 2 1395 // Check for version 2
1398 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { 1396 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1399 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__, 1397 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __func__,
1400 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); 1398 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1401 kfree (ti_manuf_desc); 1399 kfree (ti_manuf_desc);
1402 goto StayInBootMode; 1400 goto StayInBootMode;
@@ -1420,7 +1418,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1420 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header)); 1418 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header));
1421 buffer = kmalloc (buffer_size, GFP_KERNEL); 1419 buffer = kmalloc (buffer_size, GFP_KERNEL);
1422 if (!buffer) { 1420 if (!buffer) {
1423 dev_err (dev, "%s - out of memory\n", __FUNCTION__); 1421 dev_err (dev, "%s - out of memory\n", __func__);
1424 return -ENOMEM; 1422 return -ENOMEM;
1425 } 1423 }
1426 1424
@@ -1440,20 +1438,20 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1440 header->CheckSum = cs; 1438 header->CheckSum = cs;
1441 1439
1442 // Download the operational code 1440 // Download the operational code
1443 dbg ("%s - Downloading operational code image (TI UMP)", __FUNCTION__); 1441 dbg ("%s - Downloading operational code image (TI UMP)", __func__);
1444 status = TIDownloadCodeImage (serial, buffer, buffer_size); 1442 status = TIDownloadCodeImage (serial, buffer, buffer_size);
1445 1443
1446 kfree (buffer); 1444 kfree (buffer);
1447 1445
1448 if (status) { 1446 if (status) {
1449 dbg ("%s - Error downloading operational code image", __FUNCTION__); 1447 dbg ("%s - Error downloading operational code image", __func__);
1450 return status; 1448 return status;
1451 } 1449 }
1452 1450
1453 // Device will reboot 1451 // Device will reboot
1454 serial->product_info.TiMode = TI_MODE_TRANSITIONING; 1452 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1455 1453
1456 dbg ("%s - Download successful -- Device rebooting...", __FUNCTION__); 1454 dbg ("%s - Download successful -- Device rebooting...", __func__);
1457 1455
1458 /* return an error on purpose */ 1456 /* return an error on purpose */
1459 return -ENODEV; 1457 return -ENODEV;
@@ -1461,7 +1459,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1461 1459
1462StayInBootMode: 1460StayInBootMode:
1463 // Eprom is invalid or blank stay in boot mode 1461 // Eprom is invalid or blank stay in boot mode
1464 dbg ("%s - <<<<<<<<<<<<<<<STAYING IN BOOT MODE>>>>>>>>>>>>", __FUNCTION__); 1462 dbg("%s - STAYING IN BOOT MODE", __func__);
1465 serial->product_info.TiMode = TI_MODE_BOOT; 1463 serial->product_info.TiMode = TI_MODE_BOOT;
1466 1464
1467 return 0; 1465 return 0;
@@ -1472,7 +1470,7 @@ static int TISetDtr (struct edgeport_port *port)
1472{ 1470{
1473 int port_number = port->port->number - port->port->serial->minor; 1471 int port_number = port->port->number - port->port->serial->minor;
1474 1472
1475 dbg ("%s", __FUNCTION__); 1473 dbg ("%s", __func__);
1476 port->shadow_mcr |= MCR_DTR; 1474 port->shadow_mcr |= MCR_DTR;
1477 1475
1478 return TIWriteCommandSync (port->port->serial->dev, 1476 return TIWriteCommandSync (port->port->serial->dev,
@@ -1487,7 +1485,7 @@ static int TIClearDtr (struct edgeport_port *port)
1487{ 1485{
1488 int port_number = port->port->number - port->port->serial->minor; 1486 int port_number = port->port->number - port->port->serial->minor;
1489 1487
1490 dbg ("%s", __FUNCTION__); 1488 dbg ("%s", __func__);
1491 port->shadow_mcr &= ~MCR_DTR; 1489 port->shadow_mcr &= ~MCR_DTR;
1492 1490
1493 return TIWriteCommandSync (port->port->serial->dev, 1491 return TIWriteCommandSync (port->port->serial->dev,
@@ -1502,7 +1500,7 @@ static int TISetRts (struct edgeport_port *port)
1502{ 1500{
1503 int port_number = port->port->number - port->port->serial->minor; 1501 int port_number = port->port->number - port->port->serial->minor;
1504 1502
1505 dbg ("%s", __FUNCTION__); 1503 dbg ("%s", __func__);
1506 port->shadow_mcr |= MCR_RTS; 1504 port->shadow_mcr |= MCR_RTS;
1507 1505
1508 return TIWriteCommandSync (port->port->serial->dev, 1506 return TIWriteCommandSync (port->port->serial->dev,
@@ -1517,7 +1515,7 @@ static int TIClearRts (struct edgeport_port *port)
1517{ 1515{
1518 int port_number = port->port->number - port->port->serial->minor; 1516 int port_number = port->port->number - port->port->serial->minor;
1519 1517
1520 dbg ("%s", __FUNCTION__); 1518 dbg ("%s", __func__);
1521 port->shadow_mcr &= ~MCR_RTS; 1519 port->shadow_mcr &= ~MCR_RTS;
1522 1520
1523 return TIWriteCommandSync (port->port->serial->dev, 1521 return TIWriteCommandSync (port->port->serial->dev,
@@ -1532,7 +1530,7 @@ static int TISetLoopBack (struct edgeport_port *port)
1532{ 1530{
1533 int port_number = port->port->number - port->port->serial->minor; 1531 int port_number = port->port->number - port->port->serial->minor;
1534 1532
1535 dbg ("%s", __FUNCTION__); 1533 dbg ("%s", __func__);
1536 1534
1537 return TIWriteCommandSync (port->port->serial->dev, 1535 return TIWriteCommandSync (port->port->serial->dev,
1538 UMPC_SET_CLR_LOOPBACK, 1536 UMPC_SET_CLR_LOOPBACK,
@@ -1546,7 +1544,7 @@ static int TIClearLoopBack (struct edgeport_port *port)
1546{ 1544{
1547 int port_number = port->port->number - port->port->serial->minor; 1545 int port_number = port->port->number - port->port->serial->minor;
1548 1546
1549 dbg ("%s", __FUNCTION__); 1547 dbg ("%s", __func__);
1550 1548
1551 return TIWriteCommandSync (port->port->serial->dev, 1549 return TIWriteCommandSync (port->port->serial->dev,
1552 UMPC_SET_CLR_LOOPBACK, 1550 UMPC_SET_CLR_LOOPBACK,
@@ -1560,7 +1558,7 @@ static int TISetBreak (struct edgeport_port *port)
1560{ 1558{
1561 int port_number = port->port->number - port->port->serial->minor; 1559 int port_number = port->port->number - port->port->serial->minor;
1562 1560
1563 dbg ("%s", __FUNCTION__); 1561 dbg ("%s", __func__);
1564 1562
1565 return TIWriteCommandSync (port->port->serial->dev, 1563 return TIWriteCommandSync (port->port->serial->dev,
1566 UMPC_SET_CLR_BREAK, 1564 UMPC_SET_CLR_BREAK,
@@ -1574,7 +1572,7 @@ static int TIClearBreak (struct edgeport_port *port)
1574{ 1572{
1575 int port_number = port->port->number - port->port->serial->minor; 1573 int port_number = port->port->number - port->port->serial->minor;
1576 1574
1577 dbg ("%s", __FUNCTION__); 1575 dbg ("%s", __func__);
1578 1576
1579 return TIWriteCommandSync (port->port->serial->dev, 1577 return TIWriteCommandSync (port->port->serial->dev,
1580 UMPC_SET_CLR_BREAK, 1578 UMPC_SET_CLR_BREAK,
@@ -1588,7 +1586,7 @@ static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
1588{ 1586{
1589 int status = 0; 1587 int status = 0;
1590 1588
1591 dbg ("%s - %x", __FUNCTION__, mcr); 1589 dbg ("%s - %x", __func__, mcr);
1592 1590
1593 if (mcr & MCR_DTR) 1591 if (mcr & MCR_DTR)
1594 status = TISetDtr (port); 1592 status = TISetDtr (port);
@@ -1642,7 +1640,7 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1642 struct async_icount *icount; 1640 struct async_icount *icount;
1643 struct tty_struct *tty; 1641 struct tty_struct *tty;
1644 1642
1645 dbg ("%s - %02x", __FUNCTION__, msr); 1643 dbg ("%s - %02x", __func__, msr);
1646 1644
1647 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 1645 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1648 icount = &edge_port->icount; 1646 icount = &edge_port->icount;
@@ -1681,7 +1679,7 @@ static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8
1681 struct async_icount *icount; 1679 struct async_icount *icount;
1682 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); 1680 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
1683 1681
1684 dbg ("%s - %02x", __FUNCTION__, new_lsr); 1682 dbg ("%s - %02x", __func__, new_lsr);
1685 1683
1686 edge_port->shadow_lsr = lsr; 1684 edge_port->shadow_lsr = lsr;
1687 1685
@@ -1712,7 +1710,7 @@ static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8
1712 1710
1713static void edge_interrupt_callback (struct urb *urb) 1711static void edge_interrupt_callback (struct urb *urb)
1714{ 1712{
1715 struct edgeport_serial *edge_serial = (struct edgeport_serial *)urb->context; 1713 struct edgeport_serial *edge_serial = urb->context;
1716 struct usb_serial_port *port; 1714 struct usb_serial_port *port;
1717 struct edgeport_port *edge_port; 1715 struct edgeport_port *edge_port;
1718 unsigned char *data = urb->transfer_buffer; 1716 unsigned char *data = urb->transfer_buffer;
@@ -1724,7 +1722,7 @@ static void edge_interrupt_callback (struct urb *urb)
1724 __u8 msr; 1722 __u8 msr;
1725 int status = urb->status; 1723 int status = urb->status;
1726 1724
1727 dbg("%s", __FUNCTION__); 1725 dbg("%s", __func__);
1728 1726
1729 switch (status) { 1727 switch (status) {
1730 case 0: 1728 case 0:
@@ -1735,34 +1733,34 @@ static void edge_interrupt_callback (struct urb *urb)
1735 case -ESHUTDOWN: 1733 case -ESHUTDOWN:
1736 /* this urb is terminated, clean up */ 1734 /* this urb is terminated, clean up */
1737 dbg("%s - urb shutting down with status: %d", 1735 dbg("%s - urb shutting down with status: %d",
1738 __FUNCTION__, status); 1736 __func__, status);
1739 return; 1737 return;
1740 default: 1738 default:
1741 dev_err(&urb->dev->dev, "%s - nonzero urb status received: " 1739 dev_err(&urb->dev->dev, "%s - nonzero urb status received: "
1742 "%d\n", __FUNCTION__, status); 1740 "%d\n", __func__, status);
1743 goto exit; 1741 goto exit;
1744 } 1742 }
1745 1743
1746 if (!length) { 1744 if (!length) {
1747 dbg ("%s - no data in urb", __FUNCTION__); 1745 dbg ("%s - no data in urb", __func__);
1748 goto exit; 1746 goto exit;
1749 } 1747 }
1750 1748
1751 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __FUNCTION__, length, data); 1749 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data);
1752 1750
1753 if (length != 2) { 1751 if (length != 2) {
1754 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__, length); 1752 dbg ("%s - expecting packet of size 2, got %d", __func__, length);
1755 goto exit; 1753 goto exit;
1756 } 1754 }
1757 1755
1758 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]); 1756 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]);
1759 function = TIUMP_GET_FUNC_FROM_CODE (data[0]); 1757 function = TIUMP_GET_FUNC_FROM_CODE (data[0]);
1760 dbg ("%s - port_number %d, function %d, info 0x%x", 1758 dbg ("%s - port_number %d, function %d, info 0x%x",
1761 __FUNCTION__, port_number, function, data[1]); 1759 __func__, port_number, function, data[1]);
1762 port = edge_serial->serial->port[port_number]; 1760 port = edge_serial->serial->port[port_number];
1763 edge_port = usb_get_serial_port_data(port); 1761 edge_port = usb_get_serial_port_data(port);
1764 if (!edge_port) { 1762 if (!edge_port) {
1765 dbg ("%s - edge_port not found", __FUNCTION__); 1763 dbg ("%s - edge_port not found", __func__);
1766 return; 1764 return;
1767 } 1765 }
1768 switch (function) { 1766 switch (function) {
@@ -1771,12 +1769,12 @@ static void edge_interrupt_callback (struct urb *urb)
1771 if (lsr & UMP_UART_LSR_DATA_MASK) { 1769 if (lsr & UMP_UART_LSR_DATA_MASK) {
1772 /* Save the LSR event for bulk read completion routine */ 1770 /* Save the LSR event for bulk read completion routine */
1773 dbg ("%s - LSR Event Port %u LSR Status = %02x", 1771 dbg ("%s - LSR Event Port %u LSR Status = %02x",
1774 __FUNCTION__, port_number, lsr); 1772 __func__, port_number, lsr);
1775 edge_port->lsr_event = 1; 1773 edge_port->lsr_event = 1;
1776 edge_port->lsr_mask = lsr; 1774 edge_port->lsr_mask = lsr;
1777 } else { 1775 } else {
1778 dbg ("%s - ===== Port %d LSR Status = %02x ======", 1776 dbg ("%s - ===== Port %d LSR Status = %02x ======",
1779 __FUNCTION__, port_number, lsr); 1777 __func__, port_number, lsr);
1780 handle_new_lsr (edge_port, 0, lsr, 0); 1778 handle_new_lsr (edge_port, 0, lsr, 0);
1781 } 1779 }
1782 break; 1780 break;
@@ -1785,13 +1783,13 @@ static void edge_interrupt_callback (struct urb *urb)
1785 /* Copy MSR from UMP */ 1783 /* Copy MSR from UMP */
1786 msr = data[1]; 1784 msr = data[1];
1787 dbg ("%s - ===== Port %u MSR Status = %02x ======\n", 1785 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1788 __FUNCTION__, port_number, msr); 1786 __func__, port_number, msr);
1789 handle_new_msr (edge_port, msr); 1787 handle_new_msr (edge_port, msr);
1790 break; 1788 break;
1791 1789
1792 default: 1790 default:
1793 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n", 1791 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n",
1794 __FUNCTION__, data[1]); 1792 __func__, data[1]);
1795 break; 1793 break;
1796 1794
1797 } 1795 }
@@ -1800,19 +1798,19 @@ exit:
1800 retval = usb_submit_urb (urb, GFP_ATOMIC); 1798 retval = usb_submit_urb (urb, GFP_ATOMIC);
1801 if (retval) 1799 if (retval)
1802 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 1800 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1803 __FUNCTION__, retval); 1801 __func__, retval);
1804} 1802}
1805 1803
1806static void edge_bulk_in_callback (struct urb *urb) 1804static void edge_bulk_in_callback (struct urb *urb)
1807{ 1805{
1808 struct edgeport_port *edge_port = (struct edgeport_port *)urb->context; 1806 struct edgeport_port *edge_port = urb->context;
1809 unsigned char *data = urb->transfer_buffer; 1807 unsigned char *data = urb->transfer_buffer;
1810 struct tty_struct *tty; 1808 struct tty_struct *tty;
1811 int retval = 0; 1809 int retval = 0;
1812 int port_number; 1810 int port_number;
1813 int status = urb->status; 1811 int status = urb->status;
1814 1812
1815 dbg("%s", __FUNCTION__); 1813 dbg("%s", __func__);
1816 1814
1817 switch (status) { 1815 switch (status) {
1818 case 0: 1816 case 0:
@@ -1823,18 +1821,18 @@ static void edge_bulk_in_callback (struct urb *urb)
1823 case -ESHUTDOWN: 1821 case -ESHUTDOWN:
1824 /* this urb is terminated, clean up */ 1822 /* this urb is terminated, clean up */
1825 dbg("%s - urb shutting down with status: %d", 1823 dbg("%s - urb shutting down with status: %d",
1826 __FUNCTION__, status); 1824 __func__, status);
1827 return; 1825 return;
1828 default: 1826 default:
1829 dev_err (&urb->dev->dev,"%s - nonzero read bulk status received: %d\n", 1827 dev_err (&urb->dev->dev,"%s - nonzero read bulk status received: %d\n",
1830 __FUNCTION__, status); 1828 __func__, status);
1831 } 1829 }
1832 1830
1833 if (status == -EPIPE) 1831 if (status == -EPIPE)
1834 goto exit; 1832 goto exit;
1835 1833
1836 if (status) { 1834 if (status) {
1837 dev_err(&urb->dev->dev,"%s - stopping read!\n", __FUNCTION__); 1835 dev_err(&urb->dev->dev,"%s - stopping read!\n", __func__);
1838 return; 1836 return;
1839 } 1837 }
1840 1838
@@ -1843,7 +1841,7 @@ static void edge_bulk_in_callback (struct urb *urb)
1843 if (edge_port->lsr_event) { 1841 if (edge_port->lsr_event) {
1844 edge_port->lsr_event = 0; 1842 edge_port->lsr_event = 0;
1845 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======", 1843 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1846 __FUNCTION__, port_number, edge_port->lsr_mask, *data); 1844 __func__, port_number, edge_port->lsr_mask, *data);
1847 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data); 1845 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data);
1848 /* Adjust buffer length/pointer */ 1846 /* Adjust buffer length/pointer */
1849 --urb->actual_length; 1847 --urb->actual_length;
@@ -1852,10 +1850,10 @@ static void edge_bulk_in_callback (struct urb *urb)
1852 1850
1853 tty = edge_port->port->tty; 1851 tty = edge_port->port->tty;
1854 if (tty && urb->actual_length) { 1852 if (tty && urb->actual_length) {
1855 usb_serial_debug_data(debug, &edge_port->port->dev, __FUNCTION__, urb->actual_length, data); 1853 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, urb->actual_length, data);
1856 1854
1857 if (edge_port->close_pending) { 1855 if (edge_port->close_pending) {
1858 dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__); 1856 dbg ("%s - close is pending, dropping data on the floor.", __func__);
1859 } else { 1857 } else {
1860 edge_tty_recv(&edge_port->port->dev, tty, data, urb->actual_length); 1858 edge_tty_recv(&edge_port->port->dev, tty, data, urb->actual_length);
1861 } 1859 }
@@ -1874,7 +1872,7 @@ exit:
1874 spin_unlock(&edge_port->ep_lock); 1872 spin_unlock(&edge_port->ep_lock);
1875 if (retval) 1873 if (retval)
1876 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 1874 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1877 __FUNCTION__, retval); 1875 __func__, retval);
1878} 1876}
1879 1877
1880static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length) 1878static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length)
@@ -1885,7 +1883,7 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c
1885 cnt = tty_buffer_request_room(tty, length); 1883 cnt = tty_buffer_request_room(tty, length);
1886 if (cnt < length) { 1884 if (cnt < length) {
1887 dev_err(dev, "%s - dropping data, %d bytes lost\n", 1885 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1888 __FUNCTION__, length - cnt); 1886 __func__, length - cnt);
1889 if(cnt == 0) 1887 if(cnt == 0)
1890 break; 1888 break;
1891 } 1889 }
@@ -1899,11 +1897,11 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c
1899 1897
1900static void edge_bulk_out_callback (struct urb *urb) 1898static void edge_bulk_out_callback (struct urb *urb)
1901{ 1899{
1902 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1900 struct usb_serial_port *port = urb->context;
1903 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1901 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1904 int status = urb->status; 1902 int status = urb->status;
1905 1903
1906 dbg ("%s - port %d", __FUNCTION__, port->number); 1904 dbg ("%s - port %d", __func__, port->number);
1907 1905
1908 edge_port->ep_write_urb_in_use = 0; 1906 edge_port->ep_write_urb_in_use = 0;
1909 1907
@@ -1916,11 +1914,11 @@ static void edge_bulk_out_callback (struct urb *urb)
1916 case -ESHUTDOWN: 1914 case -ESHUTDOWN:
1917 /* this urb is terminated, clean up */ 1915 /* this urb is terminated, clean up */
1918 dbg("%s - urb shutting down with status: %d", 1916 dbg("%s - urb shutting down with status: %d",
1919 __FUNCTION__, status); 1917 __func__, status);
1920 return; 1918 return;
1921 default: 1919 default:
1922 dev_err(&urb->dev->dev, "%s - nonzero write bulk status " 1920 dev_err(&urb->dev->dev, "%s - nonzero write bulk status "
1923 "received: %d\n", __FUNCTION__, status); 1921 "received: %d\n", __func__, status);
1924 } 1922 }
1925 1923
1926 /* send any buffered data */ 1924 /* send any buffered data */
@@ -1938,13 +1936,12 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
1938 u16 open_settings; 1936 u16 open_settings;
1939 u8 transaction_timeout; 1937 u8 transaction_timeout;
1940 1938
1941 dbg("%s - port %d", __FUNCTION__, port->number); 1939 dbg("%s - port %d", __func__, port->number);
1942 1940
1943 if (edge_port == NULL) 1941 if (edge_port == NULL)
1944 return -ENODEV; 1942 return -ENODEV;
1945 1943
1946 if (port->tty) 1944 port->tty->low_latency = low_latency;
1947 port->tty->low_latency = low_latency;
1948 1945
1949 port_number = port->number - port->serial->minor; 1946 port_number = port->number - port->serial->minor;
1950 switch (port_number) { 1947 switch (port_number) {
@@ -1962,7 +1959,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
1962 } 1959 }
1963 1960
1964 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x", 1961 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1965 __FUNCTION__, port_number, edge_port->uart_base, edge_port->dma_address); 1962 __func__, port_number, edge_port->uart_base, edge_port->dma_address);
1966 1963
1967 dev = port->serial->dev; 1964 dev = port->serial->dev;
1968 1965
@@ -1973,7 +1970,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
1973 status = TIClearLoopBack (edge_port); 1970 status = TIClearLoopBack (edge_port);
1974 if (status) { 1971 if (status) {
1975 dev_err(&port->dev,"%s - cannot send clear loopback command, %d\n", 1972 dev_err(&port->dev,"%s - cannot send clear loopback command, %d\n",
1976 __FUNCTION__, status); 1973 __func__, status);
1977 return status; 1974 return status;
1978 } 1975 }
1979 1976
@@ -1992,7 +1989,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
1992 UMP_PIPE_TRANS_TIMEOUT_ENA | 1989 UMP_PIPE_TRANS_TIMEOUT_ENA |
1993 (transaction_timeout << 2)); 1990 (transaction_timeout << 2));
1994 1991
1995 dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__); 1992 dbg ("%s - Sending UMPC_OPEN_PORT", __func__);
1996 1993
1997 /* Tell TI to open and start the port */ 1994 /* Tell TI to open and start the port */
1998 status = TIWriteCommandSync (dev, 1995 status = TIWriteCommandSync (dev,
@@ -2002,7 +1999,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2002 NULL, 1999 NULL,
2003 0); 2000 0);
2004 if (status) { 2001 if (status) {
2005 dev_err(&port->dev,"%s - cannot send open command, %d\n", __FUNCTION__, status); 2002 dev_err(&port->dev,"%s - cannot send open command, %d\n", __func__, status);
2006 return status; 2003 return status;
2007 } 2004 }
2008 2005
@@ -2014,14 +2011,14 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2014 NULL, 2011 NULL,
2015 0); 2012 0);
2016 if (status) { 2013 if (status) {
2017 dev_err(&port->dev,"%s - cannot send start DMA command, %d\n", __FUNCTION__, status); 2014 dev_err(&port->dev,"%s - cannot send start DMA command, %d\n", __func__, status);
2018 return status; 2015 return status;
2019 } 2016 }
2020 2017
2021 /* Clear TX and RX buffers in UMP */ 2018 /* Clear TX and RX buffers in UMP */
2022 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN); 2019 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
2023 if (status) { 2020 if (status) {
2024 dev_err(&port->dev,"%s - cannot send clear buffers command, %d\n", __FUNCTION__, status); 2021 dev_err(&port->dev,"%s - cannot send clear buffers command, %d\n", __func__, status);
2025 return status; 2022 return status;
2026 } 2023 }
2027 2024
@@ -2033,7 +2030,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2033 &edge_port->shadow_msr, // TransferBuffer 2030 &edge_port->shadow_msr, // TransferBuffer
2034 1); // TransferBufferLength 2031 1); // TransferBufferLength
2035 if (status) { 2032 if (status) {
2036 dev_err(&port->dev,"%s - cannot send read MSR command, %d\n", __FUNCTION__, status); 2033 dev_err(&port->dev,"%s - cannot send read MSR command, %d\n", __func__, status);
2037 return status; 2034 return status;
2038 } 2035 }
2039 2036
@@ -2050,7 +2047,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2050 /* we are the first port to be opened, let's post the interrupt urb */ 2047 /* we are the first port to be opened, let's post the interrupt urb */
2051 urb = edge_serial->serial->port[0]->interrupt_in_urb; 2048 urb = edge_serial->serial->port[0]->interrupt_in_urb;
2052 if (!urb) { 2049 if (!urb) {
2053 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__); 2050 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __func__);
2054 status = -EINVAL; 2051 status = -EINVAL;
2055 goto release_es_lock; 2052 goto release_es_lock;
2056 } 2053 }
@@ -2059,7 +2056,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2059 urb->dev = dev; 2056 urb->dev = dev;
2060 status = usb_submit_urb (urb, GFP_KERNEL); 2057 status = usb_submit_urb (urb, GFP_KERNEL);
2061 if (status) { 2058 if (status) {
2062 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status); 2059 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __func__, status);
2063 goto release_es_lock; 2060 goto release_es_lock;
2064 } 2061 }
2065 } 2062 }
@@ -2074,7 +2071,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2074 /* start up our bulk read urb */ 2071 /* start up our bulk read urb */
2075 urb = port->read_urb; 2072 urb = port->read_urb;
2076 if (!urb) { 2073 if (!urb) {
2077 dev_err (&port->dev, "%s - no read urb present, exiting\n", __FUNCTION__); 2074 dev_err (&port->dev, "%s - no read urb present, exiting\n", __func__);
2078 status = -EINVAL; 2075 status = -EINVAL;
2079 goto unlink_int_urb; 2076 goto unlink_int_urb;
2080 } 2077 }
@@ -2084,13 +2081,13 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2084 urb->dev = dev; 2081 urb->dev = dev;
2085 status = usb_submit_urb (urb, GFP_KERNEL); 2082 status = usb_submit_urb (urb, GFP_KERNEL);
2086 if (status) { 2083 if (status) {
2087 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__, status); 2084 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status);
2088 goto unlink_int_urb; 2085 goto unlink_int_urb;
2089 } 2086 }
2090 2087
2091 ++edge_serial->num_ports_open; 2088 ++edge_serial->num_ports_open;
2092 2089
2093 dbg("%s - exited", __FUNCTION__); 2090 dbg("%s - exited", __func__);
2094 2091
2095 goto release_es_lock; 2092 goto release_es_lock;
2096 2093
@@ -2109,7 +2106,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2109 int port_number; 2106 int port_number;
2110 int status; 2107 int status;
2111 2108
2112 dbg("%s - port %d", __FUNCTION__, port->number); 2109 dbg("%s - port %d", __func__, port->number);
2113 2110
2114 edge_serial = usb_get_serial_data(port->serial); 2111 edge_serial = usb_get_serial_data(port->serial);
2115 edge_port = usb_get_serial_port_data(port); 2112 edge_port = usb_get_serial_port_data(port);
@@ -2129,7 +2126,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2129 2126
2130 /* assuming we can still talk to the device, 2127 /* assuming we can still talk to the device,
2131 * send a close port command to it */ 2128 * send a close port command to it */
2132 dbg("%s - send umpc_close_port", __FUNCTION__); 2129 dbg("%s - send umpc_close_port", __func__);
2133 port_number = port->number - port->serial->minor; 2130 port_number = port->number - port->serial->minor;
2134 status = TIWriteCommandSync (port->serial->dev, 2131 status = TIWriteCommandSync (port->serial->dev,
2135 UMPC_CLOSE_PORT, 2132 UMPC_CLOSE_PORT,
@@ -2147,7 +2144,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2147 mutex_unlock(&edge_serial->es_lock); 2144 mutex_unlock(&edge_serial->es_lock);
2148 edge_port->close_pending = 0; 2145 edge_port->close_pending = 0;
2149 2146
2150 dbg("%s - exited", __FUNCTION__); 2147 dbg("%s - exited", __func__);
2151} 2148}
2152 2149
2153static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count) 2150static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count)
@@ -2155,10 +2152,10 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
2155 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2152 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2156 unsigned long flags; 2153 unsigned long flags;
2157 2154
2158 dbg("%s - port %d", __FUNCTION__, port->number); 2155 dbg("%s - port %d", __func__, port->number);
2159 2156
2160 if (count == 0) { 2157 if (count == 0) {
2161 dbg("%s - write request of 0 bytes", __FUNCTION__); 2158 dbg("%s - write request of 0 bytes", __func__);
2162 return 0; 2159 return 0;
2163 } 2160 }
2164 2161
@@ -2184,7 +2181,7 @@ static void edge_send(struct usb_serial_port *port)
2184 unsigned long flags; 2181 unsigned long flags;
2185 2182
2186 2183
2187 dbg("%s - port %d", __FUNCTION__, port->number); 2184 dbg("%s - port %d", __func__, port->number);
2188 2185
2189 spin_lock_irqsave(&edge_port->ep_lock, flags); 2186 spin_lock_irqsave(&edge_port->ep_lock, flags);
2190 2187
@@ -2206,7 +2203,7 @@ static void edge_send(struct usb_serial_port *port)
2206 2203
2207 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2204 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2208 2205
2209 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); 2206 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer);
2210 2207
2211 /* set up our urb */ 2208 /* set up our urb */
2212 usb_fill_bulk_urb (port->write_urb, port->serial->dev, 2209 usb_fill_bulk_urb (port->write_urb, port->serial->dev,
@@ -2219,7 +2216,7 @@ static void edge_send(struct usb_serial_port *port)
2219 /* send the data out the bulk port */ 2216 /* send the data out the bulk port */
2220 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 2217 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
2221 if (result) { 2218 if (result) {
2222 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 2219 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result);
2223 edge_port->ep_write_urb_in_use = 0; 2220 edge_port->ep_write_urb_in_use = 0;
2224 // TODO: reschedule edge_send 2221 // TODO: reschedule edge_send
2225 } else { 2222 } else {
@@ -2240,7 +2237,7 @@ static int edge_write_room (struct usb_serial_port *port)
2240 int room = 0; 2237 int room = 0;
2241 unsigned long flags; 2238 unsigned long flags;
2242 2239
2243 dbg("%s - port %d", __FUNCTION__, port->number); 2240 dbg("%s - port %d", __func__, port->number);
2244 2241
2245 if (edge_port == NULL) 2242 if (edge_port == NULL)
2246 return -ENODEV; 2243 return -ENODEV;
@@ -2251,7 +2248,7 @@ static int edge_write_room (struct usb_serial_port *port)
2251 room = edge_buf_space_avail(edge_port->ep_out_buf); 2248 room = edge_buf_space_avail(edge_port->ep_out_buf);
2252 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2249 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2253 2250
2254 dbg("%s - returns %d", __FUNCTION__, room); 2251 dbg("%s - returns %d", __func__, room);
2255 return room; 2252 return room;
2256} 2253}
2257 2254
@@ -2261,7 +2258,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
2261 int chars = 0; 2258 int chars = 0;
2262 unsigned long flags; 2259 unsigned long flags;
2263 2260
2264 dbg("%s - port %d", __FUNCTION__, port->number); 2261 dbg("%s - port %d", __func__, port->number);
2265 2262
2266 if (edge_port == NULL) 2263 if (edge_port == NULL)
2267 return -ENODEV; 2264 return -ENODEV;
@@ -2272,7 +2269,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
2272 chars = edge_buf_data_avail(edge_port->ep_out_buf); 2269 chars = edge_buf_data_avail(edge_port->ep_out_buf);
2273 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2270 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2274 2271
2275 dbg ("%s - returns %d", __FUNCTION__, chars); 2272 dbg ("%s - returns %d", __func__, chars);
2276 return chars; 2273 return chars;
2277} 2274}
2278 2275
@@ -2282,14 +2279,14 @@ static void edge_throttle (struct usb_serial_port *port)
2282 struct tty_struct *tty; 2279 struct tty_struct *tty;
2283 int status; 2280 int status;
2284 2281
2285 dbg("%s - port %d", __FUNCTION__, port->number); 2282 dbg("%s - port %d", __func__, port->number);
2286 2283
2287 if (edge_port == NULL) 2284 if (edge_port == NULL)
2288 return; 2285 return;
2289 2286
2290 tty = port->tty; 2287 tty = port->tty;
2291 if (!tty) { 2288 if (!tty) {
2292 dbg ("%s - no tty available", __FUNCTION__); 2289 dbg ("%s - no tty available", __func__);
2293 return; 2290 return;
2294 } 2291 }
2295 2292
@@ -2298,7 +2295,7 @@ static void edge_throttle (struct usb_serial_port *port)
2298 unsigned char stop_char = STOP_CHAR(tty); 2295 unsigned char stop_char = STOP_CHAR(tty);
2299 status = edge_write (port, &stop_char, 1); 2296 status = edge_write (port, &stop_char, 1);
2300 if (status <= 0) { 2297 if (status <= 0) {
2301 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __FUNCTION__, status); 2298 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
2302 } 2299 }
2303 } 2300 }
2304 2301
@@ -2315,14 +2312,14 @@ static void edge_unthrottle (struct usb_serial_port *port)
2315 struct tty_struct *tty; 2312 struct tty_struct *tty;
2316 int status; 2313 int status;
2317 2314
2318 dbg("%s - port %d", __FUNCTION__, port->number); 2315 dbg("%s - port %d", __func__, port->number);
2319 2316
2320 if (edge_port == NULL) 2317 if (edge_port == NULL)
2321 return; 2318 return;
2322 2319
2323 tty = port->tty; 2320 tty = port->tty;
2324 if (!tty) { 2321 if (!tty) {
2325 dbg ("%s - no tty available", __FUNCTION__); 2322 dbg ("%s - no tty available", __func__);
2326 return; 2323 return;
2327 } 2324 }
2328 2325
@@ -2331,7 +2328,7 @@ static void edge_unthrottle (struct usb_serial_port *port)
2331 unsigned char start_char = START_CHAR(tty); 2328 unsigned char start_char = START_CHAR(tty);
2332 status = edge_write (port, &start_char, 1); 2329 status = edge_write (port, &start_char, 1);
2333 if (status <= 0) { 2330 if (status <= 0) {
2334 dev_err(&port->dev, "%s - failed to write start character, %d\n", __FUNCTION__, status); 2331 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
2335 } 2332 }
2336 } 2333 }
2337 2334
@@ -2340,7 +2337,7 @@ static void edge_unthrottle (struct usb_serial_port *port)
2340 if (C_CRTSCTS(tty)) { 2337 if (C_CRTSCTS(tty)) {
2341 status = restart_read(edge_port); 2338 status = restart_read(edge_port);
2342 if (status) 2339 if (status)
2343 dev_err(&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__, status); 2340 dev_err(&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status);
2344 } 2341 }
2345 2342
2346} 2343}
@@ -2390,13 +2387,13 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2390 int status; 2387 int status;
2391 int port_number = edge_port->port->number - edge_port->port->serial->minor; 2388 int port_number = edge_port->port->number - edge_port->port->serial->minor;
2392 2389
2393 dbg("%s - port %d", __FUNCTION__, edge_port->port->number); 2390 dbg("%s - port %d", __func__, edge_port->port->number);
2394 2391
2395 tty = edge_port->port->tty; 2392 tty = edge_port->port->tty;
2396 2393
2397 config = kmalloc (sizeof (*config), GFP_KERNEL); 2394 config = kmalloc (sizeof (*config), GFP_KERNEL);
2398 if (!config) { 2395 if (!config) {
2399 dev_err (&edge_port->port->dev, "%s - out of memory\n", __FUNCTION__); 2396 dev_err (&edge_port->port->dev, "%s - out of memory\n", __func__);
2400 return; 2397 return;
2401 } 2398 }
2402 2399
@@ -2412,20 +2409,20 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2412 switch (cflag & CSIZE) { 2409 switch (cflag & CSIZE) {
2413 case CS5: 2410 case CS5:
2414 config->bDataBits = UMP_UART_CHAR5BITS; 2411 config->bDataBits = UMP_UART_CHAR5BITS;
2415 dbg ("%s - data bits = 5", __FUNCTION__); 2412 dbg ("%s - data bits = 5", __func__);
2416 break; 2413 break;
2417 case CS6: 2414 case CS6:
2418 config->bDataBits = UMP_UART_CHAR6BITS; 2415 config->bDataBits = UMP_UART_CHAR6BITS;
2419 dbg ("%s - data bits = 6", __FUNCTION__); 2416 dbg ("%s - data bits = 6", __func__);
2420 break; 2417 break;
2421 case CS7: 2418 case CS7:
2422 config->bDataBits = UMP_UART_CHAR7BITS; 2419 config->bDataBits = UMP_UART_CHAR7BITS;
2423 dbg ("%s - data bits = 7", __FUNCTION__); 2420 dbg ("%s - data bits = 7", __func__);
2424 break; 2421 break;
2425 default: 2422 default:
2426 case CS8: 2423 case CS8:
2427 config->bDataBits = UMP_UART_CHAR8BITS; 2424 config->bDataBits = UMP_UART_CHAR8BITS;
2428 dbg ("%s - data bits = 8", __FUNCTION__); 2425 dbg ("%s - data bits = 8", __func__);
2429 break; 2426 break;
2430 } 2427 }
2431 2428
@@ -2433,32 +2430,32 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2433 if (cflag & PARODD) { 2430 if (cflag & PARODD) {
2434 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY; 2431 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2435 config->bParity = UMP_UART_ODDPARITY; 2432 config->bParity = UMP_UART_ODDPARITY;
2436 dbg("%s - parity = odd", __FUNCTION__); 2433 dbg("%s - parity = odd", __func__);
2437 } else { 2434 } else {
2438 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY; 2435 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2439 config->bParity = UMP_UART_EVENPARITY; 2436 config->bParity = UMP_UART_EVENPARITY;
2440 dbg("%s - parity = even", __FUNCTION__); 2437 dbg("%s - parity = even", __func__);
2441 } 2438 }
2442 } else { 2439 } else {
2443 config->bParity = UMP_UART_NOPARITY; 2440 config->bParity = UMP_UART_NOPARITY;
2444 dbg("%s - parity = none", __FUNCTION__); 2441 dbg("%s - parity = none", __func__);
2445 } 2442 }
2446 2443
2447 if (cflag & CSTOPB) { 2444 if (cflag & CSTOPB) {
2448 config->bStopBits = UMP_UART_STOPBIT2; 2445 config->bStopBits = UMP_UART_STOPBIT2;
2449 dbg("%s - stop bits = 2", __FUNCTION__); 2446 dbg("%s - stop bits = 2", __func__);
2450 } else { 2447 } else {
2451 config->bStopBits = UMP_UART_STOPBIT1; 2448 config->bStopBits = UMP_UART_STOPBIT1;
2452 dbg("%s - stop bits = 1", __FUNCTION__); 2449 dbg("%s - stop bits = 1", __func__);
2453 } 2450 }
2454 2451
2455 /* figure out the flow control settings */ 2452 /* figure out the flow control settings */
2456 if (cflag & CRTSCTS) { 2453 if (cflag & CRTSCTS) {
2457 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW; 2454 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2458 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW; 2455 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
2459 dbg("%s - RTS/CTS is enabled", __FUNCTION__); 2456 dbg("%s - RTS/CTS is enabled", __func__);
2460 } else { 2457 } else {
2461 dbg("%s - RTS/CTS is disabled", __FUNCTION__); 2458 dbg("%s - RTS/CTS is disabled", __func__);
2462 tty->hw_stopped = 0; 2459 tty->hw_stopped = 0;
2463 restart_read(edge_port); 2460 restart_read(edge_port);
2464 } 2461 }
@@ -2472,18 +2469,18 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2472 if (I_IXOFF(tty)) { 2469 if (I_IXOFF(tty)) {
2473 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X; 2470 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
2474 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", 2471 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2475 __FUNCTION__, config->cXon, config->cXoff); 2472 __func__, config->cXon, config->cXoff);
2476 } else { 2473 } else {
2477 dbg ("%s - INBOUND XON/XOFF is disabled", __FUNCTION__); 2474 dbg ("%s - INBOUND XON/XOFF is disabled", __func__);
2478 } 2475 }
2479 2476
2480 /* if we are implementing OUTBOUND XON/XOFF */ 2477 /* if we are implementing OUTBOUND XON/XOFF */
2481 if (I_IXON(tty)) { 2478 if (I_IXON(tty)) {
2482 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X; 2479 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
2483 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", 2480 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2484 __FUNCTION__, config->cXon, config->cXoff); 2481 __func__, config->cXon, config->cXoff);
2485 } else { 2482 } else {
2486 dbg ("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__); 2483 dbg ("%s - OUTBOUND XON/XOFF is disabled", __func__);
2487 } 2484 }
2488 } 2485 }
2489 2486
@@ -2502,7 +2499,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2502 2499
2503 /* FIXME: Recompute actual baud from divisor here */ 2500 /* FIXME: Recompute actual baud from divisor here */
2504 2501
2505 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate); 2502 dbg ("%s - baud rate = %d, wBaudRate = %d", __func__, baud, config->wBaudRate);
2506 2503
2507 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate)); 2504 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate));
2508 dbg ("wFlags: 0x%x", config->wFlags); 2505 dbg ("wFlags: 0x%x", config->wFlags);
@@ -2525,7 +2522,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2525 sizeof(*config)); 2522 sizeof(*config));
2526 if (status) { 2523 if (status) {
2527 dbg ("%s - error %d when trying to write config to device", 2524 dbg ("%s - error %d when trying to write config to device",
2528 __FUNCTION__, status); 2525 __func__, status);
2529 } 2526 }
2530 2527
2531 kfree (config); 2528 kfree (config);
@@ -2541,12 +2538,12 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
2541 2538
2542 cflag = tty->termios->c_cflag; 2539 cflag = tty->termios->c_cflag;
2543 2540
2544 dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 2541 dbg("%s - clfag %08x iflag %08x", __func__,
2545 tty->termios->c_cflag, tty->termios->c_iflag); 2542 tty->termios->c_cflag, tty->termios->c_iflag);
2546 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, 2543 dbg("%s - old clfag %08x old iflag %08x", __func__,
2547 old_termios->c_cflag, old_termios->c_iflag); 2544 old_termios->c_cflag, old_termios->c_iflag);
2548 2545
2549 dbg("%s - port %d", __FUNCTION__, port->number); 2546 dbg("%s - port %d", __func__, port->number);
2550 2547
2551 if (edge_port == NULL) 2548 if (edge_port == NULL)
2552 return; 2549 return;
@@ -2561,9 +2558,11 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
2561{ 2558{
2562 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2559 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2563 unsigned int mcr; 2560 unsigned int mcr;
2561 unsigned long flags;
2564 2562
2565 dbg("%s - port %d", __FUNCTION__, port->number); 2563 dbg("%s - port %d", __func__, port->number);
2566 2564
2565 spin_lock_irqsave(&edge_port->ep_lock, flags);
2567 mcr = edge_port->shadow_mcr; 2566 mcr = edge_port->shadow_mcr;
2568 if (set & TIOCM_RTS) 2567 if (set & TIOCM_RTS)
2569 mcr |= MCR_RTS; 2568 mcr |= MCR_RTS;
@@ -2580,6 +2579,7 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
2580 mcr &= ~MCR_LOOPBACK; 2579 mcr &= ~MCR_LOOPBACK;
2581 2580
2582 edge_port->shadow_mcr = mcr; 2581 edge_port->shadow_mcr = mcr;
2582 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2583 2583
2584 TIRestoreMCR (edge_port, mcr); 2584 TIRestoreMCR (edge_port, mcr);
2585 2585
@@ -2592,8 +2592,11 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2592 unsigned int result = 0; 2592 unsigned int result = 0;
2593 unsigned int msr; 2593 unsigned int msr;
2594 unsigned int mcr; 2594 unsigned int mcr;
2595 unsigned long flags;
2595 2596
2596 dbg("%s - port %d", __FUNCTION__, port->number); 2597 dbg("%s - port %d", __func__, port->number);
2598
2599 spin_lock_irqsave(&edge_port->ep_lock, flags);
2597 2600
2598 msr = edge_port->shadow_msr; 2601 msr = edge_port->shadow_msr;
2599 mcr = edge_port->shadow_mcr; 2602 mcr = edge_port->shadow_mcr;
@@ -2605,7 +2608,8 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2605 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */ 2608 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2606 2609
2607 2610
2608 dbg("%s -- %x", __FUNCTION__, result); 2611 dbg("%s -- %x", __func__, result);
2612 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2609 2613
2610 return result; 2614 return result;
2611} 2615}
@@ -2644,30 +2648,30 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
2644 struct async_icount cnow; 2648 struct async_icount cnow;
2645 struct async_icount cprev; 2649 struct async_icount cprev;
2646 2650
2647 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd); 2651 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
2648 2652
2649 switch (cmd) { 2653 switch (cmd) {
2650 case TIOCINQ: 2654 case TIOCINQ:
2651 dbg("%s - (%d) TIOCINQ", __FUNCTION__, port->number); 2655 dbg("%s - (%d) TIOCINQ", __func__, port->number);
2652// return get_number_bytes_avail(edge_port, (unsigned int *) arg); 2656// return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2653 break; 2657 break;
2654 2658
2655 case TIOCSERGETLSR: 2659 case TIOCSERGETLSR:
2656 dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__, port->number); 2660 dbg("%s - (%d) TIOCSERGETLSR", __func__, port->number);
2657// return get_lsr_info(edge_port, (unsigned int *) arg); 2661// return get_lsr_info(edge_port, (unsigned int *) arg);
2658 break; 2662 break;
2659 2663
2660 case TIOCGSERIAL: 2664 case TIOCGSERIAL:
2661 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__, port->number); 2665 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
2662 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 2666 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
2663 break; 2667 break;
2664 2668
2665 case TIOCSSERIAL: 2669 case TIOCSSERIAL:
2666 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__, port->number); 2670 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number);
2667 break; 2671 break;
2668 2672
2669 case TIOCMIWAIT: 2673 case TIOCMIWAIT:
2670 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__, port->number); 2674 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
2671 cprev = edge_port->icount; 2675 cprev = edge_port->icount;
2672 while (1) { 2676 while (1) {
2673 interruptible_sleep_on(&edge_port->delta_msr_wait); 2677 interruptible_sleep_on(&edge_port->delta_msr_wait);
@@ -2690,7 +2694,7 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
2690 break; 2694 break;
2691 2695
2692 case TIOCGICOUNT: 2696 case TIOCGICOUNT:
2693 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__, 2697 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2694 port->number, edge_port->icount.rx, edge_port->icount.tx); 2698 port->number, edge_port->icount.rx, edge_port->icount.tx);
2695 if (copy_to_user((void __user *)arg, &edge_port->icount, sizeof(edge_port->icount))) 2699 if (copy_to_user((void __user *)arg, &edge_port->icount, sizeof(edge_port->icount)))
2696 return -EFAULT; 2700 return -EFAULT;
@@ -2705,7 +2709,7 @@ static void edge_break (struct usb_serial_port *port, int break_state)
2705 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2709 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2706 int status; 2710 int status;
2707 2711
2708 dbg ("%s - state = %d", __FUNCTION__, break_state); 2712 dbg ("%s - state = %d", __func__, break_state);
2709 2713
2710 /* chase the port close */ 2714 /* chase the port close */
2711 TIChasePort (edge_port, 0, 0); 2715 TIChasePort (edge_port, 0, 0);
@@ -2717,7 +2721,7 @@ static void edge_break (struct usb_serial_port *port, int break_state)
2717 } 2721 }
2718 if (status) { 2722 if (status) {
2719 dbg ("%s - error %d sending break set/clear command.", 2723 dbg ("%s - error %d sending break set/clear command.",
2720 __FUNCTION__, status); 2724 __func__, status);
2721 } 2725 }
2722} 2726}
2723 2727
@@ -2734,7 +2738,7 @@ static int edge_startup (struct usb_serial *serial)
2734 /* create our private serial structure */ 2738 /* create our private serial structure */
2735 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); 2739 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
2736 if (edge_serial == NULL) { 2740 if (edge_serial == NULL) {
2737 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2741 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
2738 return -ENOMEM; 2742 return -ENOMEM;
2739 } 2743 }
2740 mutex_init(&edge_serial->es_lock); 2744 mutex_init(&edge_serial->es_lock);
@@ -2751,13 +2755,13 @@ static int edge_startup (struct usb_serial *serial)
2751 for (i = 0; i < serial->num_ports; ++i) { 2755 for (i = 0; i < serial->num_ports; ++i) {
2752 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL); 2756 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2753 if (edge_port == NULL) { 2757 if (edge_port == NULL) {
2754 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2758 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
2755 goto cleanup; 2759 goto cleanup;
2756 } 2760 }
2757 spin_lock_init(&edge_port->ep_lock); 2761 spin_lock_init(&edge_port->ep_lock);
2758 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE); 2762 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE);
2759 if (edge_port->ep_out_buf == NULL) { 2763 if (edge_port->ep_out_buf == NULL) {
2760 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2764 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
2761 kfree(edge_port); 2765 kfree(edge_port);
2762 goto cleanup; 2766 goto cleanup;
2763 } 2767 }
@@ -2786,7 +2790,7 @@ static void edge_shutdown (struct usb_serial *serial)
2786 int i; 2790 int i;
2787 struct edgeport_port *edge_port; 2791 struct edgeport_port *edge_port;
2788 2792
2789 dbg ("%s", __FUNCTION__); 2793 dbg ("%s", __func__);
2790 2794
2791 for (i = 0; i < serial->num_ports; ++i) { 2795 for (i = 0; i < serial->num_ports; ++i) {
2792 edge_port = usb_get_serial_port_data(serial->port[i]); 2796 edge_port = usb_get_serial_port_data(serial->port[i]);
@@ -2818,12 +2822,12 @@ static ssize_t store_uart_mode(struct device *dev,
2818 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2822 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2819 unsigned int v = simple_strtoul(valbuf, NULL, 0); 2823 unsigned int v = simple_strtoul(valbuf, NULL, 0);
2820 2824
2821 dbg("%s: setting uart_mode = %d", __FUNCTION__, v); 2825 dbg("%s: setting uart_mode = %d", __func__, v);
2822 2826
2823 if (v < 256) 2827 if (v < 256)
2824 edge_port->bUartMode = v; 2828 edge_port->bUartMode = v;
2825 else 2829 else
2826 dev_err(dev, "%s - uart_mode %d is invalid\n", __FUNCTION__, v); 2830 dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v);
2827 2831
2828 return count; 2832 return count;
2829} 2833}
@@ -3028,9 +3032,6 @@ static struct usb_serial_driver edgeport_1port_device = {
3028 .description = "Edgeport TI 1 port adapter", 3032 .description = "Edgeport TI 1 port adapter",
3029 .usb_driver = &io_driver, 3033 .usb_driver = &io_driver,
3030 .id_table = edgeport_1port_id_table, 3034 .id_table = edgeport_1port_id_table,
3031 .num_interrupt_in = 1,
3032 .num_bulk_in = 1,
3033 .num_bulk_out = 1,
3034 .num_ports = 1, 3035 .num_ports = 1,
3035 .open = edge_open, 3036 .open = edge_open,
3036 .close = edge_close, 3037 .close = edge_close,
@@ -3060,9 +3061,6 @@ static struct usb_serial_driver edgeport_2port_device = {
3060 .description = "Edgeport TI 2 port adapter", 3061 .description = "Edgeport TI 2 port adapter",
3061 .usb_driver = &io_driver, 3062 .usb_driver = &io_driver,
3062 .id_table = edgeport_2port_id_table, 3063 .id_table = edgeport_2port_id_table,
3063 .num_interrupt_in = 1,
3064 .num_bulk_in = 2,
3065 .num_bulk_out = 2,
3066 .num_ports = 2, 3064 .num_ports = 2,
3067 .open = edge_open, 3065 .open = edge_open,
3068 .close = edge_close, 3066 .close = edge_close,
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 9b38a08ac83a..ea924dc48496 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -570,10 +570,7 @@ static struct usb_serial_driver ipaq_device = {
570 .description = "PocketPC PDA", 570 .description = "PocketPC PDA",
571 .usb_driver = &ipaq_driver, 571 .usb_driver = &ipaq_driver,
572 .id_table = ipaq_id_table, 572 .id_table = ipaq_id_table,
573 .num_interrupt_in = NUM_DONT_CARE, 573 .num_ports = 2,
574 .num_bulk_in = 1,
575 .num_bulk_out = 1,
576 .num_ports = 1,
577 .open = ipaq_open, 574 .open = ipaq_open,
578 .close = ipaq_close, 575 .close = ipaq_close,
579 .attach = ipaq_startup, 576 .attach = ipaq_startup,
@@ -597,13 +594,13 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
597 int i, result = 0; 594 int i, result = 0;
598 int retries = connect_retries; 595 int retries = connect_retries;
599 596
600 dbg("%s - port %d", __FUNCTION__, port->number); 597 dbg("%s - port %d", __func__, port->number);
601 598
602 bytes_in = 0; 599 bytes_in = 0;
603 bytes_out = 0; 600 bytes_out = 0;
604 priv = kmalloc(sizeof(struct ipaq_private), GFP_KERNEL); 601 priv = kmalloc(sizeof(struct ipaq_private), GFP_KERNEL);
605 if (priv == NULL) { 602 if (priv == NULL) {
606 err("%s - Out of memory", __FUNCTION__); 603 err("%s - Out of memory", __func__);
607 return -ENOMEM; 604 return -ENOMEM;
608 } 605 }
609 usb_set_serial_port_data(port, priv); 606 usb_set_serial_port_data(port, priv);
@@ -682,7 +679,7 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
682 } 679 }
683 680
684 if (!retries && result) { 681 if (!retries && result) {
685 err("%s - failed doing control urb, error %d", __FUNCTION__, 682 err("%s - failed doing control urb, error %d", __func__,
686 result); 683 result);
687 goto error; 684 goto error;
688 } 685 }
@@ -695,7 +692,7 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
695 692
696 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 693 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
697 if (result) { 694 if (result) {
698 err("%s - failed submitting read urb, error %d", __FUNCTION__, result); 695 err("%s - failed submitting read urb, error %d", __func__, result);
699 goto error; 696 goto error;
700 } 697 }
701 698
@@ -703,7 +700,7 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
703 700
704enomem: 701enomem:
705 result = -ENOMEM; 702 result = -ENOMEM;
706 err("%s - Out of memory", __FUNCTION__); 703 err("%s - Out of memory", __func__);
707error: 704error:
708 ipaq_destroy_lists(port); 705 ipaq_destroy_lists(port);
709 kfree(priv); 706 kfree(priv);
@@ -715,7 +712,7 @@ static void ipaq_close(struct usb_serial_port *port, struct file *filp)
715{ 712{
716 struct ipaq_private *priv = usb_get_serial_port_data(port); 713 struct ipaq_private *priv = usb_get_serial_port_data(port);
717 714
718 dbg("%s - port %d", __FUNCTION__, port->number); 715 dbg("%s - port %d", __func__, port->number);
719 716
720 /* 717 /*
721 * shut down bulk read and write 718 * shut down bulk read and write
@@ -732,21 +729,21 @@ static void ipaq_close(struct usb_serial_port *port, struct file *filp)
732 729
733static void ipaq_read_bulk_callback(struct urb *urb) 730static void ipaq_read_bulk_callback(struct urb *urb)
734{ 731{
735 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 732 struct usb_serial_port *port = urb->context;
736 struct tty_struct *tty; 733 struct tty_struct *tty;
737 unsigned char *data = urb->transfer_buffer; 734 unsigned char *data = urb->transfer_buffer;
738 int result; 735 int result;
739 int status = urb->status; 736 int status = urb->status;
740 737
741 dbg("%s - port %d", __FUNCTION__, port->number); 738 dbg("%s - port %d", __func__, port->number);
742 739
743 if (status) { 740 if (status) {
744 dbg("%s - nonzero read bulk status received: %d", 741 dbg("%s - nonzero read bulk status received: %d",
745 __FUNCTION__, status); 742 __func__, status);
746 return; 743 return;
747 } 744 }
748 745
749 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 746 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
750 747
751 tty = port->tty; 748 tty = port->tty;
752 if (tty && urb->actual_length) { 749 if (tty && urb->actual_length) {
@@ -763,7 +760,7 @@ static void ipaq_read_bulk_callback(struct urb *urb)
763 ipaq_read_bulk_callback, port); 760 ipaq_read_bulk_callback, port);
764 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 761 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
765 if (result) 762 if (result)
766 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 763 err("%s - failed resubmitting read urb, error %d", __func__, result);
767 return; 764 return;
768} 765}
769 766
@@ -774,7 +771,7 @@ static int ipaq_write(struct usb_serial_port *port, const unsigned char *buf,
774 int bytes_sent = 0; 771 int bytes_sent = 0;
775 int transfer_size; 772 int transfer_size;
776 773
777 dbg("%s - port %d", __FUNCTION__, port->number); 774 dbg("%s - port %d", __func__, port->number);
778 775
779 while (count > 0) { 776 while (count > 0) {
780 transfer_size = min(count, PACKET_SIZE); 777 transfer_size = min(count, PACKET_SIZE);
@@ -799,7 +796,7 @@ static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *bu
799 unsigned long flags; 796 unsigned long flags;
800 797
801 if (priv->free_len <= 0) { 798 if (priv->free_len <= 0) {
802 dbg("%s - we're stuffed", __FUNCTION__); 799 dbg("%s - we're stuffed", __func__);
803 return -EAGAIN; 800 return -EAGAIN;
804 } 801 }
805 802
@@ -811,12 +808,12 @@ static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *bu
811 } 808 }
812 spin_unlock_irqrestore(&write_list_lock, flags); 809 spin_unlock_irqrestore(&write_list_lock, flags);
813 if (pkt == NULL) { 810 if (pkt == NULL) {
814 dbg("%s - we're stuffed", __FUNCTION__); 811 dbg("%s - we're stuffed", __func__);
815 return -EAGAIN; 812 return -EAGAIN;
816 } 813 }
817 814
818 memcpy(pkt->data, buf, count); 815 memcpy(pkt->data, buf, count);
819 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, pkt->data); 816 usb_serial_debug_data(debug, &port->dev, __func__, count, pkt->data);
820 817
821 pkt->len = count; 818 pkt->len = count;
822 pkt->written = 0; 819 pkt->written = 0;
@@ -829,7 +826,7 @@ static int ipaq_write_bulk(struct usb_serial_port *port, const unsigned char *bu
829 spin_unlock_irqrestore(&write_list_lock, flags); 826 spin_unlock_irqrestore(&write_list_lock, flags);
830 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 827 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
831 if (result) { 828 if (result) {
832 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 829 err("%s - failed submitting write urb, error %d", __func__, result);
833 } 830 }
834 } else { 831 } else {
835 spin_unlock_irqrestore(&write_list_lock, flags); 832 spin_unlock_irqrestore(&write_list_lock, flags);
@@ -872,17 +869,17 @@ static void ipaq_write_gather(struct usb_serial_port *port)
872 869
873static void ipaq_write_bulk_callback(struct urb *urb) 870static void ipaq_write_bulk_callback(struct urb *urb)
874{ 871{
875 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 872 struct usb_serial_port *port = urb->context;
876 struct ipaq_private *priv = usb_get_serial_port_data(port); 873 struct ipaq_private *priv = usb_get_serial_port_data(port);
877 unsigned long flags; 874 unsigned long flags;
878 int result; 875 int result;
879 int status = urb->status; 876 int status = urb->status;
880 877
881 dbg("%s - port %d", __FUNCTION__, port->number); 878 dbg("%s - port %d", __func__, port->number);
882 879
883 if (status) { 880 if (status) {
884 dbg("%s - nonzero write bulk status received: %d", 881 dbg("%s - nonzero write bulk status received: %d",
885 __FUNCTION__, status); 882 __func__, status);
886 return; 883 return;
887 } 884 }
888 885
@@ -892,7 +889,7 @@ static void ipaq_write_bulk_callback(struct urb *urb)
892 spin_unlock_irqrestore(&write_list_lock, flags); 889 spin_unlock_irqrestore(&write_list_lock, flags);
893 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 890 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
894 if (result) { 891 if (result) {
895 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 892 err("%s - failed submitting write urb, error %d", __func__, result);
896 } 893 }
897 } else { 894 } else {
898 priv->active = 0; 895 priv->active = 0;
@@ -906,7 +903,7 @@ static int ipaq_write_room(struct usb_serial_port *port)
906{ 903{
907 struct ipaq_private *priv = usb_get_serial_port_data(port); 904 struct ipaq_private *priv = usb_get_serial_port_data(port);
908 905
909 dbg("%s - freelen %d", __FUNCTION__, priv->free_len); 906 dbg("%s - freelen %d", __func__, priv->free_len);
910 return priv->free_len; 907 return priv->free_len;
911} 908}
912 909
@@ -914,7 +911,7 @@ static int ipaq_chars_in_buffer(struct usb_serial_port *port)
914{ 911{
915 struct ipaq_private *priv = usb_get_serial_port_data(port); 912 struct ipaq_private *priv = usb_get_serial_port_data(port);
916 913
917 dbg("%s - queuelen %d", __FUNCTION__, priv->queue_len); 914 dbg("%s - queuelen %d", __func__, priv->queue_len);
918 return priv->queue_len; 915 return priv->queue_len;
919} 916}
920 917
@@ -936,7 +933,7 @@ static void ipaq_destroy_lists(struct usb_serial_port *port)
936 933
937static int ipaq_startup(struct usb_serial *serial) 934static int ipaq_startup(struct usb_serial *serial)
938{ 935{
939 dbg("%s", __FUNCTION__); 936 dbg("%s", __func__);
940 if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 937 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
941 err("active config #%d != 1 ??", 938 err("active config #%d != 1 ??",
942 serial->dev->actconfig->desc.bConfigurationValue); 939 serial->dev->actconfig->desc.bConfigurationValue);
@@ -947,7 +944,7 @@ static int ipaq_startup(struct usb_serial *serial)
947 944
948static void ipaq_shutdown(struct usb_serial *serial) 945static void ipaq_shutdown(struct usb_serial *serial)
949{ 946{
950 dbg("%s", __FUNCTION__); 947 dbg("%s", __func__);
951} 948}
952 949
953static int __init ipaq_init(void) 950static int __init ipaq_init(void)
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index cbe5530f3db2..bc85ca5c1c37 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -169,15 +169,15 @@ static void ipw_read_bulk_callback(struct urb *urb)
169 int result; 169 int result;
170 int status = urb->status; 170 int status = urb->status;
171 171
172 dbg("%s - port %d", __FUNCTION__, port->number); 172 dbg("%s - port %d", __func__, port->number);
173 173
174 if (status) { 174 if (status) {
175 dbg("%s - nonzero read bulk status received: %d", 175 dbg("%s - nonzero read bulk status received: %d",
176 __FUNCTION__, status); 176 __func__, status);
177 return; 177 return;
178 } 178 }
179 179
180 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 180 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
181 181
182 tty = port->tty; 182 tty = port->tty;
183 if (tty && urb->actual_length) { 183 if (tty && urb->actual_length) {
@@ -195,7 +195,7 @@ static void ipw_read_bulk_callback(struct urb *urb)
195 ipw_read_bulk_callback, port); 195 ipw_read_bulk_callback, port);
196 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 196 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
197 if (result) 197 if (result)
198 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 198 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
199 return; 199 return;
200} 200}
201 201
@@ -206,7 +206,7 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
206 u8 *buf_flow_init; 206 u8 *buf_flow_init;
207 int result; 207 int result;
208 208
209 dbg("%s", __FUNCTION__); 209 dbg("%s", __func__);
210 210
211 buf_flow_init = kmemdup(buf_flow_static, 16, GFP_KERNEL); 211 buf_flow_init = kmemdup(buf_flow_static, 16, GFP_KERNEL);
212 if (!buf_flow_init) 212 if (!buf_flow_init)
@@ -217,7 +217,7 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
217 217
218 /* --1: Tell the modem to initialize (we think) From sniffs this is always the 218 /* --1: Tell the modem to initialize (we think) From sniffs this is always the
219 * first thing that gets sent to the modem during opening of the device */ 219 * first thing that gets sent to the modem during opening of the device */
220 dbg("%s: Sending SIO_INIT (we guess)",__FUNCTION__); 220 dbg("%s: Sending SIO_INIT (we guess)",__func__);
221 result = usb_control_msg(dev, usb_sndctrlpipe(dev,0), 221 result = usb_control_msg(dev, usb_sndctrlpipe(dev,0),
222 IPW_SIO_INIT, 222 IPW_SIO_INIT,
223 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 223 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -234,7 +234,7 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
234 usb_clear_halt(dev, usb_sndbulkpipe(dev, port->bulk_out_endpointAddress)); 234 usb_clear_halt(dev, usb_sndbulkpipe(dev, port->bulk_out_endpointAddress));
235 235
236 /*--2: Start reading from the device */ 236 /*--2: Start reading from the device */
237 dbg("%s: setting up bulk read callback",__FUNCTION__); 237 dbg("%s: setting up bulk read callback",__func__);
238 usb_fill_bulk_urb(port->read_urb, dev, 238 usb_fill_bulk_urb(port->read_urb, dev,
239 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), 239 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
240 port->bulk_in_buffer, 240 port->bulk_in_buffer,
@@ -242,10 +242,10 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
242 ipw_read_bulk_callback, port); 242 ipw_read_bulk_callback, port);
243 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 243 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
244 if (result < 0) 244 if (result < 0)
245 dbg("%s - usb_submit_urb(read bulk) failed with status %d", __FUNCTION__, result); 245 dbg("%s - usb_submit_urb(read bulk) failed with status %d", __func__, result);
246 246
247 /*--3: Tell the modem to open the floodgates on the rx bulk channel */ 247 /*--3: Tell the modem to open the floodgates on the rx bulk channel */
248 dbg("%s:asking modem for RxRead (RXBULK_ON)",__FUNCTION__); 248 dbg("%s:asking modem for RxRead (RXBULK_ON)",__func__);
249 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 249 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
250 IPW_SIO_RXCTL, 250 IPW_SIO_RXCTL,
251 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 251 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -258,7 +258,7 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
258 dev_err(&port->dev, "Enabling bulk RxRead failed (error = %d)\n", result); 258 dev_err(&port->dev, "Enabling bulk RxRead failed (error = %d)\n", result);
259 259
260 /*--4: setup the initial flowcontrol */ 260 /*--4: setup the initial flowcontrol */
261 dbg("%s:setting init flowcontrol (%s)",__FUNCTION__,buf_flow_init); 261 dbg("%s:setting init flowcontrol (%s)",__func__,buf_flow_init);
262 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 262 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
263 IPW_SIO_HANDFLOW, 263 IPW_SIO_HANDFLOW,
264 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 264 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -272,7 +272,7 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
272 272
273 273
274 /*--5: raise the dtr */ 274 /*--5: raise the dtr */
275 dbg("%s:raising dtr",__FUNCTION__); 275 dbg("%s:raising dtr",__func__);
276 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 276 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
277 IPW_SIO_SET_PIN, 277 IPW_SIO_SET_PIN,
278 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 278 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -285,7 +285,7 @@ static int ipw_open(struct usb_serial_port *port, struct file *filp)
285 dev_err(&port->dev, "setting dtr failed (error = %d)\n", result); 285 dev_err(&port->dev, "setting dtr failed (error = %d)\n", result);
286 286
287 /*--6: raise the rts */ 287 /*--6: raise the rts */
288 dbg("%s:raising rts",__FUNCTION__); 288 dbg("%s:raising rts",__func__);
289 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 289 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
290 IPW_SIO_SET_PIN, 290 IPW_SIO_SET_PIN,
291 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 291 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -307,12 +307,12 @@ static void ipw_close(struct usb_serial_port *port, struct file * filp)
307 int result; 307 int result;
308 308
309 if (tty_hung_up_p(filp)) { 309 if (tty_hung_up_p(filp)) {
310 dbg("%s: tty_hung_up_p ...", __FUNCTION__); 310 dbg("%s: tty_hung_up_p ...", __func__);
311 return; 311 return;
312 } 312 }
313 313
314 /*--1: drop the dtr */ 314 /*--1: drop the dtr */
315 dbg("%s:dropping dtr",__FUNCTION__); 315 dbg("%s:dropping dtr",__func__);
316 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 316 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
317 IPW_SIO_SET_PIN, 317 IPW_SIO_SET_PIN,
318 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 318 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -325,7 +325,7 @@ static void ipw_close(struct usb_serial_port *port, struct file * filp)
325 dev_err(&port->dev, "dropping dtr failed (error = %d)\n", result); 325 dev_err(&port->dev, "dropping dtr failed (error = %d)\n", result);
326 326
327 /*--2: drop the rts */ 327 /*--2: drop the rts */
328 dbg("%s:dropping rts",__FUNCTION__); 328 dbg("%s:dropping rts",__func__);
329 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 329 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
330 IPW_SIO_SET_PIN, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 330 IPW_SIO_SET_PIN, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
331 IPW_PIN_CLRRTS, 331 IPW_PIN_CLRRTS,
@@ -338,7 +338,7 @@ static void ipw_close(struct usb_serial_port *port, struct file * filp)
338 338
339 339
340 /*--3: purge */ 340 /*--3: purge */
341 dbg("%s:sending purge",__FUNCTION__); 341 dbg("%s:sending purge",__func__);
342 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 342 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
343 IPW_SIO_PURGE, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 343 IPW_SIO_PURGE, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
344 0x03, 344 0x03,
@@ -373,13 +373,13 @@ static void ipw_write_bulk_callback(struct urb *urb)
373 struct usb_serial_port *port = urb->context; 373 struct usb_serial_port *port = urb->context;
374 int status = urb->status; 374 int status = urb->status;
375 375
376 dbg("%s", __FUNCTION__); 376 dbg("%s", __func__);
377 377
378 port->write_urb_busy = 0; 378 port->write_urb_busy = 0;
379 379
380 if (status) 380 if (status)
381 dbg("%s - nonzero write bulk status received: %d", 381 dbg("%s - nonzero write bulk status received: %d",
382 __FUNCTION__, status); 382 __func__, status);
383 383
384 usb_serial_port_softint(port); 384 usb_serial_port_softint(port);
385} 385}
@@ -389,18 +389,18 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
389 struct usb_device *dev = port->serial->dev; 389 struct usb_device *dev = port->serial->dev;
390 int ret; 390 int ret;
391 391
392 dbg("%s: TOP: count=%d, in_interrupt=%ld", __FUNCTION__, 392 dbg("%s: TOP: count=%d, in_interrupt=%ld", __func__,
393 count, in_interrupt() ); 393 count, in_interrupt() );
394 394
395 if (count == 0) { 395 if (count == 0) {
396 dbg("%s - write request of 0 bytes", __FUNCTION__); 396 dbg("%s - write request of 0 bytes", __func__);
397 return 0; 397 return 0;
398 } 398 }
399 399
400 spin_lock_bh(&port->lock); 400 spin_lock_bh(&port->lock);
401 if (port->write_urb_busy) { 401 if (port->write_urb_busy) {
402 spin_unlock_bh(&port->lock); 402 spin_unlock_bh(&port->lock);
403 dbg("%s - already writing", __FUNCTION__); 403 dbg("%s - already writing", __func__);
404 return 0; 404 return 0;
405 } 405 }
406 port->write_urb_busy = 1; 406 port->write_urb_busy = 1;
@@ -409,7 +409,7 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
409 count = min(count, port->bulk_out_size); 409 count = min(count, port->bulk_out_size);
410 memcpy(port->bulk_out_buffer, buf, count); 410 memcpy(port->bulk_out_buffer, buf, count);
411 411
412 dbg("%s count now:%d", __FUNCTION__, count); 412 dbg("%s count now:%d", __func__, count);
413 413
414 usb_fill_bulk_urb(port->write_urb, dev, 414 usb_fill_bulk_urb(port->write_urb, dev,
415 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress), 415 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress),
@@ -421,11 +421,11 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
421 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); 421 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
422 if (ret != 0) { 422 if (ret != 0) {
423 port->write_urb_busy = 0; 423 port->write_urb_busy = 0;
424 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __FUNCTION__, ret); 424 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __func__, ret);
425 return ret; 425 return ret;
426 } 426 }
427 427
428 dbg("%s returning %d", __FUNCTION__, count); 428 dbg("%s returning %d", __func__, count);
429 return count; 429 return count;
430} 430}
431 431
@@ -448,9 +448,6 @@ static struct usb_serial_driver ipw_device = {
448 .description = "IPWireless converter", 448 .description = "IPWireless converter",
449 .usb_driver = &usb_ipw_driver, 449 .usb_driver = &usb_ipw_driver,
450 .id_table = usb_ipw_ids, 450 .id_table = usb_ipw_ids,
451 .num_interrupt_in = NUM_DONT_CARE,
452 .num_bulk_in = 1,
453 .num_bulk_out = 1,
454 .num_ports = 1, 451 .num_ports = 1,
455 .open = ipw_open, 452 .open = ipw_open,
456 .close = ipw_close, 453 .close = ipw_close,
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 6b803ab98543..004d57385a75 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -145,9 +145,6 @@ static struct usb_serial_driver ir_device = {
145 .description = "IR Dongle", 145 .description = "IR Dongle",
146 .usb_driver = &ir_driver, 146 .usb_driver = &ir_driver,
147 .id_table = id_table, 147 .id_table = id_table,
148 .num_interrupt_in = 1,
149 .num_bulk_in = 1,
150 .num_bulk_out = 1,
151 .num_ports = 1, 148 .num_ports = 1,
152 .set_termios = ir_set_termios, 149 .set_termios = ir_set_termios,
153 .attach = ir_startup, 150 .attach = ir_startup,
@@ -198,16 +195,16 @@ static struct irda_class_desc *irda_usb_find_class_desc(struct usb_device *dev,
198 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 195 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
199 0, ifnum, desc, sizeof(*desc), 1000); 196 0, ifnum, desc, sizeof(*desc), 1000);
200 197
201 dbg("%s - ret=%d", __FUNCTION__, ret); 198 dbg("%s - ret=%d", __func__, ret);
202 if (ret < sizeof(*desc)) { 199 if (ret < sizeof(*desc)) {
203 dbg("%s - class descriptor read %s (%d)", 200 dbg("%s - class descriptor read %s (%d)",
204 __FUNCTION__, 201 __func__,
205 (ret<0) ? "failed" : "too short", 202 (ret<0) ? "failed" : "too short",
206 ret); 203 ret);
207 goto error; 204 goto error;
208 } 205 }
209 if (desc->bDescriptorType != USB_DT_IRDA) { 206 if (desc->bDescriptorType != USB_DT_IRDA) {
210 dbg("%s - bad class descriptor type", __FUNCTION__); 207 dbg("%s - bad class descriptor type", __func__);
211 goto error; 208 goto error;
212 } 209 }
213 210
@@ -251,7 +248,7 @@ static int ir_startup (struct usb_serial *serial)
251 } 248 }
252 249
253 dbg ("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s", 250 dbg ("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s",
254 __FUNCTION__, 251 __func__,
255 (irda_desc->wBaudRate & 0x0001) ? " 2400" : "", 252 (irda_desc->wBaudRate & 0x0001) ? " 2400" : "",
256 (irda_desc->wBaudRate & 0x0002) ? " 9600" : "", 253 (irda_desc->wBaudRate & 0x0002) ? " 9600" : "",
257 (irda_desc->wBaudRate & 0x0004) ? " 19200" : "", 254 (irda_desc->wBaudRate & 0x0004) ? " 19200" : "",
@@ -284,13 +281,13 @@ static int ir_open (struct usb_serial_port *port, struct file *filp)
284 char *buffer; 281 char *buffer;
285 int result = 0; 282 int result = 0;
286 283
287 dbg("%s - port %d", __FUNCTION__, port->number); 284 dbg("%s - port %d", __func__, port->number);
288 285
289 if (buffer_size) { 286 if (buffer_size) {
290 /* override the default buffer sizes */ 287 /* override the default buffer sizes */
291 buffer = kmalloc (buffer_size, GFP_KERNEL); 288 buffer = kmalloc (buffer_size, GFP_KERNEL);
292 if (!buffer) { 289 if (!buffer) {
293 dev_err (&port->dev, "%s - out of memory.\n", __FUNCTION__); 290 dev_err (&port->dev, "%s - out of memory.\n", __func__);
294 return -ENOMEM; 291 return -ENOMEM;
295 } 292 }
296 kfree (port->read_urb->transfer_buffer); 293 kfree (port->read_urb->transfer_buffer);
@@ -299,7 +296,7 @@ static int ir_open (struct usb_serial_port *port, struct file *filp)
299 296
300 buffer = kmalloc (buffer_size, GFP_KERNEL); 297 buffer = kmalloc (buffer_size, GFP_KERNEL);
301 if (!buffer) { 298 if (!buffer) {
302 dev_err (&port->dev, "%s - out of memory.\n", __FUNCTION__); 299 dev_err (&port->dev, "%s - out of memory.\n", __func__);
303 return -ENOMEM; 300 return -ENOMEM;
304 } 301 }
305 kfree (port->write_urb->transfer_buffer); 302 kfree (port->write_urb->transfer_buffer);
@@ -319,14 +316,14 @@ static int ir_open (struct usb_serial_port *port, struct file *filp)
319 port); 316 port);
320 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 317 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
321 if (result) 318 if (result)
322 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 319 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result);
323 320
324 return result; 321 return result;
325} 322}
326 323
327static void ir_close (struct usb_serial_port *port, struct file * filp) 324static void ir_close (struct usb_serial_port *port, struct file * filp)
328{ 325{
329 dbg("%s - port %d", __FUNCTION__, port->number); 326 dbg("%s - port %d", __func__, port->number);
330 327
331 /* shutdown our bulk read */ 328 /* shutdown our bulk read */
332 usb_kill_urb(port->read_urb); 329 usb_kill_urb(port->read_urb);
@@ -338,10 +335,10 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
338 int result; 335 int result;
339 int transfer_size; 336 int transfer_size;
340 337
341 dbg("%s - port = %d, count = %d", __FUNCTION__, port->number, count); 338 dbg("%s - port = %d, count = %d", __func__, port->number, count);
342 339
343 if (!port->tty) { 340 if (!port->tty) {
344 dev_err (&port->dev, "%s - no tty???\n", __FUNCTION__); 341 dev_err (&port->dev, "%s - no tty???\n", __func__);
345 return 0; 342 return 0;
346 } 343 }
347 344
@@ -351,7 +348,7 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
351 spin_lock_bh(&port->lock); 348 spin_lock_bh(&port->lock);
352 if (port->write_urb_busy) { 349 if (port->write_urb_busy) {
353 spin_unlock_bh(&port->lock); 350 spin_unlock_bh(&port->lock);
354 dbg("%s - already writing", __FUNCTION__); 351 dbg("%s - already writing", __func__);
355 return 0; 352 return 0;
356 } 353 }
357 port->write_urb_busy = 1; 354 port->write_urb_busy = 1;
@@ -387,7 +384,7 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
387 result = usb_submit_urb (port->write_urb, GFP_ATOMIC); 384 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
388 if (result) { 385 if (result) {
389 port->write_urb_busy = 0; 386 port->write_urb_busy = 0;
390 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 387 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result);
391 } else 388 } else
392 result = transfer_size; 389 result = transfer_size;
393 390
@@ -396,22 +393,22 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
396 393
397static void ir_write_bulk_callback (struct urb *urb) 394static void ir_write_bulk_callback (struct urb *urb)
398{ 395{
399 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 396 struct usb_serial_port *port = urb->context;
400 int status = urb->status; 397 int status = urb->status;
401 398
402 dbg("%s - port %d", __FUNCTION__, port->number); 399 dbg("%s - port %d", __func__, port->number);
403 400
404 port->write_urb_busy = 0; 401 port->write_urb_busy = 0;
405 if (status) { 402 if (status) {
406 dbg("%s - nonzero write bulk status received: %d", 403 dbg("%s - nonzero write bulk status received: %d",
407 __FUNCTION__, status); 404 __func__, status);
408 return; 405 return;
409 } 406 }
410 407
411 usb_serial_debug_data ( 408 usb_serial_debug_data (
412 debug, 409 debug,
413 &port->dev, 410 &port->dev,
414 __FUNCTION__, 411 __func__,
415 urb->actual_length, 412 urb->actual_length,
416 urb->transfer_buffer); 413 urb->transfer_buffer);
417 414
@@ -420,16 +417,16 @@ static void ir_write_bulk_callback (struct urb *urb)
420 417
421static void ir_read_bulk_callback (struct urb *urb) 418static void ir_read_bulk_callback (struct urb *urb)
422{ 419{
423 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 420 struct usb_serial_port *port = urb->context;
424 struct tty_struct *tty; 421 struct tty_struct *tty;
425 unsigned char *data = urb->transfer_buffer; 422 unsigned char *data = urb->transfer_buffer;
426 int result; 423 int result;
427 int status = urb->status; 424 int status = urb->status;
428 425
429 dbg("%s - port %d", __FUNCTION__, port->number); 426 dbg("%s - port %d", __func__, port->number);
430 427
431 if (!port->open_count) { 428 if (!port->open_count) {
432 dbg("%s - port closed.", __FUNCTION__); 429 dbg("%s - port closed.", __func__);
433 return; 430 return;
434 } 431 }
435 432
@@ -447,7 +444,7 @@ static void ir_read_bulk_callback (struct urb *urb)
447 usb_serial_debug_data ( 444 usb_serial_debug_data (
448 debug, 445 debug,
449 &port->dev, 446 &port->dev,
450 __FUNCTION__, 447 __func__,
451 urb->actual_length, 448 urb->actual_length,
452 data); 449 data);
453 450
@@ -480,13 +477,13 @@ static void ir_read_bulk_callback (struct urb *urb)
480 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 477 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
481 if (result) 478 if (result)
482 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", 479 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
483 __FUNCTION__, result); 480 __func__, result);
484 481
485 break ; 482 break ;
486 483
487 default: 484 default:
488 dbg("%s - nonzero read bulk status received: %d", 485 dbg("%s - nonzero read bulk status received: %d",
489 __FUNCTION__, 486 __func__,
490 status); 487 status);
491 break ; 488 break ;
492 489
@@ -502,7 +499,7 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t
502 speed_t baud; 499 speed_t baud;
503 int ir_baud; 500 int ir_baud;
504 501
505 dbg("%s - port %d", __FUNCTION__, port->number); 502 dbg("%s - port %d", __func__, port->number);
506 503
507 baud = tty_get_baud_rate(port->tty); 504 baud = tty_get_baud_rate(port->tty);
508 505
@@ -554,7 +551,7 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t
554 551
555 result = usb_submit_urb (port->write_urb, GFP_KERNEL); 552 result = usb_submit_urb (port->write_urb, GFP_KERNEL);
556 if (result) 553 if (result)
557 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 554 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result);
558 555
559 /* Only speed changes are supported */ 556 /* Only speed changes are supported */
560 tty_termios_copy_hw(port->tty->termios, old_termios); 557 tty_termios_copy_hw(port->tty->termios, old_termios);
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index fde188e23ce1..8a217648b250 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -98,10 +98,10 @@ static int iuu_alloc_buf(struct iuu_private *priv)
98 priv->writebuf = kzalloc(256, GFP_KERNEL); 98 priv->writebuf = kzalloc(256, GFP_KERNEL);
99 if (!priv->buf || !priv->dbgbuf || !priv->writebuf) { 99 if (!priv->buf || !priv->dbgbuf || !priv->writebuf) {
100 iuu_free_buf(priv); 100 iuu_free_buf(priv);
101 dbg("%s problem allocation buffer", __FUNCTION__); 101 dbg("%s problem allocation buffer", __func__);
102 return -ENOMEM; 102 return -ENOMEM;
103 } 103 }
104 dbg("%s - Privates buffers allocation success", __FUNCTION__); 104 dbg("%s - Privates buffers allocation success", __func__);
105 return 0; 105 return 0;
106} 106}
107 107
@@ -109,7 +109,7 @@ static int iuu_startup(struct usb_serial *serial)
109{ 109{
110 struct iuu_private *priv; 110 struct iuu_private *priv;
111 priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL); 111 priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL);
112 dbg("%s- priv allocation success", __FUNCTION__); 112 dbg("%s- priv allocation success", __func__);
113 if (!priv) 113 if (!priv)
114 return -ENOMEM; 114 return -ENOMEM;
115 if (iuu_alloc_buf(priv)) { 115 if (iuu_alloc_buf(priv)) {
@@ -130,17 +130,17 @@ static void iuu_shutdown(struct usb_serial *serial)
130 if (!port) 130 if (!port)
131 return; 131 return;
132 132
133 dbg("%s", __FUNCTION__); 133 dbg("%s", __func__);
134 134
135 if (priv) { 135 if (priv) {
136 iuu_free_buf(priv); 136 iuu_free_buf(priv);
137 dbg("%s - I will free all", __FUNCTION__); 137 dbg("%s - I will free all", __func__);
138 usb_set_serial_port_data(port, NULL); 138 usb_set_serial_port_data(port, NULL);
139 139
140 dbg("%s - priv is not anymore in port structure", __FUNCTION__); 140 dbg("%s - priv is not anymore in port structure", __func__);
141 kfree(priv); 141 kfree(priv);
142 142
143 dbg("%s priv is now kfree", __FUNCTION__); 143 dbg("%s priv is now kfree", __func__);
144 } 144 }
145} 145}
146 146
@@ -148,20 +148,21 @@ static int iuu_tiocmset(struct usb_serial_port *port, struct file *file,
148 unsigned int set, unsigned int clear) 148 unsigned int set, unsigned int clear)
149{ 149{
150 struct iuu_private *priv = usb_get_serial_port_data(port); 150 struct iuu_private *priv = usb_get_serial_port_data(port);
151 struct tty_struct *tty; 151 unsigned long flags;
152 tty = port->tty;
153 152
154 dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __FUNCTION__, 153 /* FIXME: locking on tiomstatus */
154 dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __func__,
155 port->number, set, clear); 155 port->number, set, clear);
156
157 spin_lock_irqsave(&priv->lock, flags);
156 if (set & TIOCM_RTS) 158 if (set & TIOCM_RTS)
157 priv->tiostatus = TIOCM_RTS; 159 priv->tiostatus = TIOCM_RTS;
158 160
159 if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) { 161 if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) {
160 dbg("%s TIOCMSET RESET called !!!", __FUNCTION__); 162 dbg("%s TIOCMSET RESET called !!!", __func__);
161 priv->reset = 1; 163 priv->reset = 1;
162 return 0;
163 } 164 }
164 165 spin_unlock_irqrestore(&priv->lock, flags);
165 return 0; 166 return 0;
166} 167}
167 168
@@ -173,17 +174,24 @@ static int iuu_tiocmset(struct usb_serial_port *port, struct file *file,
173static int iuu_tiocmget(struct usb_serial_port *port, struct file *file) 174static int iuu_tiocmget(struct usb_serial_port *port, struct file *file)
174{ 175{
175 struct iuu_private *priv = usb_get_serial_port_data(port); 176 struct iuu_private *priv = usb_get_serial_port_data(port);
176 return priv->tiostatus; 177 unsigned long flags;
178 int rc;
179
180 spin_lock_irqsave(&priv->lock, flags);
181 rc = priv->tiostatus;
182 spin_unlock_irqrestore(&priv->lock, flags);
183
184 return rc;
177} 185}
178 186
179static void iuu_rxcmd(struct urb *urb) 187static void iuu_rxcmd(struct urb *urb)
180{ 188{
181 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 189 struct usb_serial_port *port = urb->context;
182 int result; 190 int result;
183 dbg("%s - enter", __FUNCTION__); 191 dbg("%s - enter", __func__);
184 192
185 if (urb->status) { 193 if (urb->status) {
186 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 194 dbg("%s - urb->status = %d", __func__, urb->status);
187 /* error stop all */ 195 /* error stop all */
188 return; 196 return;
189 } 197 }
@@ -203,7 +211,7 @@ static int iuu_reset(struct usb_serial_port *port, u8 wt)
203 struct iuu_private *priv = usb_get_serial_port_data(port); 211 struct iuu_private *priv = usb_get_serial_port_data(port);
204 int result; 212 int result;
205 char *buf_ptr = port->write_urb->transfer_buffer; 213 char *buf_ptr = port->write_urb->transfer_buffer;
206 dbg("%s - enter", __FUNCTION__); 214 dbg("%s - enter", __func__);
207 215
208 /* Prepare the reset sequence */ 216 /* Prepare the reset sequence */
209 217
@@ -232,19 +240,19 @@ static int iuu_reset(struct usb_serial_port *port, u8 wt)
232 */ 240 */
233static void iuu_update_status_callback(struct urb *urb) 241static void iuu_update_status_callback(struct urb *urb)
234{ 242{
235 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 243 struct usb_serial_port *port = urb->context;
236 struct iuu_private *priv = usb_get_serial_port_data(port); 244 struct iuu_private *priv = usb_get_serial_port_data(port);
237 u8 *st; 245 u8 *st;
238 dbg("%s - enter", __FUNCTION__); 246 dbg("%s - enter", __func__);
239 247
240 if (urb->status) { 248 if (urb->status) {
241 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 249 dbg("%s - urb->status = %d", __func__, urb->status);
242 /* error stop all */ 250 /* error stop all */
243 return; 251 return;
244 } 252 }
245 253
246 st = urb->transfer_buffer; 254 st = urb->transfer_buffer;
247 dbg("%s - enter", __FUNCTION__); 255 dbg("%s - enter", __func__);
248 if (urb->actual_length == 1) { 256 if (urb->actual_length == 1) {
249 switch (st[0]) { 257 switch (st[0]) {
250 case 0x1: 258 case 0x1:
@@ -262,11 +270,11 @@ static void iuu_update_status_callback(struct urb *urb)
262 270
263static void iuu_status_callback(struct urb *urb) 271static void iuu_status_callback(struct urb *urb)
264{ 272{
265 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 273 struct usb_serial_port *port = urb->context;
266 int result; 274 int result;
267 dbg("%s - enter", __FUNCTION__); 275 dbg("%s - enter", __func__);
268 276
269 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 277 dbg("%s - urb->status = %d", __func__, urb->status);
270 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 278 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
271 usb_rcvbulkpipe(port->serial->dev, 279 usb_rcvbulkpipe(port->serial->dev,
272 port->bulk_in_endpointAddress), 280 port->bulk_in_endpointAddress),
@@ -279,7 +287,7 @@ static int iuu_status(struct usb_serial_port *port)
279{ 287{
280 int result; 288 int result;
281 289
282 dbg("%s - enter", __FUNCTION__); 290 dbg("%s - enter", __func__);
283 291
284 memset(port->write_urb->transfer_buffer, IUU_GET_STATE_REGISTER, 1); 292 memset(port->write_urb->transfer_buffer, IUU_GET_STATE_REGISTER, 1);
285 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 293 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
@@ -298,7 +306,7 @@ static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
298 struct usb_serial *serial = port->serial; 306 struct usb_serial *serial = port->serial;
299 int actual = 0; 307 int actual = 0;
300 308
301 dbg("%s - enter", __FUNCTION__); 309 dbg("%s - enter", __func__);
302 310
303 /* send the data out the bulk port */ 311 /* send the data out the bulk port */
304 312
@@ -309,9 +317,9 @@ static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
309 count, &actual, HZ * 1); 317 count, &actual, HZ * 1);
310 318
311 if (status != IUU_OPERATION_OK) { 319 if (status != IUU_OPERATION_OK) {
312 dbg("%s - error = %2x", __FUNCTION__, status); 320 dbg("%s - error = %2x", __func__, status);
313 } else { 321 } else {
314 dbg("%s - write OK !", __FUNCTION__); 322 dbg("%s - write OK !", __func__);
315 } 323 }
316 return status; 324 return status;
317} 325}
@@ -322,7 +330,7 @@ static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
322 struct usb_serial *serial = port->serial; 330 struct usb_serial *serial = port->serial;
323 int actual = 0; 331 int actual = 0;
324 332
325 dbg("%s - enter", __FUNCTION__); 333 dbg("%s - enter", __func__);
326 334
327 /* send the data out the bulk port */ 335 /* send the data out the bulk port */
328 336
@@ -333,9 +341,9 @@ static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
333 count, &actual, HZ * 1); 341 count, &actual, HZ * 1);
334 342
335 if (status != IUU_OPERATION_OK) { 343 if (status != IUU_OPERATION_OK) {
336 dbg("%s - error = %2x", __FUNCTION__, status); 344 dbg("%s - error = %2x", __func__, status);
337 } else { 345 } else {
338 dbg("%s - read OK !", __FUNCTION__); 346 dbg("%s - read OK !", __func__);
339 } 347 }
340 348
341 return status; 349 return status;
@@ -350,7 +358,7 @@ static int iuu_led(struct usb_serial_port *port, unsigned int R,
350 if (!buf) 358 if (!buf)
351 return -ENOMEM; 359 return -ENOMEM;
352 360
353 dbg("%s - enter", __FUNCTION__); 361 dbg("%s - enter", __func__);
354 362
355 buf[0] = IUU_SET_LED; 363 buf[0] = IUU_SET_LED;
356 buf[1] = R & 0xFF; 364 buf[1] = R & 0xFF;
@@ -363,9 +371,9 @@ static int iuu_led(struct usb_serial_port *port, unsigned int R,
363 status = bulk_immediate(port, buf, 8); 371 status = bulk_immediate(port, buf, 8);
364 kfree(buf); 372 kfree(buf);
365 if (status != IUU_OPERATION_OK) 373 if (status != IUU_OPERATION_OK)
366 dbg("%s - led error status = %2x", __FUNCTION__, status); 374 dbg("%s - led error status = %2x", __func__, status);
367 else 375 else
368 dbg("%s - led OK !", __FUNCTION__); 376 dbg("%s - led OK !", __func__);
369 return IUU_OPERATION_OK; 377 return IUU_OPERATION_OK;
370} 378}
371 379
@@ -384,7 +392,7 @@ static void iuu_rgbf_fill_buffer(u8 *buf, u8 r1, u8 r2, u8 g1, u8 g2, u8 b1,
384 392
385static void iuu_led_activity_on(struct urb *urb) 393static void iuu_led_activity_on(struct urb *urb)
386{ 394{
387 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 395 struct usb_serial_port *port = urb->context;
388 int result; 396 int result;
389 char *buf_ptr = port->write_urb->transfer_buffer; 397 char *buf_ptr = port->write_urb->transfer_buffer;
390 *buf_ptr++ = IUU_SET_LED; 398 *buf_ptr++ = IUU_SET_LED;
@@ -405,7 +413,7 @@ static void iuu_led_activity_on(struct urb *urb)
405 413
406static void iuu_led_activity_off(struct urb *urb) 414static void iuu_led_activity_off(struct urb *urb)
407{ 415{
408 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 416 struct usb_serial_port *port = urb->context;
409 int result; 417 int result;
410 char *buf_ptr = port->write_urb->transfer_buffer; 418 char *buf_ptr = port->write_urb->transfer_buffer;
411 if (xmas == 1) { 419 if (xmas == 1) {
@@ -443,7 +451,7 @@ static int iuu_clk(struct usb_serial_port *port, int dwFrq)
443 unsigned int P2 = 0; 451 unsigned int P2 = 0;
444 int frq = (int)dwFrq; 452 int frq = (int)dwFrq;
445 453
446 dbg("%s - enter", __FUNCTION__); 454 dbg("%s - enter", __func__);
447 455
448 if (frq == 0) { 456 if (frq == 0) {
449 priv->buf[Count++] = IUU_UART_WRITE_I2C; 457 priv->buf[Count++] = IUU_UART_WRITE_I2C;
@@ -453,7 +461,7 @@ static int iuu_clk(struct usb_serial_port *port, int dwFrq)
453 461
454 status = bulk_immediate(port, (u8 *) priv->buf, Count); 462 status = bulk_immediate(port, (u8 *) priv->buf, Count);
455 if (status != 0) { 463 if (status != 0) {
456 dbg("%s - write error ", __FUNCTION__); 464 dbg("%s - write error ", __func__);
457 return status; 465 return status;
458 } 466 }
459 } else if (frq == 3579000) { 467 } else if (frq == 3579000) {
@@ -562,7 +570,7 @@ static int iuu_clk(struct usb_serial_port *port, int dwFrq)
562 570
563 status = bulk_immediate(port, (u8 *) priv->buf, Count); 571 status = bulk_immediate(port, (u8 *) priv->buf, Count);
564 if (status != IUU_OPERATION_OK) 572 if (status != IUU_OPERATION_OK)
565 dbg("%s - write error ", __FUNCTION__); 573 dbg("%s - write error ", __func__);
566 return status; 574 return status;
567} 575}
568 576
@@ -573,7 +581,7 @@ static int iuu_uart_flush(struct usb_serial_port *port)
573 u8 rxcmd = IUU_UART_RX; 581 u8 rxcmd = IUU_UART_RX;
574 struct iuu_private *priv = usb_get_serial_port_data(port); 582 struct iuu_private *priv = usb_get_serial_port_data(port);
575 583
576 dbg("%s - enter", __FUNCTION__); 584 dbg("%s - enter", __func__);
577 585
578 if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0) 586 if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0)
579 return -EIO; 587 return -EIO;
@@ -581,50 +589,50 @@ static int iuu_uart_flush(struct usb_serial_port *port)
581 for (i = 0; i < 2; i++) { 589 for (i = 0; i < 2; i++) {
582 status = bulk_immediate(port, &rxcmd, 1); 590 status = bulk_immediate(port, &rxcmd, 1);
583 if (status != IUU_OPERATION_OK) { 591 if (status != IUU_OPERATION_OK) {
584 dbg("%s - uart_flush_write error", __FUNCTION__); 592 dbg("%s - uart_flush_write error", __func__);
585 return status; 593 return status;
586 } 594 }
587 595
588 status = read_immediate(port, &priv->len, 1); 596 status = read_immediate(port, &priv->len, 1);
589 if (status != IUU_OPERATION_OK) { 597 if (status != IUU_OPERATION_OK) {
590 dbg("%s - uart_flush_read error", __FUNCTION__); 598 dbg("%s - uart_flush_read error", __func__);
591 return status; 599 return status;
592 } 600 }
593 601
594 if (priv->len > 0) { 602 if (priv->len > 0) {
595 dbg("%s - uart_flush datalen is : %i ", __FUNCTION__, 603 dbg("%s - uart_flush datalen is : %i ", __func__,
596 priv->len); 604 priv->len);
597 status = read_immediate(port, priv->buf, priv->len); 605 status = read_immediate(port, priv->buf, priv->len);
598 if (status != IUU_OPERATION_OK) { 606 if (status != IUU_OPERATION_OK) {
599 dbg("%s - uart_flush_read error", __FUNCTION__); 607 dbg("%s - uart_flush_read error", __func__);
600 return status; 608 return status;
601 } 609 }
602 } 610 }
603 } 611 }
604 dbg("%s - uart_flush_read OK!", __FUNCTION__); 612 dbg("%s - uart_flush_read OK!", __func__);
605 iuu_led(port, 0, 0xF000, 0, 0xFF); 613 iuu_led(port, 0, 0xF000, 0, 0xFF);
606 return status; 614 return status;
607} 615}
608 616
609static void read_buf_callback(struct urb *urb) 617static void read_buf_callback(struct urb *urb)
610{ 618{
611 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 619 struct usb_serial_port *port = urb->context;
612 unsigned char *data = urb->transfer_buffer; 620 unsigned char *data = urb->transfer_buffer;
613 struct tty_struct *tty; 621 struct tty_struct *tty;
614 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 622 dbg("%s - urb->status = %d", __func__, urb->status);
615 623
616 if (urb->status) { 624 if (urb->status) {
617 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 625 dbg("%s - urb->status = %d", __func__, urb->status);
618 if (urb->status == -EPROTO) { 626 if (urb->status == -EPROTO) {
619 /* reschedule needed */ 627 /* reschedule needed */
620 } 628 }
621 return; 629 return;
622 } 630 }
623 631
624 dbg("%s - %i chars to write", __FUNCTION__, urb->actual_length); 632 dbg("%s - %i chars to write", __func__, urb->actual_length);
625 tty = port->tty; 633 tty = port->tty;
626 if (data == NULL) 634 if (data == NULL)
627 dbg("%s - data is NULL !!!", __FUNCTION__); 635 dbg("%s - data is NULL !!!", __func__);
628 if (tty && urb->actual_length && data) { 636 if (tty && urb->actual_length && data) {
629 tty_insert_flip_string(tty, data, urb->actual_length); 637 tty_insert_flip_string(tty, data, urb->actual_length);
630 tty_flip_buffer_push(tty); 638 tty_flip_buffer_push(tty);
@@ -639,7 +647,7 @@ static int iuu_bulk_write(struct usb_serial_port *port)
639 int result; 647 int result;
640 int i; 648 int i;
641 char *buf_ptr = port->write_urb->transfer_buffer; 649 char *buf_ptr = port->write_urb->transfer_buffer;
642 dbg("%s - enter", __FUNCTION__); 650 dbg("%s - enter", __func__);
643 651
644 *buf_ptr++ = IUU_UART_ESC; 652 *buf_ptr++ = IUU_UART_ESC;
645 *buf_ptr++ = IUU_UART_TX; 653 *buf_ptr++ = IUU_UART_TX;
@@ -652,7 +660,7 @@ static int iuu_bulk_write(struct usb_serial_port *port)
652 sprintf(priv->dbgbuf + i*2 , 660 sprintf(priv->dbgbuf + i*2 ,
653 "%02X", priv->writebuf[i]); 661 "%02X", priv->writebuf[i]);
654 priv->dbgbuf[priv->writelen+i*2] = 0; 662 priv->dbgbuf[priv->writelen+i*2] = 0;
655 dbg("%s - writing %i chars : %s", __FUNCTION__, 663 dbg("%s - writing %i chars : %s", __func__,
656 priv->writelen, priv->dbgbuf); 664 priv->writelen, priv->dbgbuf);
657 } 665 }
658 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 666 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
@@ -671,7 +679,7 @@ static int iuu_bulk_write(struct usb_serial_port *port)
671static int iuu_read_buf(struct usb_serial_port *port, int len) 679static int iuu_read_buf(struct usb_serial_port *port, int len)
672{ 680{
673 int result; 681 int result;
674 dbg("%s - enter", __FUNCTION__); 682 dbg("%s - enter", __func__);
675 683
676 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 684 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
677 usb_rcvbulkpipe(port->serial->dev, 685 usb_rcvbulkpipe(port->serial->dev,
@@ -684,7 +692,7 @@ static int iuu_read_buf(struct usb_serial_port *port, int len)
684 692
685static void iuu_uart_read_callback(struct urb *urb) 693static void iuu_uart_read_callback(struct urb *urb)
686{ 694{
687 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 695 struct usb_serial_port *port = urb->context;
688 struct iuu_private *priv = usb_get_serial_port_data(port); 696 struct iuu_private *priv = usb_get_serial_port_data(port);
689 unsigned int flags; 697 unsigned int flags;
690 int status; 698 int status;
@@ -693,21 +701,21 @@ static void iuu_uart_read_callback(struct urb *urb)
693 unsigned char *data = urb->transfer_buffer; 701 unsigned char *data = urb->transfer_buffer;
694 priv->poll++; 702 priv->poll++;
695 703
696 dbg("%s - enter", __FUNCTION__); 704 dbg("%s - enter", __func__);
697 705
698 if (urb->status) { 706 if (urb->status) {
699 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 707 dbg("%s - urb->status = %d", __func__, urb->status);
700 /* error stop all */ 708 /* error stop all */
701 return; 709 return;
702 } 710 }
703 if (data == NULL) 711 if (data == NULL)
704 dbg("%s - data is NULL !!!", __FUNCTION__); 712 dbg("%s - data is NULL !!!", __func__);
705 713
706 if (urb->actual_length == 1 && data != NULL) 714 if (urb->actual_length == 1 && data != NULL)
707 len = (int) data[0]; 715 len = (int) data[0];
708 716
709 if (urb->actual_length > 1) { 717 if (urb->actual_length > 1) {
710 dbg("%s - urb->actual_length = %i", __FUNCTION__, 718 dbg("%s - urb->actual_length = %i", __func__,
711 urb->actual_length); 719 urb->actual_length);
712 error = 1; 720 error = 1;
713 return; 721 return;
@@ -716,7 +724,7 @@ static void iuu_uart_read_callback(struct urb *urb)
716 724
717 if (len > 0 && error == 0) { 725 if (len > 0 && error == 0) {
718 dbg("%s - call read buf - len to read is %i ", 726 dbg("%s - call read buf - len to read is %i ",
719 __FUNCTION__, len); 727 __func__, len);
720 status = iuu_read_buf(port, len); 728 status = iuu_read_buf(port, len);
721 return; 729 return;
722 } 730 }
@@ -742,7 +750,7 @@ static void iuu_uart_read_callback(struct urb *urb)
742 } 750 }
743 spin_unlock_irqrestore(&priv->lock, flags); 751 spin_unlock_irqrestore(&priv->lock, flags);
744 /* if nothing to write call again rxcmd */ 752 /* if nothing to write call again rxcmd */
745 dbg("%s - rxcmd recall", __FUNCTION__); 753 dbg("%s - rxcmd recall", __func__);
746 iuu_led_activity_off(urb); 754 iuu_led_activity_off(urb);
747 return; 755 return;
748} 756}
@@ -752,7 +760,7 @@ static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf,
752{ 760{
753 struct iuu_private *priv = usb_get_serial_port_data(port); 761 struct iuu_private *priv = usb_get_serial_port_data(port);
754 unsigned int flags; 762 unsigned int flags;
755 dbg("%s - enter", __FUNCTION__); 763 dbg("%s - enter", __func__);
756 764
757 if (count > 256) 765 if (count > 256)
758 return -ENOMEM; 766 return -ENOMEM;
@@ -773,14 +781,14 @@ static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf,
773 781
774static void read_rxcmd_callback(struct urb *urb) 782static void read_rxcmd_callback(struct urb *urb)
775{ 783{
776 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 784 struct usb_serial_port *port = urb->context;
777 int result; 785 int result;
778 dbg("%s - enter", __FUNCTION__); 786 dbg("%s - enter", __func__);
779 787
780 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 788 dbg("%s - urb->status = %d", __func__, urb->status);
781 789
782 if (urb->status) { 790 if (urb->status) {
783 dbg("%s - urb->status = %d", __FUNCTION__, urb->status); 791 dbg("%s - urb->status = %d", __func__, urb->status);
784 /* error stop all */ 792 /* error stop all */
785 return; 793 return;
786 } 794 }
@@ -791,7 +799,7 @@ static void read_rxcmd_callback(struct urb *urb)
791 port->read_urb->transfer_buffer, 256, 799 port->read_urb->transfer_buffer, 256,
792 iuu_uart_read_callback, port); 800 iuu_uart_read_callback, port);
793 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 801 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
794 dbg("%s - submit result = %d", __FUNCTION__, result); 802 dbg("%s - submit result = %d", __func__, result);
795 return; 803 return;
796} 804}
797 805
@@ -812,13 +820,13 @@ static int iuu_uart_on(struct usb_serial_port *port)
812 820
813 status = bulk_immediate(port, buf, 4); 821 status = bulk_immediate(port, buf, 4);
814 if (status != IUU_OPERATION_OK) { 822 if (status != IUU_OPERATION_OK) {
815 dbg("%s - uart_on error", __FUNCTION__); 823 dbg("%s - uart_on error", __func__);
816 goto uart_enable_failed; 824 goto uart_enable_failed;
817 } 825 }
818 /* iuu_reset() the card after iuu_uart_on() */ 826 /* iuu_reset() the card after iuu_uart_on() */
819 status = iuu_uart_flush(port); 827 status = iuu_uart_flush(port);
820 if (status != IUU_OPERATION_OK) 828 if (status != IUU_OPERATION_OK)
821 dbg("%s - uart_flush error", __FUNCTION__); 829 dbg("%s - uart_flush error", __func__);
822uart_enable_failed: 830uart_enable_failed:
823 kfree(buf); 831 kfree(buf);
824 return status; 832 return status;
@@ -836,7 +844,7 @@ static int iuu_uart_off(struct usb_serial_port *port)
836 844
837 status = bulk_immediate(port, buf, 1); 845 status = bulk_immediate(port, buf, 1);
838 if (status != IUU_OPERATION_OK) 846 if (status != IUU_OPERATION_OK)
839 dbg("%s - uart_off error", __FUNCTION__); 847 dbg("%s - uart_off error", __func__);
840 848
841 kfree(buf); 849 kfree(buf);
842 return status; 850 return status;
@@ -930,7 +938,7 @@ static int iuu_uart_baud(struct usb_serial_port *port, u32 baud,
930 938
931 status = bulk_immediate(port, dataout, DataCount); 939 status = bulk_immediate(port, dataout, DataCount);
932 if (status != IUU_OPERATION_OK) 940 if (status != IUU_OPERATION_OK)
933 dbg("%s - uart_off error", __FUNCTION__); 941 dbg("%s - uart_off error", __func__);
934 kfree(dataout); 942 kfree(dataout);
935 return status; 943 return status;
936} 944}
@@ -952,7 +960,7 @@ static void iuu_close(struct usb_serial_port *port, struct file *filp)
952 if (!serial) 960 if (!serial)
953 return; 961 return;
954 962
955 dbg("%s - port %d", __FUNCTION__, port->number); 963 dbg("%s - port %d", __func__, port->number);
956 964
957 iuu_uart_off(port); 965 iuu_uart_off(port);
958 if (serial->dev) { 966 if (serial->dev) {
@@ -969,7 +977,7 @@ static void iuu_close(struct usb_serial_port *port, struct file *filp)
969 } 977 }
970 /* free writebuf */ 978 /* free writebuf */
971 /* shutdown our urbs */ 979 /* shutdown our urbs */
972 dbg("%s - shutting down urbs", __FUNCTION__); 980 dbg("%s - shutting down urbs", __func__);
973 usb_kill_urb(port->write_urb); 981 usb_kill_urb(port->write_urb);
974 usb_kill_urb(port->read_urb); 982 usb_kill_urb(port->read_urb);
975 usb_kill_urb(port->interrupt_in_urb); 983 usb_kill_urb(port->interrupt_in_urb);
@@ -990,7 +998,7 @@ static int iuu_open(struct usb_serial_port *port, struct file *filp)
990 unsigned long flags; 998 unsigned long flags;
991 struct iuu_private *priv = usb_get_serial_port_data(port); 999 struct iuu_private *priv = usb_get_serial_port_data(port);
992 1000
993 dbg("%s - port %d", __FUNCTION__, port->number); 1001 dbg("%s - port %d", __func__, port->number);
994 usb_clear_halt(serial->dev, port->write_urb->pipe); 1002 usb_clear_halt(serial->dev, port->write_urb->pipe);
995 usb_clear_halt(serial->dev, port->read_urb->pipe); 1003 usb_clear_halt(serial->dev, port->read_urb->pipe);
996 1004
@@ -1127,7 +1135,7 @@ static int iuu_open(struct usb_serial_port *port, struct file *filp)
1127 1135
1128 iuu_uart_flush(port); 1136 iuu_uart_flush(port);
1129 1137
1130 dbg("%s - initialization done", __FUNCTION__); 1138 dbg("%s - initialization done", __func__);
1131 1139
1132 memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1); 1140 memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1);
1133 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 1141 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
@@ -1139,11 +1147,11 @@ static int iuu_open(struct usb_serial_port *port, struct file *filp)
1139 1147
1140 if (result) { 1148 if (result) {
1141 dev_err(&port->dev, "%s - failed submitting read urb," 1149 dev_err(&port->dev, "%s - failed submitting read urb,"
1142 " error %d\n", __FUNCTION__, result); 1150 " error %d\n", __func__, result);
1143 iuu_close(port, NULL); 1151 iuu_close(port, NULL);
1144 return -EPROTO; 1152 return -EPROTO;
1145 } else { 1153 } else {
1146 dbg("%s - rxcmd OK", __FUNCTION__); 1154 dbg("%s - rxcmd OK", __func__);
1147 } 1155 }
1148 return result; 1156 return result;
1149} 1157}
@@ -1154,9 +1162,6 @@ static struct usb_serial_driver iuu_device = {
1154 .name = "iuu_phoenix", 1162 .name = "iuu_phoenix",
1155 }, 1163 },
1156 .id_table = id_table, 1164 .id_table = id_table,
1157 .num_interrupt_in = NUM_DONT_CARE,
1158 .num_bulk_in = 1,
1159 .num_bulk_out = 1,
1160 .num_ports = 1, 1165 .num_ports = 1,
1161 .open = iuu_open, 1166 .open = iuu_open,
1162 .close = iuu_close, 1167 .close = iuu_close,
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index ea7bba69f4da..3df8a66c5c3c 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -244,13 +244,13 @@ module_exit(keyspan_exit);
244 244
245static void keyspan_rx_throttle (struct usb_serial_port *port) 245static void keyspan_rx_throttle (struct usb_serial_port *port)
246{ 246{
247 dbg("%s - port %d", __FUNCTION__, port->number); 247 dbg("%s - port %d", __func__, port->number);
248} 248}
249 249
250 250
251static void keyspan_rx_unthrottle (struct usb_serial_port *port) 251static void keyspan_rx_unthrottle (struct usb_serial_port *port)
252{ 252{
253 dbg("%s - port %d", __FUNCTION__, port->number); 253 dbg("%s - port %d", __func__, port->number);
254} 254}
255 255
256 256
@@ -258,7 +258,7 @@ static void keyspan_break_ctl (struct usb_serial_port *port, int break_state)
258{ 258{
259 struct keyspan_port_private *p_priv; 259 struct keyspan_port_private *p_priv;
260 260
261 dbg("%s", __FUNCTION__); 261 dbg("%s", __func__);
262 262
263 p_priv = usb_get_serial_port_data(port); 263 p_priv = usb_get_serial_port_data(port);
264 264
@@ -280,7 +280,7 @@ static void keyspan_set_termios (struct usb_serial_port *port,
280 unsigned int cflag; 280 unsigned int cflag;
281 struct tty_struct *tty = port->tty; 281 struct tty_struct *tty = port->tty;
282 282
283 dbg("%s", __FUNCTION__); 283 dbg("%s", __func__);
284 284
285 p_priv = usb_get_serial_port_data(port); 285 p_priv = usb_get_serial_port_data(port);
286 d_details = p_priv->device_details; 286 d_details = p_priv->device_details;
@@ -377,7 +377,7 @@ static int keyspan_write(struct usb_serial_port *port,
377 } 377 }
378 378
379 dbg("%s - for port %d (%d chars), flip=%d", 379 dbg("%s - for port %d (%d chars), flip=%d",
380 __FUNCTION__, port->number, count, p_priv->out_flip); 380 __func__, port->number, count, p_priv->out_flip);
381 381
382 for (left = count; left > 0; left -= todo) { 382 for (left = count; left > 0; left -= todo) {
383 todo = left; 383 todo = left;
@@ -389,11 +389,11 @@ static int keyspan_write(struct usb_serial_port *port,
389 /* Check we have a valid urb/endpoint before we use it... */ 389 /* Check we have a valid urb/endpoint before we use it... */
390 if ((this_urb = p_priv->out_urbs[flip]) == NULL) { 390 if ((this_urb = p_priv->out_urbs[flip]) == NULL) {
391 /* no bulk out, so return 0 bytes written */ 391 /* no bulk out, so return 0 bytes written */
392 dbg("%s - no output urb :(", __FUNCTION__); 392 dbg("%s - no output urb :(", __func__);
393 return count; 393 return count;
394 } 394 }
395 395
396 dbg("%s - endpoint %d flip %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), flip); 396 dbg("%s - endpoint %d flip %d", __func__, usb_pipeendpoint(this_urb->pipe), flip);
397 397
398 if (this_urb->status == -EINPROGRESS) { 398 if (this_urb->status == -EINPROGRESS) {
399 if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ)) 399 if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ))
@@ -435,17 +435,17 @@ static void usa26_indat_callback(struct urb *urb)
435 unsigned char *data = urb->transfer_buffer; 435 unsigned char *data = urb->transfer_buffer;
436 int status = urb->status; 436 int status = urb->status;
437 437
438 dbg ("%s", __FUNCTION__); 438 dbg ("%s", __func__);
439 439
440 endpoint = usb_pipeendpoint(urb->pipe); 440 endpoint = usb_pipeendpoint(urb->pipe);
441 441
442 if (status) { 442 if (status) {
443 dbg("%s - nonzero status: %x on endpoint %d.", 443 dbg("%s - nonzero status: %x on endpoint %d.",
444 __FUNCTION__, status, endpoint); 444 __func__, status, endpoint);
445 return; 445 return;
446 } 446 }
447 447
448 port = (struct usb_serial_port *) urb->context; 448 port = urb->context;
449 tty = port->tty; 449 tty = port->tty;
450 if (tty && urb->actual_length) { 450 if (tty && urb->actual_length) {
451 /* 0x80 bit is error flag */ 451 /* 0x80 bit is error flag */
@@ -459,7 +459,7 @@ static void usa26_indat_callback(struct urb *urb)
459 } 459 }
460 } else { 460 } else {
461 /* some bytes had errors, every byte has status */ 461 /* some bytes had errors, every byte has status */
462 dbg("%s - RX error!!!!", __FUNCTION__); 462 dbg("%s - RX error!!!!", __func__);
463 for (i = 0; i + 1 < urb->actual_length; i += 2) { 463 for (i = 0; i + 1 < urb->actual_length; i += 2) {
464 int stat = data[i], flag = 0; 464 int stat = data[i], flag = 0;
465 if (stat & RXERROR_OVERRUN) 465 if (stat & RXERROR_OVERRUN)
@@ -479,7 +479,7 @@ static void usa26_indat_callback(struct urb *urb)
479 urb->dev = port->serial->dev; 479 urb->dev = port->serial->dev;
480 if (port->open_count) 480 if (port->open_count)
481 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 481 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
482 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 482 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
483 } 483 }
484 return; 484 return;
485} 485}
@@ -490,9 +490,9 @@ static void usa2x_outdat_callback(struct urb *urb)
490 struct usb_serial_port *port; 490 struct usb_serial_port *port;
491 struct keyspan_port_private *p_priv; 491 struct keyspan_port_private *p_priv;
492 492
493 port = (struct usb_serial_port *) urb->context; 493 port = urb->context;
494 p_priv = usb_get_serial_port_data(port); 494 p_priv = usb_get_serial_port_data(port);
495 dbg ("%s - urb %d", __FUNCTION__, urb == p_priv->out_urbs[1]); 495 dbg ("%s - urb %d", __func__, urb == p_priv->out_urbs[1]);
496 496
497 if (port->open_count) 497 if (port->open_count)
498 usb_serial_port_softint(port); 498 usb_serial_port_softint(port);
@@ -500,7 +500,7 @@ static void usa2x_outdat_callback(struct urb *urb)
500 500
501static void usa26_inack_callback(struct urb *urb) 501static void usa26_inack_callback(struct urb *urb)
502{ 502{
503 dbg ("%s", __FUNCTION__); 503 dbg ("%s", __func__);
504 504
505} 505}
506 506
@@ -509,11 +509,11 @@ static void usa26_outcont_callback(struct urb *urb)
509 struct usb_serial_port *port; 509 struct usb_serial_port *port;
510 struct keyspan_port_private *p_priv; 510 struct keyspan_port_private *p_priv;
511 511
512 port = (struct usb_serial_port *) urb->context; 512 port = urb->context;
513 p_priv = usb_get_serial_port_data(port); 513 p_priv = usb_get_serial_port_data(port);
514 514
515 if (p_priv->resend_cont) { 515 if (p_priv->resend_cont) {
516 dbg ("%s - sending setup", __FUNCTION__); 516 dbg ("%s - sending setup", __func__);
517 keyspan_usa26_send_setup(port->serial, port, p_priv->resend_cont - 1); 517 keyspan_usa26_send_setup(port->serial, port, p_priv->resend_cont - 1);
518 } 518 }
519} 519}
@@ -528,14 +528,14 @@ static void usa26_instat_callback(struct urb *urb)
528 int old_dcd_state, err; 528 int old_dcd_state, err;
529 int status = urb->status; 529 int status = urb->status;
530 530
531 serial = (struct usb_serial *) urb->context; 531 serial = urb->context;
532 532
533 if (status) { 533 if (status) {
534 dbg("%s - nonzero status: %x", __FUNCTION__, status); 534 dbg("%s - nonzero status: %x", __func__, status);
535 return; 535 return;
536 } 536 }
537 if (urb->actual_length != 9) { 537 if (urb->actual_length != 9) {
538 dbg("%s - %d byte report??", __FUNCTION__, urb->actual_length); 538 dbg("%s - %d byte report??", __func__, urb->actual_length);
539 goto exit; 539 goto exit;
540 } 540 }
541 541
@@ -543,7 +543,7 @@ static void usa26_instat_callback(struct urb *urb)
543 543
544#if 0 544#if 0
545 dbg("%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d", 545 dbg("%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d",
546 __FUNCTION__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr, msg->ri, msg->_txOff, 546 __func__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr, msg->ri, msg->_txOff,
547 msg->_txXoff, msg->rxEnabled, msg->controlResponse); 547 msg->_txXoff, msg->rxEnabled, msg->controlResponse);
548#endif 548#endif
549 549
@@ -552,7 +552,7 @@ static void usa26_instat_callback(struct urb *urb)
552 552
553 /* Check port number from message and retrieve private data */ 553 /* Check port number from message and retrieve private data */
554 if (msg->port >= serial->num_ports) { 554 if (msg->port >= serial->num_ports) {
555 dbg ("%s - Unexpected port number %d", __FUNCTION__, msg->port); 555 dbg ("%s - Unexpected port number %d", __func__, msg->port);
556 goto exit; 556 goto exit;
557 } 557 }
558 port = serial->port[msg->port]; 558 port = serial->port[msg->port];
@@ -576,14 +576,14 @@ static void usa26_instat_callback(struct urb *urb)
576 /* Resubmit urb so we continue receiving */ 576 /* Resubmit urb so we continue receiving */
577 urb->dev = serial->dev; 577 urb->dev = serial->dev;
578 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 578 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
579 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 579 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
580 } 580 }
581exit: ; 581exit: ;
582} 582}
583 583
584static void usa26_glocont_callback(struct urb *urb) 584static void usa26_glocont_callback(struct urb *urb)
585{ 585{
586 dbg ("%s", __FUNCTION__); 586 dbg ("%s", __func__);
587 587
588} 588}
589 589
@@ -597,9 +597,9 @@ static void usa28_indat_callback(struct urb *urb)
597 struct keyspan_port_private *p_priv; 597 struct keyspan_port_private *p_priv;
598 int status = urb->status; 598 int status = urb->status;
599 599
600 dbg ("%s", __FUNCTION__); 600 dbg ("%s", __func__);
601 601
602 port = (struct usb_serial_port *) urb->context; 602 port = urb->context;
603 p_priv = usb_get_serial_port_data(port); 603 p_priv = usb_get_serial_port_data(port);
604 data = urb->transfer_buffer; 604 data = urb->transfer_buffer;
605 605
@@ -609,11 +609,11 @@ static void usa28_indat_callback(struct urb *urb)
609 do { 609 do {
610 if (status) { 610 if (status) {
611 dbg("%s - nonzero status: %x on endpoint %d.", 611 dbg("%s - nonzero status: %x on endpoint %d.",
612 __FUNCTION__, status, usb_pipeendpoint(urb->pipe)); 612 __func__, status, usb_pipeendpoint(urb->pipe));
613 return; 613 return;
614 } 614 }
615 615
616 port = (struct usb_serial_port *) urb->context; 616 port = urb->context;
617 p_priv = usb_get_serial_port_data(port); 617 p_priv = usb_get_serial_port_data(port);
618 data = urb->transfer_buffer; 618 data = urb->transfer_buffer;
619 619
@@ -629,7 +629,7 @@ static void usa28_indat_callback(struct urb *urb)
629 urb->dev = port->serial->dev; 629 urb->dev = port->serial->dev;
630 if (port->open_count) 630 if (port->open_count)
631 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 631 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
632 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 632 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
633 } 633 }
634 p_priv->in_flip ^= 1; 634 p_priv->in_flip ^= 1;
635 635
@@ -639,7 +639,7 @@ static void usa28_indat_callback(struct urb *urb)
639 639
640static void usa28_inack_callback(struct urb *urb) 640static void usa28_inack_callback(struct urb *urb)
641{ 641{
642 dbg ("%s", __FUNCTION__); 642 dbg ("%s", __func__);
643} 643}
644 644
645static void usa28_outcont_callback(struct urb *urb) 645static void usa28_outcont_callback(struct urb *urb)
@@ -647,11 +647,11 @@ static void usa28_outcont_callback(struct urb *urb)
647 struct usb_serial_port *port; 647 struct usb_serial_port *port;
648 struct keyspan_port_private *p_priv; 648 struct keyspan_port_private *p_priv;
649 649
650 port = (struct usb_serial_port *) urb->context; 650 port = urb->context;
651 p_priv = usb_get_serial_port_data(port); 651 p_priv = usb_get_serial_port_data(port);
652 652
653 if (p_priv->resend_cont) { 653 if (p_priv->resend_cont) {
654 dbg ("%s - sending setup", __FUNCTION__); 654 dbg ("%s - sending setup", __func__);
655 keyspan_usa28_send_setup(port->serial, port, p_priv->resend_cont - 1); 655 keyspan_usa28_send_setup(port->serial, port, p_priv->resend_cont - 1);
656 } 656 }
657} 657}
@@ -667,19 +667,19 @@ static void usa28_instat_callback(struct urb *urb)
667 int old_dcd_state; 667 int old_dcd_state;
668 int status = urb->status; 668 int status = urb->status;
669 669
670 serial = (struct usb_serial *) urb->context; 670 serial = urb->context;
671 671
672 if (status) { 672 if (status) {
673 dbg("%s - nonzero status: %x", __FUNCTION__, status); 673 dbg("%s - nonzero status: %x", __func__, status);
674 return; 674 return;
675 } 675 }
676 676
677 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) { 677 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
678 dbg("%s - bad length %d", __FUNCTION__, urb->actual_length); 678 dbg("%s - bad length %d", __func__, urb->actual_length);
679 goto exit; 679 goto exit;
680 } 680 }
681 681
682 /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __FUNCTION__ 682 /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__
683 data[0], data[1], data[2], data[3], data[4], data[5], 683 data[0], data[1], data[2], data[3], data[4], data[5],
684 data[6], data[7], data[8], data[9], data[10], data[11]);*/ 684 data[6], data[7], data[8], data[9], data[10], data[11]);*/
685 685
@@ -689,7 +689,7 @@ static void usa28_instat_callback(struct urb *urb)
689 689
690 /* Check port number from message and retrieve private data */ 690 /* Check port number from message and retrieve private data */
691 if (msg->port >= serial->num_ports) { 691 if (msg->port >= serial->num_ports) {
692 dbg ("%s - Unexpected port number %d", __FUNCTION__, msg->port); 692 dbg ("%s - Unexpected port number %d", __func__, msg->port);
693 goto exit; 693 goto exit;
694 } 694 }
695 port = serial->port[msg->port]; 695 port = serial->port[msg->port];
@@ -713,14 +713,14 @@ static void usa28_instat_callback(struct urb *urb)
713 /* Resubmit urb so we continue receiving */ 713 /* Resubmit urb so we continue receiving */
714 urb->dev = serial->dev; 714 urb->dev = serial->dev;
715 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 715 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
716 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 716 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
717 } 717 }
718exit: ; 718exit: ;
719} 719}
720 720
721static void usa28_glocont_callback(struct urb *urb) 721static void usa28_glocont_callback(struct urb *urb)
722{ 722{
723 dbg ("%s", __FUNCTION__); 723 dbg ("%s", __func__);
724} 724}
725 725
726 726
@@ -731,15 +731,15 @@ static void usa49_glocont_callback(struct urb *urb)
731 struct keyspan_port_private *p_priv; 731 struct keyspan_port_private *p_priv;
732 int i; 732 int i;
733 733
734 dbg ("%s", __FUNCTION__); 734 dbg ("%s", __func__);
735 735
736 serial = (struct usb_serial *) urb->context; 736 serial = urb->context;
737 for (i = 0; i < serial->num_ports; ++i) { 737 for (i = 0; i < serial->num_ports; ++i) {
738 port = serial->port[i]; 738 port = serial->port[i];
739 p_priv = usb_get_serial_port_data(port); 739 p_priv = usb_get_serial_port_data(port);
740 740
741 if (p_priv->resend_cont) { 741 if (p_priv->resend_cont) {
742 dbg ("%s - sending setup", __FUNCTION__); 742 dbg ("%s - sending setup", __func__);
743 keyspan_usa49_send_setup(serial, port, p_priv->resend_cont - 1); 743 keyspan_usa49_send_setup(serial, port, p_priv->resend_cont - 1);
744 break; 744 break;
745 } 745 }
@@ -759,21 +759,21 @@ static void usa49_instat_callback(struct urb *urb)
759 int old_dcd_state; 759 int old_dcd_state;
760 int status = urb->status; 760 int status = urb->status;
761 761
762 dbg ("%s", __FUNCTION__); 762 dbg ("%s", __func__);
763 763
764 serial = (struct usb_serial *) urb->context; 764 serial = urb->context;
765 765
766 if (status) { 766 if (status) {
767 dbg("%s - nonzero status: %x", __FUNCTION__, status); 767 dbg("%s - nonzero status: %x", __func__, status);
768 return; 768 return;
769 } 769 }
770 770
771 if (urb->actual_length != sizeof(struct keyspan_usa49_portStatusMessage)) { 771 if (urb->actual_length != sizeof(struct keyspan_usa49_portStatusMessage)) {
772 dbg("%s - bad length %d", __FUNCTION__, urb->actual_length); 772 dbg("%s - bad length %d", __func__, urb->actual_length);
773 goto exit; 773 goto exit;
774 } 774 }
775 775
776 /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __FUNCTION__, 776 /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __func__,
777 data[0], data[1], data[2], data[3], data[4], data[5], 777 data[0], data[1], data[2], data[3], data[4], data[5],
778 data[6], data[7], data[8], data[9], data[10]);*/ 778 data[6], data[7], data[8], data[9], data[10]);*/
779 779
@@ -782,7 +782,7 @@ static void usa49_instat_callback(struct urb *urb)
782 782
783 /* Check port number from message and retrieve private data */ 783 /* Check port number from message and retrieve private data */
784 if (msg->portNumber >= serial->num_ports) { 784 if (msg->portNumber >= serial->num_ports) {
785 dbg ("%s - Unexpected port number %d", __FUNCTION__, msg->portNumber); 785 dbg ("%s - Unexpected port number %d", __func__, msg->portNumber);
786 goto exit; 786 goto exit;
787 } 787 }
788 port = serial->port[msg->portNumber]; 788 port = serial->port[msg->portNumber];
@@ -807,14 +807,14 @@ static void usa49_instat_callback(struct urb *urb)
807 urb->dev = serial->dev; 807 urb->dev = serial->dev;
808 808
809 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 809 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
810 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 810 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
811 } 811 }
812exit: ; 812exit: ;
813} 813}
814 814
815static void usa49_inack_callback(struct urb *urb) 815static void usa49_inack_callback(struct urb *urb)
816{ 816{
817 dbg ("%s", __FUNCTION__); 817 dbg ("%s", __func__);
818} 818}
819 819
820static void usa49_indat_callback(struct urb *urb) 820static void usa49_indat_callback(struct urb *urb)
@@ -826,17 +826,17 @@ static void usa49_indat_callback(struct urb *urb)
826 unsigned char *data = urb->transfer_buffer; 826 unsigned char *data = urb->transfer_buffer;
827 int status = urb->status; 827 int status = urb->status;
828 828
829 dbg ("%s", __FUNCTION__); 829 dbg ("%s", __func__);
830 830
831 endpoint = usb_pipeendpoint(urb->pipe); 831 endpoint = usb_pipeendpoint(urb->pipe);
832 832
833 if (status) { 833 if (status) {
834 dbg("%s - nonzero status: %x on endpoint %d.", __FUNCTION__, 834 dbg("%s - nonzero status: %x on endpoint %d.", __func__,
835 status, endpoint); 835 status, endpoint);
836 return; 836 return;
837 } 837 }
838 838
839 port = (struct usb_serial_port *) urb->context; 839 port = urb->context;
840 tty = port->tty; 840 tty = port->tty;
841 if (tty && urb->actual_length) { 841 if (tty && urb->actual_length) {
842 /* 0x80 bit is error flag */ 842 /* 0x80 bit is error flag */
@@ -866,7 +866,7 @@ static void usa49_indat_callback(struct urb *urb)
866 urb->dev = port->serial->dev; 866 urb->dev = port->serial->dev;
867 if (port->open_count) 867 if (port->open_count)
868 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 868 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
869 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 869 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
870 } 870 }
871} 871}
872 872
@@ -879,12 +879,12 @@ static void usa49wg_indat_callback(struct urb *urb)
879 unsigned char *data = urb->transfer_buffer; 879 unsigned char *data = urb->transfer_buffer;
880 int status = urb->status; 880 int status = urb->status;
881 881
882 dbg ("%s", __FUNCTION__); 882 dbg ("%s", __func__);
883 883
884 serial = urb->context; 884 serial = urb->context;
885 885
886 if (status) { 886 if (status) {
887 dbg("%s - nonzero status: %x", __FUNCTION__, status); 887 dbg("%s - nonzero status: %x", __func__, status);
888 return; 888 return;
889 } 889 }
890 890
@@ -898,7 +898,7 @@ static void usa49wg_indat_callback(struct urb *urb)
898 /* Check port number from message*/ 898 /* Check port number from message*/
899 if (data[i] >= serial->num_ports) { 899 if (data[i] >= serial->num_ports) {
900 dbg ("%s - Unexpected port number %d", 900 dbg ("%s - Unexpected port number %d",
901 __FUNCTION__, data[i]); 901 __func__, data[i]);
902 return; 902 return;
903 } 903 }
904 port = serial->port[data[i++]]; 904 port = serial->port[data[i++]];
@@ -944,13 +944,13 @@ static void usa49wg_indat_callback(struct urb *urb)
944 944
945 err = usb_submit_urb(urb, GFP_ATOMIC); 945 err = usb_submit_urb(urb, GFP_ATOMIC);
946 if (err != 0) 946 if (err != 0)
947 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 947 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
948} 948}
949 949
950/* not used, usa-49 doesn't have per-port control endpoints */ 950/* not used, usa-49 doesn't have per-port control endpoints */
951static void usa49_outcont_callback(struct urb *urb) 951static void usa49_outcont_callback(struct urb *urb)
952{ 952{
953 dbg ("%s", __FUNCTION__); 953 dbg ("%s", __func__);
954} 954}
955 955
956static void usa90_indat_callback(struct urb *urb) 956static void usa90_indat_callback(struct urb *urb)
@@ -963,17 +963,17 @@ static void usa90_indat_callback(struct urb *urb)
963 unsigned char *data = urb->transfer_buffer; 963 unsigned char *data = urb->transfer_buffer;
964 int status = urb->status; 964 int status = urb->status;
965 965
966 dbg ("%s", __FUNCTION__); 966 dbg ("%s", __func__);
967 967
968 endpoint = usb_pipeendpoint(urb->pipe); 968 endpoint = usb_pipeendpoint(urb->pipe);
969 969
970 if (status) { 970 if (status) {
971 dbg("%s - nonzero status: %x on endpoint %d.", 971 dbg("%s - nonzero status: %x on endpoint %d.",
972 __FUNCTION__, status, endpoint); 972 __func__, status, endpoint);
973 return; 973 return;
974 } 974 }
975 975
976 port = (struct usb_serial_port *) urb->context; 976 port = urb->context;
977 p_priv = usb_get_serial_port_data(port); 977 p_priv = usb_get_serial_port_data(port);
978 978
979 tty = port->tty; 979 tty = port->tty;
@@ -1000,7 +1000,7 @@ static void usa90_indat_callback(struct urb *urb)
1000 } 1000 }
1001 else { 1001 else {
1002 /* some bytes had errors, every byte has status */ 1002 /* some bytes had errors, every byte has status */
1003 dbg("%s - RX error!!!!", __FUNCTION__); 1003 dbg("%s - RX error!!!!", __func__);
1004 for (i = 0; i + 1 < urb->actual_length; i += 2) { 1004 for (i = 0; i + 1 < urb->actual_length; i += 2) {
1005 int stat = data[i], flag = 0; 1005 int stat = data[i], flag = 0;
1006 if (stat & RXERROR_OVERRUN) 1006 if (stat & RXERROR_OVERRUN)
@@ -1021,7 +1021,7 @@ static void usa90_indat_callback(struct urb *urb)
1021 urb->dev = port->serial->dev; 1021 urb->dev = port->serial->dev;
1022 if (port->open_count) 1022 if (port->open_count)
1023 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1023 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
1024 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 1024 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
1025 } 1025 }
1026 return; 1026 return;
1027} 1027}
@@ -1037,14 +1037,14 @@ static void usa90_instat_callback(struct urb *urb)
1037 int old_dcd_state, err; 1037 int old_dcd_state, err;
1038 int status = urb->status; 1038 int status = urb->status;
1039 1039
1040 serial = (struct usb_serial *) urb->context; 1040 serial = urb->context;
1041 1041
1042 if (status) { 1042 if (status) {
1043 dbg("%s - nonzero status: %x", __FUNCTION__, status); 1043 dbg("%s - nonzero status: %x", __func__, status);
1044 return; 1044 return;
1045 } 1045 }
1046 if (urb->actual_length < 14) { 1046 if (urb->actual_length < 14) {
1047 dbg("%s - %d byte report??", __FUNCTION__, urb->actual_length); 1047 dbg("%s - %d byte report??", __func__, urb->actual_length);
1048 goto exit; 1048 goto exit;
1049 } 1049 }
1050 1050
@@ -1073,7 +1073,7 @@ static void usa90_instat_callback(struct urb *urb)
1073 /* Resubmit urb so we continue receiving */ 1073 /* Resubmit urb so we continue receiving */
1074 urb->dev = serial->dev; 1074 urb->dev = serial->dev;
1075 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1075 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
1076 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 1076 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
1077 } 1077 }
1078exit: 1078exit:
1079 ; 1079 ;
@@ -1084,11 +1084,11 @@ static void usa90_outcont_callback(struct urb *urb)
1084 struct usb_serial_port *port; 1084 struct usb_serial_port *port;
1085 struct keyspan_port_private *p_priv; 1085 struct keyspan_port_private *p_priv;
1086 1086
1087 port = (struct usb_serial_port *) urb->context; 1087 port = urb->context;
1088 p_priv = usb_get_serial_port_data(port); 1088 p_priv = usb_get_serial_port_data(port);
1089 1089
1090 if (p_priv->resend_cont) { 1090 if (p_priv->resend_cont) {
1091 dbg ("%s - sending setup", __FUNCTION__); 1091 dbg ("%s - sending setup", __func__);
1092 keyspan_usa90_send_setup(port->serial, port, p_priv->resend_cont - 1); 1092 keyspan_usa90_send_setup(port->serial, port, p_priv->resend_cont - 1);
1093 } 1093 }
1094} 1094}
@@ -1105,17 +1105,17 @@ static void usa67_instat_callback(struct urb *urb)
1105 int old_dcd_state; 1105 int old_dcd_state;
1106 int status = urb->status; 1106 int status = urb->status;
1107 1107
1108 dbg ("%s", __FUNCTION__); 1108 dbg ("%s", __func__);
1109 1109
1110 serial = urb->context; 1110 serial = urb->context;
1111 1111
1112 if (status) { 1112 if (status) {
1113 dbg("%s - nonzero status: %x", __FUNCTION__, status); 1113 dbg("%s - nonzero status: %x", __func__, status);
1114 return; 1114 return;
1115 } 1115 }
1116 1116
1117 if (urb->actual_length != sizeof(struct keyspan_usa67_portStatusMessage)) { 1117 if (urb->actual_length != sizeof(struct keyspan_usa67_portStatusMessage)) {
1118 dbg("%s - bad length %d", __FUNCTION__, urb->actual_length); 1118 dbg("%s - bad length %d", __func__, urb->actual_length);
1119 return; 1119 return;
1120 } 1120 }
1121 1121
@@ -1125,7 +1125,7 @@ static void usa67_instat_callback(struct urb *urb)
1125 1125
1126 /* Check port number from message and retrieve private data */ 1126 /* Check port number from message and retrieve private data */
1127 if (msg->port >= serial->num_ports) { 1127 if (msg->port >= serial->num_ports) {
1128 dbg ("%s - Unexpected port number %d", __FUNCTION__, msg->port); 1128 dbg ("%s - Unexpected port number %d", __func__, msg->port);
1129 return; 1129 return;
1130 } 1130 }
1131 1131
@@ -1149,7 +1149,7 @@ static void usa67_instat_callback(struct urb *urb)
1149 urb->dev = serial->dev; 1149 urb->dev = serial->dev;
1150 err = usb_submit_urb(urb, GFP_ATOMIC); 1150 err = usb_submit_urb(urb, GFP_ATOMIC);
1151 if (err != 0) 1151 if (err != 0)
1152 dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err); 1152 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
1153} 1153}
1154 1154
1155static void usa67_glocont_callback(struct urb *urb) 1155static void usa67_glocont_callback(struct urb *urb)
@@ -1159,7 +1159,7 @@ static void usa67_glocont_callback(struct urb *urb)
1159 struct keyspan_port_private *p_priv; 1159 struct keyspan_port_private *p_priv;
1160 int i; 1160 int i;
1161 1161
1162 dbg ("%s", __FUNCTION__); 1162 dbg ("%s", __func__);
1163 1163
1164 serial = urb->context; 1164 serial = urb->context;
1165 for (i = 0; i < serial->num_ports; ++i) { 1165 for (i = 0; i < serial->num_ports; ++i) {
@@ -1167,7 +1167,7 @@ static void usa67_glocont_callback(struct urb *urb)
1167 p_priv = usb_get_serial_port_data(port); 1167 p_priv = usb_get_serial_port_data(port);
1168 1168
1169 if (p_priv->resend_cont) { 1169 if (p_priv->resend_cont) {
1170 dbg ("%s - sending setup", __FUNCTION__); 1170 dbg ("%s - sending setup", __func__);
1171 keyspan_usa67_send_setup(serial, port, 1171 keyspan_usa67_send_setup(serial, port,
1172 p_priv->resend_cont - 1); 1172 p_priv->resend_cont - 1);
1173 break; 1173 break;
@@ -1183,10 +1183,11 @@ static int keyspan_write_room (struct usb_serial_port *port)
1183 int data_len; 1183 int data_len;
1184 struct urb *this_urb; 1184 struct urb *this_urb;
1185 1185
1186 dbg("%s", __FUNCTION__); 1186 dbg("%s", __func__);
1187 p_priv = usb_get_serial_port_data(port); 1187 p_priv = usb_get_serial_port_data(port);
1188 d_details = p_priv->device_details; 1188 d_details = p_priv->device_details;
1189 1189
1190 /* FIXME: locking */
1190 if (d_details->msg_format == msg_usa90) 1191 if (d_details->msg_format == msg_usa90)
1191 data_len = 64; 1192 data_len = 64;
1192 else 1193 else
@@ -1203,13 +1204,13 @@ static int keyspan_write_room (struct usb_serial_port *port)
1203 if (this_urb->status != -EINPROGRESS) 1204 if (this_urb->status != -EINPROGRESS)
1204 return (data_len); 1205 return (data_len);
1205 } 1206 }
1206 return (0); 1207 return 0;
1207} 1208}
1208 1209
1209 1210
1210static int keyspan_chars_in_buffer (struct usb_serial_port *port) 1211static int keyspan_chars_in_buffer (struct usb_serial_port *port)
1211{ 1212{
1212 return (0); 1213 return 0;
1213} 1214}
1214 1215
1215 1216
@@ -1228,7 +1229,7 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1228 p_priv = usb_get_serial_port_data(port); 1229 p_priv = usb_get_serial_port_data(port);
1229 d_details = p_priv->device_details; 1230 d_details = p_priv->device_details;
1230 1231
1231 dbg("%s - port%d.", __FUNCTION__, port->number); 1232 dbg("%s - port%d.", __func__, port->number);
1232 1233
1233 /* Set some sane defaults */ 1234 /* Set some sane defaults */
1234 p_priv->rts_state = 1; 1235 p_priv->rts_state = 1;
@@ -1253,7 +1254,7 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1253 usb_clear_halt(urb->dev, urb->pipe); 1254 usb_clear_halt(urb->dev, urb->pipe);
1254 1255
1255 if ((err = usb_submit_urb(urb, GFP_KERNEL)) != 0) { 1256 if ((err = usb_submit_urb(urb, GFP_KERNEL)) != 0) {
1256 dbg("%s - submit urb %d failed (%d)", __FUNCTION__, i, err); 1257 dbg("%s - submit urb %d failed (%d)", __func__, i, err);
1257 } 1258 }
1258 } 1259 }
1259 1260
@@ -1289,7 +1290,7 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1289 //mdelay(100); 1290 //mdelay(100);
1290 //keyspan_set_termios(port, NULL); 1291 //keyspan_set_termios(port, NULL);
1291 1292
1292 return (0); 1293 return 0;
1293} 1294}
1294 1295
1295static inline void stop_urb(struct urb *urb) 1296static inline void stop_urb(struct urb *urb)
@@ -1305,7 +1306,7 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
1305 struct keyspan_serial_private *s_priv; 1306 struct keyspan_serial_private *s_priv;
1306 struct keyspan_port_private *p_priv; 1307 struct keyspan_port_private *p_priv;
1307 1308
1308 dbg("%s", __FUNCTION__); 1309 dbg("%s", __func__);
1309 s_priv = usb_get_serial_data(serial); 1310 s_priv = usb_get_serial_data(serial);
1310 p_priv = usb_get_serial_port_data(port); 1311 p_priv = usb_get_serial_port_data(port);
1311 1312
@@ -1320,7 +1321,7 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
1320 } 1321 }
1321 1322
1322 /*while (p_priv->outcont_urb->status == -EINPROGRESS) { 1323 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1323 dbg("%s - urb in progress", __FUNCTION__); 1324 dbg("%s - urb in progress", __func__);
1324 }*/ 1325 }*/
1325 1326
1326 p_priv->out_flip = 0; 1327 p_priv->out_flip = 0;
@@ -1484,10 +1485,10 @@ static struct urb *keyspan_setup_urb (struct usb_serial *serial, int endpoint,
1484 if (endpoint == -1) 1485 if (endpoint == -1)
1485 return NULL; /* endpoint not needed */ 1486 return NULL; /* endpoint not needed */
1486 1487
1487 dbg ("%s - alloc for endpoint %d.", __FUNCTION__, endpoint); 1488 dbg ("%s - alloc for endpoint %d.", __func__, endpoint);
1488 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ 1489 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1489 if (urb == NULL) { 1490 if (urb == NULL) {
1490 dbg ("%s - alloc for endpoint %d failed.", __FUNCTION__, endpoint); 1491 dbg ("%s - alloc for endpoint %d failed.", __func__, endpoint);
1491 return NULL; 1492 return NULL;
1492 } 1493 }
1493 1494
@@ -1588,7 +1589,7 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
1588 struct callbacks *cback; 1589 struct callbacks *cback;
1589 int endp; 1590 int endp;
1590 1591
1591 dbg ("%s", __FUNCTION__); 1592 dbg ("%s", __func__);
1592 1593
1593 s_priv = usb_get_serial_data(serial); 1594 s_priv = usb_get_serial_data(serial);
1594 d_details = s_priv->device_details; 1595 d_details = s_priv->device_details;
@@ -1662,7 +1663,7 @@ static int keyspan_usa19_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1662 div, /* divisor */ 1663 div, /* divisor */
1663 cnt; /* inverse of divisor (programmed into 8051) */ 1664 cnt; /* inverse of divisor (programmed into 8051) */
1664 1665
1665 dbg ("%s - %d.", __FUNCTION__, baud_rate); 1666 dbg ("%s - %d.", __func__, baud_rate);
1666 1667
1667 /* prevent divide by zero... */ 1668 /* prevent divide by zero... */
1668 if( (b16 = (baud_rate * 16L)) == 0) { 1669 if( (b16 = (baud_rate * 16L)) == 0) {
@@ -1695,7 +1696,7 @@ static int keyspan_usa19_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1695 *rate_hi = (u8) ((cnt >> 8) & 0xff); 1696 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1696 } 1697 }
1697 if (rate_low && rate_hi) { 1698 if (rate_low && rate_hi) {
1698 dbg ("%s - %d %02x %02x.", __FUNCTION__, baud_rate, *rate_hi, *rate_low); 1699 dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low);
1699 } 1700 }
1700 1701
1701 return (KEYSPAN_BAUD_RATE_OK); 1702 return (KEYSPAN_BAUD_RATE_OK);
@@ -1708,7 +1709,7 @@ static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1708 u32 b16, /* baud rate times 16 (actual rate used internally) */ 1709 u32 b16, /* baud rate times 16 (actual rate used internally) */
1709 div; /* divisor */ 1710 div; /* divisor */
1710 1711
1711 dbg ("%s - %d.", __FUNCTION__, baud_rate); 1712 dbg ("%s - %d.", __func__, baud_rate);
1712 1713
1713 /* prevent divide by zero... */ 1714 /* prevent divide by zero... */
1714 if( (b16 = (baud_rate * 16L)) == 0) 1715 if( (b16 = (baud_rate * 16L)) == 0)
@@ -1731,7 +1732,7 @@ static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1731 *rate_hi = (u8) ((div >> 8) & 0xff); 1732 *rate_hi = (u8) ((div >> 8) & 0xff);
1732 1733
1733 if (rate_low && rate_hi) 1734 if (rate_low && rate_hi)
1734 dbg ("%s - %d %02x %02x.", __FUNCTION__, baud_rate, *rate_hi, *rate_low); 1735 dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low);
1735 1736
1736 return (KEYSPAN_BAUD_RATE_OK); 1737 return (KEYSPAN_BAUD_RATE_OK);
1737} 1738}
@@ -1748,7 +1749,7 @@ static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1748 u8 best_prescaler; 1749 u8 best_prescaler;
1749 int i; 1750 int i;
1750 1751
1751 dbg ("%s - %d.", __FUNCTION__, baud_rate); 1752 dbg ("%s - %d.", __func__, baud_rate);
1752 1753
1753 /* prevent divide by zero */ 1754 /* prevent divide by zero */
1754 if( (b16 = baud_rate * 16L) == 0) { 1755 if( (b16 = baud_rate * 16L) == 0) {
@@ -1796,7 +1797,7 @@ static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1796 } 1797 }
1797 if (prescaler) { 1798 if (prescaler) {
1798 *prescaler = best_prescaler; 1799 *prescaler = best_prescaler;
1799 /* dbg("%s - %d %d", __FUNCTION__, *prescaler, div); */ 1800 /* dbg("%s - %d %d", __func__, *prescaler, div); */
1800 } 1801 }
1801 return (KEYSPAN_BAUD_RATE_OK); 1802 return (KEYSPAN_BAUD_RATE_OK);
1802} 1803}
@@ -1809,7 +1810,7 @@ static int keyspan_usa28_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1809 div, /* divisor */ 1810 div, /* divisor */
1810 cnt; /* inverse of divisor (programmed into 8051) */ 1811 cnt; /* inverse of divisor (programmed into 8051) */
1811 1812
1812 dbg ("%s - %d.", __FUNCTION__, baud_rate); 1813 dbg ("%s - %d.", __func__, baud_rate);
1813 1814
1814 /* prevent divide by zero */ 1815 /* prevent divide by zero */
1815 if ((b16 = baud_rate * 16L) == 0) 1816 if ((b16 = baud_rate * 16L) == 0)
@@ -1848,7 +1849,7 @@ static int keyspan_usa28_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1848 if (rate_hi) { 1849 if (rate_hi) {
1849 *rate_hi = (u8) ((cnt >> 8) & 0xff); 1850 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1850 } 1851 }
1851 dbg ("%s - %d OK.", __FUNCTION__, baud_rate); 1852 dbg ("%s - %d OK.", __func__, baud_rate);
1852 return (KEYSPAN_BAUD_RATE_OK); 1853 return (KEYSPAN_BAUD_RATE_OK);
1853} 1854}
1854 1855
@@ -1864,7 +1865,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1864 struct urb *this_urb; 1865 struct urb *this_urb;
1865 int device_port, err; 1866 int device_port, err;
1866 1867
1867 dbg ("%s reset=%d", __FUNCTION__, reset_port); 1868 dbg ("%s reset=%d", __func__, reset_port);
1868 1869
1869 s_priv = usb_get_serial_data(serial); 1870 s_priv = usb_get_serial_data(serial);
1870 p_priv = usb_get_serial_port_data(port); 1871 p_priv = usb_get_serial_port_data(port);
@@ -1874,11 +1875,11 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1874 outcont_urb = d_details->outcont_endpoints[port->number]; 1875 outcont_urb = d_details->outcont_endpoints[port->number];
1875 this_urb = p_priv->outcont_urb; 1876 this_urb = p_priv->outcont_urb;
1876 1877
1877 dbg("%s - endpoint %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe)); 1878 dbg("%s - endpoint %d", __func__, usb_pipeendpoint(this_urb->pipe));
1878 1879
1879 /* Make sure we have an urb then send the message */ 1880 /* Make sure we have an urb then send the message */
1880 if (this_urb == NULL) { 1881 if (this_urb == NULL) {
1881 dbg("%s - oops no urb.", __FUNCTION__); 1882 dbg("%s - oops no urb.", __func__);
1882 return -1; 1883 return -1;
1883 } 1884 }
1884 1885
@@ -1887,7 +1888,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1887 if ((reset_port + 1) > p_priv->resend_cont) 1888 if ((reset_port + 1) > p_priv->resend_cont)
1888 p_priv->resend_cont = reset_port + 1; 1889 p_priv->resend_cont = reset_port + 1;
1889 if (this_urb->status == -EINPROGRESS) { 1890 if (this_urb->status == -EINPROGRESS) {
1890 /* dbg ("%s - already writing", __FUNCTION__); */ 1891 /* dbg ("%s - already writing", __func__); */
1891 mdelay(5); 1892 mdelay(5);
1892 return(-1); 1893 return(-1);
1893 } 1894 }
@@ -1901,7 +1902,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1901 if (d_details->calculate_baud_rate 1902 if (d_details->calculate_baud_rate
1902 (p_priv->baud, d_details->baudclk, &msg.baudHi, 1903 (p_priv->baud, d_details->baudclk, &msg.baudHi,
1903 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 1904 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) {
1904 dbg("%s - Invalid baud rate %d requested, using 9600.", __FUNCTION__, 1905 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
1905 p_priv->baud); 1906 p_priv->baud);
1906 msg.baudLo = 0; 1907 msg.baudLo = 0;
1907 msg.baudHi = 125; /* Values for 9600 baud */ 1908 msg.baudHi = 125; /* Values for 9600 baud */
@@ -1996,17 +1997,17 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
1996 1997
1997 this_urb->dev = serial->dev; 1998 this_urb->dev = serial->dev;
1998 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 1999 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
1999 dbg("%s - usb_submit_urb(setup) failed (%d)", __FUNCTION__, err); 2000 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2000 } 2001 }
2001#if 0 2002#if 0
2002 else { 2003 else {
2003 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __FUNCTION__ 2004 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__
2004 outcont_urb, this_urb->transfer_buffer_length, 2005 outcont_urb, this_urb->transfer_buffer_length,
2005 usb_pipeendpoint(this_urb->pipe)); 2006 usb_pipeendpoint(this_urb->pipe));
2006 } 2007 }
2007#endif 2008#endif
2008 2009
2009 return (0); 2010 return 0;
2010} 2011}
2011 2012
2012static int keyspan_usa28_send_setup(struct usb_serial *serial, 2013static int keyspan_usa28_send_setup(struct usb_serial *serial,
@@ -2020,7 +2021,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2020 struct urb *this_urb; 2021 struct urb *this_urb;
2021 int device_port, err; 2022 int device_port, err;
2022 2023
2023 dbg ("%s", __FUNCTION__); 2024 dbg ("%s", __func__);
2024 2025
2025 s_priv = usb_get_serial_data(serial); 2026 s_priv = usb_get_serial_data(serial);
2026 p_priv = usb_get_serial_port_data(port); 2027 p_priv = usb_get_serial_port_data(port);
@@ -2029,7 +2030,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2029 2030
2030 /* only do something if we have a bulk out endpoint */ 2031 /* only do something if we have a bulk out endpoint */
2031 if ((this_urb = p_priv->outcont_urb) == NULL) { 2032 if ((this_urb = p_priv->outcont_urb) == NULL) {
2032 dbg("%s - oops no urb.", __FUNCTION__); 2033 dbg("%s - oops no urb.", __func__);
2033 return -1; 2034 return -1;
2034 } 2035 }
2035 2036
@@ -2038,7 +2039,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2038 if ((reset_port + 1) > p_priv->resend_cont) 2039 if ((reset_port + 1) > p_priv->resend_cont)
2039 p_priv->resend_cont = reset_port + 1; 2040 p_priv->resend_cont = reset_port + 1;
2040 if (this_urb->status == -EINPROGRESS) { 2041 if (this_urb->status == -EINPROGRESS) {
2041 dbg ("%s already writing", __FUNCTION__); 2042 dbg ("%s already writing", __func__);
2042 mdelay(5); 2043 mdelay(5);
2043 return(-1); 2044 return(-1);
2044 } 2045 }
@@ -2048,7 +2049,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2048 msg.setBaudRate = 1; 2049 msg.setBaudRate = 1;
2049 if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk, 2050 if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
2050 &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2051 &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE ) {
2051 dbg("%s - Invalid baud rate requested %d.", __FUNCTION__, p_priv->baud); 2052 dbg("%s - Invalid baud rate requested %d.", __func__, p_priv->baud);
2052 msg.baudLo = 0xff; 2053 msg.baudLo = 0xff;
2053 msg.baudHi = 0xb2; /* Values for 9600 baud */ 2054 msg.baudHi = 0xb2; /* Values for 9600 baud */
2054 } 2055 }
@@ -2122,16 +2123,16 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
2122 2123
2123 this_urb->dev = serial->dev; 2124 this_urb->dev = serial->dev;
2124 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2125 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
2125 dbg("%s - usb_submit_urb(setup) failed", __FUNCTION__); 2126 dbg("%s - usb_submit_urb(setup) failed", __func__);
2126 } 2127 }
2127#if 0 2128#if 0
2128 else { 2129 else {
2129 dbg("%s - usb_submit_urb(setup) OK %d bytes", __FUNCTION__, 2130 dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__,
2130 this_urb->transfer_buffer_length); 2131 this_urb->transfer_buffer_length);
2131 } 2132 }
2132#endif 2133#endif
2133 2134
2134 return (0); 2135 return 0;
2135} 2136}
2136 2137
2137static int keyspan_usa49_send_setup(struct usb_serial *serial, 2138static int keyspan_usa49_send_setup(struct usb_serial *serial,
@@ -2146,7 +2147,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2146 struct urb *this_urb; 2147 struct urb *this_urb;
2147 int err, device_port; 2148 int err, device_port;
2148 2149
2149 dbg ("%s", __FUNCTION__); 2150 dbg ("%s", __func__);
2150 2151
2151 s_priv = usb_get_serial_data(serial); 2152 s_priv = usb_get_serial_data(serial);
2152 p_priv = usb_get_serial_port_data(port); 2153 p_priv = usb_get_serial_port_data(port);
@@ -2157,11 +2158,11 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2157 /* Work out which port within the device is being setup */ 2158 /* Work out which port within the device is being setup */
2158 device_port = port->number - port->serial->minor; 2159 device_port = port->number - port->serial->minor;
2159 2160
2160 dbg("%s - endpoint %d port %d (%d)",__FUNCTION__, usb_pipeendpoint(this_urb->pipe), port->number, device_port); 2161 dbg("%s - endpoint %d port %d (%d)",__func__, usb_pipeendpoint(this_urb->pipe), port->number, device_port);
2161 2162
2162 /* Make sure we have an urb then send the message */ 2163 /* Make sure we have an urb then send the message */
2163 if (this_urb == NULL) { 2164 if (this_urb == NULL) {
2164 dbg("%s - oops no urb for port %d.", __FUNCTION__, port->number); 2165 dbg("%s - oops no urb for port %d.", __func__, port->number);
2165 return -1; 2166 return -1;
2166 } 2167 }
2167 2168
@@ -2171,7 +2172,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2171 p_priv->resend_cont = reset_port + 1; 2172 p_priv->resend_cont = reset_port + 1;
2172 2173
2173 if (this_urb->status == -EINPROGRESS) { 2174 if (this_urb->status == -EINPROGRESS) {
2174 /* dbg ("%s - already writing", __FUNCTION__); */ 2175 /* dbg ("%s - already writing", __func__); */
2175 mdelay(5); 2176 mdelay(5);
2176 return(-1); 2177 return(-1);
2177 } 2178 }
@@ -2188,7 +2189,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2188 if (d_details->calculate_baud_rate 2189 if (d_details->calculate_baud_rate
2189 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2190 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2190 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2191 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) {
2191 dbg("%s - Invalid baud rate %d requested, using 9600.", __FUNCTION__, 2192 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
2192 p_priv->baud); 2193 p_priv->baud);
2193 msg.baudLo = 0; 2194 msg.baudLo = 0;
2194 msg.baudHi = 125; /* Values for 9600 baud */ 2195 msg.baudHi = 125; /* Values for 9600 baud */
@@ -2307,17 +2308,17 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
2307 this_urb->dev = serial->dev; 2308 this_urb->dev = serial->dev;
2308 } 2309 }
2309 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2310 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
2310 dbg("%s - usb_submit_urb(setup) failed (%d)", __FUNCTION__, err); 2311 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2311 } 2312 }
2312#if 0 2313#if 0
2313 else { 2314 else {
2314 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __FUNCTION__, 2315 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__,
2315 outcont_urb, this_urb->transfer_buffer_length, 2316 outcont_urb, this_urb->transfer_buffer_length,
2316 usb_pipeendpoint(this_urb->pipe)); 2317 usb_pipeendpoint(this_urb->pipe));
2317 } 2318 }
2318#endif 2319#endif
2319 2320
2320 return (0); 2321 return 0;
2321} 2322}
2322 2323
2323static int keyspan_usa90_send_setup(struct usb_serial *serial, 2324static int keyspan_usa90_send_setup(struct usb_serial *serial,
@@ -2332,7 +2333,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2332 int err; 2333 int err;
2333 u8 prescaler; 2334 u8 prescaler;
2334 2335
2335 dbg ("%s", __FUNCTION__); 2336 dbg ("%s", __func__);
2336 2337
2337 s_priv = usb_get_serial_data(serial); 2338 s_priv = usb_get_serial_data(serial);
2338 p_priv = usb_get_serial_port_data(port); 2339 p_priv = usb_get_serial_port_data(port);
@@ -2340,7 +2341,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2340 2341
2341 /* only do something if we have a bulk out endpoint */ 2342 /* only do something if we have a bulk out endpoint */
2342 if ((this_urb = p_priv->outcont_urb) == NULL) { 2343 if ((this_urb = p_priv->outcont_urb) == NULL) {
2343 dbg("%s - oops no urb.", __FUNCTION__); 2344 dbg("%s - oops no urb.", __func__);
2344 return -1; 2345 return -1;
2345 } 2346 }
2346 2347
@@ -2349,7 +2350,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2349 if ((reset_port + 1) > p_priv->resend_cont) 2350 if ((reset_port + 1) > p_priv->resend_cont)
2350 p_priv->resend_cont = reset_port + 1; 2351 p_priv->resend_cont = reset_port + 1;
2351 if (this_urb->status == -EINPROGRESS) { 2352 if (this_urb->status == -EINPROGRESS) {
2352 dbg ("%s already writing", __FUNCTION__); 2353 dbg ("%s already writing", __func__);
2353 mdelay(5); 2354 mdelay(5);
2354 return(-1); 2355 return(-1);
2355 } 2356 }
@@ -2363,7 +2364,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2363 if (d_details->calculate_baud_rate 2364 if (d_details->calculate_baud_rate
2364 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2365 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2365 &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE ) { 2366 &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE ) {
2366 dbg("%s - Invalid baud rate %d requested, using 9600.", __FUNCTION__, 2367 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
2367 p_priv->baud); 2368 p_priv->baud);
2368 p_priv->baud = 9600; 2369 p_priv->baud = 9600;
2369 d_details->calculate_baud_rate (p_priv->baud, d_details->baudclk, 2370 d_details->calculate_baud_rate (p_priv->baud, d_details->baudclk,
@@ -2453,9 +2454,9 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2453 2454
2454 this_urb->dev = serial->dev; 2455 this_urb->dev = serial->dev;
2455 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 2456 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
2456 dbg("%s - usb_submit_urb(setup) failed (%d)", __FUNCTION__, err); 2457 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2457 } 2458 }
2458 return (0); 2459 return 0;
2459} 2460}
2460 2461
2461static int keyspan_usa67_send_setup(struct usb_serial *serial, 2462static int keyspan_usa67_send_setup(struct usb_serial *serial,
@@ -2469,7 +2470,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2469 struct urb *this_urb; 2470 struct urb *this_urb;
2470 int err, device_port; 2471 int err, device_port;
2471 2472
2472 dbg ("%s", __FUNCTION__); 2473 dbg ("%s", __func__);
2473 2474
2474 s_priv = usb_get_serial_data(serial); 2475 s_priv = usb_get_serial_data(serial);
2475 p_priv = usb_get_serial_port_data(port); 2476 p_priv = usb_get_serial_port_data(port);
@@ -2482,7 +2483,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2482 2483
2483 /* Make sure we have an urb then send the message */ 2484 /* Make sure we have an urb then send the message */
2484 if (this_urb == NULL) { 2485 if (this_urb == NULL) {
2485 dbg("%s - oops no urb for port %d.", __FUNCTION__, 2486 dbg("%s - oops no urb for port %d.", __func__,
2486 port->number); 2487 port->number);
2487 return -1; 2488 return -1;
2488 } 2489 }
@@ -2492,7 +2493,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2492 if ((reset_port + 1) > p_priv->resend_cont) 2493 if ((reset_port + 1) > p_priv->resend_cont)
2493 p_priv->resend_cont = reset_port + 1; 2494 p_priv->resend_cont = reset_port + 1;
2494 if (this_urb->status == -EINPROGRESS) { 2495 if (this_urb->status == -EINPROGRESS) {
2495 /* dbg ("%s - already writing", __FUNCTION__); */ 2496 /* dbg ("%s - already writing", __func__); */
2496 mdelay(5); 2497 mdelay(5);
2497 return(-1); 2498 return(-1);
2498 } 2499 }
@@ -2508,7 +2509,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2508 if (d_details->calculate_baud_rate 2509 if (d_details->calculate_baud_rate
2509 (p_priv->baud, d_details->baudclk, &msg.baudHi, 2510 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2510 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) { 2511 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE ) {
2511 dbg("%s - Invalid baud rate %d requested, using 9600.", __FUNCTION__, 2512 dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
2512 p_priv->baud); 2513 p_priv->baud);
2513 msg.baudLo = 0; 2514 msg.baudLo = 0;
2514 msg.baudHi = 125; /* Values for 9600 baud */ 2515 msg.baudHi = 125; /* Values for 9600 baud */
@@ -2601,9 +2602,9 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
2601 2602
2602 err = usb_submit_urb(this_urb, GFP_ATOMIC); 2603 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2603 if (err != 0) 2604 if (err != 0)
2604 dbg("%s - usb_submit_urb(setup) failed (%d)", __FUNCTION__, 2605 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__,
2605 err); 2606 err);
2606 return (0); 2607 return 0;
2607} 2608}
2608 2609
2609static void keyspan_send_setup(struct usb_serial_port *port, int reset_port) 2610static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
@@ -2612,7 +2613,7 @@ static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2612 struct keyspan_serial_private *s_priv; 2613 struct keyspan_serial_private *s_priv;
2613 const struct keyspan_device_details *d_details; 2614 const struct keyspan_device_details *d_details;
2614 2615
2615 dbg ("%s", __FUNCTION__); 2616 dbg ("%s", __func__);
2616 2617
2617 s_priv = usb_get_serial_data(serial); 2618 s_priv = usb_get_serial_data(serial);
2618 d_details = s_priv->device_details; 2619 d_details = s_priv->device_details;
@@ -2647,20 +2648,20 @@ static int keyspan_startup (struct usb_serial *serial)
2647 struct keyspan_port_private *p_priv; 2648 struct keyspan_port_private *p_priv;
2648 const struct keyspan_device_details *d_details; 2649 const struct keyspan_device_details *d_details;
2649 2650
2650 dbg("%s", __FUNCTION__); 2651 dbg("%s", __func__);
2651 2652
2652 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i) 2653 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2653 if (d_details->product_id == le16_to_cpu(serial->dev->descriptor.idProduct)) 2654 if (d_details->product_id == le16_to_cpu(serial->dev->descriptor.idProduct))
2654 break; 2655 break;
2655 if (d_details == NULL) { 2656 if (d_details == NULL) {
2656 dev_err(&serial->dev->dev, "%s - unknown product id %x\n", __FUNCTION__, le16_to_cpu(serial->dev->descriptor.idProduct)); 2657 dev_err(&serial->dev->dev, "%s - unknown product id %x\n", __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2657 return 1; 2658 return 1;
2658 } 2659 }
2659 2660
2660 /* Setup private data for serial driver */ 2661 /* Setup private data for serial driver */
2661 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL); 2662 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2662 if (!s_priv) { 2663 if (!s_priv) {
2663 dbg("%s - kmalloc for keyspan_serial_private failed.", __FUNCTION__); 2664 dbg("%s - kmalloc for keyspan_serial_private failed.", __func__);
2664 return -ENOMEM; 2665 return -ENOMEM;
2665 } 2666 }
2666 2667
@@ -2672,7 +2673,7 @@ static int keyspan_startup (struct usb_serial *serial)
2672 port = serial->port[i]; 2673 port = serial->port[i];
2673 p_priv = kzalloc(sizeof(struct keyspan_port_private), GFP_KERNEL); 2674 p_priv = kzalloc(sizeof(struct keyspan_port_private), GFP_KERNEL);
2674 if (!p_priv) { 2675 if (!p_priv) {
2675 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __FUNCTION__, i); 2676 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i);
2676 return (1); 2677 return (1);
2677 } 2678 }
2678 p_priv->device_details = d_details; 2679 p_priv->device_details = d_details;
@@ -2685,18 +2686,18 @@ static int keyspan_startup (struct usb_serial *serial)
2685 s_priv->instat_urb->dev = serial->dev; 2686 s_priv->instat_urb->dev = serial->dev;
2686 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL); 2687 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2687 if (err != 0) 2688 if (err != 0)
2688 dbg("%s - submit instat urb failed %d", __FUNCTION__, 2689 dbg("%s - submit instat urb failed %d", __func__,
2689 err); 2690 err);
2690 } 2691 }
2691 if (s_priv->indat_urb != NULL) { 2692 if (s_priv->indat_urb != NULL) {
2692 s_priv->indat_urb->dev = serial->dev; 2693 s_priv->indat_urb->dev = serial->dev;
2693 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL); 2694 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2694 if (err != 0) 2695 if (err != 0)
2695 dbg("%s - submit indat urb failed %d", __FUNCTION__, 2696 dbg("%s - submit indat urb failed %d", __func__,
2696 err); 2697 err);
2697 } 2698 }
2698 2699
2699 return (0); 2700 return 0;
2700} 2701}
2701 2702
2702static void keyspan_shutdown (struct usb_serial *serial) 2703static void keyspan_shutdown (struct usb_serial *serial)
@@ -2706,7 +2707,7 @@ static void keyspan_shutdown (struct usb_serial *serial)
2706 struct keyspan_serial_private *s_priv; 2707 struct keyspan_serial_private *s_priv;
2707 struct keyspan_port_private *p_priv; 2708 struct keyspan_port_private *p_priv;
2708 2709
2709 dbg("%s", __FUNCTION__); 2710 dbg("%s", __func__);
2710 2711
2711 s_priv = usb_get_serial_data(serial); 2712 s_priv = usb_get_serial_data(serial);
2712 2713
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index 74ce8bca3e66..8d6ed0293bfa 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -636,10 +636,6 @@ static struct usb_serial_driver keyspan_pre_device = {
636 }, 636 },
637 .description = "Keyspan - (without firmware)", 637 .description = "Keyspan - (without firmware)",
638 .id_table = keyspan_pre_ids, 638 .id_table = keyspan_pre_ids,
639 .num_interrupt_in = NUM_DONT_CARE,
640 .num_interrupt_out = NUM_DONT_CARE,
641 .num_bulk_in = NUM_DONT_CARE,
642 .num_bulk_out = NUM_DONT_CARE,
643 .num_ports = 1, 639 .num_ports = 1,
644 .attach = keyspan_fake_startup, 640 .attach = keyspan_fake_startup,
645}; 641};
@@ -651,10 +647,6 @@ static struct usb_serial_driver keyspan_1port_device = {
651 }, 647 },
652 .description = "Keyspan 1 port adapter", 648 .description = "Keyspan 1 port adapter",
653 .id_table = keyspan_1port_ids, 649 .id_table = keyspan_1port_ids,
654 .num_interrupt_in = NUM_DONT_CARE,
655 .num_interrupt_out = NUM_DONT_CARE,
656 .num_bulk_in = NUM_DONT_CARE,
657 .num_bulk_out = NUM_DONT_CARE,
658 .num_ports = 1, 650 .num_ports = 1,
659 .open = keyspan_open, 651 .open = keyspan_open,
660 .close = keyspan_close, 652 .close = keyspan_close,
@@ -679,10 +671,6 @@ static struct usb_serial_driver keyspan_2port_device = {
679 }, 671 },
680 .description = "Keyspan 2 port adapter", 672 .description = "Keyspan 2 port adapter",
681 .id_table = keyspan_2port_ids, 673 .id_table = keyspan_2port_ids,
682 .num_interrupt_in = NUM_DONT_CARE,
683 .num_interrupt_out = NUM_DONT_CARE,
684 .num_bulk_in = NUM_DONT_CARE,
685 .num_bulk_out = NUM_DONT_CARE,
686 .num_ports = 2, 674 .num_ports = 2,
687 .open = keyspan_open, 675 .open = keyspan_open,
688 .close = keyspan_close, 676 .close = keyspan_close,
@@ -707,10 +695,6 @@ static struct usb_serial_driver keyspan_4port_device = {
707 }, 695 },
708 .description = "Keyspan 4 port adapter", 696 .description = "Keyspan 4 port adapter",
709 .id_table = keyspan_4port_ids, 697 .id_table = keyspan_4port_ids,
710 .num_interrupt_in = NUM_DONT_CARE,
711 .num_interrupt_out = NUM_DONT_CARE,
712 .num_bulk_in = NUM_DONT_CARE,
713 .num_bulk_out = NUM_DONT_CARE,
714 .num_ports = 4, 698 .num_ports = 4,
715 .open = keyspan_open, 699 .open = keyspan_open,
716 .close = keyspan_close, 700 .close = keyspan_close,
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index b1fa5a376e96..ff54203944ca 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -208,13 +208,13 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
208 2000); 208 2000);
209 if (result < 0) 209 if (result < 0)
210 dbg("%s - error %d from usb_control_msg", 210 dbg("%s - error %d from usb_control_msg",
211 __FUNCTION__, result); 211 __func__, result);
212} 212}
213 213
214 214
215static void keyspan_pda_rx_interrupt (struct urb *urb) 215static void keyspan_pda_rx_interrupt (struct urb *urb)
216{ 216{
217 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 217 struct usb_serial_port *port = urb->context;
218 struct tty_struct *tty = port->tty; 218 struct tty_struct *tty = port->tty;
219 unsigned char *data = urb->transfer_buffer; 219 unsigned char *data = urb->transfer_buffer;
220 int i; 220 int i;
@@ -232,11 +232,11 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
232 case -ESHUTDOWN: 232 case -ESHUTDOWN:
233 /* this urb is terminated, clean up */ 233 /* this urb is terminated, clean up */
234 dbg("%s - urb shutting down with status: %d", 234 dbg("%s - urb shutting down with status: %d",
235 __FUNCTION__, status); 235 __func__, status);
236 return; 236 return;
237 default: 237 default:
238 dbg("%s - nonzero urb status received: %d", 238 dbg("%s - nonzero urb status received: %d",
239 __FUNCTION__, status); 239 __func__, status);
240 goto exit; 240 goto exit;
241 } 241 }
242 242
@@ -274,7 +274,7 @@ exit:
274 retval = usb_submit_urb (urb, GFP_ATOMIC); 274 retval = usb_submit_urb (urb, GFP_ATOMIC);
275 if (retval) 275 if (retval)
276 err ("%s - usb_submit_urb failed with result %d", 276 err ("%s - usb_submit_urb failed with result %d",
277 __FUNCTION__, retval); 277 __func__, retval);
278} 278}
279 279
280 280
@@ -358,7 +358,7 @@ static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state
358 value, 0, NULL, 0, 2000); 358 value, 0, NULL, 0, 2000);
359 if (result < 0) 359 if (result < 0)
360 dbg("%s - error %d from usb_control_msg", 360 dbg("%s - error %d from usb_control_msg",
361 __FUNCTION__, result); 361 __func__, result);
362 /* there is something funky about this.. the TCSBRK that 'cu' performs 362 /* there is something funky about this.. the TCSBRK that 'cu' performs
363 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4 363 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
364 seconds apart, but it feels like the break sent isn't as long as it 364 seconds apart, but it feels like the break sent isn't as long as it
@@ -608,7 +608,7 @@ exit:
608 608
609static void keyspan_pda_write_bulk_callback (struct urb *urb) 609static void keyspan_pda_write_bulk_callback (struct urb *urb)
610{ 610{
611 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 611 struct usb_serial_port *port = urb->context;
612 struct keyspan_pda_private *priv; 612 struct keyspan_pda_private *priv;
613 613
614 port->write_urb_busy = 0; 614 port->write_urb_busy = 0;
@@ -636,14 +636,19 @@ static int keyspan_pda_write_room (struct usb_serial_port *port)
636static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port) 636static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port)
637{ 637{
638 struct keyspan_pda_private *priv; 638 struct keyspan_pda_private *priv;
639 unsigned long flags;
640 int ret = 0;
639 641
640 priv = usb_get_serial_port_data(port); 642 priv = usb_get_serial_port_data(port);
641 643
642 /* when throttled, return at least WAKEUP_CHARS to tell select() (via 644 /* when throttled, return at least WAKEUP_CHARS to tell select() (via
643 n_tty.c:normal_poll() ) that we're not writeable. */ 645 n_tty.c:normal_poll() ) that we're not writeable. */
646
647 spin_lock_irqsave(&port->lock, flags);
644 if (port->write_urb_busy || priv->tx_throttled) 648 if (port->write_urb_busy || priv->tx_throttled)
645 return 256; 649 ret = 256;
646 return 0; 650 spin_unlock_irqrestore(&port->lock, flags);
651 return ret;
647} 652}
648 653
649 654
@@ -665,11 +670,11 @@ static int keyspan_pda_open (struct usb_serial_port *port, struct file *filp)
665 1, 670 1,
666 2000); 671 2000);
667 if (rc < 0) { 672 if (rc < 0) {
668 dbg("%s - roomquery failed", __FUNCTION__); 673 dbg("%s - roomquery failed", __func__);
669 goto error; 674 goto error;
670 } 675 }
671 if (rc == 0) { 676 if (rc == 0) {
672 dbg("%s - roomquery returned 0 bytes", __FUNCTION__); 677 dbg("%s - roomquery returned 0 bytes", __func__);
673 rc = -EIO; 678 rc = -EIO;
674 goto error; 679 goto error;
675 } 680 }
@@ -688,7 +693,7 @@ static int keyspan_pda_open (struct usb_serial_port *port, struct file *filp)
688 port->interrupt_in_urb->dev = serial->dev; 693 port->interrupt_in_urb->dev = serial->dev;
689 rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 694 rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
690 if (rc) { 695 if (rc) {
691 dbg("%s - usb_submit_urb(read int) failed", __FUNCTION__); 696 dbg("%s - usb_submit_urb(read int) failed", __func__);
692 goto error; 697 goto error;
693 } 698 }
694 699
@@ -732,7 +737,7 @@ static int keyspan_pda_fake_startup (struct usb_serial *serial)
732 record = &xircom_pgs_firmware[0]; 737 record = &xircom_pgs_firmware[0];
733#endif 738#endif
734 if (record == NULL) { 739 if (record == NULL) {
735 err("%s: unknown vendor, aborting.", __FUNCTION__); 740 err("%s: unknown vendor, aborting.", __func__);
736 return -ENODEV; 741 return -ENODEV;
737 } 742 }
738 743
@@ -779,7 +784,7 @@ static int keyspan_pda_startup (struct usb_serial *serial)
779 784
780static void keyspan_pda_shutdown (struct usb_serial *serial) 785static void keyspan_pda_shutdown (struct usb_serial *serial)
781{ 786{
782 dbg("%s", __FUNCTION__); 787 dbg("%s", __func__);
783 788
784 kfree(usb_get_serial_port_data(serial->port[0])); 789 kfree(usb_get_serial_port_data(serial->port[0]));
785} 790}
@@ -793,9 +798,6 @@ static struct usb_serial_driver keyspan_pda_fake_device = {
793 .description = "Keyspan PDA - (prerenumeration)", 798 .description = "Keyspan PDA - (prerenumeration)",
794 .usb_driver = &keyspan_pda_driver, 799 .usb_driver = &keyspan_pda_driver,
795 .id_table = id_table_fake, 800 .id_table = id_table_fake,
796 .num_interrupt_in = NUM_DONT_CARE,
797 .num_bulk_in = NUM_DONT_CARE,
798 .num_bulk_out = NUM_DONT_CARE,
799 .num_ports = 1, 801 .num_ports = 1,
800 .attach = keyspan_pda_fake_startup, 802 .attach = keyspan_pda_fake_startup,
801}; 803};
@@ -810,9 +812,6 @@ static struct usb_serial_driver xircom_pgs_fake_device = {
810 .description = "Xircom / Entregra PGS - (prerenumeration)", 812 .description = "Xircom / Entregra PGS - (prerenumeration)",
811 .usb_driver = &keyspan_pda_driver, 813 .usb_driver = &keyspan_pda_driver,
812 .id_table = id_table_fake_xircom, 814 .id_table = id_table_fake_xircom,
813 .num_interrupt_in = NUM_DONT_CARE,
814 .num_bulk_in = NUM_DONT_CARE,
815 .num_bulk_out = NUM_DONT_CARE,
816 .num_ports = 1, 815 .num_ports = 1,
817 .attach = keyspan_pda_fake_startup, 816 .attach = keyspan_pda_fake_startup,
818}; 817};
@@ -826,9 +825,6 @@ static struct usb_serial_driver keyspan_pda_device = {
826 .description = "Keyspan PDA", 825 .description = "Keyspan PDA",
827 .usb_driver = &keyspan_pda_driver, 826 .usb_driver = &keyspan_pda_driver,
828 .id_table = id_table_std, 827 .id_table = id_table_std,
829 .num_interrupt_in = 1,
830 .num_bulk_in = 0,
831 .num_bulk_out = 1,
832 .num_ports = 1, 828 .num_ports = 1,
833 .open = keyspan_pda_open, 829 .open = keyspan_pda_open,
834 .close = keyspan_pda_close, 830 .close = keyspan_pda_close,
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 55736df7d2f4..b395ac759888 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -126,9 +126,6 @@ static struct usb_serial_driver kl5kusb105d_device = {
126 .description = "KL5KUSB105D / PalmConnect", 126 .description = "KL5KUSB105D / PalmConnect",
127 .usb_driver = &kl5kusb105d_driver, 127 .usb_driver = &kl5kusb105d_driver,
128 .id_table = id_table, 128 .id_table = id_table,
129 .num_interrupt_in = 1,
130 .num_bulk_in = 1,
131 .num_bulk_out = 1,
132 .num_ports = 1, 129 .num_ports = 1,
133 .open = klsi_105_open, 130 .open = klsi_105_open,
134 .close = klsi_105_close, 131 .close = klsi_105_close,
@@ -194,7 +191,7 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
194 if (rc < 0) 191 if (rc < 0)
195 err("Change port settings failed (error = %d)", rc); 192 err("Change port settings failed (error = %d)", rc);
196 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d", 193 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
197 __FUNCTION__, 194 __func__,
198 settings->pktlen, 195 settings->pktlen,
199 settings->baudrate, settings->databits, 196 settings->baudrate, settings->databits,
200 settings->unknown1, settings->unknown2); 197 settings->unknown1, settings->unknown2);
@@ -225,7 +222,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
225 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1}; 222 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1};
226 __u16 status; 223 __u16 status;
227 224
228 info("%s - sending SIO Poll request", __FUNCTION__); 225 info("%s - sending SIO Poll request", __func__);
229 rc = usb_control_msg(port->serial->dev, 226 rc = usb_control_msg(port->serial->dev,
230 usb_rcvctrlpipe(port->serial->dev, 0), 227 usb_rcvctrlpipe(port->serial->dev, 0),
231 KL5KUSB105A_SIO_POLL, 228 KL5KUSB105A_SIO_POLL,
@@ -240,7 +237,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
240 else { 237 else {
241 status = le16_to_cpu(*(u16 *)status_buf); 238 status = le16_to_cpu(*(u16 *)status_buf);
242 239
243 info("%s - read status %x %x", __FUNCTION__, 240 info("%s - read status %x %x", __func__,
244 status_buf[0], status_buf[1]); 241 status_buf[0], status_buf[1]);
245 242
246 *line_state_p = klsi_105_status2linestate(status); 243 *line_state_p = klsi_105_status2linestate(status);
@@ -268,7 +265,7 @@ static int klsi_105_startup (struct usb_serial *serial)
268 priv = kmalloc(sizeof(struct klsi_105_private), 265 priv = kmalloc(sizeof(struct klsi_105_private),
269 GFP_KERNEL); 266 GFP_KERNEL);
270 if (!priv) { 267 if (!priv) {
271 dbg("%skmalloc for klsi_105_private failed.", __FUNCTION__); 268 dbg("%skmalloc for klsi_105_private failed.", __func__);
272 i--; 269 i--;
273 goto err_cleanup; 270 goto err_cleanup;
274 } 271 }
@@ -298,7 +295,7 @@ static int klsi_105_startup (struct usb_serial *serial)
298 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, 295 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE,
299 GFP_KERNEL); 296 GFP_KERNEL);
300 if (!urb->transfer_buffer) { 297 if (!urb->transfer_buffer) {
301 err("%s - out of memory for urb buffers.", __FUNCTION__); 298 err("%s - out of memory for urb buffers.", __func__);
302 goto err_cleanup; 299 goto err_cleanup;
303 } 300 }
304 } 301 }
@@ -328,7 +325,7 @@ static void klsi_105_shutdown (struct usb_serial *serial)
328{ 325{
329 int i; 326 int i;
330 327
331 dbg("%s", __FUNCTION__); 328 dbg("%s", __func__);
332 329
333 /* stop reads and writes on all ports */ 330 /* stop reads and writes on all ports */
334 for (i=0; i < serial->num_ports; ++i) { 331 for (i=0; i < serial->num_ports; ++i) {
@@ -373,7 +370,7 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
373 struct klsi_105_port_settings cfg; 370 struct klsi_105_port_settings cfg;
374 unsigned long flags; 371 unsigned long flags;
375 372
376 dbg("%s port %d", __FUNCTION__, port->number); 373 dbg("%s port %d", __func__, port->number);
377 374
378 /* force low_latency on so that our tty_push actually forces 375 /* force low_latency on so that our tty_push actually forces
379 * the data through 376 * the data through
@@ -419,7 +416,7 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
419 416
420 rc = usb_submit_urb(port->read_urb, GFP_KERNEL); 417 rc = usb_submit_urb(port->read_urb, GFP_KERNEL);
421 if (rc) { 418 if (rc) {
422 err("%s - failed submitting read urb, error %d", __FUNCTION__, rc); 419 err("%s - failed submitting read urb, error %d", __func__, rc);
423 retval = rc; 420 retval = rc;
424 goto exit; 421 goto exit;
425 } 422 }
@@ -437,14 +434,14 @@ static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
437 err("Enabling read failed (error = %d)", rc); 434 err("Enabling read failed (error = %d)", rc);
438 retval = rc; 435 retval = rc;
439 } else 436 } else
440 dbg("%s - enabled reading", __FUNCTION__); 437 dbg("%s - enabled reading", __func__);
441 438
442 rc = klsi_105_get_line_state(port, &line_state); 439 rc = klsi_105_get_line_state(port, &line_state);
443 if (rc >= 0) { 440 if (rc >= 0) {
444 spin_lock_irqsave (&priv->lock, flags); 441 spin_lock_irqsave (&priv->lock, flags);
445 priv->line_state = line_state; 442 priv->line_state = line_state;
446 spin_unlock_irqrestore (&priv->lock, flags); 443 spin_unlock_irqrestore (&priv->lock, flags);
447 dbg("%s - read line state 0x%lx", __FUNCTION__, line_state); 444 dbg("%s - read line state 0x%lx", __func__, line_state);
448 retval = 0; 445 retval = 0;
449 } else 446 } else
450 retval = rc; 447 retval = rc;
@@ -459,7 +456,7 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
459 struct klsi_105_private *priv = usb_get_serial_port_data(port); 456 struct klsi_105_private *priv = usb_get_serial_port_data(port);
460 int rc; 457 int rc;
461 458
462 dbg("%s port %d", __FUNCTION__, port->number); 459 dbg("%s port %d", __func__, port->number);
463 460
464 mutex_lock(&port->serial->disc_mutex); 461 mutex_lock(&port->serial->disc_mutex);
465 if (!port->serial->disconnected) { 462 if (!port->serial->disconnected) {
@@ -502,7 +499,7 @@ static int klsi_105_write (struct usb_serial_port *port,
502 int result, size; 499 int result, size;
503 int bytes_sent=0; 500 int bytes_sent=0;
504 501
505 dbg("%s - port %d", __FUNCTION__, port->number); 502 dbg("%s - port %d", __func__, port->number);
506 503
507 while (count > 0) { 504 while (count > 0) {
508 /* try to find a free urb (write 0 bytes if none) */ 505 /* try to find a free urb (write 0 bytes if none) */
@@ -514,21 +511,21 @@ static int klsi_105_write (struct usb_serial_port *port,
514 for (i=0; i<NUM_URBS; i++) { 511 for (i=0; i<NUM_URBS; i++) {
515 if (priv->write_urb_pool[i]->status != -EINPROGRESS) { 512 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
516 urb = priv->write_urb_pool[i]; 513 urb = priv->write_urb_pool[i];
517 dbg("%s - using pool URB %d", __FUNCTION__, i); 514 dbg("%s - using pool URB %d", __func__, i);
518 break; 515 break;
519 } 516 }
520 } 517 }
521 spin_unlock_irqrestore (&priv->lock, flags); 518 spin_unlock_irqrestore (&priv->lock, flags);
522 519
523 if (urb==NULL) { 520 if (urb==NULL) {
524 dbg("%s - no more free urbs", __FUNCTION__); 521 dbg("%s - no more free urbs", __func__);
525 goto exit; 522 goto exit;
526 } 523 }
527 524
528 if (urb->transfer_buffer == NULL) { 525 if (urb->transfer_buffer == NULL) {
529 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 526 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
530 if (urb->transfer_buffer == NULL) { 527 if (urb->transfer_buffer == NULL) {
531 err("%s - no more kernel memory...", __FUNCTION__); 528 err("%s - no more kernel memory...", __func__);
532 goto exit; 529 goto exit;
533 } 530 }
534 } 531 }
@@ -554,7 +551,7 @@ static int klsi_105_write (struct usb_serial_port *port,
554 /* send the data out the bulk port */ 551 /* send the data out the bulk port */
555 result = usb_submit_urb(urb, GFP_ATOMIC); 552 result = usb_submit_urb(urb, GFP_ATOMIC);
556 if (result) { 553 if (result) {
557 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 554 err("%s - failed submitting write urb, error %d", __func__, result);
558 goto exit; 555 goto exit;
559 } 556 }
560 buf += size; 557 buf += size;
@@ -570,13 +567,13 @@ exit:
570 567
571static void klsi_105_write_bulk_callback ( struct urb *urb) 568static void klsi_105_write_bulk_callback ( struct urb *urb)
572{ 569{
573 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 570 struct usb_serial_port *port = urb->context;
574 int status = urb->status; 571 int status = urb->status;
575 572
576 dbg("%s - port %d", __FUNCTION__, port->number); 573 dbg("%s - port %d", __func__, port->number);
577 574
578 if (status) { 575 if (status) {
579 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, 576 dbg("%s - nonzero write bulk status received: %d", __func__,
580 status); 577 status);
581 return; 578 return;
582 } 579 }
@@ -603,7 +600,7 @@ static int klsi_105_chars_in_buffer (struct usb_serial_port *port)
603 600
604 spin_unlock_irqrestore (&priv->lock, flags); 601 spin_unlock_irqrestore (&priv->lock, flags);
605 602
606 dbg("%s - returns %d", __FUNCTION__, chars); 603 dbg("%s - returns %d", __func__, chars);
607 return (chars); 604 return (chars);
608} 605}
609 606
@@ -623,7 +620,7 @@ static int klsi_105_write_room (struct usb_serial_port *port)
623 620
624 spin_unlock_irqrestore (&priv->lock, flags); 621 spin_unlock_irqrestore (&priv->lock, flags);
625 622
626 dbg("%s - returns %d", __FUNCTION__, room); 623 dbg("%s - returns %d", __func__, room);
627 return (room); 624 return (room);
628} 625}
629 626
@@ -631,18 +628,18 @@ static int klsi_105_write_room (struct usb_serial_port *port)
631 628
632static void klsi_105_read_bulk_callback (struct urb *urb) 629static void klsi_105_read_bulk_callback (struct urb *urb)
633{ 630{
634 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 631 struct usb_serial_port *port = urb->context;
635 struct klsi_105_private *priv = usb_get_serial_port_data(port); 632 struct klsi_105_private *priv = usb_get_serial_port_data(port);
636 struct tty_struct *tty; 633 struct tty_struct *tty;
637 unsigned char *data = urb->transfer_buffer; 634 unsigned char *data = urb->transfer_buffer;
638 int rc; 635 int rc;
639 int status = urb->status; 636 int status = urb->status;
640 637
641 dbg("%s - port %d", __FUNCTION__, port->number); 638 dbg("%s - port %d", __func__, port->number);
642 639
643 /* The urb might have been killed. */ 640 /* The urb might have been killed. */
644 if (status) { 641 if (status) {
645 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, 642 dbg("%s - nonzero read bulk status received: %d", __func__,
646 status); 643 status);
647 return; 644 return;
648 } 645 }
@@ -652,12 +649,12 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
652 */ 649 */
653 if (urb->actual_length == 0) { 650 if (urb->actual_length == 0) {
654 /* empty urbs seem to happen, we ignore them */ 651 /* empty urbs seem to happen, we ignore them */
655 /* dbg("%s - emtpy URB", __FUNCTION__); */ 652 /* dbg("%s - emtpy URB", __func__); */
656 ; 653 ;
657 } else if (urb->actual_length <= 2) { 654 } else if (urb->actual_length <= 2) {
658 dbg("%s - size %d URB not understood", __FUNCTION__, 655 dbg("%s - size %d URB not understood", __func__,
659 urb->actual_length); 656 urb->actual_length);
660 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 657 usb_serial_debug_data(debug, &port->dev, __func__,
661 urb->actual_length, data); 658 urb->actual_length, data);
662 } else { 659 } else {
663 int bytes_sent = ((__u8 *) data)[0] + 660 int bytes_sent = ((__u8 *) data)[0] +
@@ -669,12 +666,12 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
669 * intermixed tty_flip_buffer_push()s 666 * intermixed tty_flip_buffer_push()s
670 * FIXME 667 * FIXME
671 */ 668 */
672 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 669 usb_serial_debug_data(debug, &port->dev, __func__,
673 urb->actual_length, data); 670 urb->actual_length, data);
674 671
675 if (bytes_sent + 2 > urb->actual_length) { 672 if (bytes_sent + 2 > urb->actual_length) {
676 dbg("%s - trying to read more data than available" 673 dbg("%s - trying to read more data than available"
677 " (%d vs. %d)", __FUNCTION__, 674 " (%d vs. %d)", __func__,
678 bytes_sent+2, urb->actual_length); 675 bytes_sent+2, urb->actual_length);
679 /* cap at implied limit */ 676 /* cap at implied limit */
680 bytes_sent = urb->actual_length - 2; 677 bytes_sent = urb->actual_length - 2;
@@ -697,7 +694,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
697 port); 694 port);
698 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC); 695 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
699 if (rc) 696 if (rc)
700 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, rc); 697 err("%s - failed resubmitting read urb, error %d", __func__, rc);
701} /* klsi_105_read_bulk_callback */ 698} /* klsi_105_read_bulk_callback */
702 699
703 700
@@ -705,12 +702,14 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
705 struct ktermios *old_termios) 702 struct ktermios *old_termios)
706{ 703{
707 struct klsi_105_private *priv = usb_get_serial_port_data(port); 704 struct klsi_105_private *priv = usb_get_serial_port_data(port);
708 unsigned int iflag = port->tty->termios->c_iflag; 705 struct tty_struct *tty = port->tty;
706 unsigned int iflag = tty->termios->c_iflag;
709 unsigned int old_iflag = old_termios->c_iflag; 707 unsigned int old_iflag = old_termios->c_iflag;
710 unsigned int cflag = port->tty->termios->c_cflag; 708 unsigned int cflag = tty->termios->c_cflag;
711 unsigned int old_cflag = old_termios->c_cflag; 709 unsigned int old_cflag = old_termios->c_cflag;
712 struct klsi_105_port_settings cfg; 710 struct klsi_105_port_settings cfg;
713 unsigned long flags; 711 unsigned long flags;
712 speed_t baud;
714 713
715 /* lock while we are modifying the settings */ 714 /* lock while we are modifying the settings */
716 spin_lock_irqsave (&priv->lock, flags); 715 spin_lock_irqsave (&priv->lock, flags);
@@ -718,10 +717,12 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
718 /* 717 /*
719 * Update baud rate 718 * Update baud rate
720 */ 719 */
720 baud = tty_get_baud_rate(tty);
721
721 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) { 722 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) {
722 /* reassert DTR and (maybe) RTS on transition from B0 */ 723 /* reassert DTR and (maybe) RTS on transition from B0 */
723 if( (old_cflag & CBAUD) == B0 ) { 724 if( (old_cflag & CBAUD) == B0 ) {
724 dbg("%s: baud was B0", __FUNCTION__); 725 dbg("%s: baud was B0", __func__);
725#if 0 726#if 0
726 priv->control_state |= TIOCM_DTR; 727 priv->control_state |= TIOCM_DTR;
727 /* don't set RTS if using hardware flow control */ 728 /* don't set RTS if using hardware flow control */
@@ -731,8 +732,8 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
731 mct_u232_set_modem_ctrl(serial, priv->control_state); 732 mct_u232_set_modem_ctrl(serial, priv->control_state);
732#endif 733#endif
733 } 734 }
734 735 }
735 switch(tty_get_baud_rate(port->tty)) { 736 switch(baud) {
736 case 0: /* handled below */ 737 case 0: /* handled below */
737 break; 738 break;
738 case 1200: 739 case 1200:
@@ -760,35 +761,36 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
760 priv->cfg.baudrate = kl5kusb105a_sio_b115200; 761 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
761 break; 762 break;
762 default: 763 default:
763 err("KLSI USB->Serial converter:" 764 dbg("KLSI USB->Serial converter:"
764 " unsupported baudrate request, using default" 765 " unsupported baudrate request, using default"
765 " of 9600"); 766 " of 9600");
766 priv->cfg.baudrate = kl5kusb105a_sio_b9600; 767 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
768 baud = 9600;
767 break; 769 break;
768 } 770 }
769 if ((cflag & CBAUD) == B0 ) { 771 if ((cflag & CBAUD) == B0 ) {
770 dbg("%s: baud is B0", __FUNCTION__); 772 dbg("%s: baud is B0", __func__);
771 /* Drop RTS and DTR */ 773 /* Drop RTS and DTR */
772 /* maybe this should be simulated by sending read 774 /* maybe this should be simulated by sending read
773 * disable and read enable messages? 775 * disable and read enable messages?
774 */ 776 */
775 ; 777 ;
776#if 0 778#if 0
777 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 779 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
778 mct_u232_set_modem_ctrl(serial, priv->control_state); 780 mct_u232_set_modem_ctrl(serial, priv->control_state);
779#endif 781#endif
780 }
781 } 782 }
783 tty_encode_baud_rate(tty, baud, baud);
782 784
783 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 785 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
784 /* set the number of data bits */ 786 /* set the number of data bits */
785 switch (cflag & CSIZE) { 787 switch (cflag & CSIZE) {
786 case CS5: 788 case CS5:
787 dbg("%s - 5 bits/byte not supported", __FUNCTION__); 789 dbg("%s - 5 bits/byte not supported", __func__);
788 spin_unlock_irqrestore (&priv->lock, flags); 790 spin_unlock_irqrestore (&priv->lock, flags);
789 return ; 791 return ;
790 case CS6: 792 case CS6:
791 dbg("%s - 6 bits/byte not supported", __FUNCTION__); 793 dbg("%s - 6 bits/byte not supported", __func__);
792 spin_unlock_irqrestore (&priv->lock, flags); 794 spin_unlock_irqrestore (&priv->lock, flags);
793 return ; 795 return ;
794 case CS7: 796 case CS7:
@@ -810,6 +812,8 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
810 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD)) 812 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
811 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) { 813 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) {
812 814
815 /* Not currently supported */
816 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
813#if 0 817#if 0
814 priv->last_lcr = 0; 818 priv->last_lcr = 0;
815 819
@@ -837,6 +841,8 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
837 || (iflag & IXON) != (old_iflag & IXON) 841 || (iflag & IXON) != (old_iflag & IXON)
838 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) { 842 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) {
839 843
844 /* Not currently supported */
845 tty->termios->c_cflag &= ~CRTSCTS;
840 /* Drop DTR/RTS if no flow control otherwise assert */ 846 /* Drop DTR/RTS if no flow control otherwise assert */
841#if 0 847#if 0
842 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) ) 848 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) )
@@ -862,7 +868,7 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
862 struct mct_u232_private *priv = (struct mct_u232_private *)port->private; 868 struct mct_u232_private *priv = (struct mct_u232_private *)port->private;
863 unsigned char lcr = priv->last_lcr; 869 unsigned char lcr = priv->last_lcr;
864 870
865 dbg("%sstate=%d", __FUNCTION__, break_state); 871 dbg("%sstate=%d", __func__, break_state);
866 872
867 if (break_state) 873 if (break_state)
868 lcr |= MCT_U232_SET_BREAK; 874 lcr |= MCT_U232_SET_BREAK;
@@ -877,7 +883,7 @@ static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file)
877 unsigned long flags; 883 unsigned long flags;
878 int rc; 884 int rc;
879 unsigned long line_state; 885 unsigned long line_state;
880 dbg("%s - request, just guessing", __FUNCTION__); 886 dbg("%s - request, just guessing", __func__);
881 887
882 rc = klsi_105_get_line_state(port, &line_state); 888 rc = klsi_105_get_line_state(port, &line_state);
883 if (rc < 0) { 889 if (rc < 0) {
@@ -889,7 +895,7 @@ static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file)
889 spin_lock_irqsave (&priv->lock, flags); 895 spin_lock_irqsave (&priv->lock, flags);
890 priv->line_state = line_state; 896 priv->line_state = line_state;
891 spin_unlock_irqrestore (&priv->lock, flags); 897 spin_unlock_irqrestore (&priv->lock, flags);
892 dbg("%s - read line state 0x%lx", __FUNCTION__, line_state); 898 dbg("%s - read line state 0x%lx", __func__, line_state);
893 return (int)line_state; 899 return (int)line_state;
894} 900}
895 901
@@ -898,7 +904,7 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
898{ 904{
899 int retval = -EINVAL; 905 int retval = -EINVAL;
900 906
901 dbg("%s", __FUNCTION__); 907 dbg("%s", __func__);
902 908
903/* if this ever gets implemented, it should be done something like this: 909/* if this ever gets implemented, it should be done something like this:
904 struct usb_serial *serial = port->serial; 910 struct usb_serial *serial = port->serial;
@@ -924,7 +930,7 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
924 930
925static void klsi_105_throttle (struct usb_serial_port *port) 931static void klsi_105_throttle (struct usb_serial_port *port)
926{ 932{
927 dbg("%s - port %d", __FUNCTION__, port->number); 933 dbg("%s - port %d", __func__, port->number);
928 usb_kill_urb(port->read_urb); 934 usb_kill_urb(port->read_urb);
929} 935}
930 936
@@ -932,12 +938,12 @@ static void klsi_105_unthrottle (struct usb_serial_port *port)
932{ 938{
933 int result; 939 int result;
934 940
935 dbg("%s - port %d", __FUNCTION__, port->number); 941 dbg("%s - port %d", __func__, port->number);
936 942
937 port->read_urb->dev = port->serial->dev; 943 port->read_urb->dev = port->serial->dev;
938 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 944 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
939 if (result) 945 if (result)
940 err("%s - failed submitting read urb, error %d", __FUNCTION__, 946 err("%s - failed submitting read urb, error %d", __func__,
941 result); 947 result);
942} 948}
943 949
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 17b3baead4ad..693f00da7c03 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -113,10 +113,6 @@ static struct usb_serial_driver kobil_device = {
113 .description = "KOBIL USB smart card terminal", 113 .description = "KOBIL USB smart card terminal",
114 .usb_driver = &kobil_driver, 114 .usb_driver = &kobil_driver,
115 .id_table = id_table, 115 .id_table = id_table,
116 .num_interrupt_in = NUM_DONT_CARE,
117 .num_interrupt_out = NUM_DONT_CARE,
118 .num_bulk_in = 0,
119 .num_bulk_out = 0,
120 .num_ports = 1, 116 .num_ports = 1,
121 .attach = kobil_startup, 117 .attach = kobil_startup,
122 .shutdown = kobil_shutdown, 118 .shutdown = kobil_shutdown,
@@ -139,7 +135,6 @@ struct kobil_private {
139 int filled; // index of the last char in buf 135 int filled; // index of the last char in buf
140 int cur_pos; // index of the next char to send in buf 136 int cur_pos; // index of the next char to send in buf
141 __u16 device_type; 137 __u16 device_type;
142 int line_state;
143}; 138};
144 139
145 140
@@ -161,7 +156,6 @@ static int kobil_startup (struct usb_serial *serial)
161 priv->filled = 0; 156 priv->filled = 0;
162 priv->cur_pos = 0; 157 priv->cur_pos = 0;
163 priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct); 158 priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
164 priv->line_state = 0;
165 159
166 switch (priv->device_type){ 160 switch (priv->device_type){
167 case KOBIL_ADAPTER_B_PRODUCT_ID: 161 case KOBIL_ADAPTER_B_PRODUCT_ID:
@@ -189,11 +183,11 @@ static int kobil_startup (struct usb_serial *serial)
189 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { 183 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
190 endpoint = &altsetting->endpoint[i]; 184 endpoint = &altsetting->endpoint[i];
191 if (usb_endpoint_is_int_out(&endpoint->desc)) { 185 if (usb_endpoint_is_int_out(&endpoint->desc)) {
192 dbg("%s Found interrupt out endpoint. Address: %d", __FUNCTION__, endpoint->desc.bEndpointAddress); 186 dbg("%s Found interrupt out endpoint. Address: %d", __func__, endpoint->desc.bEndpointAddress);
193 priv->write_int_endpoint_address = endpoint->desc.bEndpointAddress; 187 priv->write_int_endpoint_address = endpoint->desc.bEndpointAddress;
194 } 188 }
195 if (usb_endpoint_is_int_in(&endpoint->desc)) { 189 if (usb_endpoint_is_int_in(&endpoint->desc)) {
196 dbg("%s Found interrupt in endpoint. Address: %d", __FUNCTION__, endpoint->desc.bEndpointAddress); 190 dbg("%s Found interrupt in endpoint. Address: %d", __func__, endpoint->desc.bEndpointAddress);
197 priv->read_int_endpoint_address = endpoint->desc.bEndpointAddress; 191 priv->read_int_endpoint_address = endpoint->desc.bEndpointAddress;
198 } 192 }
199 } 193 }
@@ -204,7 +198,7 @@ static int kobil_startup (struct usb_serial *serial)
204static void kobil_shutdown (struct usb_serial *serial) 198static void kobil_shutdown (struct usb_serial *serial)
205{ 199{
206 int i; 200 int i;
207 dbg("%s - port %d", __FUNCTION__, serial->port[0]->number); 201 dbg("%s - port %d", __func__, serial->port[0]->number);
208 202
209 for (i=0; i < serial->num_ports; ++i) { 203 for (i=0; i < serial->num_ports; ++i) {
210 while (serial->port[i]->open_count > 0) { 204 while (serial->port[i]->open_count > 0) {
@@ -224,9 +218,8 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
224 int transfer_buffer_length = 8; 218 int transfer_buffer_length = 8;
225 int write_urb_transfer_buffer_length = 8; 219 int write_urb_transfer_buffer_length = 8;
226 220
227 dbg("%s - port %d", __FUNCTION__, port->number); 221 dbg("%s - port %d", __func__, port->number);
228 priv = usb_get_serial_port_data(port); 222 priv = usb_get_serial_port_data(port);
229 priv->line_state = 0;
230 223
231 // someone sets the dev to 0 if the close method has been called 224 // someone sets the dev to 0 if the close method has been called
232 port->interrupt_in_urb->dev = port->serial->dev; 225 port->interrupt_in_urb->dev = port->serial->dev;
@@ -252,10 +245,10 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
252 245
253 // allocate write_urb 246 // allocate write_urb
254 if (!port->write_urb) { 247 if (!port->write_urb) {
255 dbg("%s - port %d Allocating port->write_urb", __FUNCTION__, port->number); 248 dbg("%s - port %d Allocating port->write_urb", __func__, port->number);
256 port->write_urb = usb_alloc_urb(0, GFP_KERNEL); 249 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
257 if (!port->write_urb) { 250 if (!port->write_urb) {
258 dbg("%s - port %d usb_alloc_urb failed", __FUNCTION__, port->number); 251 dbg("%s - port %d usb_alloc_urb failed", __func__, port->number);
259 kfree(transfer_buffer); 252 kfree(transfer_buffer);
260 return -ENOMEM; 253 return -ENOMEM;
261 } 254 }
@@ -281,7 +274,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
281 transfer_buffer_length, 274 transfer_buffer_length,
282 KOBIL_TIMEOUT 275 KOBIL_TIMEOUT
283 ); 276 );
284 dbg("%s - port %d Send get_HW_version URB returns: %i", __FUNCTION__, port->number, result); 277 dbg("%s - port %d Send get_HW_version URB returns: %i", __func__, port->number, result);
285 dbg("Harware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] ); 278 dbg("Harware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] );
286 279
287 // get firmware version 280 // get firmware version
@@ -295,7 +288,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
295 transfer_buffer_length, 288 transfer_buffer_length,
296 KOBIL_TIMEOUT 289 KOBIL_TIMEOUT
297 ); 290 );
298 dbg("%s - port %d Send get_FW_version URB returns: %i", __FUNCTION__, port->number, result); 291 dbg("%s - port %d Send get_FW_version URB returns: %i", __func__, port->number, result);
299 dbg("Firmware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] ); 292 dbg("Firmware version: %i.%i.%i", transfer_buffer[0], transfer_buffer[1], transfer_buffer[2] );
300 293
301 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) { 294 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
@@ -310,7 +303,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
310 0, 303 0,
311 KOBIL_TIMEOUT 304 KOBIL_TIMEOUT
312 ); 305 );
313 dbg("%s - port %d Send set_baudrate URB returns: %i", __FUNCTION__, port->number, result); 306 dbg("%s - port %d Send set_baudrate URB returns: %i", __func__, port->number, result);
314 307
315 // reset all queues 308 // reset all queues
316 result = usb_control_msg( port->serial->dev, 309 result = usb_control_msg( port->serial->dev,
@@ -323,13 +316,13 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
323 0, 316 0,
324 KOBIL_TIMEOUT 317 KOBIL_TIMEOUT
325 ); 318 );
326 dbg("%s - port %d Send reset_all_queues URB returns: %i", __FUNCTION__, port->number, result); 319 dbg("%s - port %d Send reset_all_queues URB returns: %i", __func__, port->number, result);
327 } 320 }
328 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || 321 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
329 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) { 322 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
330 // start reading (Adapter B 'cause PNP string) 323 // start reading (Adapter B 'cause PNP string)
331 result = usb_submit_urb( port->interrupt_in_urb, GFP_ATOMIC ); 324 result = usb_submit_urb( port->interrupt_in_urb, GFP_ATOMIC );
332 dbg("%s - port %d Send read URB returns: %i", __FUNCTION__, port->number, result); 325 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result);
333 } 326 }
334 327
335 kfree(transfer_buffer); 328 kfree(transfer_buffer);
@@ -339,7 +332,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
339 332
340static void kobil_close (struct usb_serial_port *port, struct file *filp) 333static void kobil_close (struct usb_serial_port *port, struct file *filp)
341{ 334{
342 dbg("%s - port %d", __FUNCTION__, port->number); 335 dbg("%s - port %d", __func__, port->number);
343 336
344 if (port->write_urb) { 337 if (port->write_urb) {
345 usb_kill_urb(port->write_urb); 338 usb_kill_urb(port->write_urb);
@@ -359,11 +352,11 @@ static void kobil_read_int_callback(struct urb *urb)
359 int status = urb->status; 352 int status = urb->status;
360// char *dbg_data; 353// char *dbg_data;
361 354
362 dbg("%s - port %d", __FUNCTION__, port->number); 355 dbg("%s - port %d", __func__, port->number);
363 356
364 if (status) { 357 if (status) {
365 dbg("%s - port %d Read int status not zero: %d", 358 dbg("%s - port %d Read int status not zero: %d",
366 __FUNCTION__, port->number, status); 359 __func__, port->number, status);
367 return; 360 return;
368 } 361 }
369 362
@@ -393,7 +386,7 @@ static void kobil_read_int_callback(struct urb *urb)
393 port->interrupt_in_urb->dev = port->serial->dev; 386 port->interrupt_in_urb->dev = port->serial->dev;
394 387
395 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 388 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
396 dbg("%s - port %d Send read URB returns: %i", __FUNCTION__, port->number, result); 389 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result);
397} 390}
398 391
399 392
@@ -411,21 +404,21 @@ static int kobil_write (struct usb_serial_port *port,
411 struct kobil_private * priv; 404 struct kobil_private * priv;
412 405
413 if (count == 0) { 406 if (count == 0) {
414 dbg("%s - port %d write request of 0 bytes", __FUNCTION__, port->number); 407 dbg("%s - port %d write request of 0 bytes", __func__, port->number);
415 return 0; 408 return 0;
416 } 409 }
417 410
418 priv = usb_get_serial_port_data(port); 411 priv = usb_get_serial_port_data(port);
419 412
420 if (count > (KOBIL_BUF_LENGTH - priv->filled)) { 413 if (count > (KOBIL_BUF_LENGTH - priv->filled)) {
421 dbg("%s - port %d Error: write request bigger than buffer size", __FUNCTION__, port->number); 414 dbg("%s - port %d Error: write request bigger than buffer size", __func__, port->number);
422 return -ENOMEM; 415 return -ENOMEM;
423 } 416 }
424 417
425 // Copy data to buffer 418 // Copy data to buffer
426 memcpy (priv->buf + priv->filled, buf, count); 419 memcpy (priv->buf + priv->filled, buf, count);
427 420
428 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, priv->buf + priv->filled); 421 usb_serial_debug_data(debug, &port->dev, __func__, count, priv->buf + priv->filled);
429 422
430 priv->filled = priv->filled + count; 423 priv->filled = priv->filled + count;
431 424
@@ -457,7 +450,7 @@ static int kobil_write (struct usb_serial_port *port,
457 450
458 priv->cur_pos = priv->cur_pos + length; 451 priv->cur_pos = priv->cur_pos + length;
459 result = usb_submit_urb( port->write_urb, GFP_NOIO ); 452 result = usb_submit_urb( port->write_urb, GFP_NOIO );
460 dbg("%s - port %d Send write URB returns: %i", __FUNCTION__, port->number, result); 453 dbg("%s - port %d Send write URB returns: %i", __func__, port->number, result);
461 todo = priv->filled - priv->cur_pos; 454 todo = priv->filled - priv->cur_pos;
462 455
463 if (todo > 0) { 456 if (todo > 0) {
@@ -478,7 +471,7 @@ static int kobil_write (struct usb_serial_port *port,
478 port->interrupt_in_urb->dev = port->serial->dev; 471 port->interrupt_in_urb->dev = port->serial->dev;
479 472
480 result = usb_submit_urb( port->interrupt_in_urb, GFP_NOIO ); 473 result = usb_submit_urb( port->interrupt_in_urb, GFP_NOIO );
481 dbg("%s - port %d Send read URB returns: %i", __FUNCTION__, port->number, result); 474 dbg("%s - port %d Send read URB returns: %i", __func__, port->number, result);
482 } 475 }
483 } 476 }
484 return count; 477 return count;
@@ -487,7 +480,7 @@ static int kobil_write (struct usb_serial_port *port,
487 480
488static int kobil_write_room (struct usb_serial_port *port) 481static int kobil_write_room (struct usb_serial_port *port)
489{ 482{
490 //dbg("%s - port %d", __FUNCTION__, port->number); 483 //dbg("%s - port %d", __func__, port->number);
491 return 8; 484 return 8;
492} 485}
493 486
@@ -522,16 +515,13 @@ static int kobil_tiocmget(struct usb_serial_port *port, struct file *file)
522 KOBIL_TIMEOUT); 515 KOBIL_TIMEOUT);
523 516
524 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x", 517 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x",
525 __FUNCTION__, port->number, result, transfer_buffer[0]); 518 __func__, port->number, result, transfer_buffer[0]);
526
527 if ((transfer_buffer[0] & SUSBCR_GSL_DSR) != 0) {
528 priv->line_state |= TIOCM_DSR;
529 } else {
530 priv->line_state &= ~TIOCM_DSR;
531 }
532 519
520 result = 0;
521 if ((transfer_buffer[0] & SUSBCR_GSL_DSR) != 0)
522 result = TIOCM_DSR;
533 kfree(transfer_buffer); 523 kfree(transfer_buffer);
534 return priv->line_state; 524 return result;
535} 525}
536 526
537static int kobil_tiocmset(struct usb_serial_port *port, struct file *file, 527static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
@@ -544,6 +534,7 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
544 unsigned char *transfer_buffer; 534 unsigned char *transfer_buffer;
545 int transfer_buffer_length = 8; 535 int transfer_buffer_length = 8;
546 536
537 /* FIXME: locking ? */
547 priv = usb_get_serial_port_data(port); 538 priv = usb_get_serial_port_data(port);
548 if ((priv->device_type == KOBIL_USBTWIN_PRODUCT_ID) || (priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)) { 539 if ((priv->device_type == KOBIL_USBTWIN_PRODUCT_ID) || (priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)) {
549 // This device doesn't support ioctl calls 540 // This device doesn't support ioctl calls
@@ -567,9 +558,9 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
567 558
568 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) { 559 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) {
569 if (dtr != 0) 560 if (dtr != 0)
570 dbg("%s - port %d Setting DTR", __FUNCTION__, port->number); 561 dbg("%s - port %d Setting DTR", __func__, port->number);
571 else 562 else
572 dbg("%s - port %d Clearing DTR", __FUNCTION__, port->number); 563 dbg("%s - port %d Clearing DTR", __func__, port->number);
573 result = usb_control_msg( port->serial->dev, 564 result = usb_control_msg( port->serial->dev,
574 usb_rcvctrlpipe(port->serial->dev, 0 ), 565 usb_rcvctrlpipe(port->serial->dev, 0 ),
575 SUSBCRequest_SetStatusLinesOrQueues, 566 SUSBCRequest_SetStatusLinesOrQueues,
@@ -581,9 +572,9 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
581 KOBIL_TIMEOUT); 572 KOBIL_TIMEOUT);
582 } else { 573 } else {
583 if (rts != 0) 574 if (rts != 0)
584 dbg("%s - port %d Setting RTS", __FUNCTION__, port->number); 575 dbg("%s - port %d Setting RTS", __func__, port->number);
585 else 576 else
586 dbg("%s - port %d Clearing RTS", __FUNCTION__, port->number); 577 dbg("%s - port %d Clearing RTS", __func__, port->number);
587 result = usb_control_msg( port->serial->dev, 578 result = usb_control_msg( port->serial->dev,
588 usb_rcvctrlpipe(port->serial->dev, 0 ), 579 usb_rcvctrlpipe(port->serial->dev, 0 ),
589 SUSBCRequest_SetStatusLinesOrQueues, 580 SUSBCRequest_SetStatusLinesOrQueues,
@@ -594,7 +585,7 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
594 0, 585 0,
595 KOBIL_TIMEOUT); 586 KOBIL_TIMEOUT);
596 } 587 }
597 dbg("%s - port %d Send set_status_line URB returns: %i", __FUNCTION__, port->number, result); 588 dbg("%s - port %d Send set_status_line URB returns: %i", __func__, port->number, result);
598 kfree(transfer_buffer); 589 kfree(transfer_buffer);
599 return (result < 0) ? result : 0; 590 return (result < 0) ? result : 0;
600} 591}
@@ -687,7 +678,7 @@ static int kobil_ioctl(struct usb_serial_port *port, struct file * file, unsigne
687 KOBIL_TIMEOUT 678 KOBIL_TIMEOUT
688 ); 679 );
689 680
690 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __FUNCTION__, port->number, result); 681 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __func__, port->number, result);
691 kfree(transfer_buffer); 682 kfree(transfer_buffer);
692 return (result < 0) ? -EFAULT : 0; 683 return (result < 0) ? -EFAULT : 0;
693 default: 684 default:
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index fc1cea4aba13..5fc2cef30e39 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -143,9 +143,6 @@ static struct usb_serial_driver mct_u232_device = {
143 .description = "MCT U232", 143 .description = "MCT U232",
144 .usb_driver = &mct_u232_driver, 144 .usb_driver = &mct_u232_driver,
145 .id_table = id_table_combined, 145 .id_table = id_table_combined,
146 .num_interrupt_in = 2,
147 .num_bulk_in = 0,
148 .num_bulk_out = 1,
149 .num_ports = 1, 146 .num_ports = 1,
150 .open = mct_u232_open, 147 .open = mct_u232_open,
151 .close = mct_u232_close, 148 .close = mct_u232_close,
@@ -402,7 +399,7 @@ static void mct_u232_shutdown (struct usb_serial *serial)
402 struct mct_u232_private *priv; 399 struct mct_u232_private *priv;
403 int i; 400 int i;
404 401
405 dbg("%s", __FUNCTION__); 402 dbg("%s", __func__);
406 403
407 for (i=0; i < serial->num_ports; ++i) { 404 for (i=0; i < serial->num_ports; ++i) {
408 /* My special items, the standard routines free my urbs */ 405 /* My special items, the standard routines free my urbs */
@@ -424,7 +421,7 @@ static int mct_u232_open (struct usb_serial_port *port, struct file *filp)
424 unsigned char last_lcr; 421 unsigned char last_lcr;
425 unsigned char last_msr; 422 unsigned char last_msr;
426 423
427 dbg("%s port %d", __FUNCTION__, port->number); 424 dbg("%s port %d", __func__, port->number);
428 425
429 /* Compensate for a hardware bug: although the Sitecom U232-P25 426 /* Compensate for a hardware bug: although the Sitecom U232-P25
430 * device reports a maximum output packet size of 32 bytes, 427 * device reports a maximum output packet size of 32 bytes,
@@ -489,7 +486,7 @@ static void mct_u232_close (struct usb_serial_port *port, struct file *filp)
489 unsigned int c_cflag; 486 unsigned int c_cflag;
490 unsigned int control_state; 487 unsigned int control_state;
491 struct mct_u232_private *priv = usb_get_serial_port_data(port); 488 struct mct_u232_private *priv = usb_get_serial_port_data(port);
492 dbg("%s port %d", __FUNCTION__, port->number); 489 dbg("%s port %d", __func__, port->number);
493 490
494 if (port->tty) { 491 if (port->tty) {
495 c_cflag = port->tty->termios->c_cflag; 492 c_cflag = port->tty->termios->c_cflag;
@@ -517,7 +514,7 @@ static void mct_u232_close (struct usb_serial_port *port, struct file *filp)
517 514
518static void mct_u232_read_int_callback (struct urb *urb) 515static void mct_u232_read_int_callback (struct urb *urb)
519{ 516{
520 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 517 struct usb_serial_port *port = urb->context;
521 struct mct_u232_private *priv = usb_get_serial_port_data(port); 518 struct mct_u232_private *priv = usb_get_serial_port_data(port);
522 struct usb_serial *serial = port->serial; 519 struct usb_serial *serial = port->serial;
523 struct tty_struct *tty; 520 struct tty_struct *tty;
@@ -535,21 +532,21 @@ static void mct_u232_read_int_callback (struct urb *urb)
535 case -ESHUTDOWN: 532 case -ESHUTDOWN:
536 /* this urb is terminated, clean up */ 533 /* this urb is terminated, clean up */
537 dbg("%s - urb shutting down with status: %d", 534 dbg("%s - urb shutting down with status: %d",
538 __FUNCTION__, status); 535 __func__, status);
539 return; 536 return;
540 default: 537 default:
541 dbg("%s - nonzero urb status received: %d", 538 dbg("%s - nonzero urb status received: %d",
542 __FUNCTION__, status); 539 __func__, status);
543 goto exit; 540 goto exit;
544 } 541 }
545 542
546 if (!serial) { 543 if (!serial) {
547 dbg("%s - bad serial pointer, exiting", __FUNCTION__); 544 dbg("%s - bad serial pointer, exiting", __func__);
548 return; 545 return;
549 } 546 }
550 547
551 dbg("%s - port %d", __FUNCTION__, port->number); 548 dbg("%s - port %d", __func__, port->number);
552 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 549 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
553 550
554 /* 551 /*
555 * Work-a-round: handle the 'usual' bulk-in pipe here 552 * Work-a-round: handle the 'usual' bulk-in pipe here
@@ -606,7 +603,7 @@ exit:
606 retval = usb_submit_urb (urb, GFP_ATOMIC); 603 retval = usb_submit_urb (urb, GFP_ATOMIC);
607 if (retval) 604 if (retval)
608 err ("%s - usb_submit_urb failed with result %d", 605 err ("%s - usb_submit_urb failed with result %d",
609 __FUNCTION__, retval); 606 __func__, retval);
610} /* mct_u232_read_int_callback */ 607} /* mct_u232_read_int_callback */
611 608
612static void mct_u232_set_termios (struct usb_serial_port *port, 609static void mct_u232_set_termios (struct usb_serial_port *port,
@@ -636,7 +633,7 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
636 633
637 /* reassert DTR and RTS on transition from B0 */ 634 /* reassert DTR and RTS on transition from B0 */
638 if ((old_cflag & CBAUD) == B0) { 635 if ((old_cflag & CBAUD) == B0) {
639 dbg("%s: baud was B0", __FUNCTION__); 636 dbg("%s: baud was B0", __func__);
640 control_state |= TIOCM_DTR | TIOCM_RTS; 637 control_state |= TIOCM_DTR | TIOCM_RTS;
641 mct_u232_set_modem_ctrl(serial, control_state); 638 mct_u232_set_modem_ctrl(serial, control_state);
642 } 639 }
@@ -644,7 +641,7 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
644 mct_u232_set_baud_rate(serial, port, tty_get_baud_rate(port->tty)); 641 mct_u232_set_baud_rate(serial, port, tty_get_baud_rate(port->tty));
645 642
646 if ((cflag & CBAUD) == B0 ) { 643 if ((cflag & CBAUD) == B0 ) {
647 dbg("%s: baud is B0", __FUNCTION__); 644 dbg("%s: baud is B0", __func__);
648 /* Drop RTS and DTR */ 645 /* Drop RTS and DTR */
649 control_state &= ~(TIOCM_DTR | TIOCM_RTS); 646 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
650 mct_u232_set_modem_ctrl(serial, control_state); 647 mct_u232_set_modem_ctrl(serial, control_state);
@@ -699,7 +696,7 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
699 unsigned char lcr; 696 unsigned char lcr;
700 unsigned long flags; 697 unsigned long flags;
701 698
702 dbg("%sstate=%d", __FUNCTION__, break_state); 699 dbg("%sstate=%d", __func__, break_state);
703 700
704 spin_lock_irqsave(&priv->lock, flags); 701 spin_lock_irqsave(&priv->lock, flags);
705 lcr = priv->last_lcr; 702 lcr = priv->last_lcr;
@@ -718,7 +715,7 @@ static int mct_u232_tiocmget (struct usb_serial_port *port, struct file *file)
718 unsigned int control_state; 715 unsigned int control_state;
719 unsigned long flags; 716 unsigned long flags;
720 717
721 dbg("%s", __FUNCTION__); 718 dbg("%s", __func__);
722 719
723 spin_lock_irqsave(&priv->lock, flags); 720 spin_lock_irqsave(&priv->lock, flags);
724 control_state = priv->control_state; 721 control_state = priv->control_state;
@@ -735,7 +732,7 @@ static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file,
735 unsigned int control_state; 732 unsigned int control_state;
736 unsigned long flags; 733 unsigned long flags;
737 734
738 dbg("%s", __FUNCTION__); 735 dbg("%s", __func__);
739 736
740 spin_lock_irqsave(&priv->lock, flags); 737 spin_lock_irqsave(&priv->lock, flags);
741 control_state = priv->control_state; 738 control_state = priv->control_state;
@@ -757,7 +754,7 @@ static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file,
757static int mct_u232_ioctl (struct usb_serial_port *port, struct file * file, 754static int mct_u232_ioctl (struct usb_serial_port *port, struct file * file,
758 unsigned int cmd, unsigned long arg) 755 unsigned int cmd, unsigned long arg)
759{ 756{
760 dbg("%scmd=0x%x", __FUNCTION__, cmd); 757 dbg("%scmd=0x%x", __func__, cmd);
761 758
762 /* Based on code from acm.c and others */ 759 /* Based on code from acm.c and others */
763 switch (cmd) { 760 switch (cmd) {
@@ -772,7 +769,7 @@ static int mct_u232_ioctl (struct usb_serial_port *port, struct file * file,
772 return 0; 769 return 0;
773 770
774 default: 771 default:
775 dbg("%s: arg not supported - 0x%04x", __FUNCTION__,cmd); 772 dbg("%s: arg not supported - 0x%04x", __func__,cmd);
776 return(-ENOIOCTLCMD); 773 return(-ENOIOCTLCMD);
777 break; 774 break;
778 } 775 }
@@ -787,7 +784,7 @@ static void mct_u232_throttle (struct usb_serial_port *port)
787 struct tty_struct *tty; 784 struct tty_struct *tty;
788 785
789 tty = port->tty; 786 tty = port->tty;
790 dbg("%s - port %d", __FUNCTION__, port->number); 787 dbg("%s - port %d", __func__, port->number);
791 788
792 spin_lock_irqsave(&priv->lock, flags); 789 spin_lock_irqsave(&priv->lock, flags);
793 priv->rx_flags |= THROTTLED; 790 priv->rx_flags |= THROTTLED;
@@ -809,7 +806,7 @@ static void mct_u232_unthrottle (struct usb_serial_port *port)
809 unsigned int control_state; 806 unsigned int control_state;
810 struct tty_struct *tty; 807 struct tty_struct *tty;
811 808
812 dbg("%s - port %d", __FUNCTION__, port->number); 809 dbg("%s - port %d", __func__, port->number);
813 810
814 tty = port->tty; 811 tty = port->tty;
815 spin_lock_irqsave(&priv->lock, flags); 812 spin_lock_irqsave(&priv->lock, flags);
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 40f3a0188807..50f1fe263338 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -118,11 +118,11 @@ static void mos7720_interrupt_callback(struct urb *urb)
118 case -ENOENT: 118 case -ENOENT:
119 case -ESHUTDOWN: 119 case -ESHUTDOWN:
120 /* this urb is terminated, clean up */ 120 /* this urb is terminated, clean up */
121 dbg("%s - urb shutting down with status: %d", __FUNCTION__, 121 dbg("%s - urb shutting down with status: %d", __func__,
122 status); 122 status);
123 return; 123 return;
124 default: 124 default:
125 dbg("%s - nonzero urb status received: %d", __FUNCTION__, 125 dbg("%s - nonzero urb status received: %d", __func__,
126 status); 126 status);
127 goto exit; 127 goto exit;
128 } 128 }
@@ -183,7 +183,7 @@ exit:
183 if (result) 183 if (result)
184 dev_err(&urb->dev->dev, 184 dev_err(&urb->dev->dev,
185 "%s - Error %d submitting control urb\n", 185 "%s - Error %d submitting control urb\n",
186 __FUNCTION__, result); 186 __func__, result);
187 return; 187 return;
188} 188}
189 189
@@ -214,7 +214,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
214 214
215 port = mos7720_port->port; 215 port = mos7720_port->port;
216 216
217 dbg("Entering...%s", __FUNCTION__); 217 dbg("Entering...%s", __func__);
218 218
219 data = urb->transfer_buffer; 219 data = urb->transfer_buffer;
220 220
@@ -362,7 +362,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
362 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, 362 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
363 GFP_KERNEL); 363 GFP_KERNEL);
364 if (!urb->transfer_buffer) { 364 if (!urb->transfer_buffer) {
365 err("%s-out of memory for urb buffers.", __FUNCTION__); 365 err("%s-out of memory for urb buffers.", __func__);
366 usb_free_urb(mos7720_port->write_urb_pool[j]); 366 usb_free_urb(mos7720_port->write_urb_pool[j]);
367 mos7720_port->write_urb_pool[j] = NULL; 367 mos7720_port->write_urb_pool[j] = NULL;
368 continue; 368 continue;
@@ -479,7 +479,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
479 if (response) 479 if (response)
480 dev_err(&port->dev, 480 dev_err(&port->dev,
481 "%s - Error %d submitting control urb\n", 481 "%s - Error %d submitting control urb\n",
482 __FUNCTION__, response); 482 __func__, response);
483 } 483 }
484 484
485 /* set up our bulk in urb */ 485 /* set up our bulk in urb */
@@ -492,7 +492,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
492 response = usb_submit_urb(port->read_urb, GFP_KERNEL); 492 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
493 if (response) 493 if (response)
494 dev_err(&port->dev, 494 dev_err(&port->dev,
495 "%s - Error %d submitting read urb\n", __FUNCTION__, response); 495 "%s - Error %d submitting read urb\n", __func__, response);
496 496
497 /* initialize our icount structure */ 497 /* initialize our icount structure */
498 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount)); 498 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
@@ -521,11 +521,11 @@ static int mos7720_chars_in_buffer(struct usb_serial_port *port)
521 int chars = 0; 521 int chars = 0;
522 struct moschip_port *mos7720_port; 522 struct moschip_port *mos7720_port;
523 523
524 dbg("%s:entering ...........", __FUNCTION__); 524 dbg("%s:entering ...........", __func__);
525 525
526 mos7720_port = usb_get_serial_port_data(port); 526 mos7720_port = usb_get_serial_port_data(port);
527 if (mos7720_port == NULL) { 527 if (mos7720_port == NULL) {
528 dbg("%s:leaving ...........", __FUNCTION__); 528 dbg("%s:leaving ...........", __func__);
529 return -ENODEV; 529 return -ENODEV;
530 } 530 }
531 531
@@ -533,7 +533,7 @@ static int mos7720_chars_in_buffer(struct usb_serial_port *port)
533 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) 533 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status == -EINPROGRESS)
534 chars += URB_TRANSFER_BUFFER_SIZE; 534 chars += URB_TRANSFER_BUFFER_SIZE;
535 } 535 }
536 dbg("%s - returns %d", __FUNCTION__, chars); 536 dbg("%s - returns %d", __func__, chars);
537 return chars; 537 return chars;
538} 538}
539 539
@@ -585,7 +585,7 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
585 mutex_unlock(&serial->disc_mutex); 585 mutex_unlock(&serial->disc_mutex);
586 mos7720_port->open = 0; 586 mos7720_port->open = 0;
587 587
588 dbg("Leaving %s", __FUNCTION__); 588 dbg("Leaving %s", __func__);
589} 589}
590 590
591static void mos7720_break(struct usb_serial_port *port, int break_state) 591static void mos7720_break(struct usb_serial_port *port, int break_state)
@@ -594,7 +594,7 @@ static void mos7720_break(struct usb_serial_port *port, int break_state)
594 struct usb_serial *serial; 594 struct usb_serial *serial;
595 struct moschip_port *mos7720_port; 595 struct moschip_port *mos7720_port;
596 596
597 dbg("Entering %s", __FUNCTION__); 597 dbg("Entering %s", __func__);
598 598
599 serial = port->serial; 599 serial = port->serial;
600 600
@@ -627,20 +627,21 @@ static int mos7720_write_room(struct usb_serial_port *port)
627 int room = 0; 627 int room = 0;
628 int i; 628 int i;
629 629
630 dbg("%s:entering ...........", __FUNCTION__); 630 dbg("%s:entering ...........", __func__);
631 631
632 mos7720_port = usb_get_serial_port_data(port); 632 mos7720_port = usb_get_serial_port_data(port);
633 if (mos7720_port == NULL) { 633 if (mos7720_port == NULL) {
634 dbg("%s:leaving ...........", __FUNCTION__); 634 dbg("%s:leaving ...........", __func__);
635 return -ENODEV; 635 return -ENODEV;
636 } 636 }
637 637
638 /* FIXME: Locking */
638 for (i = 0; i < NUM_URBS; ++i) { 639 for (i = 0; i < NUM_URBS; ++i) {
639 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) 640 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS)
640 room += URB_TRANSFER_BUFFER_SIZE; 641 room += URB_TRANSFER_BUFFER_SIZE;
641 } 642 }
642 643
643 dbg("%s - returns %d", __FUNCTION__, room); 644 dbg("%s - returns %d", __func__, room);
644 return room; 645 return room;
645} 646}
646 647
@@ -657,7 +658,7 @@ static int mos7720_write(struct usb_serial_port *port,
657 struct urb *urb; 658 struct urb *urb;
658 const unsigned char *current_position = data; 659 const unsigned char *current_position = data;
659 660
660 dbg("%s:entering ...........", __FUNCTION__); 661 dbg("%s:entering ...........", __func__);
661 662
662 serial = port->serial; 663 serial = port->serial;
663 664
@@ -679,7 +680,7 @@ static int mos7720_write(struct usb_serial_port *port,
679 } 680 }
680 681
681 if (urb == NULL) { 682 if (urb == NULL) {
682 dbg("%s - no more free urbs", __FUNCTION__); 683 dbg("%s - no more free urbs", __func__);
683 goto exit; 684 goto exit;
684 } 685 }
685 686
@@ -687,14 +688,14 @@ static int mos7720_write(struct usb_serial_port *port,
687 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, 688 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
688 GFP_KERNEL); 689 GFP_KERNEL);
689 if (urb->transfer_buffer == NULL) { 690 if (urb->transfer_buffer == NULL) {
690 err("%s no more kernel memory...", __FUNCTION__); 691 err("%s no more kernel memory...", __func__);
691 goto exit; 692 goto exit;
692 } 693 }
693 } 694 }
694 transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE); 695 transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE);
695 696
696 memcpy(urb->transfer_buffer, current_position, transfer_size); 697 memcpy(urb->transfer_buffer, current_position, transfer_size);
697 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, transfer_size, 698 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size,
698 urb->transfer_buffer); 699 urb->transfer_buffer);
699 700
700 /* fill urb with data and submit */ 701 /* fill urb with data and submit */
@@ -708,7 +709,7 @@ static int mos7720_write(struct usb_serial_port *port,
708 status = usb_submit_urb(urb,GFP_ATOMIC); 709 status = usb_submit_urb(urb,GFP_ATOMIC);
709 if (status) { 710 if (status) {
710 err("%s - usb_submit_urb(write bulk) failed with status = %d", 711 err("%s - usb_submit_urb(write bulk) failed with status = %d",
711 __FUNCTION__, status); 712 __func__, status);
712 bytes_sent = status; 713 bytes_sent = status;
713 goto exit; 714 goto exit;
714 } 715 }
@@ -724,7 +725,7 @@ static void mos7720_throttle(struct usb_serial_port *port)
724 struct tty_struct *tty; 725 struct tty_struct *tty;
725 int status; 726 int status;
726 727
727 dbg("%s- port %d\n", __FUNCTION__, port->number); 728 dbg("%s- port %d\n", __func__, port->number);
728 729
729 mos7720_port = usb_get_serial_port_data(port); 730 mos7720_port = usb_get_serial_port_data(port);
730 731
@@ -736,11 +737,11 @@ static void mos7720_throttle(struct usb_serial_port *port)
736 return; 737 return;
737 } 738 }
738 739
739 dbg("%s: Entering ..........", __FUNCTION__); 740 dbg("%s: Entering ..........", __func__);
740 741
741 tty = port->tty; 742 tty = port->tty;
742 if (!tty) { 743 if (!tty) {
743 dbg("%s - no tty available", __FUNCTION__); 744 dbg("%s - no tty available", __func__);
744 return; 745 return;
745 } 746 }
746 747
@@ -773,15 +774,15 @@ static void mos7720_unthrottle(struct usb_serial_port *port)
773 return; 774 return;
774 775
775 if (!mos7720_port->open) { 776 if (!mos7720_port->open) {
776 dbg("%s - port not opened", __FUNCTION__); 777 dbg("%s - port not opened", __func__);
777 return; 778 return;
778 } 779 }
779 780
780 dbg("%s: Entering ..........", __FUNCTION__); 781 dbg("%s: Entering ..........", __func__);
781 782
782 tty = port->tty; 783 tty = port->tty;
783 if (!tty) { 784 if (!tty) {
784 dbg("%s - no tty available", __FUNCTION__); 785 dbg("%s - no tty available", __func__);
785 return; 786 return;
786 } 787 }
787 788
@@ -922,7 +923,7 @@ static int calc_baud_rate_divisor(int baudrate, int *divisor)
922 __u16 round; 923 __u16 round;
923 924
924 925
925 dbg("%s - %d", __FUNCTION__, baudrate); 926 dbg("%s - %d", __func__, baudrate);
926 927
927 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { 928 for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
928 if (divisor_table[i].baudrate == baudrate) { 929 if (divisor_table[i].baudrate == baudrate) {
@@ -973,15 +974,15 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
973 port = mos7720_port->port; 974 port = mos7720_port->port;
974 serial = port->serial; 975 serial = port->serial;
975 976
976 dbg("%s: Entering ..........", __FUNCTION__); 977 dbg("%s: Entering ..........", __func__);
977 978
978 number = port->number - port->serial->minor; 979 number = port->number - port->serial->minor;
979 dbg("%s - port = %d, baud = %d", __FUNCTION__, port->number, baudrate); 980 dbg("%s - port = %d, baud = %d", __func__, port->number, baudrate);
980 981
981 /* Calculate the Divisor */ 982 /* Calculate the Divisor */
982 status = calc_baud_rate_divisor(baudrate, &divisor); 983 status = calc_baud_rate_divisor(baudrate, &divisor);
983 if (status) { 984 if (status) {
984 err("%s - bad baud rate", __FUNCTION__); 985 err("%s - bad baud rate", __func__);
985 return status; 986 return status;
986 } 987 }
987 988
@@ -1034,16 +1035,16 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1034 serial = port->serial; 1035 serial = port->serial;
1035 port_number = port->number - port->serial->minor; 1036 port_number = port->number - port->serial->minor;
1036 1037
1037 dbg("%s - port %d", __FUNCTION__, port->number); 1038 dbg("%s - port %d", __func__, port->number);
1038 1039
1039 if (!mos7720_port->open) { 1040 if (!mos7720_port->open) {
1040 dbg("%s - port not opened", __FUNCTION__); 1041 dbg("%s - port not opened", __func__);
1041 return; 1042 return;
1042 } 1043 }
1043 1044
1044 tty = mos7720_port->port->tty; 1045 tty = mos7720_port->port->tty;
1045 1046
1046 dbg("%s: Entering ..........", __FUNCTION__); 1047 dbg("%s: Entering ..........", __func__);
1047 1048
1048 lData = UART_LCR_WLEN8; 1049 lData = UART_LCR_WLEN8;
1049 lStop = 0x00; /* 1 stop bit */ 1050 lStop = 0x00; /* 1 stop bit */
@@ -1078,14 +1079,14 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1078 if (cflag & PARENB) { 1079 if (cflag & PARENB) {
1079 if (cflag & PARODD) { 1080 if (cflag & PARODD) {
1080 lParity = UART_LCR_PARITY; 1081 lParity = UART_LCR_PARITY;
1081 dbg("%s - parity = odd", __FUNCTION__); 1082 dbg("%s - parity = odd", __func__);
1082 } else { 1083 } else {
1083 lParity = (UART_LCR_EPAR | UART_LCR_PARITY); 1084 lParity = (UART_LCR_EPAR | UART_LCR_PARITY);
1084 dbg("%s - parity = even", __FUNCTION__); 1085 dbg("%s - parity = even", __func__);
1085 } 1086 }
1086 1087
1087 } else { 1088 } else {
1088 dbg("%s - parity = none", __FUNCTION__); 1089 dbg("%s - parity = none", __func__);
1089 } 1090 }
1090 1091
1091 if (cflag & CMSPAR) 1092 if (cflag & CMSPAR)
@@ -1094,10 +1095,10 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1094 /* Change the Stop bit */ 1095 /* Change the Stop bit */
1095 if (cflag & CSTOPB) { 1096 if (cflag & CSTOPB) {
1096 lStop = UART_LCR_STOP; 1097 lStop = UART_LCR_STOP;
1097 dbg("%s - stop bits = 2", __FUNCTION__); 1098 dbg("%s - stop bits = 2", __func__);
1098 } else { 1099 } else {
1099 lStop = 0x00; 1100 lStop = 0x00;
1100 dbg("%s - stop bits = 1", __FUNCTION__); 1101 dbg("%s - stop bits = 1", __func__);
1101 } 1102 }
1102 1103
1103#define LCR_BITS_MASK 0x03 /* Mask for bits/char field */ 1104#define LCR_BITS_MASK 0x03 /* Mask for bits/char field */
@@ -1171,7 +1172,7 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1171 return; 1172 return;
1172 } 1173 }
1173 1174
1174 dbg("%s - baud rate = %d", __FUNCTION__, baud); 1175 dbg("%s - baud rate = %d", __func__, baud);
1175 status = send_cmd_write_baud_rate(mos7720_port, baud); 1176 status = send_cmd_write_baud_rate(mos7720_port, baud);
1176 /* FIXME: needs to write actual resulting baud back not just 1177 /* FIXME: needs to write actual resulting baud back not just
1177 blindly do so */ 1178 blindly do so */
@@ -1217,7 +1218,7 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1217 1218
1218 1219
1219 if (!mos7720_port->open) { 1220 if (!mos7720_port->open) {
1220 dbg("%s - port not opened", __FUNCTION__); 1221 dbg("%s - port not opened", __func__);
1221 return; 1222 return;
1222 } 1223 }
1223 1224
@@ -1225,15 +1226,15 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1225 1226
1226 cflag = tty->termios->c_cflag; 1227 cflag = tty->termios->c_cflag;
1227 1228
1228 dbg("%s - cflag %08x iflag %08x", __FUNCTION__, 1229 dbg("%s - cflag %08x iflag %08x", __func__,
1229 tty->termios->c_cflag, 1230 tty->termios->c_cflag,
1230 RELEVANT_IFLAG(tty->termios->c_iflag)); 1231 RELEVANT_IFLAG(tty->termios->c_iflag));
1231 1232
1232 dbg("%s - old cflag %08x old iflag %08x", __FUNCTION__, 1233 dbg("%s - old cflag %08x old iflag %08x", __func__,
1233 old_termios->c_cflag, 1234 old_termios->c_cflag,
1234 RELEVANT_IFLAG(old_termios->c_iflag)); 1235 RELEVANT_IFLAG(old_termios->c_iflag));
1235 1236
1236 dbg("%s - port %d", __FUNCTION__, port->number); 1237 dbg("%s - port %d", __func__, port->number);
1237 1238
1238 /* change the port settings to the new ones specified */ 1239 /* change the port settings to the new ones specified */
1239 change_port_settings(mos7720_port, old_termios); 1240 change_port_settings(mos7720_port, old_termios);
@@ -1271,7 +1272,7 @@ static int get_lsr_info(struct moschip_port *mos7720_port,
1271 1272
1272 count = mos7720_chars_in_buffer(mos7720_port->port); 1273 count = mos7720_chars_in_buffer(mos7720_port->port);
1273 if (count == 0) { 1274 if (count == 0) {
1274 dbg("%s -- Empty", __FUNCTION__); 1275 dbg("%s -- Empty", __func__);
1275 result = TIOCSER_TEMT; 1276 result = TIOCSER_TEMT;
1276 } 1277 }
1277 1278
@@ -1296,7 +1297,7 @@ static int get_number_bytes_avail(struct moschip_port *mos7720_port,
1296 1297
1297 result = tty->read_cnt; 1298 result = tty->read_cnt;
1298 1299
1299 dbg("%s(%d) = %d", __FUNCTION__, mos7720_port->port->number, result); 1300 dbg("%s(%d) = %d", __func__, mos7720_port->port->number, result);
1300 if (copy_to_user(value, &result, sizeof(int))) 1301 if (copy_to_user(value, &result, sizeof(int)))
1301 return -EFAULT; 1302 return -EFAULT;
1302 1303
@@ -1374,7 +1375,7 @@ static int get_modem_info(struct moschip_port *mos7720_port,
1374 | ((msr & UART_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */ 1375 | ((msr & UART_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
1375 1376
1376 1377
1377 dbg("%s -- %x", __FUNCTION__, result); 1378 dbg("%s -- %x", __func__, result);
1378 1379
1379 if (copy_to_user(value, &result, sizeof(int))) 1380 if (copy_to_user(value, &result, sizeof(int)))
1380 return -EFAULT; 1381 return -EFAULT;
@@ -1418,45 +1419,45 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1418 if (mos7720_port == NULL) 1419 if (mos7720_port == NULL)
1419 return -ENODEV; 1420 return -ENODEV;
1420 1421
1421 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd); 1422 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1422 1423
1423 switch (cmd) { 1424 switch (cmd) {
1424 case TIOCINQ: 1425 case TIOCINQ:
1425 /* return number of bytes available */ 1426 /* return number of bytes available */
1426 dbg("%s (%d) TIOCINQ", __FUNCTION__, port->number); 1427 dbg("%s (%d) TIOCINQ", __func__, port->number);
1427 return get_number_bytes_avail(mos7720_port, 1428 return get_number_bytes_avail(mos7720_port,
1428 (unsigned int __user *)arg); 1429 (unsigned int __user *)arg);
1429 break; 1430 break;
1430 1431
1431 case TIOCSERGETLSR: 1432 case TIOCSERGETLSR:
1432 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number); 1433 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1433 return get_lsr_info(mos7720_port, (unsigned int __user *)arg); 1434 return get_lsr_info(mos7720_port, (unsigned int __user *)arg);
1434 return 0; 1435 return 0;
1435 1436
1436 case TIOCMBIS: 1437 case TIOCMBIS:
1437 case TIOCMBIC: 1438 case TIOCMBIC:
1438 case TIOCMSET: 1439 case TIOCMSET:
1439 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, 1440 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __func__,
1440 port->number); 1441 port->number);
1441 return set_modem_info(mos7720_port, cmd, 1442 return set_modem_info(mos7720_port, cmd,
1442 (unsigned int __user *)arg); 1443 (unsigned int __user *)arg);
1443 1444
1444 case TIOCMGET: 1445 case TIOCMGET:
1445 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number); 1446 dbg("%s (%d) TIOCMGET", __func__, port->number);
1446 return get_modem_info(mos7720_port, 1447 return get_modem_info(mos7720_port,
1447 (unsigned int __user *)arg); 1448 (unsigned int __user *)arg);
1448 1449
1449 case TIOCGSERIAL: 1450 case TIOCGSERIAL:
1450 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number); 1451 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
1451 return get_serial_info(mos7720_port, 1452 return get_serial_info(mos7720_port,
1452 (struct serial_struct __user *)arg); 1453 (struct serial_struct __user *)arg);
1453 1454
1454 case TIOCSSERIAL: 1455 case TIOCSSERIAL:
1455 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number); 1456 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
1456 break; 1457 break;
1457 1458
1458 case TIOCMIWAIT: 1459 case TIOCMIWAIT:
1459 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number); 1460 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
1460 cprev = mos7720_port->icount; 1461 cprev = mos7720_port->icount;
1461 while (1) { 1462 while (1) {
1462 if (signal_pending(current)) 1463 if (signal_pending(current))
@@ -1490,7 +1491,7 @@ static int mos7720_ioctl(struct usb_serial_port *port, struct file *file,
1490 icount.brk = cnow.brk; 1491 icount.brk = cnow.brk;
1491 icount.buf_overrun = cnow.buf_overrun; 1492 icount.buf_overrun = cnow.buf_overrun;
1492 1493
1493 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__, 1494 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1494 port->number, icount.rx, icount.tx ); 1495 port->number, icount.rx, icount.tx );
1495 if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) 1496 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1496 return -EFAULT; 1497 return -EFAULT;
@@ -1508,7 +1509,7 @@ static int mos7720_startup(struct usb_serial *serial)
1508 int i; 1509 int i;
1509 char data; 1510 char data;
1510 1511
1511 dbg("%s: Entering ..........", __FUNCTION__); 1512 dbg("%s: Entering ..........", __func__);
1512 1513
1513 if (!serial) { 1514 if (!serial) {
1514 dbg("Invalid Handler"); 1515 dbg("Invalid Handler");
@@ -1520,7 +1521,7 @@ static int mos7720_startup(struct usb_serial *serial)
1520 /* create our private serial structure */ 1521 /* create our private serial structure */
1521 mos7720_serial = kzalloc(sizeof(struct moschip_serial), GFP_KERNEL); 1522 mos7720_serial = kzalloc(sizeof(struct moschip_serial), GFP_KERNEL);
1522 if (mos7720_serial == NULL) { 1523 if (mos7720_serial == NULL) {
1523 err("%s - Out of memory", __FUNCTION__); 1524 err("%s - Out of memory", __func__);
1524 return -ENOMEM; 1525 return -ENOMEM;
1525 } 1526 }
1526 1527
@@ -1533,7 +1534,7 @@ static int mos7720_startup(struct usb_serial *serial)
1533 for (i = 0; i < serial->num_ports; ++i) { 1534 for (i = 0; i < serial->num_ports; ++i) {
1534 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 1535 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
1535 if (mos7720_port == NULL) { 1536 if (mos7720_port == NULL) {
1536 err("%s - Out of memory", __FUNCTION__); 1537 err("%s - Out of memory", __func__);
1537 usb_set_serial_data(serial, NULL); 1538 usb_set_serial_data(serial, NULL);
1538 kfree(mos7720_serial); 1539 kfree(mos7720_serial);
1539 return -ENOMEM; 1540 return -ENOMEM;
@@ -1596,9 +1597,6 @@ static struct usb_serial_driver moschip7720_2port_driver = {
1596 .description = "Moschip 2 port adapter", 1597 .description = "Moschip 2 port adapter",
1597 .usb_driver = &usb_driver, 1598 .usb_driver = &usb_driver,
1598 .id_table = moschip_port_id_table, 1599 .id_table = moschip_port_id_table,
1599 .num_interrupt_in = 1,
1600 .num_bulk_in = 2,
1601 .num_bulk_out = 2,
1602 .num_ports = 2, 1600 .num_ports = 2,
1603 .open = mos7720_open, 1601 .open = mos7720_open,
1604 .close = mos7720_close, 1602 .close = mos7720_close,
@@ -1620,7 +1618,7 @@ static int __init moschip7720_init(void)
1620{ 1618{
1621 int retval; 1619 int retval;
1622 1620
1623 dbg("%s: Entering ..........", __FUNCTION__); 1621 dbg("%s: Entering ..........", __func__);
1624 1622
1625 /* Register with the usb serial */ 1623 /* Register with the usb serial */
1626 retval = usb_serial_register(&moschip7720_2port_driver); 1624 retval = usb_serial_register(&moschip7720_2port_driver);
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index aeeb9cb20999..6bcb82d3911a 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -403,7 +403,7 @@ static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
403{ 403{
404 struct async_icount *icount; 404 struct async_icount *icount;
405 405
406 dbg("%s - %02x", __FUNCTION__, new_lsr); 406 dbg("%s - %02x", __func__, new_lsr);
407 407
408 if (new_lsr & SERIAL_LSR_BI) { 408 if (new_lsr & SERIAL_LSR_BI) {
409 // 409 //
@@ -449,7 +449,7 @@ static void mos7840_control_callback(struct urb *urb)
449 int result = 0; 449 int result = 0;
450 int status = urb->status; 450 int status = urb->status;
451 451
452 mos7840_port = (struct moschip_port *)urb->context; 452 mos7840_port = urb->context;
453 453
454 switch (status) { 454 switch (status) {
455 case 0: 455 case 0:
@@ -459,21 +459,21 @@ static void mos7840_control_callback(struct urb *urb)
459 case -ENOENT: 459 case -ENOENT:
460 case -ESHUTDOWN: 460 case -ESHUTDOWN:
461 /* this urb is terminated, clean up */ 461 /* this urb is terminated, clean up */
462 dbg("%s - urb shutting down with status: %d", __FUNCTION__, 462 dbg("%s - urb shutting down with status: %d", __func__,
463 status); 463 status);
464 return; 464 return;
465 default: 465 default:
466 dbg("%s - nonzero urb status received: %d", __FUNCTION__, 466 dbg("%s - nonzero urb status received: %d", __func__,
467 status); 467 status);
468 goto exit; 468 goto exit;
469 } 469 }
470 470
471 dbg("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length); 471 dbg("%s urb buffer size is %d\n", __func__, urb->actual_length);
472 dbg("%s mos7840_port->MsrLsr is %d port %d\n", __FUNCTION__, 472 dbg("%s mos7840_port->MsrLsr is %d port %d\n", __func__,
473 mos7840_port->MsrLsr, mos7840_port->port_num); 473 mos7840_port->MsrLsr, mos7840_port->port_num);
474 data = urb->transfer_buffer; 474 data = urb->transfer_buffer;
475 regval = (__u8) data[0]; 475 regval = (__u8) data[0];
476 dbg("%s data is %x\n", __FUNCTION__, regval); 476 dbg("%s data is %x\n", __func__, regval);
477 if (mos7840_port->MsrLsr == 0) 477 if (mos7840_port->MsrLsr == 0)
478 mos7840_handle_new_msr(mos7840_port, regval); 478 mos7840_handle_new_msr(mos7840_port, regval);
479 else if (mos7840_port->MsrLsr == 1) 479 else if (mos7840_port->MsrLsr == 1)
@@ -487,7 +487,7 @@ exit:
487 if (result) { 487 if (result) {
488 dev_err(&urb->dev->dev, 488 dev_err(&urb->dev->dev,
489 "%s - Error %d submitting interrupt urb\n", 489 "%s - Error %d submitting interrupt urb\n",
490 __FUNCTION__, result); 490 __func__, result);
491 } 491 }
492} 492}
493 493
@@ -542,11 +542,11 @@ static void mos7840_interrupt_callback(struct urb *urb)
542 case -ENOENT: 542 case -ENOENT:
543 case -ESHUTDOWN: 543 case -ESHUTDOWN:
544 /* this urb is terminated, clean up */ 544 /* this urb is terminated, clean up */
545 dbg("%s - urb shutting down with status: %d", __FUNCTION__, 545 dbg("%s - urb shutting down with status: %d", __func__,
546 status); 546 status);
547 return; 547 return;
548 default: 548 default:
549 dbg("%s - nonzero urb status received: %d", __FUNCTION__, 549 dbg("%s - nonzero urb status received: %d", __func__,
550 status); 550 status);
551 goto exit; 551 goto exit;
552 } 552 }
@@ -554,7 +554,7 @@ static void mos7840_interrupt_callback(struct urb *urb)
554 length = urb->actual_length; 554 length = urb->actual_length;
555 data = urb->transfer_buffer; 555 data = urb->transfer_buffer;
556 556
557 serial = (struct usb_serial *)urb->context; 557 serial = urb->context;
558 558
559 /* Moschip get 5 bytes 559 /* Moschip get 5 bytes
560 * Byte 1 IIR Port 1 (port.number is 0) 560 * Byte 1 IIR Port 1 (port.number is 0)
@@ -614,7 +614,7 @@ exit:
614 if (result) { 614 if (result) {
615 dev_err(&urb->dev->dev, 615 dev_err(&urb->dev->dev,
616 "%s - Error %d submitting interrupt urb\n", 616 "%s - Error %d submitting interrupt urb\n",
617 __FUNCTION__, result); 617 __func__, result);
618 } 618 }
619} 619}
620 620
@@ -685,19 +685,19 @@ static void mos7840_bulk_in_callback(struct urb *urb)
685 return; 685 return;
686 } 686 }
687 687
688 mos7840_port = (struct moschip_port *)urb->context; 688 mos7840_port = urb->context;
689 if (!mos7840_port) { 689 if (!mos7840_port) {
690 dbg("%s", "NULL mos7840_port pointer \n"); 690 dbg("%s", "NULL mos7840_port pointer \n");
691 return; 691 return;
692 } 692 }
693 693
694 port = (struct usb_serial_port *)mos7840_port->port; 694 port = (struct usb_serial_port *)mos7840_port->port;
695 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 695 if (mos7840_port_paranoia_check(port, __func__)) {
696 dbg("%s", "Port Paranoia failed \n"); 696 dbg("%s", "Port Paranoia failed \n");
697 return; 697 return;
698 } 698 }
699 699
700 serial = mos7840_get_usb_serial(port, __FUNCTION__); 700 serial = mos7840_get_usb_serial(port, __func__);
701 if (!serial) { 701 if (!serial) {
702 dbg("%s\n", "Bad serial pointer "); 702 dbg("%s\n", "Bad serial pointer ");
703 return; 703 return;
@@ -752,7 +752,7 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
752 int status = urb->status; 752 int status = urb->status;
753 int i; 753 int i;
754 754
755 mos7840_port = (struct moschip_port *)urb->context; 755 mos7840_port = urb->context;
756 spin_lock(&mos7840_port->pool_lock); 756 spin_lock(&mos7840_port->pool_lock);
757 for (i = 0; i < NUM_URBS; i++) { 757 for (i = 0; i < NUM_URBS; i++) {
758 if (urb == mos7840_port->write_urb_pool[i]) { 758 if (urb == mos7840_port->write_urb_pool[i]) {
@@ -767,7 +767,7 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
767 return; 767 return;
768 } 768 }
769 769
770 if (mos7840_port_paranoia_check(mos7840_port->port, __FUNCTION__)) { 770 if (mos7840_port_paranoia_check(mos7840_port->port, __func__)) {
771 dbg("%s", "Port Paranoia failed \n"); 771 dbg("%s", "Port Paranoia failed \n");
772 return; 772 return;
773 } 773 }
@@ -815,14 +815,14 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
815 struct moschip_port *mos7840_port; 815 struct moschip_port *mos7840_port;
816 struct moschip_port *port0; 816 struct moschip_port *port0;
817 817
818 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 818 if (mos7840_port_paranoia_check(port, __func__)) {
819 dbg("%s", "Port Paranoia failed \n"); 819 dbg("%s", "Port Paranoia failed \n");
820 return -ENODEV; 820 return -ENODEV;
821 } 821 }
822 822
823 serial = port->serial; 823 serial = port->serial;
824 824
825 if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { 825 if (mos7840_serial_paranoia_check(serial, __func__)) {
826 dbg("%s", "Serial Paranoia failed \n"); 826 dbg("%s", "Serial Paranoia failed \n");
827 return -ENODEV; 827 return -ENODEV;
828 } 828 }
@@ -851,7 +851,7 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
851 if (!urb->transfer_buffer) { 851 if (!urb->transfer_buffer) {
852 usb_free_urb(urb); 852 usb_free_urb(urb);
853 mos7840_port->write_urb_pool[j] = NULL; 853 mos7840_port->write_urb_pool[j] = NULL;
854 err("%s-out of memory for urb buffers.", __FUNCTION__); 854 err("%s-out of memory for urb buffers.", __func__);
855 continue; 855 continue;
856 } 856 }
857 } 857 }
@@ -1039,7 +1039,7 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1039 GFP_KERNEL); 1039 GFP_KERNEL);
1040 if (response) { 1040 if (response) {
1041 err("%s - Error %d submitting interrupt urb", 1041 err("%s - Error %d submitting interrupt urb",
1042 __FUNCTION__, response); 1042 __func__, response);
1043 } 1043 }
1044 1044
1045 } 1045 }
@@ -1072,7 +1072,7 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp)
1072 port->bulk_in_endpointAddress); 1072 port->bulk_in_endpointAddress);
1073 response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL); 1073 response = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
1074 if (response) { 1074 if (response) {
1075 err("%s - Error %d submitting control urb", __FUNCTION__, 1075 err("%s - Error %d submitting control urb", __func__,
1076 response); 1076 response);
1077 } 1077 }
1078 1078
@@ -1116,7 +1116,7 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1116 1116
1117 dbg("%s \n", " mos7840_chars_in_buffer:entering ..........."); 1117 dbg("%s \n", " mos7840_chars_in_buffer:entering ...........");
1118 1118
1119 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1119 if (mos7840_port_paranoia_check(port, __func__)) {
1120 dbg("%s", "Invalid port \n"); 1120 dbg("%s", "Invalid port \n");
1121 return -1; 1121 return -1;
1122 } 1122 }
@@ -1134,7 +1134,7 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1134 } 1134 }
1135 } 1135 }
1136 spin_unlock_irqrestore(&mos7840_port->pool_lock,flags); 1136 spin_unlock_irqrestore(&mos7840_port->pool_lock,flags);
1137 dbg("%s - returns %d", __FUNCTION__, chars); 1137 dbg("%s - returns %d", __func__, chars);
1138 return chars; 1138 return chars;
1139 1139
1140} 1140}
@@ -1171,7 +1171,7 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1171 /* No activity.. count down section */ 1171 /* No activity.. count down section */
1172 wait--; 1172 wait--;
1173 if (wait == 0) { 1173 if (wait == 0) {
1174 dbg("%s - TIMEOUT", __FUNCTION__); 1174 dbg("%s - TIMEOUT", __func__);
1175 return; 1175 return;
1176 } else { 1176 } else {
1177 /* Reset timeout value back to seconds */ 1177 /* Reset timeout value back to seconds */
@@ -1195,12 +1195,12 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1195 1195
1196 dbg("%s\n", "mos7840_close:entering..."); 1196 dbg("%s\n", "mos7840_close:entering...");
1197 1197
1198 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1198 if (mos7840_port_paranoia_check(port, __func__)) {
1199 dbg("%s", "Port Paranoia failed \n"); 1199 dbg("%s", "Port Paranoia failed \n");
1200 return; 1200 return;
1201 } 1201 }
1202 1202
1203 serial = mos7840_get_usb_serial(port, __FUNCTION__); 1203 serial = mos7840_get_usb_serial(port, __func__);
1204 if (!serial) { 1204 if (!serial) {
1205 dbg("%s", "Serial Paranoia failed \n"); 1205 dbg("%s", "Serial Paranoia failed \n");
1206 return; 1206 return;
@@ -1314,7 +1314,7 @@ static void mos7840_block_until_chase_response(struct moschip_port
1314 /* No activity.. count down section */ 1314 /* No activity.. count down section */
1315 wait--; 1315 wait--;
1316 if (wait == 0) { 1316 if (wait == 0) {
1317 dbg("%s - TIMEOUT", __FUNCTION__); 1317 dbg("%s - TIMEOUT", __func__);
1318 return; 1318 return;
1319 } else { 1319 } else {
1320 /* Reset timeout value back to seconds */ 1320 /* Reset timeout value back to seconds */
@@ -1337,12 +1337,12 @@ static void mos7840_break(struct usb_serial_port *port, int break_state)
1337 dbg("%s \n", "Entering ..........."); 1337 dbg("%s \n", "Entering ...........");
1338 dbg("mos7840_break: Start\n"); 1338 dbg("mos7840_break: Start\n");
1339 1339
1340 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1340 if (mos7840_port_paranoia_check(port, __func__)) {
1341 dbg("%s", "Port Paranoia failed \n"); 1341 dbg("%s", "Port Paranoia failed \n");
1342 return; 1342 return;
1343 } 1343 }
1344 1344
1345 serial = mos7840_get_usb_serial(port, __FUNCTION__); 1345 serial = mos7840_get_usb_serial(port, __func__);
1346 if (!serial) { 1346 if (!serial) {
1347 dbg("%s", "Serial Paranoia failed \n"); 1347 dbg("%s", "Serial Paranoia failed \n");
1348 return; 1348 return;
@@ -1392,7 +1392,7 @@ static int mos7840_write_room(struct usb_serial_port *port)
1392 1392
1393 dbg("%s \n", " mos7840_write_room:entering ..........."); 1393 dbg("%s \n", " mos7840_write_room:entering ...........");
1394 1394
1395 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1395 if (mos7840_port_paranoia_check(port, __func__)) {
1396 dbg("%s", "Invalid port \n"); 1396 dbg("%s", "Invalid port \n");
1397 dbg("%s \n", " mos7840_write_room:leaving ..........."); 1397 dbg("%s \n", " mos7840_write_room:leaving ...........");
1398 return -1; 1398 return -1;
@@ -1413,7 +1413,7 @@ static int mos7840_write_room(struct usb_serial_port *port)
1413 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 1413 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1414 1414
1415 room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1; 1415 room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1;
1416 dbg("%s - returns %d", __FUNCTION__, room); 1416 dbg("%s - returns %d", __func__, room);
1417 return room; 1417 return room;
1418 1418
1419} 1419}
@@ -1480,13 +1480,13 @@ static int mos7840_write(struct usb_serial_port *port,
1480 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); 1480 status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
1481#endif 1481#endif
1482 1482
1483 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1483 if (mos7840_port_paranoia_check(port, __func__)) {
1484 dbg("%s", "Port Paranoia failed \n"); 1484 dbg("%s", "Port Paranoia failed \n");
1485 return -1; 1485 return -1;
1486 } 1486 }
1487 1487
1488 serial = port->serial; 1488 serial = port->serial;
1489 if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { 1489 if (mos7840_serial_paranoia_check(serial, __func__)) {
1490 dbg("%s", "Serial Paranoia failed \n"); 1490 dbg("%s", "Serial Paranoia failed \n");
1491 return -1; 1491 return -1;
1492 } 1492 }
@@ -1512,7 +1512,7 @@ static int mos7840_write(struct usb_serial_port *port,
1512 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); 1512 spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
1513 1513
1514 if (urb == NULL) { 1514 if (urb == NULL) {
1515 dbg("%s - no more free urbs", __FUNCTION__); 1515 dbg("%s - no more free urbs", __func__);
1516 goto exit; 1516 goto exit;
1517 } 1517 }
1518 1518
@@ -1521,7 +1521,7 @@ static int mos7840_write(struct usb_serial_port *port,
1521 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 1521 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1522 1522
1523 if (urb->transfer_buffer == NULL) { 1523 if (urb->transfer_buffer == NULL) {
1524 err("%s no more kernel memory...", __FUNCTION__); 1524 err("%s no more kernel memory...", __func__);
1525 goto exit; 1525 goto exit;
1526 } 1526 }
1527 } 1527 }
@@ -1547,7 +1547,7 @@ static int mos7840_write(struct usb_serial_port *port,
1547 if (status) { 1547 if (status) {
1548 mos7840_port->busy[i] = 0; 1548 mos7840_port->busy[i] = 0;
1549 err("%s - usb_submit_urb(write bulk) failed with status = %d", 1549 err("%s - usb_submit_urb(write bulk) failed with status = %d",
1550 __FUNCTION__, status); 1550 __func__, status);
1551 bytes_sent = status; 1551 bytes_sent = status;
1552 goto exit; 1552 goto exit;
1553 } 1553 }
@@ -1573,7 +1573,7 @@ static void mos7840_throttle(struct usb_serial_port *port)
1573 struct tty_struct *tty; 1573 struct tty_struct *tty;
1574 int status; 1574 int status;
1575 1575
1576 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1576 if (mos7840_port_paranoia_check(port, __func__)) {
1577 dbg("%s", "Invalid port \n"); 1577 dbg("%s", "Invalid port \n");
1578 return; 1578 return;
1579 } 1579 }
@@ -1594,7 +1594,7 @@ static void mos7840_throttle(struct usb_serial_port *port)
1594 1594
1595 tty = port->tty; 1595 tty = port->tty;
1596 if (!tty) { 1596 if (!tty) {
1597 dbg("%s - no tty available", __FUNCTION__); 1597 dbg("%s - no tty available", __func__);
1598 return; 1598 return;
1599 } 1599 }
1600 1600
@@ -1634,7 +1634,7 @@ static void mos7840_unthrottle(struct usb_serial_port *port)
1634 int status; 1634 int status;
1635 struct moschip_port *mos7840_port = mos7840_get_port_private(port); 1635 struct moschip_port *mos7840_port = mos7840_get_port_private(port);
1636 1636
1637 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1637 if (mos7840_port_paranoia_check(port, __func__)) {
1638 dbg("%s", "Invalid port \n"); 1638 dbg("%s", "Invalid port \n");
1639 return; 1639 return;
1640 } 1640 }
@@ -1643,7 +1643,7 @@ static void mos7840_unthrottle(struct usb_serial_port *port)
1643 return; 1643 return;
1644 1644
1645 if (!mos7840_port->open) { 1645 if (!mos7840_port->open) {
1646 dbg("%s - port not opened", __FUNCTION__); 1646 dbg("%s - port not opened", __func__);
1647 return; 1647 return;
1648 } 1648 }
1649 1649
@@ -1651,7 +1651,7 @@ static void mos7840_unthrottle(struct usb_serial_port *port)
1651 1651
1652 tty = port->tty; 1652 tty = port->tty;
1653 if (!tty) { 1653 if (!tty) {
1654 dbg("%s - no tty available", __FUNCTION__); 1654 dbg("%s - no tty available", __func__);
1655 return; 1655 return;
1656 } 1656 }
1657 1657
@@ -1688,7 +1688,7 @@ static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file)
1688 int status = 0; 1688 int status = 0;
1689 mos7840_port = mos7840_get_port_private(port); 1689 mos7840_port = mos7840_get_port_private(port);
1690 1690
1691 dbg("%s - port %d", __FUNCTION__, port->number); 1691 dbg("%s - port %d", __func__, port->number);
1692 1692
1693 if (mos7840_port == NULL) 1693 if (mos7840_port == NULL)
1694 return -ENODEV; 1694 return -ENODEV;
@@ -1703,7 +1703,7 @@ static int mos7840_tiocmget(struct usb_serial_port *port, struct file *file)
1703 | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) 1703 | ((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0)
1704 | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); 1704 | ((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0);
1705 1705
1706 dbg("%s - 0x%04X", __FUNCTION__, result); 1706 dbg("%s - 0x%04X", __func__, result);
1707 1707
1708 return result; 1708 return result;
1709} 1709}
@@ -1715,13 +1715,14 @@ static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file,
1715 unsigned int mcr; 1715 unsigned int mcr;
1716 unsigned int status; 1716 unsigned int status;
1717 1717
1718 dbg("%s - port %d", __FUNCTION__, port->number); 1718 dbg("%s - port %d", __func__, port->number);
1719 1719
1720 mos7840_port = mos7840_get_port_private(port); 1720 mos7840_port = mos7840_get_port_private(port);
1721 1721
1722 if (mos7840_port == NULL) 1722 if (mos7840_port == NULL)
1723 return -ENODEV; 1723 return -ENODEV;
1724 1724
1725 /* FIXME: What locks the port registers ? */
1725 mcr = mos7840_port->shadowMCR; 1726 mcr = mos7840_port->shadowMCR;
1726 if (clear & TIOCM_RTS) 1727 if (clear & TIOCM_RTS)
1727 mcr &= ~MCR_RTS; 1728 mcr &= ~MCR_RTS;
@@ -1758,7 +1759,7 @@ static int mos7840_calc_baud_rate_divisor(int baudRate, int *divisor,
1758 __u16 * clk_sel_val) 1759 __u16 * clk_sel_val)
1759{ 1760{
1760 1761
1761 dbg("%s - %d", __FUNCTION__, baudRate); 1762 dbg("%s - %d", __func__, baudRate);
1762 1763
1763 if (baudRate <= 115200) { 1764 if (baudRate <= 115200) {
1764 *divisor = 115200 / baudRate; 1765 *divisor = 115200 / baudRate;
@@ -1841,12 +1842,12 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1841 return -1; 1842 return -1;
1842 1843
1843 port = (struct usb_serial_port *)mos7840_port->port; 1844 port = (struct usb_serial_port *)mos7840_port->port;
1844 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1845 if (mos7840_port_paranoia_check(port, __func__)) {
1845 dbg("%s", "Invalid port \n"); 1846 dbg("%s", "Invalid port \n");
1846 return -1; 1847 return -1;
1847 } 1848 }
1848 1849
1849 if (mos7840_serial_paranoia_check(port->serial, __FUNCTION__)) { 1850 if (mos7840_serial_paranoia_check(port->serial, __func__)) {
1850 dbg("%s", "Invalid Serial \n"); 1851 dbg("%s", "Invalid Serial \n");
1851 return -1; 1852 return -1;
1852 } 1853 }
@@ -1855,7 +1856,7 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1855 1856
1856 number = mos7840_port->port->number - mos7840_port->port->serial->minor; 1857 number = mos7840_port->port->number - mos7840_port->port->serial->minor;
1857 1858
1858 dbg("%s - port = %d, baud = %d", __FUNCTION__, 1859 dbg("%s - port = %d, baud = %d", __func__,
1859 mos7840_port->port->number, baudRate); 1860 mos7840_port->port->number, baudRate);
1860 //reset clk_uart_sel in spregOffset 1861 //reset clk_uart_sel in spregOffset
1861 if (baudRate > 115200) { 1862 if (baudRate > 115200) {
@@ -1915,7 +1916,7 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1915 /* Calculate the Divisor */ 1916 /* Calculate the Divisor */
1916 1917
1917 if (status) { 1918 if (status) {
1918 err("%s - bad baud rate", __FUNCTION__); 1919 err("%s - bad baud rate", __func__);
1919 dbg("%s\n", "bad baud rate"); 1920 dbg("%s\n", "bad baud rate");
1920 return status; 1921 return status;
1921 } 1922 }
@@ -1969,22 +1970,22 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
1969 1970
1970 port = (struct usb_serial_port *)mos7840_port->port; 1971 port = (struct usb_serial_port *)mos7840_port->port;
1971 1972
1972 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 1973 if (mos7840_port_paranoia_check(port, __func__)) {
1973 dbg("%s", "Invalid port \n"); 1974 dbg("%s", "Invalid port \n");
1974 return; 1975 return;
1975 } 1976 }
1976 1977
1977 if (mos7840_serial_paranoia_check(port->serial, __FUNCTION__)) { 1978 if (mos7840_serial_paranoia_check(port->serial, __func__)) {
1978 dbg("%s", "Invalid Serial \n"); 1979 dbg("%s", "Invalid Serial \n");
1979 return; 1980 return;
1980 } 1981 }
1981 1982
1982 serial = port->serial; 1983 serial = port->serial;
1983 1984
1984 dbg("%s - port %d", __FUNCTION__, mos7840_port->port->number); 1985 dbg("%s - port %d", __func__, mos7840_port->port->number);
1985 1986
1986 if (!mos7840_port->open) { 1987 if (!mos7840_port->open) {
1987 dbg("%s - port not opened", __FUNCTION__); 1988 dbg("%s - port not opened", __func__);
1988 return; 1989 return;
1989 } 1990 }
1990 1991
@@ -2023,14 +2024,14 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2023 if (cflag & PARENB) { 2024 if (cflag & PARENB) {
2024 if (cflag & PARODD) { 2025 if (cflag & PARODD) {
2025 lParity = LCR_PAR_ODD; 2026 lParity = LCR_PAR_ODD;
2026 dbg("%s - parity = odd", __FUNCTION__); 2027 dbg("%s - parity = odd", __func__);
2027 } else { 2028 } else {
2028 lParity = LCR_PAR_EVEN; 2029 lParity = LCR_PAR_EVEN;
2029 dbg("%s - parity = even", __FUNCTION__); 2030 dbg("%s - parity = even", __func__);
2030 } 2031 }
2031 2032
2032 } else { 2033 } else {
2033 dbg("%s - parity = none", __FUNCTION__); 2034 dbg("%s - parity = none", __func__);
2034 } 2035 }
2035 2036
2036 if (cflag & CMSPAR) { 2037 if (cflag & CMSPAR) {
@@ -2040,10 +2041,10 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2040 /* Change the Stop bit */ 2041 /* Change the Stop bit */
2041 if (cflag & CSTOPB) { 2042 if (cflag & CSTOPB) {
2042 lStop = LCR_STOP_2; 2043 lStop = LCR_STOP_2;
2043 dbg("%s - stop bits = 2", __FUNCTION__); 2044 dbg("%s - stop bits = 2", __func__);
2044 } else { 2045 } else {
2045 lStop = LCR_STOP_1; 2046 lStop = LCR_STOP_1;
2046 dbg("%s - stop bits = 1", __FUNCTION__); 2047 dbg("%s - stop bits = 1", __func__);
2047 } 2048 }
2048 2049
2049 /* Update the LCR with the correct value */ 2050 /* Update the LCR with the correct value */
@@ -2100,7 +2101,7 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2100 baud = 9600; 2101 baud = 9600;
2101 } 2102 }
2102 2103
2103 dbg("%s - baud rate = %d", __FUNCTION__, baud); 2104 dbg("%s - baud rate = %d", __func__, baud);
2104 status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud); 2105 status = mos7840_send_cmd_write_baud_rate(mos7840_port, baud);
2105 2106
2106 /* Enable Interrupts */ 2107 /* Enable Interrupts */
@@ -2140,14 +2141,14 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2140 struct moschip_port *mos7840_port; 2141 struct moschip_port *mos7840_port;
2141 struct tty_struct *tty; 2142 struct tty_struct *tty;
2142 dbg("mos7840_set_termios: START\n"); 2143 dbg("mos7840_set_termios: START\n");
2143 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 2144 if (mos7840_port_paranoia_check(port, __func__)) {
2144 dbg("%s", "Invalid port \n"); 2145 dbg("%s", "Invalid port \n");
2145 return; 2146 return;
2146 } 2147 }
2147 2148
2148 serial = port->serial; 2149 serial = port->serial;
2149 2150
2150 if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { 2151 if (mos7840_serial_paranoia_check(serial, __func__)) {
2151 dbg("%s", "Invalid Serial \n"); 2152 dbg("%s", "Invalid Serial \n");
2152 return; 2153 return;
2153 } 2154 }
@@ -2160,7 +2161,7 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2160 tty = port->tty; 2161 tty = port->tty;
2161 2162
2162 if (!mos7840_port->open) { 2163 if (!mos7840_port->open) {
2163 dbg("%s - port not opened", __FUNCTION__); 2164 dbg("%s - port not opened", __func__);
2164 return; 2165 return;
2165 } 2166 }
2166 2167
@@ -2168,11 +2169,11 @@ static void mos7840_set_termios(struct usb_serial_port *port,
2168 2169
2169 cflag = tty->termios->c_cflag; 2170 cflag = tty->termios->c_cflag;
2170 2171
2171 dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 2172 dbg("%s - clfag %08x iflag %08x", __func__,
2172 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag)); 2173 tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag));
2173 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, 2174 dbg("%s - old clfag %08x old iflag %08x", __func__,
2174 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); 2175 old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
2175 dbg("%s - port %d", __FUNCTION__, port->number); 2176 dbg("%s - port %d", __func__, port->number);
2176 2177
2177 /* change the port settings to the new ones specified */ 2178 /* change the port settings to the new ones specified */
2178 2179
@@ -2213,7 +2214,7 @@ static int mos7840_get_lsr_info(struct moschip_port *mos7840_port,
2213 2214
2214 count = mos7840_chars_in_buffer(mos7840_port->port); 2215 count = mos7840_chars_in_buffer(mos7840_port->port);
2215 if (count == 0) { 2216 if (count == 0) {
2216 dbg("%s -- Empty", __FUNCTION__); 2217 dbg("%s -- Empty", __func__);
2217 result = TIOCSER_TEMT; 2218 result = TIOCSER_TEMT;
2218 } 2219 }
2219 2220
@@ -2240,7 +2241,7 @@ static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2240 return -1; 2241 return -1;
2241 2242
2242 port = (struct usb_serial_port *)mos7840_port->port; 2243 port = (struct usb_serial_port *)mos7840_port->port;
2243 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 2244 if (mos7840_port_paranoia_check(port, __func__)) {
2244 dbg("%s", "Invalid port \n"); 2245 dbg("%s", "Invalid port \n");
2245 return -1; 2246 return -1;
2246 } 2247 }
@@ -2314,7 +2315,7 @@ static int mos7840_get_modem_info(struct moschip_port *mos7840_port,
2314 |((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */ 2315 |((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */
2315 |((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */ 2316 |((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */
2316 2317
2317 dbg("%s -- %x", __FUNCTION__, result); 2318 dbg("%s -- %x", __func__, result);
2318 2319
2319 if (copy_to_user(value, &result, sizeof(int))) 2320 if (copy_to_user(value, &result, sizeof(int)))
2320 return -EFAULT; 2321 return -EFAULT;
@@ -2371,7 +2372,7 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2371 struct serial_icounter_struct icount; 2372 struct serial_icounter_struct icount;
2372 int mosret = 0; 2373 int mosret = 0;
2373 2374
2374 if (mos7840_port_paranoia_check(port, __FUNCTION__)) { 2375 if (mos7840_port_paranoia_check(port, __func__)) {
2375 dbg("%s", "Invalid port \n"); 2376 dbg("%s", "Invalid port \n");
2376 return -1; 2377 return -1;
2377 } 2378 }
@@ -2383,39 +2384,39 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2383 2384
2384 tty = mos7840_port->port->tty; 2385 tty = mos7840_port->port->tty;
2385 2386
2386 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd); 2387 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
2387 2388
2388 switch (cmd) { 2389 switch (cmd) {
2389 /* return number of bytes available */ 2390 /* return number of bytes available */
2390 2391
2391 case TIOCSERGETLSR: 2392 case TIOCSERGETLSR:
2392 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number); 2393 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
2393 return mos7840_get_lsr_info(mos7840_port, argp); 2394 return mos7840_get_lsr_info(mos7840_port, argp);
2394 return 0; 2395 return 0;
2395 2396
2396 case TIOCMBIS: 2397 case TIOCMBIS:
2397 case TIOCMBIC: 2398 case TIOCMBIC:
2398 case TIOCMSET: 2399 case TIOCMSET:
2399 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, 2400 dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __func__,
2400 port->number); 2401 port->number);
2401 mosret = 2402 mosret =
2402 mos7840_set_modem_info(mos7840_port, cmd, argp); 2403 mos7840_set_modem_info(mos7840_port, cmd, argp);
2403 return mosret; 2404 return mosret;
2404 2405
2405 case TIOCMGET: 2406 case TIOCMGET:
2406 dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number); 2407 dbg("%s (%d) TIOCMGET", __func__, port->number);
2407 return mos7840_get_modem_info(mos7840_port, argp); 2408 return mos7840_get_modem_info(mos7840_port, argp);
2408 2409
2409 case TIOCGSERIAL: 2410 case TIOCGSERIAL:
2410 dbg("%s (%d) TIOCGSERIAL", __FUNCTION__, port->number); 2411 dbg("%s (%d) TIOCGSERIAL", __func__, port->number);
2411 return mos7840_get_serial_info(mos7840_port, argp); 2412 return mos7840_get_serial_info(mos7840_port, argp);
2412 2413
2413 case TIOCSSERIAL: 2414 case TIOCSSERIAL:
2414 dbg("%s (%d) TIOCSSERIAL", __FUNCTION__, port->number); 2415 dbg("%s (%d) TIOCSSERIAL", __func__, port->number);
2415 break; 2416 break;
2416 2417
2417 case TIOCMIWAIT: 2418 case TIOCMIWAIT:
2418 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number); 2419 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
2419 cprev = mos7840_port->icount; 2420 cprev = mos7840_port->icount;
2420 while (1) { 2421 while (1) {
2421 //interruptible_sleep_on(&mos7840_port->delta_msr_wait); 2422 //interruptible_sleep_on(&mos7840_port->delta_msr_wait);
@@ -2458,7 +2459,7 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2458 icount.brk = cnow.brk; 2459 icount.brk = cnow.brk;
2459 icount.buf_overrun = cnow.buf_overrun; 2460 icount.buf_overrun = cnow.buf_overrun;
2460 2461
2461 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__, 2462 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2462 port->number, icount.rx, icount.tx); 2463 port->number, icount.rx, icount.tx);
2463 if (copy_to_user(argp, &icount, sizeof(icount))) 2464 if (copy_to_user(argp, &icount, sizeof(icount)))
2464 return -EFAULT; 2465 return -EFAULT;
@@ -2521,7 +2522,7 @@ static int mos7840_startup(struct usb_serial *serial)
2521 for (i = 0; i < serial->num_ports; ++i) { 2522 for (i = 0; i < serial->num_ports; ++i) {
2522 mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 2523 mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
2523 if (mos7840_port == NULL) { 2524 if (mos7840_port == NULL) {
2524 err("%s - Out of memory", __FUNCTION__); 2525 err("%s - Out of memory", __func__);
2525 status = -ENOMEM; 2526 status = -ENOMEM;
2526 i--; /* don't follow NULL pointer cleaning up */ 2527 i--; /* don't follow NULL pointer cleaning up */
2527 goto error; 2528 goto error;
@@ -2799,12 +2800,7 @@ static struct usb_serial_driver moschip7840_4port_device = {
2799 .description = DRIVER_DESC, 2800 .description = DRIVER_DESC,
2800 .usb_driver = &io_driver, 2801 .usb_driver = &io_driver,
2801 .id_table = moschip_port_id_table, 2802 .id_table = moschip_port_id_table,
2802 .num_interrupt_in = 1, //NUM_DONT_CARE,//1,
2803#ifdef check
2804 .num_bulk_in = 4,
2805 .num_bulk_out = 4,
2806 .num_ports = 4, 2803 .num_ports = 4,
2807#endif
2808 .open = mos7840_open, 2804 .open = mos7840_open,
2809 .close = mos7840_close, 2805 .close = mos7840_close,
2810 .write = mos7840_write, 2806 .write = mos7840_write,
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
index 7f337c9aeb5f..43c8894353bf 100644
--- a/drivers/usb/serial/navman.c
+++ b/drivers/usb/serial/navman.c
@@ -6,6 +6,10 @@
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation. 8 * version 2 as published by the Free Software Foundation.
9 *
10 * TODO:
11 * Add termios method that uses copy_hw but also kills all echo
12 * flags as the navman is rx only so cannot echo.
9 */ 13 */
10 14
11#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -49,15 +53,15 @@ static void navman_read_int_callback(struct urb *urb)
49 case -ESHUTDOWN: 53 case -ESHUTDOWN:
50 /* this urb is terminated, clean up */ 54 /* this urb is terminated, clean up */
51 dbg("%s - urb shutting down with status: %d", 55 dbg("%s - urb shutting down with status: %d",
52 __FUNCTION__, status); 56 __func__, status);
53 return; 57 return;
54 default: 58 default:
55 dbg("%s - nonzero urb status received: %d", 59 dbg("%s - nonzero urb status received: %d",
56 __FUNCTION__, status); 60 __func__, status);
57 goto exit; 61 goto exit;
58 } 62 }
59 63
60 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 64 usb_serial_debug_data(debug, &port->dev, __func__,
61 urb->actual_length, data); 65 urb->actual_length, data);
62 66
63 tty = port->tty; 67 tty = port->tty;
@@ -72,29 +76,29 @@ exit:
72 if (result) 76 if (result)
73 dev_err(&urb->dev->dev, 77 dev_err(&urb->dev->dev,
74 "%s - Error %d submitting interrupt urb\n", 78 "%s - Error %d submitting interrupt urb\n",
75 __FUNCTION__, result); 79 __func__, result);
76} 80}
77 81
78static int navman_open(struct usb_serial_port *port, struct file *filp) 82static int navman_open(struct usb_serial_port *port, struct file *filp)
79{ 83{
80 int result = 0; 84 int result = 0;
81 85
82 dbg("%s - port %d", __FUNCTION__, port->number); 86 dbg("%s - port %d", __func__, port->number);
83 87
84 if (port->interrupt_in_urb) { 88 if (port->interrupt_in_urb) {
85 dbg("%s - adding interrupt input for treo", __FUNCTION__); 89 dbg("%s - adding interrupt input for treo", __func__);
86 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 90 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
87 if (result) 91 if (result)
88 dev_err(&port->dev, 92 dev_err(&port->dev,
89 "%s - failed submitting interrupt urb, error %d\n", 93 "%s - failed submitting interrupt urb, error %d\n",
90 __FUNCTION__, result); 94 __func__, result);
91 } 95 }
92 return result; 96 return result;
93} 97}
94 98
95static void navman_close(struct usb_serial_port *port, struct file *filp) 99static void navman_close(struct usb_serial_port *port, struct file *filp)
96{ 100{
97 dbg("%s - port %d", __FUNCTION__, port->number); 101 dbg("%s - port %d", __func__, port->number);
98 102
99 usb_kill_urb(port->interrupt_in_urb); 103 usb_kill_urb(port->interrupt_in_urb);
100} 104}
@@ -102,16 +106,12 @@ static void navman_close(struct usb_serial_port *port, struct file *filp)
102static int navman_write(struct usb_serial_port *port, 106static int navman_write(struct usb_serial_port *port,
103 const unsigned char *buf, int count) 107 const unsigned char *buf, int count)
104{ 108{
105 dbg("%s - port %d", __FUNCTION__, port->number); 109 dbg("%s - port %d", __func__, port->number);
106 110
107 /* 111 /*
108 * This device can't write any data, only read from the device 112 * This device can't write any data, only read from the device
109 * so we just silently eat all data sent to us and say it was
110 * successfully sent.
111 * Evil, I know, but do you have a better idea?
112 */ 113 */
113 114 return -EOPNOTSUPP;
114 return count;
115} 115}
116 116
117static struct usb_serial_driver navman_device = { 117static struct usb_serial_driver navman_device = {
@@ -121,9 +121,6 @@ static struct usb_serial_driver navman_device = {
121 }, 121 },
122 .id_table = id_table, 122 .id_table = id_table,
123 .usb_driver = &navman_driver, 123 .usb_driver = &navman_driver,
124 .num_interrupt_in = NUM_DONT_CARE,
125 .num_bulk_in = NUM_DONT_CARE,
126 .num_bulk_out = NUM_DONT_CARE,
127 .num_ports = 1, 124 .num_ports = 1,
128 .open = navman_open, 125 .open = navman_open,
129 .close = navman_close, 126 .close = navman_close,
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index ee94d9616d82..7b7422f49478 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -95,9 +95,6 @@ static struct usb_serial_driver zyxel_omninet_device = {
95 .description = "ZyXEL - omni.net lcd plus usb", 95 .description = "ZyXEL - omni.net lcd plus usb",
96 .usb_driver = &omninet_driver, 96 .usb_driver = &omninet_driver,
97 .id_table = id_table, 97 .id_table = id_table,
98 .num_interrupt_in = 1,
99 .num_bulk_in = 1,
100 .num_bulk_out = 2,
101 .num_ports = 1, 98 .num_ports = 1,
102 .attach = omninet_attach, 99 .attach = omninet_attach,
103 .open = omninet_open, 100 .open = omninet_open,
@@ -153,7 +150,7 @@ static int omninet_attach (struct usb_serial *serial)
153 150
154 od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); 151 od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL );
155 if( !od ) { 152 if( !od ) {
156 err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct omninet_data)); 153 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct omninet_data));
157 return -ENOMEM; 154 return -ENOMEM;
158 } 155 }
159 usb_set_serial_port_data(port, od); 156 usb_set_serial_port_data(port, od);
@@ -166,7 +163,7 @@ static int omninet_open (struct usb_serial_port *port, struct file *filp)
166 struct usb_serial_port *wport; 163 struct usb_serial_port *wport;
167 int result = 0; 164 int result = 0;
168 165
169 dbg("%s - port %d", __FUNCTION__, port->number); 166 dbg("%s - port %d", __func__, port->number);
170 167
171 wport = serial->port[1]; 168 wport = serial->port[1];
172 wport->tty = port->tty; 169 wport->tty = port->tty;
@@ -178,7 +175,7 @@ static int omninet_open (struct usb_serial_port *port, struct file *filp)
178 omninet_read_bulk_callback, port); 175 omninet_read_bulk_callback, port);
179 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 176 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
180 if (result) { 177 if (result) {
181 err("%s - failed submitting read urb, error %d", __FUNCTION__, result); 178 err("%s - failed submitting read urb, error %d", __func__, result);
182 } 179 }
183 180
184 return result; 181 return result;
@@ -186,7 +183,7 @@ static int omninet_open (struct usb_serial_port *port, struct file *filp)
186 183
187static void omninet_close (struct usb_serial_port *port, struct file * filp) 184static void omninet_close (struct usb_serial_port *port, struct file * filp)
188{ 185{
189 dbg("%s - port %d", __FUNCTION__, port->number); 186 dbg("%s - port %d", __func__, port->number);
190 usb_kill_urb(port->read_urb); 187 usb_kill_urb(port->read_urb);
191} 188}
192 189
@@ -197,18 +194,18 @@ static void omninet_close (struct usb_serial_port *port, struct file * filp)
197 194
198static void omninet_read_bulk_callback (struct urb *urb) 195static void omninet_read_bulk_callback (struct urb *urb)
199{ 196{
200 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 197 struct usb_serial_port *port = urb->context;
201 unsigned char *data = urb->transfer_buffer; 198 unsigned char *data = urb->transfer_buffer;
202 struct omninet_header *header = (struct omninet_header *) &data[0]; 199 struct omninet_header *header = (struct omninet_header *) &data[0];
203 int status = urb->status; 200 int status = urb->status;
204 int i; 201 int i;
205 int result; 202 int result;
206 203
207 dbg("%s - port %d", __FUNCTION__, port->number); 204 dbg("%s - port %d", __func__, port->number);
208 205
209 if (status) { 206 if (status) {
210 dbg("%s - nonzero read bulk status received: %d", 207 dbg("%s - nonzero read bulk status received: %d",
211 __FUNCTION__, status); 208 __func__, status);
212 return; 209 return;
213 } 210 }
214 211
@@ -236,7 +233,7 @@ static void omninet_read_bulk_callback (struct urb *urb)
236 omninet_read_bulk_callback, port); 233 omninet_read_bulk_callback, port);
237 result = usb_submit_urb(urb, GFP_ATOMIC); 234 result = usb_submit_urb(urb, GFP_ATOMIC);
238 if (result) 235 if (result)
239 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 236 err("%s - failed resubmitting read urb, error %d", __func__, result);
240 237
241 return; 238 return;
242} 239}
@@ -251,17 +248,17 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
251 248
252 int result; 249 int result;
253 250
254 dbg("%s - port %d", __FUNCTION__, port->number); 251 dbg("%s - port %d", __func__, port->number);
255 252
256 if (count == 0) { 253 if (count == 0) {
257 dbg("%s - write request of 0 bytes", __FUNCTION__); 254 dbg("%s - write request of 0 bytes", __func__);
258 return (0); 255 return (0);
259 } 256 }
260 257
261 spin_lock_bh(&wport->lock); 258 spin_lock_bh(&wport->lock);
262 if (wport->write_urb_busy) { 259 if (wport->write_urb_busy) {
263 spin_unlock_bh(&wport->lock); 260 spin_unlock_bh(&wport->lock);
264 dbg("%s - already writing", __FUNCTION__); 261 dbg("%s - already writing", __func__);
265 return 0; 262 return 0;
266 } 263 }
267 wport->write_urb_busy = 1; 264 wport->write_urb_busy = 1;
@@ -271,7 +268,7 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
271 268
272 memcpy (wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count); 269 memcpy (wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count);
273 270
274 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, wport->write_urb->transfer_buffer); 271 usb_serial_debug_data(debug, &port->dev, __func__, count, wport->write_urb->transfer_buffer);
275 272
276 header->oh_seq = od->od_outseq++; 273 header->oh_seq = od->od_outseq++;
277 header->oh_len = count; 274 header->oh_len = count;
@@ -285,7 +282,7 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
285 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 282 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
286 if (result) { 283 if (result) {
287 wport->write_urb_busy = 0; 284 wport->write_urb_busy = 0;
288 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 285 err("%s - failed submitting write urb, error %d", __func__, result);
289 } else 286 } else
290 result = count; 287 result = count;
291 288
@@ -298,12 +295,13 @@ static int omninet_write_room (struct usb_serial_port *port)
298 struct usb_serial *serial = port->serial; 295 struct usb_serial *serial = port->serial;
299 struct usb_serial_port *wport = serial->port[1]; 296 struct usb_serial_port *wport = serial->port[1];
300 297
301 int room = 0; // Default: no room 298 int room = 0; /* Default: no room */
302 299
300 /* FIXME: no consistent locking for write_urb_busy */
303 if (wport->write_urb_busy) 301 if (wport->write_urb_busy)
304 room = wport->bulk_out_size - OMNINET_HEADERLEN; 302 room = wport->bulk_out_size - OMNINET_HEADERLEN;
305 303
306 dbg("%s - returns %d", __FUNCTION__, room); 304 dbg("%s - returns %d", __func__, room);
307 305
308 return (room); 306 return (room);
309} 307}
@@ -311,15 +309,15 @@ static int omninet_write_room (struct usb_serial_port *port)
311static void omninet_write_bulk_callback (struct urb *urb) 309static void omninet_write_bulk_callback (struct urb *urb)
312{ 310{
313/* struct omninet_header *header = (struct omninet_header *) urb->transfer_buffer; */ 311/* struct omninet_header *header = (struct omninet_header *) urb->transfer_buffer; */
314 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 312 struct usb_serial_port *port = urb->context;
315 int status = urb->status; 313 int status = urb->status;
316 314
317 dbg("%s - port %0x\n", __FUNCTION__, port->number); 315 dbg("%s - port %0x\n", __func__, port->number);
318 316
319 port->write_urb_busy = 0; 317 port->write_urb_busy = 0;
320 if (status) { 318 if (status) {
321 dbg("%s - nonzero write bulk status received: %d", 319 dbg("%s - nonzero write bulk status received: %d",
322 __FUNCTION__, status); 320 __func__, status);
323 return; 321 return;
324 } 322 }
325 323
@@ -331,7 +329,7 @@ static void omninet_shutdown (struct usb_serial *serial)
331{ 329{
332 struct usb_serial_port *wport = serial->port[1]; 330 struct usb_serial_port *wport = serial->port[1];
333 struct usb_serial_port *port = serial->port[0]; 331 struct usb_serial_port *port = serial->port[0];
334 dbg ("%s", __FUNCTION__); 332 dbg ("%s", __func__);
335 333
336 usb_kill_urb(wport->write_urb); 334 usb_kill_urb(wport->write_urb);
337 kfree(usb_get_serial_port_data(port)); 335 kfree(usb_get_serial_port_data(port));
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index d101025a4c63..e4be2d442b1e 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -28,7 +28,7 @@
28 device features. 28 device features.
29*/ 29*/
30 30
31#define DRIVER_VERSION "v0.7.1" 31#define DRIVER_VERSION "v0.7.2"
32#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>" 32#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
33#define DRIVER_DESC "USB Driver for GSM modems" 33#define DRIVER_DESC "USB Driver for GSM modems"
34 34
@@ -325,9 +325,6 @@ static struct usb_serial_driver option_1port_device = {
325 .description = "GSM modem (1-port)", 325 .description = "GSM modem (1-port)",
326 .usb_driver = &option_driver, 326 .usb_driver = &option_driver,
327 .id_table = option_ids, 327 .id_table = option_ids,
328 .num_interrupt_in = NUM_DONT_CARE,
329 .num_bulk_in = NUM_DONT_CARE,
330 .num_bulk_out = NUM_DONT_CARE,
331 .num_ports = 1, 328 .num_ports = 1,
332 .open = option_open, 329 .open = option_open,
333 .close = option_close, 330 .close = option_close,
@@ -411,24 +408,24 @@ module_exit(option_exit);
411 408
412static void option_rx_throttle(struct usb_serial_port *port) 409static void option_rx_throttle(struct usb_serial_port *port)
413{ 410{
414 dbg("%s", __FUNCTION__); 411 dbg("%s", __func__);
415} 412}
416 413
417static void option_rx_unthrottle(struct usb_serial_port *port) 414static void option_rx_unthrottle(struct usb_serial_port *port)
418{ 415{
419 dbg("%s", __FUNCTION__); 416 dbg("%s", __func__);
420} 417}
421 418
422static void option_break_ctl(struct usb_serial_port *port, int break_state) 419static void option_break_ctl(struct usb_serial_port *port, int break_state)
423{ 420{
424 /* Unfortunately, I don't know how to send a break */ 421 /* Unfortunately, I don't know how to send a break */
425 dbg("%s", __FUNCTION__); 422 dbg("%s", __func__);
426} 423}
427 424
428static void option_set_termios(struct usb_serial_port *port, 425static void option_set_termios(struct usb_serial_port *port,
429 struct ktermios *old_termios) 426 struct ktermios *old_termios)
430{ 427{
431 dbg("%s", __FUNCTION__); 428 dbg("%s", __func__);
432 /* Doesn't support option setting */ 429 /* Doesn't support option setting */
433 tty_termios_copy_hw(port->tty->termios, old_termios); 430 tty_termios_copy_hw(port->tty->termios, old_termios);
434 option_send_setup(port); 431 option_send_setup(port);
@@ -458,6 +455,7 @@ static int option_tiocmset(struct usb_serial_port *port, struct file *file,
458 455
459 portdata = usb_get_serial_port_data(port); 456 portdata = usb_get_serial_port_data(port);
460 457
458 /* FIXME: what locks portdata fields ? */
461 if (set & TIOCM_RTS) 459 if (set & TIOCM_RTS)
462 portdata->rts_state = 1; 460 portdata->rts_state = 1;
463 if (set & TIOCM_DTR) 461 if (set & TIOCM_DTR)
@@ -488,7 +486,7 @@ static int option_write(struct usb_serial_port *port,
488 486
489 portdata = usb_get_serial_port_data(port); 487 portdata = usb_get_serial_port_data(port);
490 488
491 dbg("%s: write (%d chars)", __FUNCTION__, count); 489 dbg("%s: write (%d chars)", __func__, count);
492 490
493 i = 0; 491 i = 0;
494 left = count; 492 left = count;
@@ -509,7 +507,7 @@ static int option_write(struct usb_serial_port *port,
509 dbg("usb_write %p failed (err=%d)", 507 dbg("usb_write %p failed (err=%d)",
510 this_urb, this_urb->status); 508 this_urb, this_urb->status);
511 509
512 dbg("%s: endpoint %d buf %d", __FUNCTION__, 510 dbg("%s: endpoint %d buf %d", __func__,
513 usb_pipeendpoint(this_urb->pipe), i); 511 usb_pipeendpoint(this_urb->pipe), i);
514 512
515 /* send the data */ 513 /* send the data */
@@ -531,7 +529,7 @@ static int option_write(struct usb_serial_port *port,
531 } 529 }
532 530
533 count -= left; 531 count -= left;
534 dbg("%s: wrote (did %d)", __FUNCTION__, count); 532 dbg("%s: wrote (did %d)", __func__, count);
535 return count; 533 return count;
536} 534}
537 535
@@ -544,14 +542,14 @@ static void option_indat_callback(struct urb *urb)
544 unsigned char *data = urb->transfer_buffer; 542 unsigned char *data = urb->transfer_buffer;
545 int status = urb->status; 543 int status = urb->status;
546 544
547 dbg("%s: %p", __FUNCTION__, urb); 545 dbg("%s: %p", __func__, urb);
548 546
549 endpoint = usb_pipeendpoint(urb->pipe); 547 endpoint = usb_pipeendpoint(urb->pipe);
550 port = (struct usb_serial_port *) urb->context; 548 port = urb->context;
551 549
552 if (status) { 550 if (status) {
553 dbg("%s: nonzero status: %d on endpoint %02x.", 551 dbg("%s: nonzero status: %d on endpoint %02x.",
554 __FUNCTION__, status, endpoint); 552 __func__, status, endpoint);
555 } else { 553 } else {
556 tty = port->tty; 554 tty = port->tty;
557 if (urb->actual_length) { 555 if (urb->actual_length) {
@@ -559,7 +557,7 @@ static void option_indat_callback(struct urb *urb)
559 tty_insert_flip_string(tty, data, urb->actual_length); 557 tty_insert_flip_string(tty, data, urb->actual_length);
560 tty_flip_buffer_push(tty); 558 tty_flip_buffer_push(tty);
561 } else { 559 } else {
562 dbg("%s: empty read urb received", __FUNCTION__); 560 dbg("%s: empty read urb received", __func__);
563 } 561 }
564 562
565 /* Resubmit urb so we continue receiving */ 563 /* Resubmit urb so we continue receiving */
@@ -567,7 +565,7 @@ static void option_indat_callback(struct urb *urb)
567 err = usb_submit_urb(urb, GFP_ATOMIC); 565 err = usb_submit_urb(urb, GFP_ATOMIC);
568 if (err) 566 if (err)
569 printk(KERN_ERR "%s: resubmit read urb failed. " 567 printk(KERN_ERR "%s: resubmit read urb failed. "
570 "(%d)", __FUNCTION__, err); 568 "(%d)", __func__, err);
571 } 569 }
572 } 570 }
573 return; 571 return;
@@ -579,9 +577,9 @@ static void option_outdat_callback(struct urb *urb)
579 struct option_port_private *portdata; 577 struct option_port_private *portdata;
580 int i; 578 int i;
581 579
582 dbg("%s", __FUNCTION__); 580 dbg("%s", __func__);
583 581
584 port = (struct usb_serial_port *) urb->context; 582 port = urb->context;
585 583
586 usb_serial_port_softint(port); 584 usb_serial_port_softint(port);
587 585
@@ -599,19 +597,19 @@ static void option_instat_callback(struct urb *urb)
599{ 597{
600 int err; 598 int err;
601 int status = urb->status; 599 int status = urb->status;
602 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 600 struct usb_serial_port *port = urb->context;
603 struct option_port_private *portdata = usb_get_serial_port_data(port); 601 struct option_port_private *portdata = usb_get_serial_port_data(port);
604 struct usb_serial *serial = port->serial; 602 struct usb_serial *serial = port->serial;
605 603
606 dbg("%s", __FUNCTION__); 604 dbg("%s", __func__);
607 dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata); 605 dbg("%s: urb %p port %p has data %p", __func__,urb,port,portdata);
608 606
609 if (status == 0) { 607 if (status == 0) {
610 struct usb_ctrlrequest *req_pkt = 608 struct usb_ctrlrequest *req_pkt =
611 (struct usb_ctrlrequest *)urb->transfer_buffer; 609 (struct usb_ctrlrequest *)urb->transfer_buffer;
612 610
613 if (!req_pkt) { 611 if (!req_pkt) {
614 dbg("%s: NULL req_pkt\n", __FUNCTION__); 612 dbg("%s: NULL req_pkt\n", __func__);
615 return; 613 return;
616 } 614 }
617 if ((req_pkt->bRequestType == 0xA1) && 615 if ((req_pkt->bRequestType == 0xA1) &&
@@ -621,7 +619,7 @@ static void option_instat_callback(struct urb *urb)
621 urb->transfer_buffer + 619 urb->transfer_buffer +
622 sizeof(struct usb_ctrlrequest)); 620 sizeof(struct usb_ctrlrequest));
623 621
624 dbg("%s: signal x%x", __FUNCTION__, signals); 622 dbg("%s: signal x%x", __func__, signals);
625 623
626 old_dcd_state = portdata->dcd_state; 624 old_dcd_state = portdata->dcd_state;
627 portdata->cts_state = 1; 625 portdata->cts_state = 1;
@@ -633,11 +631,11 @@ static void option_instat_callback(struct urb *urb)
633 old_dcd_state && !portdata->dcd_state) 631 old_dcd_state && !portdata->dcd_state)
634 tty_hangup(port->tty); 632 tty_hangup(port->tty);
635 } else { 633 } else {
636 dbg("%s: type %x req %x", __FUNCTION__, 634 dbg("%s: type %x req %x", __func__,
637 req_pkt->bRequestType,req_pkt->bRequest); 635 req_pkt->bRequestType,req_pkt->bRequest);
638 } 636 }
639 } else 637 } else
640 dbg("%s: error %d", __FUNCTION__, status); 638 dbg("%s: error %d", __func__, status);
641 639
642 /* Resubmit urb so we continue receiving IRQ data */ 640 /* Resubmit urb so we continue receiving IRQ data */
643 if (status != -ESHUTDOWN) { 641 if (status != -ESHUTDOWN) {
@@ -645,7 +643,7 @@ static void option_instat_callback(struct urb *urb)
645 err = usb_submit_urb(urb, GFP_ATOMIC); 643 err = usb_submit_urb(urb, GFP_ATOMIC);
646 if (err) 644 if (err)
647 dbg("%s: resubmit intr urb failed. (%d)", 645 dbg("%s: resubmit intr urb failed. (%d)",
648 __FUNCTION__, err); 646 __func__, err);
649 } 647 }
650} 648}
651 649
@@ -658,13 +656,14 @@ static int option_write_room(struct usb_serial_port *port)
658 656
659 portdata = usb_get_serial_port_data(port); 657 portdata = usb_get_serial_port_data(port);
660 658
659
661 for (i=0; i < N_OUT_URB; i++) { 660 for (i=0; i < N_OUT_URB; i++) {
662 this_urb = portdata->out_urbs[i]; 661 this_urb = portdata->out_urbs[i];
663 if (this_urb && !test_bit(i, &portdata->out_busy)) 662 if (this_urb && !test_bit(i, &portdata->out_busy))
664 data_len += OUT_BUFLEN; 663 data_len += OUT_BUFLEN;
665 } 664 }
666 665
667 dbg("%s: %d", __FUNCTION__, data_len); 666 dbg("%s: %d", __func__, data_len);
668 return data_len; 667 return data_len;
669} 668}
670 669
@@ -679,10 +678,12 @@ static int option_chars_in_buffer(struct usb_serial_port *port)
679 678
680 for (i=0; i < N_OUT_URB; i++) { 679 for (i=0; i < N_OUT_URB; i++) {
681 this_urb = portdata->out_urbs[i]; 680 this_urb = portdata->out_urbs[i];
681 /* FIXME: This locking is insufficient as this_urb may
682 go unused during the test */
682 if (this_urb && test_bit(i, &portdata->out_busy)) 683 if (this_urb && test_bit(i, &portdata->out_busy))
683 data_len += this_urb->transfer_buffer_length; 684 data_len += this_urb->transfer_buffer_length;
684 } 685 }
685 dbg("%s: %d", __FUNCTION__, data_len); 686 dbg("%s: %d", __func__, data_len);
686 return data_len; 687 return data_len;
687} 688}
688 689
@@ -695,7 +696,7 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
695 696
696 portdata = usb_get_serial_port_data(port); 697 portdata = usb_get_serial_port_data(port);
697 698
698 dbg("%s", __FUNCTION__); 699 dbg("%s", __func__);
699 700
700 /* Set some sane defaults */ 701 /* Set some sane defaults */
701 portdata->rts_state = 1; 702 portdata->rts_state = 1;
@@ -707,7 +708,7 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
707 if (! urb) 708 if (! urb)
708 continue; 709 continue;
709 if (urb->dev != serial->dev) { 710 if (urb->dev != serial->dev) {
710 dbg("%s: dev %p != %p", __FUNCTION__, 711 dbg("%s: dev %p != %p", __func__,
711 urb->dev, serial->dev); 712 urb->dev, serial->dev);
712 continue; 713 continue;
713 } 714 }
@@ -721,7 +722,7 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
721 err = usb_submit_urb(urb, GFP_KERNEL); 722 err = usb_submit_urb(urb, GFP_KERNEL);
722 if (err) { 723 if (err) {
723 dbg("%s: submit urb %d failed (%d) %d", 724 dbg("%s: submit urb %d failed (%d) %d",
724 __FUNCTION__, i, err, 725 __func__, i, err,
725 urb->transfer_buffer_length); 726 urb->transfer_buffer_length);
726 } 727 }
727 } 728 }
@@ -749,7 +750,7 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
749 struct usb_serial *serial = port->serial; 750 struct usb_serial *serial = port->serial;
750 struct option_port_private *portdata; 751 struct option_port_private *portdata;
751 752
752 dbg("%s", __FUNCTION__); 753 dbg("%s", __func__);
753 portdata = usb_get_serial_port_data(port); 754 portdata = usb_get_serial_port_data(port);
754 755
755 portdata->rts_state = 0; 756 portdata->rts_state = 0;
@@ -782,7 +783,7 @@ static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
782 783
783 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ 784 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
784 if (urb == NULL) { 785 if (urb == NULL) {
785 dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint); 786 dbg("%s: alloc for endpoint %d failed.", __func__, endpoint);
786 return NULL; 787 return NULL;
787 } 788 }
788 789
@@ -801,7 +802,7 @@ static void option_setup_urbs(struct usb_serial *serial)
801 struct usb_serial_port *port; 802 struct usb_serial_port *port;
802 struct option_port_private *portdata; 803 struct option_port_private *portdata;
803 804
804 dbg("%s", __FUNCTION__); 805 dbg("%s", __func__);
805 806
806 for (i = 0; i < serial->num_ports; i++) { 807 for (i = 0; i < serial->num_ports; i++) {
807 port = serial->port[i]; 808 port = serial->port[i];
@@ -823,15 +824,18 @@ static void option_setup_urbs(struct usb_serial *serial)
823 } 824 }
824} 825}
825 826
827
828/** send RTS/DTR state to the port.
829 *
830 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN
831 * CDC.
832*/
826static int option_send_setup(struct usb_serial_port *port) 833static int option_send_setup(struct usb_serial_port *port)
827{ 834{
828 struct usb_serial *serial = port->serial; 835 struct usb_serial *serial = port->serial;
829 struct option_port_private *portdata; 836 struct option_port_private *portdata;
830 837 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
831 dbg("%s", __FUNCTION__); 838 dbg("%s", __func__);
832
833 if (port->number != 0)
834 return 0;
835 839
836 portdata = usb_get_serial_port_data(port); 840 portdata = usb_get_serial_port_data(port);
837 841
@@ -844,7 +848,7 @@ static int option_send_setup(struct usb_serial_port *port)
844 848
845 return usb_control_msg(serial->dev, 849 return usb_control_msg(serial->dev,
846 usb_rcvctrlpipe(serial->dev, 0), 850 usb_rcvctrlpipe(serial->dev, 0),
847 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); 851 0x22,0x21,val,ifNum,NULL,0,USB_CTRL_SET_TIMEOUT);
848 } 852 }
849 853
850 return 0; 854 return 0;
@@ -857,7 +861,7 @@ static int option_startup(struct usb_serial *serial)
857 struct option_port_private *portdata; 861 struct option_port_private *portdata;
858 u8 *buffer; 862 u8 *buffer;
859 863
860 dbg("%s", __FUNCTION__); 864 dbg("%s", __func__);
861 865
862 /* Now setup per port private data */ 866 /* Now setup per port private data */
863 for (i = 0; i < serial->num_ports; i++) { 867 for (i = 0; i < serial->num_ports; i++) {
@@ -865,7 +869,7 @@ static int option_startup(struct usb_serial *serial)
865 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); 869 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
866 if (!portdata) { 870 if (!portdata) {
867 dbg("%s: kmalloc for option_port_private (%d) failed!.", 871 dbg("%s: kmalloc for option_port_private (%d) failed!.",
868 __FUNCTION__, i); 872 __func__, i);
869 return (1); 873 return (1);
870 } 874 }
871 875
@@ -890,7 +894,7 @@ static int option_startup(struct usb_serial *serial)
890 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 894 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
891 if (err) 895 if (err)
892 dbg("%s: submit irq_in urb failed %d", 896 dbg("%s: submit irq_in urb failed %d",
893 __FUNCTION__, err); 897 __func__, err);
894 } 898 }
895 899
896 option_setup_urbs(serial); 900 option_setup_urbs(serial);
@@ -914,7 +918,7 @@ static void option_shutdown(struct usb_serial *serial)
914 struct usb_serial_port *port; 918 struct usb_serial_port *port;
915 struct option_port_private *portdata; 919 struct option_port_private *portdata;
916 920
917 dbg("%s", __FUNCTION__); 921 dbg("%s", __func__);
918 922
919 /* Stop reading/writing urbs */ 923 /* Stop reading/writing urbs */
920 for (i = 0; i < serial->num_ports; ++i) { 924 for (i = 0; i < serial->num_ports; ++i) {
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index a3847d6c946e..d92bb6501c84 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -179,9 +179,6 @@ static struct usb_serial_driver oti6858_device = {
179 .name = "oti6858", 179 .name = "oti6858",
180 }, 180 },
181 .id_table = id_table, 181 .id_table = id_table,
182 .num_interrupt_in = 1,
183 .num_bulk_in = 1,
184 .num_bulk_out = 1,
185 .num_ports = 1, 182 .num_ports = 1,
186 .open = oti6858_open, 183 .open = oti6858_open,
187 .close = oti6858_close, 184 .close = oti6858_close,
@@ -238,10 +235,10 @@ static void setup_line(struct work_struct *work)
238 unsigned long flags; 235 unsigned long flags;
239 int result; 236 int result;
240 237
241 dbg("%s(port = %d)", __FUNCTION__, port->number); 238 dbg("%s(port = %d)", __func__, port->number);
242 239
243 if ((new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { 240 if ((new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) {
244 dev_err(&port->dev, "%s(): out of memory!\n", __FUNCTION__); 241 dev_err(&port->dev, "%s(): out of memory!\n", __func__);
245 /* we will try again */ 242 /* we will try again */
246 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); 243 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2));
247 return; 244 return;
@@ -256,7 +253,7 @@ static void setup_line(struct work_struct *work)
256 100); 253 100);
257 254
258 if (result != OTI6858_CTRL_PKT_SIZE) { 255 if (result != OTI6858_CTRL_PKT_SIZE) {
259 dev_err(&port->dev, "%s(): error reading status\n", __FUNCTION__); 256 dev_err(&port->dev, "%s(): error reading status\n", __func__);
260 kfree(new_setup); 257 kfree(new_setup);
261 /* we will try again */ 258 /* we will try again */
262 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); 259 schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2));
@@ -289,12 +286,12 @@ static void setup_line(struct work_struct *work)
289 priv->setup_done = 1; 286 priv->setup_done = 1;
290 spin_unlock_irqrestore(&priv->lock, flags); 287 spin_unlock_irqrestore(&priv->lock, flags);
291 288
292 dbg("%s(): submitting interrupt urb", __FUNCTION__); 289 dbg("%s(): submitting interrupt urb", __func__);
293 port->interrupt_in_urb->dev = port->serial->dev; 290 port->interrupt_in_urb->dev = port->serial->dev;
294 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 291 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
295 if (result != 0) { 292 if (result != 0) {
296 dev_err(&port->dev, "%s(): usb_submit_urb() failed" 293 dev_err(&port->dev, "%s(): usb_submit_urb() failed"
297 " with error %d\n", __FUNCTION__, result); 294 " with error %d\n", __func__, result);
298 } 295 }
299} 296}
300 297
@@ -306,7 +303,7 @@ void send_data(struct work_struct *work)
306 unsigned long flags; 303 unsigned long flags;
307 unsigned char allow; 304 unsigned char allow;
308 305
309 dbg("%s(port = %d)", __FUNCTION__, port->number); 306 dbg("%s(port = %d)", __func__, port->number);
310 307
311 spin_lock_irqsave(&priv->lock, flags); 308 spin_lock_irqsave(&priv->lock, flags);
312 if (priv->flags.write_urb_in_use) { 309 if (priv->flags.write_urb_in_use) {
@@ -334,12 +331,12 @@ void send_data(struct work_struct *work)
334 if (count == 0) { 331 if (count == 0) {
335 priv->flags.write_urb_in_use = 0; 332 priv->flags.write_urb_in_use = 0;
336 333
337 dbg("%s(): submitting interrupt urb", __FUNCTION__); 334 dbg("%s(): submitting interrupt urb", __func__);
338 port->interrupt_in_urb->dev = port->serial->dev; 335 port->interrupt_in_urb->dev = port->serial->dev;
339 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 336 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
340 if (result != 0) { 337 if (result != 0) {
341 dev_err(&port->dev, "%s(): usb_submit_urb() failed" 338 dev_err(&port->dev, "%s(): usb_submit_urb() failed"
342 " with error %d\n", __FUNCTION__, result); 339 " with error %d\n", __func__, result);
343 } 340 }
344 return; 341 return;
345 } 342 }
@@ -353,7 +350,7 @@ void send_data(struct work_struct *work)
353 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 350 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
354 if (result != 0) { 351 if (result != 0) {
355 dev_err(&port->dev, "%s(): usb_submit_urb() failed" 352 dev_err(&port->dev, "%s(): usb_submit_urb() failed"
356 " with error %d\n", __FUNCTION__, result); 353 " with error %d\n", __func__, result);
357 priv->flags.write_urb_in_use = 0; 354 priv->flags.write_urb_in_use = 0;
358 } 355 }
359 356
@@ -404,7 +401,7 @@ static int oti6858_write(struct usb_serial_port *port,
404 struct oti6858_private *priv = usb_get_serial_port_data(port); 401 struct oti6858_private *priv = usb_get_serial_port_data(port);
405 unsigned long flags; 402 unsigned long flags;
406 403
407 dbg("%s(port = %d, count = %d)", __FUNCTION__, port->number, count); 404 dbg("%s(port = %d, count = %d)", __func__, port->number, count);
408 405
409 if (!count) 406 if (!count)
410 return count; 407 return count;
@@ -422,7 +419,7 @@ static int oti6858_write_room(struct usb_serial_port *port)
422 int room = 0; 419 int room = 0;
423 unsigned long flags; 420 unsigned long flags;
424 421
425 dbg("%s(port = %d)", __FUNCTION__, port->number); 422 dbg("%s(port = %d)", __func__, port->number);
426 423
427 spin_lock_irqsave(&priv->lock, flags); 424 spin_lock_irqsave(&priv->lock, flags);
428 room = oti6858_buf_space_avail(priv->buf); 425 room = oti6858_buf_space_avail(priv->buf);
@@ -437,7 +434,7 @@ static int oti6858_chars_in_buffer(struct usb_serial_port *port)
437 int chars = 0; 434 int chars = 0;
438 unsigned long flags; 435 unsigned long flags;
439 436
440 dbg("%s(port = %d)", __FUNCTION__, port->number); 437 dbg("%s(port = %d)", __func__, port->number);
441 438
442 spin_lock_irqsave(&priv->lock, flags); 439 spin_lock_irqsave(&priv->lock, flags);
443 chars = oti6858_buf_data_avail(priv->buf); 440 chars = oti6858_buf_data_avail(priv->buf);
@@ -456,10 +453,10 @@ static void oti6858_set_termios(struct usb_serial_port *port,
456 u16 divisor; 453 u16 divisor;
457 int br; 454 int br;
458 455
459 dbg("%s(port = %d)", __FUNCTION__, port->number); 456 dbg("%s(port = %d)", __func__, port->number);
460 457
461 if (!port->tty || !port->tty->termios) { 458 if (!port->tty || !port->tty->termios) {
462 dbg("%s(): no tty structures", __FUNCTION__); 459 dbg("%s(): no tty structures", __func__);
463 return; 460 return;
464 } 461 }
465 462
@@ -575,7 +572,7 @@ static int oti6858_open(struct usb_serial_port *port, struct file *filp)
575 unsigned long flags; 572 unsigned long flags;
576 int result; 573 int result;
577 574
578 dbg("%s(port = %d)", __FUNCTION__, port->number); 575 dbg("%s(port = %d)", __func__, port->number);
579 576
580 usb_clear_halt(serial->dev, port->write_urb->pipe); 577 usb_clear_halt(serial->dev, port->write_urb->pipe);
581 usb_clear_halt(serial->dev, port->read_urb->pipe); 578 usb_clear_halt(serial->dev, port->read_urb->pipe);
@@ -584,7 +581,7 @@ static int oti6858_open(struct usb_serial_port *port, struct file *filp)
584 return 0; 581 return 0;
585 582
586 if ((buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { 583 if ((buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) {
587 dev_err(&port->dev, "%s(): out of memory!\n", __FUNCTION__); 584 dev_err(&port->dev, "%s(): out of memory!\n", __func__);
588 return -ENOMEM; 585 return -ENOMEM;
589 } 586 }
590 587
@@ -613,12 +610,12 @@ static int oti6858_open(struct usb_serial_port *port, struct file *filp)
613 spin_unlock_irqrestore(&priv->lock, flags); 610 spin_unlock_irqrestore(&priv->lock, flags);
614 kfree(buf); 611 kfree(buf);
615 612
616 dbg("%s(): submitting interrupt urb", __FUNCTION__); 613 dbg("%s(): submitting interrupt urb", __func__);
617 port->interrupt_in_urb->dev = serial->dev; 614 port->interrupt_in_urb->dev = serial->dev;
618 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 615 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
619 if (result != 0) { 616 if (result != 0) {
620 dev_err(&port->dev, "%s(): usb_submit_urb() failed" 617 dev_err(&port->dev, "%s(): usb_submit_urb() failed"
621 " with error %d\n", __FUNCTION__, result); 618 " with error %d\n", __func__, result);
622 oti6858_close(port, NULL); 619 oti6858_close(port, NULL);
623 return -EPROTO; 620 return -EPROTO;
624 } 621 }
@@ -637,14 +634,14 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
637 long timeout; 634 long timeout;
638 wait_queue_t wait; 635 wait_queue_t wait;
639 636
640 dbg("%s(port = %d)", __FUNCTION__, port->number); 637 dbg("%s(port = %d)", __func__, port->number);
641 638
642 /* wait for data to drain from the buffer */ 639 /* wait for data to drain from the buffer */
643 spin_lock_irqsave(&priv->lock, flags); 640 spin_lock_irqsave(&priv->lock, flags);
644 timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */ 641 timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */
645 init_waitqueue_entry(&wait, current); 642 init_waitqueue_entry(&wait, current);
646 add_wait_queue(&port->tty->write_wait, &wait); 643 add_wait_queue(&port->tty->write_wait, &wait);
647 dbg("%s(): entering wait loop", __FUNCTION__); 644 dbg("%s(): entering wait loop", __func__);
648 for (;;) { 645 for (;;) {
649 set_current_state(TASK_INTERRUPTIBLE); 646 set_current_state(TASK_INTERRUPTIBLE);
650 if (oti6858_buf_data_avail(priv->buf) == 0 647 if (oti6858_buf_data_avail(priv->buf) == 0
@@ -657,7 +654,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
657 } 654 }
658 set_current_state(TASK_RUNNING); 655 set_current_state(TASK_RUNNING);
659 remove_wait_queue(&port->tty->write_wait, &wait); 656 remove_wait_queue(&port->tty->write_wait, &wait);
660 dbg("%s(): after wait loop", __FUNCTION__); 657 dbg("%s(): after wait loop", __func__);
661 658
662 /* clear out any remaining data in the buffer */ 659 /* clear out any remaining data in the buffer */
663 oti6858_buf_clear(priv->buf); 660 oti6858_buf_clear(priv->buf);
@@ -678,7 +675,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
678 */ 675 */
679 timeout = 2*HZ; 676 timeout = 2*HZ;
680 schedule_timeout_interruptible(timeout); 677 schedule_timeout_interruptible(timeout);
681 dbg("%s(): after schedule_timeout_interruptible()", __FUNCTION__); 678 dbg("%s(): after schedule_timeout_interruptible()", __func__);
682 679
683 /* cancel scheduled setup */ 680 /* cancel scheduled setup */
684 cancel_delayed_work(&priv->delayed_setup_work); 681 cancel_delayed_work(&priv->delayed_setup_work);
@@ -686,7 +683,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
686 flush_scheduled_work(); 683 flush_scheduled_work();
687 684
688 /* shutdown our urbs */ 685 /* shutdown our urbs */
689 dbg("%s(): shutting down urbs", __FUNCTION__); 686 dbg("%s(): shutting down urbs", __func__);
690 usb_kill_urb(port->write_urb); 687 usb_kill_urb(port->write_urb);
691 usb_kill_urb(port->read_urb); 688 usb_kill_urb(port->read_urb);
692 usb_kill_urb(port->interrupt_in_urb); 689 usb_kill_urb(port->interrupt_in_urb);
@@ -709,7 +706,7 @@ static int oti6858_tiocmset(struct usb_serial_port *port, struct file *file,
709 u8 control; 706 u8 control;
710 707
711 dbg("%s(port = %d, set = 0x%08x, clear = 0x%08x)", 708 dbg("%s(port = %d, set = 0x%08x, clear = 0x%08x)",
712 __FUNCTION__, port->number, set, clear); 709 __func__, port->number, set, clear);
713 710
714 if (!usb_get_intfdata(port->serial->interface)) 711 if (!usb_get_intfdata(port->serial->interface))
715 return -ENODEV; 712 return -ENODEV;
@@ -741,7 +738,7 @@ static int oti6858_tiocmget(struct usb_serial_port *port, struct file *file)
741 unsigned pin_state; 738 unsigned pin_state;
742 unsigned result = 0; 739 unsigned result = 0;
743 740
744 dbg("%s(port = %d)", __FUNCTION__, port->number); 741 dbg("%s(port = %d)", __func__, port->number);
745 742
746 if (!usb_get_intfdata(port->serial->interface)) 743 if (!usb_get_intfdata(port->serial->interface))
747 return -ENODEV; 744 return -ENODEV;
@@ -764,7 +761,7 @@ static int oti6858_tiocmget(struct usb_serial_port *port, struct file *file)
764 if ((pin_state & PIN_DCD) != 0) 761 if ((pin_state & PIN_DCD) != 0)
765 result |= TIOCM_CD; 762 result |= TIOCM_CD;
766 763
767 dbg("%s() = 0x%08x", __FUNCTION__, result); 764 dbg("%s() = 0x%08x", __func__, result);
768 765
769 return result; 766 return result;
770} 767}
@@ -811,13 +808,9 @@ static int oti6858_ioctl(struct usb_serial_port *port, struct file *file,
811 unsigned int x; 808 unsigned int x;
812 809
813 dbg("%s(port = %d, cmd = 0x%04x, arg = 0x%08lx)", 810 dbg("%s(port = %d, cmd = 0x%04x, arg = 0x%08lx)",
814 __FUNCTION__, port->number, cmd, arg); 811 __func__, port->number, cmd, arg);
815 812
816 switch (cmd) { 813 switch (cmd) {
817 case TCFLSH:
818 /* FIXME */
819 return 0;
820
821 case TIOCMBIS: 814 case TIOCMBIS:
822 if (copy_from_user(&x, user_arg, sizeof(x))) 815 if (copy_from_user(&x, user_arg, sizeof(x)))
823 return -EFAULT; 816 return -EFAULT;
@@ -829,11 +822,11 @@ static int oti6858_ioctl(struct usb_serial_port *port, struct file *file,
829 return oti6858_tiocmset(port, NULL, 0, x); 822 return oti6858_tiocmset(port, NULL, 0, x);
830 823
831 case TIOCMIWAIT: 824 case TIOCMIWAIT:
832 dbg("%s(): TIOCMIWAIT", __FUNCTION__); 825 dbg("%s(): TIOCMIWAIT", __func__);
833 return wait_modem_info(port, arg); 826 return wait_modem_info(port, arg);
834 827
835 default: 828 default:
836 dbg("%s(): 0x%04x not supported", __FUNCTION__, cmd); 829 dbg("%s(): 0x%04x not supported", __func__, cmd);
837 break; 830 break;
838 } 831 }
839 832
@@ -844,10 +837,10 @@ static void oti6858_break_ctl(struct usb_serial_port *port, int break_state)
844{ 837{
845 int state; 838 int state;
846 839
847 dbg("%s(port = %d)", __FUNCTION__, port->number); 840 dbg("%s(port = %d)", __func__, port->number);
848 841
849 state = (break_state == 0) ? 0 : 1; 842 state = (break_state == 0) ? 0 : 1;
850 dbg("%s(): turning break %s", __FUNCTION__, state ? "on" : "off"); 843 dbg("%s(): turning break %s", __func__, state ? "on" : "off");
851 844
852 /* FIXME */ 845 /* FIXME */
853/* 846/*
@@ -855,7 +848,7 @@ static void oti6858_break_ctl(struct usb_serial_port *port, int break_state)
855 BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 848 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
856 0, NULL, 0, 100); 849 0, NULL, 0, 100);
857 if (result != 0) 850 if (result != 0)
858 dbg("%s(): error sending break", __FUNCTION__); 851 dbg("%s(): error sending break", __func__);
859 */ 852 */
860} 853}
861 854
@@ -864,7 +857,7 @@ static void oti6858_shutdown(struct usb_serial *serial)
864 struct oti6858_private *priv; 857 struct oti6858_private *priv;
865 int i; 858 int i;
866 859
867 dbg("%s()", __FUNCTION__); 860 dbg("%s()", __func__);
868 861
869 for (i = 0; i < serial->num_ports; ++i) { 862 for (i = 0; i < serial->num_ports; ++i) {
870 priv = usb_get_serial_port_data(serial->port[i]); 863 priv = usb_get_serial_port_data(serial->port[i]);
@@ -878,13 +871,13 @@ static void oti6858_shutdown(struct usb_serial *serial)
878 871
879static void oti6858_read_int_callback(struct urb *urb) 872static void oti6858_read_int_callback(struct urb *urb)
880{ 873{
881 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 874 struct usb_serial_port *port = urb->context;
882 struct oti6858_private *priv = usb_get_serial_port_data(port); 875 struct oti6858_private *priv = usb_get_serial_port_data(port);
883 int transient = 0, can_recv = 0, resubmit = 1; 876 int transient = 0, can_recv = 0, resubmit = 1;
884 int status = urb->status; 877 int status = urb->status;
885 878
886 dbg("%s(port = %d, status = %d)", 879 dbg("%s(port = %d, status = %d)",
887 __FUNCTION__, port->number, status); 880 __func__, port->number, status);
888 881
889 switch (status) { 882 switch (status) {
890 case 0: 883 case 0:
@@ -895,11 +888,11 @@ static void oti6858_read_int_callback(struct urb *urb)
895 case -ESHUTDOWN: 888 case -ESHUTDOWN:
896 /* this urb is terminated, clean up */ 889 /* this urb is terminated, clean up */
897 dbg("%s(): urb shutting down with status: %d", 890 dbg("%s(): urb shutting down with status: %d",
898 __FUNCTION__, status); 891 __func__, status);
899 return; 892 return;
900 default: 893 default:
901 dbg("%s(): nonzero urb status received: %d", 894 dbg("%s(): nonzero urb status received: %d",
902 __FUNCTION__, status); 895 __func__, status);
903 break; 896 break;
904 } 897 }
905 898
@@ -916,7 +909,7 @@ static void oti6858_read_int_callback(struct urb *urb)
916 priv->setup_done = 0; 909 priv->setup_done = 0;
917 resubmit = 0; 910 resubmit = 0;
918 dbg("%s(): scheduling setup_line()", 911 dbg("%s(): scheduling setup_line()",
919 __FUNCTION__); 912 __func__);
920 schedule_delayed_work(&priv->delayed_setup_work, 0); 913 schedule_delayed_work(&priv->delayed_setup_work, 0);
921 } 914 }
922 } 915 }
@@ -931,7 +924,7 @@ static void oti6858_read_int_callback(struct urb *urb)
931 priv->setup_done = 0; 924 priv->setup_done = 0;
932 resubmit = 0; 925 resubmit = 0;
933 dbg("%s(): scheduling setup_line()", 926 dbg("%s(): scheduling setup_line()",
934 __FUNCTION__); 927 __func__);
935 schedule_delayed_work(&priv->delayed_setup_work, 0); 928 schedule_delayed_work(&priv->delayed_setup_work, 0);
936 } 929 }
937 } 930 }
@@ -960,7 +953,7 @@ static void oti6858_read_int_callback(struct urb *urb)
960 if (result != 0) { 953 if (result != 0) {
961 priv->flags.read_urb_in_use = 0; 954 priv->flags.read_urb_in_use = 0;
962 dev_err(&port->dev, "%s(): usb_submit_urb() failed," 955 dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
963 " error %d\n", __FUNCTION__, result); 956 " error %d\n", __func__, result);
964 } else { 957 } else {
965 resubmit = 0; 958 resubmit = 0;
966 } 959 }
@@ -979,20 +972,20 @@ static void oti6858_read_int_callback(struct urb *urb)
979 if (resubmit) { 972 if (resubmit) {
980 int result; 973 int result;
981 974
982// dbg("%s(): submitting interrupt urb", __FUNCTION__); 975// dbg("%s(): submitting interrupt urb", __func__);
983 urb->dev = port->serial->dev; 976 urb->dev = port->serial->dev;
984 result = usb_submit_urb(urb, GFP_ATOMIC); 977 result = usb_submit_urb(urb, GFP_ATOMIC);
985 if (result != 0) { 978 if (result != 0) {
986 dev_err(&urb->dev->dev, 979 dev_err(&urb->dev->dev,
987 "%s(): usb_submit_urb() failed with" 980 "%s(): usb_submit_urb() failed with"
988 " error %d\n", __FUNCTION__, result); 981 " error %d\n", __func__, result);
989 } 982 }
990 } 983 }
991} 984}
992 985
993static void oti6858_read_bulk_callback(struct urb *urb) 986static void oti6858_read_bulk_callback(struct urb *urb)
994{ 987{
995 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 988 struct usb_serial_port *port = urb->context;
996 struct oti6858_private *priv = usb_get_serial_port_data(port); 989 struct oti6858_private *priv = usb_get_serial_port_data(port);
997 struct tty_struct *tty; 990 struct tty_struct *tty;
998 unsigned char *data = urb->transfer_buffer; 991 unsigned char *data = urb->transfer_buffer;
@@ -1001,7 +994,7 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1001 int result; 994 int result;
1002 995
1003 dbg("%s(port = %d, status = %d)", 996 dbg("%s(port = %d, status = %d)",
1004 __FUNCTION__, port->number, status); 997 __func__, port->number, status);
1005 998
1006 spin_lock_irqsave(&priv->lock, flags); 999 spin_lock_irqsave(&priv->lock, flags);
1007 priv->flags.read_urb_in_use = 0; 1000 priv->flags.read_urb_in_use = 0;
@@ -1009,20 +1002,20 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1009 1002
1010 if (status != 0) { 1003 if (status != 0) {
1011 if (!port->open_count) { 1004 if (!port->open_count) {
1012 dbg("%s(): port is closed, exiting", __FUNCTION__); 1005 dbg("%s(): port is closed, exiting", __func__);
1013 return; 1006 return;
1014 } 1007 }
1015 /* 1008 /*
1016 if (status == -EPROTO) { 1009 if (status == -EPROTO) {
1017 // PL2303 mysteriously fails with -EPROTO reschedule the read 1010 // PL2303 mysteriously fails with -EPROTO reschedule the read
1018 dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__); 1011 dbg("%s - caught -EPROTO, resubmitting the urb", __func__);
1019 result = usb_submit_urb(urb, GFP_ATOMIC); 1012 result = usb_submit_urb(urb, GFP_ATOMIC);
1020 if (result) 1013 if (result)
1021 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 1014 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
1022 return; 1015 return;
1023 } 1016 }
1024 */ 1017 */
1025 dbg("%s(): unable to handle the error, exiting", __FUNCTION__); 1018 dbg("%s(): unable to handle the error, exiting", __func__);
1026 return; 1019 return;
1027 } 1020 }
1028 1021
@@ -1038,20 +1031,20 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1038 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1031 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1039 if (result != 0) { 1032 if (result != 0) {
1040 dev_err(&port->dev, "%s(): usb_submit_urb() failed," 1033 dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
1041 " error %d\n", __FUNCTION__, result); 1034 " error %d\n", __func__, result);
1042 } 1035 }
1043 } 1036 }
1044} 1037}
1045 1038
1046static void oti6858_write_bulk_callback(struct urb *urb) 1039static void oti6858_write_bulk_callback(struct urb *urb)
1047{ 1040{
1048 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 1041 struct usb_serial_port *port = urb->context;
1049 struct oti6858_private *priv = usb_get_serial_port_data(port); 1042 struct oti6858_private *priv = usb_get_serial_port_data(port);
1050 int status = urb->status; 1043 int status = urb->status;
1051 int result; 1044 int result;
1052 1045
1053 dbg("%s(port = %d, status = %d)", 1046 dbg("%s(port = %d, status = %d)",
1054 __FUNCTION__, port->number, status); 1047 __func__, port->number, status);
1055 1048
1056 switch (status) { 1049 switch (status) {
1057 case 0: 1050 case 0:
@@ -1062,21 +1055,21 @@ static void oti6858_write_bulk_callback(struct urb *urb)
1062 case -ESHUTDOWN: 1055 case -ESHUTDOWN:
1063 /* this urb is terminated, clean up */ 1056 /* this urb is terminated, clean up */
1064 dbg("%s(): urb shutting down with status: %d", 1057 dbg("%s(): urb shutting down with status: %d",
1065 __FUNCTION__, status); 1058 __func__, status);
1066 priv->flags.write_urb_in_use = 0; 1059 priv->flags.write_urb_in_use = 0;
1067 return; 1060 return;
1068 default: 1061 default:
1069 /* error in the urb, so we have to resubmit it */ 1062 /* error in the urb, so we have to resubmit it */
1070 dbg("%s(): nonzero write bulk status received: %d", 1063 dbg("%s(): nonzero write bulk status received: %d",
1071 __FUNCTION__, status); 1064 __func__, status);
1072 dbg("%s(): overflow in write", __FUNCTION__); 1065 dbg("%s(): overflow in write", __func__);
1073 1066
1074 port->write_urb->transfer_buffer_length = 1; 1067 port->write_urb->transfer_buffer_length = 1;
1075 port->write_urb->dev = port->serial->dev; 1068 port->write_urb->dev = port->serial->dev;
1076 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 1069 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1077 if (result) { 1070 if (result) {
1078 dev_err(&port->dev, "%s(): usb_submit_urb() failed," 1071 dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
1079 " error %d\n", __FUNCTION__, result); 1072 " error %d\n", __func__, result);
1080 } else { 1073 } else {
1081 return; 1074 return;
1082 } 1075 }
@@ -1086,11 +1079,11 @@ static void oti6858_write_bulk_callback(struct urb *urb)
1086 1079
1087 // schedule the interrupt urb if we are still open */ 1080 // schedule the interrupt urb if we are still open */
1088 port->interrupt_in_urb->dev = port->serial->dev; 1081 port->interrupt_in_urb->dev = port->serial->dev;
1089 dbg("%s(): submitting interrupt urb", __FUNCTION__); 1082 dbg("%s(): submitting interrupt urb", __func__);
1090 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1083 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1091 if (result != 0) { 1084 if (result != 0) {
1092 dev_err(&port->dev, "%s(): failed submitting int urb," 1085 dev_err(&port->dev, "%s(): failed submitting int urb,"
1093 " error %d\n", __FUNCTION__, result); 1086 " error %d\n", __func__, result);
1094 } 1087 }
1095} 1088}
1096 1089
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 2af778555bdc..c605fb68f807 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -410,7 +410,7 @@ static int set_control_lines(struct usb_device *dev, u8 value)
410 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 410 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
411 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, 411 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
412 value, 0, NULL, 0, 100); 412 value, 0, NULL, 0, 100);
413 dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval); 413 dbg("%s - value = %d, retval = %d", __func__, value, retval);
414 return retval; 414 return retval;
415} 415}
416 416
@@ -420,7 +420,7 @@ static void pl2303_send(struct usb_serial_port *port)
420 struct pl2303_private *priv = usb_get_serial_port_data(port); 420 struct pl2303_private *priv = usb_get_serial_port_data(port);
421 unsigned long flags; 421 unsigned long flags;
422 422
423 dbg("%s - port %d", __FUNCTION__, port->number); 423 dbg("%s - port %d", __func__, port->number);
424 424
425 spin_lock_irqsave(&priv->lock, flags); 425 spin_lock_irqsave(&priv->lock, flags);
426 426
@@ -441,7 +441,7 @@ static void pl2303_send(struct usb_serial_port *port)
441 441
442 spin_unlock_irqrestore(&priv->lock, flags); 442 spin_unlock_irqrestore(&priv->lock, flags);
443 443
444 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, 444 usb_serial_debug_data(debug, &port->dev, __func__, count,
445 port->write_urb->transfer_buffer); 445 port->write_urb->transfer_buffer);
446 446
447 port->write_urb->transfer_buffer_length = count; 447 port->write_urb->transfer_buffer_length = count;
@@ -449,7 +449,7 @@ static void pl2303_send(struct usb_serial_port *port)
449 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 449 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
450 if (result) { 450 if (result) {
451 dev_err(&port->dev, "%s - failed submitting write urb," 451 dev_err(&port->dev, "%s - failed submitting write urb,"
452 " error %d\n", __FUNCTION__, result); 452 " error %d\n", __func__, result);
453 priv->write_urb_in_use = 0; 453 priv->write_urb_in_use = 0;
454 // TODO: reschedule pl2303_send 454 // TODO: reschedule pl2303_send
455 } 455 }
@@ -463,7 +463,7 @@ static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf,
463 struct pl2303_private *priv = usb_get_serial_port_data(port); 463 struct pl2303_private *priv = usb_get_serial_port_data(port);
464 unsigned long flags; 464 unsigned long flags;
465 465
466 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); 466 dbg("%s - port %d, %d bytes", __func__, port->number, count);
467 467
468 if (!count) 468 if (!count)
469 return count; 469 return count;
@@ -483,13 +483,13 @@ static int pl2303_write_room(struct usb_serial_port *port)
483 int room = 0; 483 int room = 0;
484 unsigned long flags; 484 unsigned long flags;
485 485
486 dbg("%s - port %d", __FUNCTION__, port->number); 486 dbg("%s - port %d", __func__, port->number);
487 487
488 spin_lock_irqsave(&priv->lock, flags); 488 spin_lock_irqsave(&priv->lock, flags);
489 room = pl2303_buf_space_avail(priv->buf); 489 room = pl2303_buf_space_avail(priv->buf);
490 spin_unlock_irqrestore(&priv->lock, flags); 490 spin_unlock_irqrestore(&priv->lock, flags);
491 491
492 dbg("%s - returns %d", __FUNCTION__, room); 492 dbg("%s - returns %d", __func__, room);
493 return room; 493 return room;
494} 494}
495 495
@@ -499,13 +499,13 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port)
499 int chars = 0; 499 int chars = 0;
500 unsigned long flags; 500 unsigned long flags;
501 501
502 dbg("%s - port %d", __FUNCTION__, port->number); 502 dbg("%s - port %d", __func__, port->number);
503 503
504 spin_lock_irqsave(&priv->lock, flags); 504 spin_lock_irqsave(&priv->lock, flags);
505 chars = pl2303_buf_data_avail(priv->buf); 505 chars = pl2303_buf_data_avail(priv->buf);
506 spin_unlock_irqrestore(&priv->lock, flags); 506 spin_unlock_irqrestore(&priv->lock, flags);
507 507
508 dbg("%s - returns %d", __FUNCTION__, chars); 508 dbg("%s - returns %d", __func__, chars);
509 return chars; 509 return chars;
510} 510}
511 511
@@ -521,7 +521,7 @@ static void pl2303_set_termios(struct usb_serial_port *port,
521 int i; 521 int i;
522 u8 control; 522 u8 control;
523 523
524 dbg("%s - port %d", __FUNCTION__, port->number); 524 dbg("%s - port %d", __func__, port->number);
525 525
526 spin_lock_irqsave(&priv->lock, flags); 526 spin_lock_irqsave(&priv->lock, flags);
527 if (!priv->termios_initialized) { 527 if (!priv->termios_initialized) {
@@ -545,7 +545,9 @@ static void pl2303_set_termios(struct usb_serial_port *port,
545 545
546 buf = kzalloc(7, GFP_KERNEL); 546 buf = kzalloc(7, GFP_KERNEL);
547 if (!buf) { 547 if (!buf) {
548 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); 548 dev_err(&port->dev, "%s - out of memory.\n", __func__);
549 /* Report back no change occurred */
550 *port->tty->termios = *old_termios;
549 return; 551 return;
550 } 552 }
551 553
@@ -563,11 +565,11 @@ static void pl2303_set_termios(struct usb_serial_port *port,
563 default: 565 default:
564 case CS8: buf[6] = 8; break; 566 case CS8: buf[6] = 8; break;
565 } 567 }
566 dbg("%s - data bits = %d", __FUNCTION__, buf[6]); 568 dbg("%s - data bits = %d", __func__, buf[6]);
567 } 569 }
568 570
569 baud = tty_get_baud_rate(port->tty);; 571 baud = tty_get_baud_rate(port->tty);;
570 dbg("%s - baud = %d", __FUNCTION__, baud); 572 dbg("%s - baud = %d", __func__, baud);
571 if (baud) { 573 if (baud) {
572 buf[0] = baud & 0xff; 574 buf[0] = baud & 0xff;
573 buf[1] = (baud >> 8) & 0xff; 575 buf[1] = (baud >> 8) & 0xff;
@@ -580,10 +582,10 @@ static void pl2303_set_termios(struct usb_serial_port *port,
580 /* For reference buf[4]=2 is 2 stop bits */ 582 /* For reference buf[4]=2 is 2 stop bits */
581 if (cflag & CSTOPB) { 583 if (cflag & CSTOPB) {
582 buf[4] = 2; 584 buf[4] = 2;
583 dbg("%s - stop bits = 2", __FUNCTION__); 585 dbg("%s - stop bits = 2", __func__);
584 } else { 586 } else {
585 buf[4] = 0; 587 buf[4] = 0;
586 dbg("%s - stop bits = 1", __FUNCTION__); 588 dbg("%s - stop bits = 1", __func__);
587 } 589 }
588 590
589 if (cflag & PARENB) { 591 if (cflag & PARENB) {
@@ -594,14 +596,14 @@ static void pl2303_set_termios(struct usb_serial_port *port,
594 /* For reference buf[5]=4 is space parity */ 596 /* For reference buf[5]=4 is space parity */
595 if (cflag & PARODD) { 597 if (cflag & PARODD) {
596 buf[5] = 1; 598 buf[5] = 1;
597 dbg("%s - parity = odd", __FUNCTION__); 599 dbg("%s - parity = odd", __func__);
598 } else { 600 } else {
599 buf[5] = 2; 601 buf[5] = 2;
600 dbg("%s - parity = even", __FUNCTION__); 602 dbg("%s - parity = even", __func__);
601 } 603 }
602 } else { 604 } else {
603 buf[5] = 0; 605 buf[5] = 0;
604 dbg("%s - parity = none", __FUNCTION__); 606 dbg("%s - parity = none", __func__);
605 } 607 }
606 608
607 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 609 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
@@ -657,7 +659,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
657 long timeout; 659 long timeout;
658 wait_queue_t wait; 660 wait_queue_t wait;
659 661
660 dbg("%s - port %d", __FUNCTION__, port->number); 662 dbg("%s - port %d", __func__, port->number);
661 663
662 /* wait for data to drain from the buffer */ 664 /* wait for data to drain from the buffer */
663 spin_lock_irqsave(&priv->lock, flags); 665 spin_lock_irqsave(&priv->lock, flags);
@@ -695,7 +697,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
695 schedule_timeout_interruptible(timeout); 697 schedule_timeout_interruptible(timeout);
696 698
697 /* shutdown our urbs */ 699 /* shutdown our urbs */
698 dbg("%s - shutting down urbs", __FUNCTION__); 700 dbg("%s - shutting down urbs", __func__);
699 usb_kill_urb(port->write_urb); 701 usb_kill_urb(port->write_urb);
700 usb_kill_urb(port->read_urb); 702 usb_kill_urb(port->read_urb);
701 usb_kill_urb(port->interrupt_in_urb); 703 usb_kill_urb(port->interrupt_in_urb);
@@ -719,7 +721,7 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
719 struct pl2303_private *priv = usb_get_serial_port_data(port); 721 struct pl2303_private *priv = usb_get_serial_port_data(port);
720 int result; 722 int result;
721 723
722 dbg("%s - port %d", __FUNCTION__, port->number); 724 dbg("%s - port %d", __func__, port->number);
723 725
724 if (priv->type != HX) { 726 if (priv->type != HX) {
725 usb_clear_halt(serial->dev, port->write_urb->pipe); 727 usb_clear_halt(serial->dev, port->write_urb->pipe);
@@ -737,22 +739,22 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
737 739
738 //FIXME: need to assert RTS and DTR if CRTSCTS off 740 //FIXME: need to assert RTS and DTR if CRTSCTS off
739 741
740 dbg("%s - submitting read urb", __FUNCTION__); 742 dbg("%s - submitting read urb", __func__);
741 port->read_urb->dev = serial->dev; 743 port->read_urb->dev = serial->dev;
742 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 744 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
743 if (result) { 745 if (result) {
744 dev_err(&port->dev, "%s - failed submitting read urb," 746 dev_err(&port->dev, "%s - failed submitting read urb,"
745 " error %d\n", __FUNCTION__, result); 747 " error %d\n", __func__, result);
746 pl2303_close(port, NULL); 748 pl2303_close(port, NULL);
747 return -EPROTO; 749 return -EPROTO;
748 } 750 }
749 751
750 dbg("%s - submitting interrupt urb", __FUNCTION__); 752 dbg("%s - submitting interrupt urb", __func__);
751 port->interrupt_in_urb->dev = serial->dev; 753 port->interrupt_in_urb->dev = serial->dev;
752 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 754 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
753 if (result) { 755 if (result) {
754 dev_err(&port->dev, "%s - failed submitting interrupt urb," 756 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
755 " error %d\n", __FUNCTION__, result); 757 " error %d\n", __func__, result);
756 pl2303_close(port, NULL); 758 pl2303_close(port, NULL);
757 return -EPROTO; 759 return -EPROTO;
758 } 760 }
@@ -792,7 +794,7 @@ static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file)
792 unsigned int status; 794 unsigned int status;
793 unsigned int result; 795 unsigned int result;
794 796
795 dbg("%s (%d)", __FUNCTION__, port->number); 797 dbg("%s (%d)", __func__, port->number);
796 798
797 if (!usb_get_intfdata(port->serial->interface)) 799 if (!usb_get_intfdata(port->serial->interface))
798 return -ENODEV; 800 return -ENODEV;
@@ -809,7 +811,7 @@ static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file)
809 | ((status & UART_RING) ? TIOCM_RI : 0) 811 | ((status & UART_RING) ? TIOCM_RI : 0)
810 | ((status & UART_DCD) ? TIOCM_CD : 0); 812 | ((status & UART_DCD) ? TIOCM_CD : 0);
811 813
812 dbg("%s - result = %x", __FUNCTION__, result); 814 dbg("%s - result = %x", __func__, result);
813 815
814 return result; 816 return result;
815} 817}
@@ -853,15 +855,15 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
853static int pl2303_ioctl(struct usb_serial_port *port, struct file *file, 855static int pl2303_ioctl(struct usb_serial_port *port, struct file *file,
854 unsigned int cmd, unsigned long arg) 856 unsigned int cmd, unsigned long arg)
855{ 857{
856 dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd); 858 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
857 859
858 switch (cmd) { 860 switch (cmd) {
859 case TIOCMIWAIT: 861 case TIOCMIWAIT:
860 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number); 862 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
861 return wait_modem_info(port, arg); 863 return wait_modem_info(port, arg);
862 864
863 default: 865 default:
864 dbg("%s not supported = 0x%04x", __FUNCTION__, cmd); 866 dbg("%s not supported = 0x%04x", __func__, cmd);
865 break; 867 break;
866 } 868 }
867 869
@@ -874,19 +876,19 @@ static void pl2303_break_ctl(struct usb_serial_port *port, int break_state)
874 u16 state; 876 u16 state;
875 int result; 877 int result;
876 878
877 dbg("%s - port %d", __FUNCTION__, port->number); 879 dbg("%s - port %d", __func__, port->number);
878 880
879 if (break_state == 0) 881 if (break_state == 0)
880 state = BREAK_OFF; 882 state = BREAK_OFF;
881 else 883 else
882 state = BREAK_ON; 884 state = BREAK_ON;
883 dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on"); 885 dbg("%s - turning break %s", __func__, state==BREAK_OFF ? "off" : "on");
884 886
885 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 887 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
886 BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 888 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
887 0, NULL, 0, 100); 889 0, NULL, 0, 100);
888 if (result) 890 if (result)
889 dbg("%s - error sending break = %d", __FUNCTION__, result); 891 dbg("%s - error sending break = %d", __func__, result);
890} 892}
891 893
892static void pl2303_shutdown(struct usb_serial *serial) 894static void pl2303_shutdown(struct usb_serial *serial)
@@ -894,7 +896,7 @@ static void pl2303_shutdown(struct usb_serial *serial)
894 int i; 896 int i;
895 struct pl2303_private *priv; 897 struct pl2303_private *priv;
896 898
897 dbg("%s", __FUNCTION__); 899 dbg("%s", __func__);
898 900
899 for (i = 0; i < serial->num_ports; ++i) { 901 for (i = 0; i < serial->num_ports; ++i) {
900 priv = usb_get_serial_port_data(serial->port[i]); 902 priv = usb_get_serial_port_data(serial->port[i]);
@@ -943,13 +945,13 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
943 945
944static void pl2303_read_int_callback(struct urb *urb) 946static void pl2303_read_int_callback(struct urb *urb)
945{ 947{
946 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 948 struct usb_serial_port *port = urb->context;
947 unsigned char *data = urb->transfer_buffer; 949 unsigned char *data = urb->transfer_buffer;
948 unsigned int actual_length = urb->actual_length; 950 unsigned int actual_length = urb->actual_length;
949 int status = urb->status; 951 int status = urb->status;
950 int retval; 952 int retval;
951 953
952 dbg("%s (%d)", __FUNCTION__, port->number); 954 dbg("%s (%d)", __func__, port->number);
953 955
954 switch (status) { 956 switch (status) {
955 case 0: 957 case 0:
@@ -959,16 +961,16 @@ static void pl2303_read_int_callback(struct urb *urb)
959 case -ENOENT: 961 case -ENOENT:
960 case -ESHUTDOWN: 962 case -ESHUTDOWN:
961 /* this urb is terminated, clean up */ 963 /* this urb is terminated, clean up */
962 dbg("%s - urb shutting down with status: %d", __FUNCTION__, 964 dbg("%s - urb shutting down with status: %d", __func__,
963 status); 965 status);
964 return; 966 return;
965 default: 967 default:
966 dbg("%s - nonzero urb status received: %d", __FUNCTION__, 968 dbg("%s - nonzero urb status received: %d", __func__,
967 status); 969 status);
968 goto exit; 970 goto exit;
969 } 971 }
970 972
971 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 973 usb_serial_debug_data(debug, &port->dev, __func__,
972 urb->actual_length, urb->transfer_buffer); 974 urb->actual_length, urb->transfer_buffer);
973 975
974 pl2303_update_line_status(port, data, actual_length); 976 pl2303_update_line_status(port, data, actual_length);
@@ -978,12 +980,12 @@ exit:
978 if (retval) 980 if (retval)
979 dev_err(&urb->dev->dev, 981 dev_err(&urb->dev->dev,
980 "%s - usb_submit_urb failed with result %d\n", 982 "%s - usb_submit_urb failed with result %d\n",
981 __FUNCTION__, retval); 983 __func__, retval);
982} 984}
983 985
984static void pl2303_read_bulk_callback(struct urb *urb) 986static void pl2303_read_bulk_callback(struct urb *urb)
985{ 987{
986 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 988 struct usb_serial_port *port = urb->context;
987 struct pl2303_private *priv = usb_get_serial_port_data(port); 989 struct pl2303_private *priv = usb_get_serial_port_data(port);
988 struct tty_struct *tty; 990 struct tty_struct *tty;
989 unsigned char *data = urb->transfer_buffer; 991 unsigned char *data = urb->transfer_buffer;
@@ -994,32 +996,32 @@ static void pl2303_read_bulk_callback(struct urb *urb)
994 u8 line_status; 996 u8 line_status;
995 char tty_flag; 997 char tty_flag;
996 998
997 dbg("%s - port %d", __FUNCTION__, port->number); 999 dbg("%s - port %d", __func__, port->number);
998 1000
999 if (status) { 1001 if (status) {
1000 dbg("%s - urb status = %d", __FUNCTION__, status); 1002 dbg("%s - urb status = %d", __func__, status);
1001 if (!port->open_count) { 1003 if (!port->open_count) {
1002 dbg("%s - port is closed, exiting.", __FUNCTION__); 1004 dbg("%s - port is closed, exiting.", __func__);
1003 return; 1005 return;
1004 } 1006 }
1005 if (status == -EPROTO) { 1007 if (status == -EPROTO) {
1006 /* PL2303 mysteriously fails with -EPROTO reschedule 1008 /* PL2303 mysteriously fails with -EPROTO reschedule
1007 * the read */ 1009 * the read */
1008 dbg("%s - caught -EPROTO, resubmitting the urb", 1010 dbg("%s - caught -EPROTO, resubmitting the urb",
1009 __FUNCTION__); 1011 __func__);
1010 urb->dev = port->serial->dev; 1012 urb->dev = port->serial->dev;
1011 result = usb_submit_urb(urb, GFP_ATOMIC); 1013 result = usb_submit_urb(urb, GFP_ATOMIC);
1012 if (result) 1014 if (result)
1013 dev_err(&urb->dev->dev, "%s - failed" 1015 dev_err(&urb->dev->dev, "%s - failed"
1014 " resubmitting read urb, error %d\n", 1016 " resubmitting read urb, error %d\n",
1015 __FUNCTION__, result); 1017 __func__, result);
1016 return; 1018 return;
1017 } 1019 }
1018 dbg("%s - unable to handle the error, exiting.", __FUNCTION__); 1020 dbg("%s - unable to handle the error, exiting.", __func__);
1019 return; 1021 return;
1020 } 1022 }
1021 1023
1022 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 1024 usb_serial_debug_data(debug, &port->dev, __func__,
1023 urb->actual_length, data); 1025 urb->actual_length, data);
1024 1026
1025 /* get tty_flag from status */ 1027 /* get tty_flag from status */
@@ -1039,7 +1041,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1039 tty_flag = TTY_PARITY; 1041 tty_flag = TTY_PARITY;
1040 else if (line_status & UART_FRAME_ERROR) 1042 else if (line_status & UART_FRAME_ERROR)
1041 tty_flag = TTY_FRAME; 1043 tty_flag = TTY_FRAME;
1042 dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag); 1044 dbg("%s - tty_flag = %d", __func__, tty_flag);
1043 1045
1044 tty = port->tty; 1046 tty = port->tty;
1045 if (tty && urb->actual_length) { 1047 if (tty && urb->actual_length) {
@@ -1058,7 +1060,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1058 result = usb_submit_urb(urb, GFP_ATOMIC); 1060 result = usb_submit_urb(urb, GFP_ATOMIC);
1059 if (result) 1061 if (result)
1060 dev_err(&urb->dev->dev, "%s - failed resubmitting" 1062 dev_err(&urb->dev->dev, "%s - failed resubmitting"
1061 " read urb, error %d\n", __FUNCTION__, result); 1063 " read urb, error %d\n", __func__, result);
1062 } 1064 }
1063 1065
1064 return; 1066 return;
@@ -1066,12 +1068,12 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1066 1068
1067static void pl2303_write_bulk_callback(struct urb *urb) 1069static void pl2303_write_bulk_callback(struct urb *urb)
1068{ 1070{
1069 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 1071 struct usb_serial_port *port = urb->context;
1070 struct pl2303_private *priv = usb_get_serial_port_data(port); 1072 struct pl2303_private *priv = usb_get_serial_port_data(port);
1071 int result; 1073 int result;
1072 int status = urb->status; 1074 int status = urb->status;
1073 1075
1074 dbg("%s - port %d", __FUNCTION__, port->number); 1076 dbg("%s - port %d", __func__, port->number);
1075 1077
1076 switch (status) { 1078 switch (status) {
1077 case 0: 1079 case 0:
@@ -1081,21 +1083,21 @@ static void pl2303_write_bulk_callback(struct urb *urb)
1081 case -ENOENT: 1083 case -ENOENT:
1082 case -ESHUTDOWN: 1084 case -ESHUTDOWN:
1083 /* this urb is terminated, clean up */ 1085 /* this urb is terminated, clean up */
1084 dbg("%s - urb shutting down with status: %d", __FUNCTION__, 1086 dbg("%s - urb shutting down with status: %d", __func__,
1085 status); 1087 status);
1086 priv->write_urb_in_use = 0; 1088 priv->write_urb_in_use = 0;
1087 return; 1089 return;
1088 default: 1090 default:
1089 /* error in the urb, so we have to resubmit it */ 1091 /* error in the urb, so we have to resubmit it */
1090 dbg("%s - Overflow in write", __FUNCTION__); 1092 dbg("%s - Overflow in write", __func__);
1091 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, 1093 dbg("%s - nonzero write bulk status received: %d", __func__,
1092 status); 1094 status);
1093 port->write_urb->transfer_buffer_length = 1; 1095 port->write_urb->transfer_buffer_length = 1;
1094 port->write_urb->dev = port->serial->dev; 1096 port->write_urb->dev = port->serial->dev;
1095 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 1097 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1096 if (result) 1098 if (result)
1097 dev_err(&urb->dev->dev, "%s - failed resubmitting write" 1099 dev_err(&urb->dev->dev, "%s - failed resubmitting write"
1098 " urb, error %d\n", __FUNCTION__, result); 1100 " urb, error %d\n", __func__, result);
1099 else 1101 else
1100 return; 1102 return;
1101 } 1103 }
@@ -1114,9 +1116,6 @@ static struct usb_serial_driver pl2303_device = {
1114 }, 1116 },
1115 .id_table = id_table, 1117 .id_table = id_table,
1116 .usb_driver = &pl2303_driver, 1118 .usb_driver = &pl2303_driver,
1117 .num_interrupt_in = NUM_DONT_CARE,
1118 .num_bulk_in = 1,
1119 .num_bulk_out = 1,
1120 .num_ports = 1, 1119 .num_ports = 1,
1121 .open = pl2303_open, 1120 .open = pl2303_open,
1122 .close = pl2303_close, 1121 .close = pl2303_close,
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 4e6dcc199be9..94bddf06ea4f 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -195,18 +195,17 @@ static __u16 __inline__ fcs_compute10 (unsigned char *sp, int len, __u16 fcs)
195 195
196static void safe_read_bulk_callback (struct urb *urb) 196static void safe_read_bulk_callback (struct urb *urb)
197{ 197{
198 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 198 struct usb_serial_port *port = urb->context;
199 unsigned char *data = urb->transfer_buffer; 199 unsigned char *data = urb->transfer_buffer;
200 unsigned char length = urb->actual_length; 200 unsigned char length = urb->actual_length;
201 int i;
202 int result; 201 int result;
203 int status = urb->status; 202 int status = urb->status;
204 203
205 dbg ("%s", __FUNCTION__); 204 dbg ("%s", __func__);
206 205
207 if (status) { 206 if (status) {
208 dbg("%s - nonzero read bulk status received: %d", 207 dbg("%s - nonzero read bulk status received: %d",
209 __FUNCTION__, status); 208 __func__, status);
210 return; 209 return;
211 } 210 }
212 211
@@ -227,28 +226,20 @@ static void safe_read_bulk_callback (struct urb *urb)
227 if (safe) { 226 if (safe) {
228 __u16 fcs; 227 __u16 fcs;
229 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) { 228 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) {
230
231 int actual_length = data[length - 2] >> 2; 229 int actual_length = data[length - 2] >> 2;
232
233 if (actual_length <= (length - 2)) { 230 if (actual_length <= (length - 2)) {
234 231 info ("%s - actual: %d", __func__, actual_length);
235 info ("%s - actual: %d", __FUNCTION__, actual_length); 232 tty_insert_flip_string(port->tty, data, actual_length);
236
237 for (i = 0; i < actual_length; i++) {
238 tty_insert_flip_char (port->tty, data[i], 0);
239 }
240 tty_flip_buffer_push (port->tty); 233 tty_flip_buffer_push (port->tty);
241 } else { 234 } else {
242 err ("%s - inconsistent lengths %d:%d", __FUNCTION__, 235 err ("%s - inconsistent lengths %d:%d", __func__,
243 actual_length, length); 236 actual_length, length);
244 } 237 }
245 } else { 238 } else {
246 err ("%s - bad CRC %x", __FUNCTION__, fcs); 239 err ("%s - bad CRC %x", __func__, fcs);
247 } 240 }
248 } else { 241 } else {
249 for (i = 0; i < length; i++) { 242 tty_insert_flip_string(port->tty, data, length);
250 tty_insert_flip_char (port->tty, data[i], 0);
251 }
252 tty_flip_buffer_push (port->tty); 243 tty_flip_buffer_push (port->tty);
253 } 244 }
254 245
@@ -259,7 +250,8 @@ static void safe_read_bulk_callback (struct urb *urb)
259 safe_read_bulk_callback, port); 250 safe_read_bulk_callback, port);
260 251
261 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) { 252 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) {
262 err ("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 253 err ("%s - failed resubmitting read urb, error %d", __func__, result);
254 /* FIXME: Need a mechanism to retry later if this happens */
263 } 255 }
264} 256}
265 257
@@ -274,25 +266,25 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
274 count); 266 count);
275 267
276 if (!port->write_urb) { 268 if (!port->write_urb) {
277 dbg ("%s - write urb NULL", __FUNCTION__); 269 dbg ("%s - write urb NULL", __func__);
278 return (0); 270 return 0;
279 } 271 }
280 272
281 dbg ("safe_write write_urb: %d transfer_buffer_length", 273 dbg ("safe_write write_urb: %d transfer_buffer_length",
282 port->write_urb->transfer_buffer_length); 274 port->write_urb->transfer_buffer_length);
283 275
284 if (!port->write_urb->transfer_buffer_length) { 276 if (!port->write_urb->transfer_buffer_length) {
285 dbg ("%s - write urb transfer_buffer_length zero", __FUNCTION__); 277 dbg ("%s - write urb transfer_buffer_length zero", __func__);
286 return (0); 278 return 0;
287 } 279 }
288 if (count == 0) { 280 if (count == 0) {
289 dbg ("%s - write request of 0 bytes", __FUNCTION__); 281 dbg ("%s - write request of 0 bytes", __func__);
290 return (0); 282 return 0;
291 } 283 }
292 spin_lock_bh(&port->lock); 284 spin_lock_bh(&port->lock);
293 if (port->write_urb_busy) { 285 if (port->write_urb_busy) {
294 spin_unlock_bh(&port->lock); 286 spin_unlock_bh(&port->lock);
295 dbg("%s - already writing", __FUNCTION__); 287 dbg("%s - already writing", __func__);
296 return 0; 288 return 0;
297 } 289 }
298 port->write_urb_busy = 1; 290 port->write_urb_busy = 1;
@@ -332,7 +324,7 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
332 port->write_urb->transfer_buffer_length = count; 324 port->write_urb->transfer_buffer_length = count;
333 } 325 }
334 326
335 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); 327 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer);
336#ifdef ECHO_TX 328#ifdef ECHO_TX
337 { 329 {
338 int i; 330 int i;
@@ -349,28 +341,31 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
349 port->write_urb->dev = port->serial->dev; 341 port->write_urb->dev = port->serial->dev;
350 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { 342 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) {
351 port->write_urb_busy = 0; 343 port->write_urb_busy = 0;
352 err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); 344 err ("%s - failed submitting write urb, error %d", __func__, result);
353 return 0; 345 return 0;
354 } 346 }
355 dbg ("%s urb: %p submitted", __FUNCTION__, port->write_urb); 347 dbg ("%s urb: %p submitted", __func__, port->write_urb);
356 348
357 return (count); 349 return (count);
358} 350}
359 351
360static int safe_write_room (struct usb_serial_port *port) 352static int safe_write_room (struct usb_serial_port *port)
361{ 353{
362 int room = 0; // Default: no room 354 int room = 0; /* Default: no room */
355 unsigned long flags;
363 356
364 dbg ("%s", __FUNCTION__); 357 dbg ("%s", __func__);
365 358
359 spin_lock_irqsave(&port->lock, flags);
366 if (port->write_urb_busy) 360 if (port->write_urb_busy)
367 room = port->bulk_out_size - (safe ? 2 : 0); 361 room = port->bulk_out_size - (safe ? 2 : 0);
362 spin_unlock_irqrestore(&port->lock, flags);
368 363
369 if (room) { 364 if (room) {
370 dbg ("safe_write_room returns %d", room); 365 dbg ("safe_write_room returns %d", room);
371 } 366 }
372 367
373 return (room); 368 return room;
374} 369}
375 370
376static int safe_startup (struct usb_serial *serial) 371static int safe_startup (struct usb_serial *serial)
@@ -394,9 +389,6 @@ static struct usb_serial_driver safe_device = {
394 }, 389 },
395 .id_table = id_table, 390 .id_table = id_table,
396 .usb_driver = &safe_driver, 391 .usb_driver = &safe_driver,
397 .num_interrupt_in = NUM_DONT_CARE,
398 .num_bulk_in = NUM_DONT_CARE,
399 .num_bulk_out = NUM_DONT_CARE,
400 .num_ports = 1, 392 .num_ports = 1,
401 .write = safe_write, 393 .write = safe_write,
402 .write_room = safe_write_room, 394 .write_room = safe_write_room,
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index ed678811e6a6..29074c1ba22b 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -1,7 +1,7 @@
1/* 1/*
2 USB Driver for Sierra Wireless 2 USB Driver for Sierra Wireless
3 3
4 Copyright (C) 2006, 2007, 2008 Kevin Lloyd <linux@sierrawireless.com> 4 Copyright (C) 2006, 2007, 2008 Kevin Lloyd <klloyd@sierrawireless.com>
5 5
6 IMPORTANT DISCLAIMER: This driver is not commercially supported by 6 IMPORTANT DISCLAIMER: This driver is not commercially supported by
7 Sierra Wireless. Use at your own risk. 7 Sierra Wireless. Use at your own risk.
@@ -14,8 +14,8 @@
14 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> 14 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
15*/ 15*/
16 16
17#define DRIVER_VERSION "v.1.2.8" 17#define DRIVER_VERSION "v.1.2.9c"
18#define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>" 18#define DRIVER_AUTHOR "Kevin Lloyd <klloyd@sierrawireless.com>"
19#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" 19#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -31,7 +31,6 @@
31#define SWIMS_USB_REQUEST_SetPower 0x00 31#define SWIMS_USB_REQUEST_SetPower 0x00
32#define SWIMS_USB_REQUEST_SetNmea 0x07 32#define SWIMS_USB_REQUEST_SetNmea 0x07
33#define SWIMS_USB_REQUEST_SetMode 0x0B 33#define SWIMS_USB_REQUEST_SetMode 0x0B
34#define SWIMS_USB_REQUEST_TYPE_VSC_SET 0x40
35#define SWIMS_SET_MODE_Modem 0x0001 34#define SWIMS_SET_MODE_Modem 0x0001
36 35
37/* per port private data */ 36/* per port private data */
@@ -55,7 +54,7 @@ static int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
55 dev_dbg(&udev->dev, "%s", "SET POWER STATE\n"); 54 dev_dbg(&udev->dev, "%s", "SET POWER STATE\n");
56 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 55 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
57 SWIMS_USB_REQUEST_SetPower, /* __u8 request */ 56 SWIMS_USB_REQUEST_SetPower, /* __u8 request */
58 SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */ 57 USB_TYPE_VENDOR, /* __u8 request type */
59 swiState, /* __u16 value */ 58 swiState, /* __u16 value */
60 0, /* __u16 index */ 59 0, /* __u16 index */
61 NULL, /* void *data */ 60 NULL, /* void *data */
@@ -70,7 +69,7 @@ static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSWocMode)
70 dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n"); 69 dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n");
71 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 70 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
72 SWIMS_USB_REQUEST_SetMode, /* __u8 request */ 71 SWIMS_USB_REQUEST_SetMode, /* __u8 request */
73 SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */ 72 USB_TYPE_VENDOR, /* __u8 request type */
74 eSWocMode, /* __u16 value */ 73 eSWocMode, /* __u16 value */
75 0x0000, /* __u16 index */ 74 0x0000, /* __u16 index */
76 NULL, /* void *data */ 75 NULL, /* void *data */
@@ -85,7 +84,7 @@ static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable)
85 dev_dbg(&udev->dev, "%s", "NMEA Enable sent\n"); 84 dev_dbg(&udev->dev, "%s", "NMEA Enable sent\n");
86 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 85 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
87 SWIMS_USB_REQUEST_SetNmea, /* __u8 request */ 86 SWIMS_USB_REQUEST_SetNmea, /* __u8 request */
88 SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */ 87 USB_TYPE_VENDOR, /* __u8 request type */
89 enable, /* __u16 value */ 88 enable, /* __u16 value */
90 0x0000, /* __u16 index */ 89 0x0000, /* __u16 index */
91 NULL, /* void *data */ 90 NULL, /* void *data */
@@ -109,6 +108,26 @@ static int sierra_calc_num_ports(struct usb_serial *serial)
109 return result; 108 return result;
110} 109}
111 110
111static int sierra_calc_interface(struct usb_serial *serial)
112{
113 int interface;
114 struct usb_interface *p_interface;
115 struct usb_host_interface *p_host_interface;
116
117 /* Get the interface structure pointer from the serial struct */
118 p_interface = serial->interface;
119
120 /* Get a pointer to the host interface structure */
121 p_host_interface = p_interface->cur_altsetting;
122
123 /* read the interface descriptor for this active altsetting
124 * to find out the interface number we are on
125 */
126 interface = p_host_interface->desc.bInterfaceNumber;
127
128 return interface;
129}
130
112static int sierra_probe(struct usb_serial *serial, 131static int sierra_probe(struct usb_serial *serial,
113 const struct usb_device_id *id) 132 const struct usb_device_id *id)
114{ 133{
@@ -124,6 +143,22 @@ static int sierra_probe(struct usb_serial *serial,
124 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 143 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
125 udev = serial->dev; 144 udev = serial->dev;
126 145
146 /* Figure out the interface number from the serial structure */
147 ifnum = sierra_calc_interface(serial);
148
149 /*
150 * If this interface supports more than 1 alternate
151 * select the 2nd one
152 */
153 if (serial->interface->num_altsetting == 2) {
154 dev_dbg(&udev->dev,
155 "Selecting alt setting for interface %d\n",
156 ifnum);
157
158 /* We know the alternate setting is 1 for the MC8785 */
159 usb_set_interface(udev, ifnum, 1);
160 }
161
127 /* Check if in installer mode */ 162 /* Check if in installer mode */
128 if (truinstall && id->driver_info == DEVICE_INSTALLER) { 163 if (truinstall && id->driver_info == DEVICE_INSTALLER) {
129 dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE(SW)\n"); 164 dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE(SW)\n");
@@ -156,7 +191,7 @@ static struct usb_device_id id_table [] = {
156 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ 191 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
157 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ 192 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
158 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ 193 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
159 { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless AirCard */ 194 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0023, 0xFF, 0xFF, 0xFF) }, /* Sierra Wireless C597 */
160 195
161 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ 196 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
162 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ 197 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
@@ -164,15 +199,20 @@ static struct usb_device_id id_table [] = {
164 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ 199 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
165 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */ 200 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
166 { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */ 201 { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */
202 { USB_DEVICE(0x03f0, 0x1e1d) }, /* HP hs2300 a.k.a MC8775 */
167 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ 203 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
204 { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */
168 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ 205 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
169 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ 206 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
207 { USB_DEVICE(0x1199, 0x683B), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless MC8785 Composite*/
170 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ 208 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
171 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ 209 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
172 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ 210 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
173 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ 211 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
174 { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */ 212 { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
175 { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */ 213 { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
214 { USB_DEVICE(0x1199, 0x6859), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 885 E */
215 { USB_DEVICE(0x1199, 0x685A), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 885 E */
176 216
177 { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */ 217 { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
178 { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */ 218 { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
@@ -216,7 +256,7 @@ static int sierra_send_setup(struct usb_serial_port *port)
216 struct sierra_port_private *portdata; 256 struct sierra_port_private *portdata;
217 __u16 interface = 0; 257 __u16 interface = 0;
218 258
219 dbg("%s", __FUNCTION__); 259 dbg("%s", __func__);
220 260
221 portdata = usb_get_serial_port_data(port); 261 portdata = usb_get_serial_port_data(port);
222 262
@@ -246,24 +286,24 @@ static int sierra_send_setup(struct usb_serial_port *port)
246 286
247static void sierra_rx_throttle(struct usb_serial_port *port) 287static void sierra_rx_throttle(struct usb_serial_port *port)
248{ 288{
249 dbg("%s", __FUNCTION__); 289 dbg("%s", __func__);
250} 290}
251 291
252static void sierra_rx_unthrottle(struct usb_serial_port *port) 292static void sierra_rx_unthrottle(struct usb_serial_port *port)
253{ 293{
254 dbg("%s", __FUNCTION__); 294 dbg("%s", __func__);
255} 295}
256 296
257static void sierra_break_ctl(struct usb_serial_port *port, int break_state) 297static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
258{ 298{
259 /* Unfortunately, I don't know how to send a break */ 299 /* Unfortunately, I don't know how to send a break */
260 dbg("%s", __FUNCTION__); 300 dbg("%s", __func__);
261} 301}
262 302
263static void sierra_set_termios(struct usb_serial_port *port, 303static void sierra_set_termios(struct usb_serial_port *port,
264 struct ktermios *old_termios) 304 struct ktermios *old_termios)
265{ 305{
266 dbg("%s", __FUNCTION__); 306 dbg("%s", __func__);
267 tty_termios_copy_hw(port->tty->termios, old_termios); 307 tty_termios_copy_hw(port->tty->termios, old_termios);
268 sierra_send_setup(port); 308 sierra_send_setup(port);
269} 309}
@@ -317,14 +357,14 @@ static void sierra_outdat_callback(struct urb *urb)
317 int status = urb->status; 357 int status = urb->status;
318 unsigned long flags; 358 unsigned long flags;
319 359
320 dbg("%s - port %d", __FUNCTION__, port->number); 360 dbg("%s - port %d", __func__, port->number);
321 361
322 /* free up the transfer buffer, as usb_free_urb() does not do this */ 362 /* free up the transfer buffer, as usb_free_urb() does not do this */
323 kfree(urb->transfer_buffer); 363 kfree(urb->transfer_buffer);
324 364
325 if (status) 365 if (status)
326 dbg("%s - nonzero write bulk status received: %d", 366 dbg("%s - nonzero write bulk status received: %d",
327 __FUNCTION__, status); 367 __func__, status);
328 368
329 spin_lock_irqsave(&portdata->lock, flags); 369 spin_lock_irqsave(&portdata->lock, flags);
330 --portdata->outstanding_urbs; 370 --portdata->outstanding_urbs;
@@ -346,12 +386,12 @@ static int sierra_write(struct usb_serial_port *port,
346 386
347 portdata = usb_get_serial_port_data(port); 387 portdata = usb_get_serial_port_data(port);
348 388
349 dbg("%s: write (%d chars)", __FUNCTION__, count); 389 dbg("%s: write (%d chars)", __func__, count);
350 390
351 spin_lock_irqsave(&portdata->lock, flags); 391 spin_lock_irqsave(&portdata->lock, flags);
352 if (portdata->outstanding_urbs > N_OUT_URB) { 392 if (portdata->outstanding_urbs > N_OUT_URB) {
353 spin_unlock_irqrestore(&portdata->lock, flags); 393 spin_unlock_irqrestore(&portdata->lock, flags);
354 dbg("%s - write limit hit\n", __FUNCTION__); 394 dbg("%s - write limit hit\n", __func__);
355 return 0; 395 return 0;
356 } 396 }
357 portdata->outstanding_urbs++; 397 portdata->outstanding_urbs++;
@@ -373,7 +413,7 @@ static int sierra_write(struct usb_serial_port *port,
373 413
374 memcpy(buffer, buf, count); 414 memcpy(buffer, buf, count);
375 415
376 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer); 416 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
377 417
378 usb_fill_bulk_urb(urb, serial->dev, 418 usb_fill_bulk_urb(urb, serial->dev,
379 usb_sndbulkpipe(serial->dev, 419 usb_sndbulkpipe(serial->dev,
@@ -384,7 +424,7 @@ static int sierra_write(struct usb_serial_port *port,
384 status = usb_submit_urb(urb, GFP_ATOMIC); 424 status = usb_submit_urb(urb, GFP_ATOMIC);
385 if (status) { 425 if (status) {
386 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " 426 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed "
387 "with status = %d\n", __FUNCTION__, status); 427 "with status = %d\n", __func__, status);
388 count = status; 428 count = status;
389 goto error; 429 goto error;
390 } 430 }
@@ -414,14 +454,14 @@ static void sierra_indat_callback(struct urb *urb)
414 unsigned char *data = urb->transfer_buffer; 454 unsigned char *data = urb->transfer_buffer;
415 int status = urb->status; 455 int status = urb->status;
416 456
417 dbg("%s: %p", __FUNCTION__, urb); 457 dbg("%s: %p", __func__, urb);
418 458
419 endpoint = usb_pipeendpoint(urb->pipe); 459 endpoint = usb_pipeendpoint(urb->pipe);
420 port = (struct usb_serial_port *) urb->context; 460 port = urb->context;
421 461
422 if (status) { 462 if (status) {
423 dbg("%s: nonzero status: %d on endpoint %02x.", 463 dbg("%s: nonzero status: %d on endpoint %02x.",
424 __FUNCTION__, status, endpoint); 464 __func__, status, endpoint);
425 } else { 465 } else {
426 tty = port->tty; 466 tty = port->tty;
427 if (urb->actual_length) { 467 if (urb->actual_length) {
@@ -429,7 +469,7 @@ static void sierra_indat_callback(struct urb *urb)
429 tty_insert_flip_string(tty, data, urb->actual_length); 469 tty_insert_flip_string(tty, data, urb->actual_length);
430 tty_flip_buffer_push(tty); 470 tty_flip_buffer_push(tty);
431 } else { 471 } else {
432 dbg("%s: empty read urb received", __FUNCTION__); 472 dbg("%s: empty read urb received", __func__);
433 } 473 }
434 474
435 /* Resubmit urb so we continue receiving */ 475 /* Resubmit urb so we continue receiving */
@@ -447,19 +487,19 @@ static void sierra_instat_callback(struct urb *urb)
447{ 487{
448 int err; 488 int err;
449 int status = urb->status; 489 int status = urb->status;
450 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 490 struct usb_serial_port *port = urb->context;
451 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 491 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
452 struct usb_serial *serial = port->serial; 492 struct usb_serial *serial = port->serial;
453 493
454 dbg("%s", __FUNCTION__); 494 dbg("%s", __func__);
455 dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata); 495 dbg("%s: urb %p port %p has data %p", __func__, urb, port, portdata);
456 496
457 if (status == 0) { 497 if (status == 0) {
458 struct usb_ctrlrequest *req_pkt = 498 struct usb_ctrlrequest *req_pkt =
459 (struct usb_ctrlrequest *)urb->transfer_buffer; 499 (struct usb_ctrlrequest *)urb->transfer_buffer;
460 500
461 if (!req_pkt) { 501 if (!req_pkt) {
462 dbg("%s: NULL req_pkt\n", __FUNCTION__); 502 dbg("%s: NULL req_pkt\n", __func__);
463 return; 503 return;
464 } 504 }
465 if ((req_pkt->bRequestType == 0xA1) && 505 if ((req_pkt->bRequestType == 0xA1) &&
@@ -469,7 +509,7 @@ static void sierra_instat_callback(struct urb *urb)
469 urb->transfer_buffer + 509 urb->transfer_buffer +
470 sizeof(struct usb_ctrlrequest)); 510 sizeof(struct usb_ctrlrequest));
471 511
472 dbg("%s: signal x%x", __FUNCTION__, signals); 512 dbg("%s: signal x%x", __func__, signals);
473 513
474 old_dcd_state = portdata->dcd_state; 514 old_dcd_state = portdata->dcd_state;
475 portdata->cts_state = 1; 515 portdata->cts_state = 1;
@@ -481,11 +521,11 @@ static void sierra_instat_callback(struct urb *urb)
481 old_dcd_state && !portdata->dcd_state) 521 old_dcd_state && !portdata->dcd_state)
482 tty_hangup(port->tty); 522 tty_hangup(port->tty);
483 } else { 523 } else {
484 dbg("%s: type %x req %x", __FUNCTION__, 524 dbg("%s: type %x req %x", __func__,
485 req_pkt->bRequestType,req_pkt->bRequest); 525 req_pkt->bRequestType, req_pkt->bRequest);
486 } 526 }
487 } else 527 } else
488 dbg("%s: error %d", __FUNCTION__, status); 528 dbg("%s: error %d", __func__, status);
489 529
490 /* Resubmit urb so we continue receiving IRQ data */ 530 /* Resubmit urb so we continue receiving IRQ data */
491 if (status != -ESHUTDOWN) { 531 if (status != -ESHUTDOWN) {
@@ -493,7 +533,7 @@ static void sierra_instat_callback(struct urb *urb)
493 err = usb_submit_urb(urb, GFP_ATOMIC); 533 err = usb_submit_urb(urb, GFP_ATOMIC);
494 if (err) 534 if (err)
495 dbg("%s: resubmit intr urb failed. (%d)", 535 dbg("%s: resubmit intr urb failed. (%d)",
496 __FUNCTION__, err); 536 __func__, err);
497 } 537 }
498} 538}
499 539
@@ -502,14 +542,14 @@ static int sierra_write_room(struct usb_serial_port *port)
502 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 542 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
503 unsigned long flags; 543 unsigned long flags;
504 544
505 dbg("%s - port %d", __FUNCTION__, port->number); 545 dbg("%s - port %d", __func__, port->number);
506 546
507 /* try to give a good number back based on if we have any free urbs at 547 /* try to give a good number back based on if we have any free urbs at
508 * this point in time */ 548 * this point in time */
509 spin_lock_irqsave(&portdata->lock, flags); 549 spin_lock_irqsave(&portdata->lock, flags);
510 if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) { 550 if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) {
511 spin_unlock_irqrestore(&portdata->lock, flags); 551 spin_unlock_irqrestore(&portdata->lock, flags);
512 dbg("%s - write limit hit\n", __FUNCTION__); 552 dbg("%s - write limit hit\n", __func__);
513 return 0; 553 return 0;
514 } 554 }
515 spin_unlock_irqrestore(&portdata->lock, flags); 555 spin_unlock_irqrestore(&portdata->lock, flags);
@@ -519,13 +559,15 @@ static int sierra_write_room(struct usb_serial_port *port)
519 559
520static int sierra_chars_in_buffer(struct usb_serial_port *port) 560static int sierra_chars_in_buffer(struct usb_serial_port *port)
521{ 561{
522 dbg("%s - port %d", __FUNCTION__, port->number); 562 dbg("%s - port %d", __func__, port->number);
523 563
524 /* 564 /*
525 * We can't really account for how much data we 565 * We can't really account for how much data we
526 * have sent out, but hasn't made it through to the 566 * have sent out, but hasn't made it through to the
527 * device as we can't see the backend here, so just 567 * device as we can't see the backend here, so just
528 * tell the tty layer that everything is flushed. 568 * tell the tty layer that everything is flushed.
569 *
570 * FIXME: should walk the outstanding urbs info
529 */ 571 */
530 return 0; 572 return 0;
531} 573}
@@ -540,7 +582,7 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
540 582
541 portdata = usb_get_serial_port_data(port); 583 portdata = usb_get_serial_port_data(port);
542 584
543 dbg("%s", __FUNCTION__); 585 dbg("%s", __func__);
544 586
545 /* Set some sane defaults */ 587 /* Set some sane defaults */
546 portdata->rts_state = 1; 588 portdata->rts_state = 1;
@@ -552,7 +594,7 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
552 if (!urb) 594 if (!urb)
553 continue; 595 continue;
554 if (urb->dev != serial->dev) { 596 if (urb->dev != serial->dev) {
555 dbg("%s: dev %p != %p", __FUNCTION__, 597 dbg("%s: dev %p != %p", __func__,
556 urb->dev, serial->dev); 598 urb->dev, serial->dev);
557 continue; 599 continue;
558 } 600 }
@@ -590,7 +632,7 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
590 struct usb_serial *serial = port->serial; 632 struct usb_serial *serial = port->serial;
591 struct sierra_port_private *portdata; 633 struct sierra_port_private *portdata;
592 634
593 dbg("%s", __FUNCTION__); 635 dbg("%s", __func__);
594 portdata = usb_get_serial_port_data(port); 636 portdata = usb_get_serial_port_data(port);
595 637
596 portdata->rts_state = 0; 638 portdata->rts_state = 0;
@@ -620,7 +662,7 @@ static int sierra_startup(struct usb_serial *serial)
620 int i; 662 int i;
621 int j; 663 int j;
622 664
623 dbg("%s", __FUNCTION__); 665 dbg("%s", __func__);
624 666
625 /* Set Device mode to D0 */ 667 /* Set Device mode to D0 */
626 sierra_set_power_state(serial->dev, 0x0000); 668 sierra_set_power_state(serial->dev, 0x0000);
@@ -635,7 +677,7 @@ static int sierra_startup(struct usb_serial *serial)
635 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); 677 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
636 if (!portdata) { 678 if (!portdata) {
637 dbg("%s: kmalloc for sierra_port_private (%d) failed!.", 679 dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
638 __FUNCTION__, i); 680 __func__, i);
639 return -ENOMEM; 681 return -ENOMEM;
640 } 682 }
641 spin_lock_init(&portdata->lock); 683 spin_lock_init(&portdata->lock);
@@ -656,7 +698,7 @@ static int sierra_startup(struct usb_serial *serial)
656 urb = usb_alloc_urb(0, GFP_KERNEL); 698 urb = usb_alloc_urb(0, GFP_KERNEL);
657 if (urb == NULL) { 699 if (urb == NULL) {
658 dbg("%s: alloc for in port failed.", 700 dbg("%s: alloc for in port failed.",
659 __FUNCTION__); 701 __func__);
660 continue; 702 continue;
661 } 703 }
662 /* Fill URB using supplied data. */ 704 /* Fill URB using supplied data. */
@@ -678,7 +720,7 @@ static void sierra_shutdown(struct usb_serial *serial)
678 struct usb_serial_port *port; 720 struct usb_serial_port *port;
679 struct sierra_port_private *portdata; 721 struct sierra_port_private *portdata;
680 722
681 dbg("%s", __FUNCTION__); 723 dbg("%s", __func__);
682 724
683 for (i = 0; i < serial->num_ports; ++i) { 725 for (i = 0; i < serial->num_ports; ++i) {
684 port = serial->port[i]; 726 port = serial->port[i];
@@ -706,9 +748,6 @@ static struct usb_serial_driver sierra_device = {
706 .description = "Sierra USB modem", 748 .description = "Sierra USB modem",
707 .id_table = id_table, 749 .id_table = id_table,
708 .usb_driver = &sierra_driver, 750 .usb_driver = &sierra_driver,
709 .num_interrupt_in = NUM_DONT_CARE,
710 .num_bulk_in = NUM_DONT_CARE,
711 .num_bulk_out = NUM_DONT_CARE,
712 .calc_num_ports = sierra_calc_num_ports, 751 .calc_num_ports = sierra_calc_num_ports,
713 .probe = sierra_probe, 752 .probe = sierra_probe,
714 .open = sierra_open, 753 .open = sierra_open,
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
new file mode 100644
index 000000000000..2282d620186e
--- /dev/null
+++ b/drivers/usb/serial/spcp8x5.c
@@ -0,0 +1,1072 @@
1/*
2 * spcp8x5 USB to serial adaptor driver
3 *
4 * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn)
5 * Copyright (C) 2006 S1 Corp.
6 *
7 * Original driver for 2.6.10 pl2303 driver by
8 * Greg Kroah-Hartman (greg@kroah.com)
9 * Changes for 2.6.20 by Harald Klein <hari@vt100.at>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 *
17 */
18#include <linux/kernel.h>
19#include <linux/errno.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/tty.h>
23#include <linux/tty_driver.h>
24#include <linux/tty_flip.h>
25#include <linux/module.h>
26#include <linux/spinlock.h>
27#include <linux/usb.h>
28#include <linux/usb/serial.h>
29
30
31/* Version Information */
32#define DRIVER_VERSION "v0.04"
33#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver"
34
35static int debug;
36
37#define SPCP8x5_007_VID 0x04FC
38#define SPCP8x5_007_PID 0x0201
39#define SPCP8x5_008_VID 0x04fc
40#define SPCP8x5_008_PID 0x0235
41#define SPCP8x5_PHILIPS_VID 0x0471
42#define SPCP8x5_PHILIPS_PID 0x081e
43#define SPCP8x5_INTERMATIC_VID 0x04FC
44#define SPCP8x5_INTERMATIC_PID 0x0204
45#define SPCP8x5_835_VID 0x04fc
46#define SPCP8x5_835_PID 0x0231
47
48static struct usb_device_id id_table [] = {
49 { USB_DEVICE(SPCP8x5_PHILIPS_VID , SPCP8x5_PHILIPS_PID)},
50 { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)},
51 { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)},
52 { USB_DEVICE(SPCP8x5_008_VID, SPCP8x5_008_PID)},
53 { USB_DEVICE(SPCP8x5_007_VID, SPCP8x5_007_PID)},
54 { } /* Terminating entry */
55};
56MODULE_DEVICE_TABLE(usb, id_table);
57
58struct spcp8x5_usb_ctrl_arg {
59 u8 type;
60 u8 cmd;
61 u8 cmd_type;
62 u16 value;
63 u16 index;
64 u16 length;
65};
66
67/* wait 30s before close */
68#define SPCP8x5_CLOSING_WAIT (30*HZ)
69
70#define SPCP8x5_BUF_SIZE 1024
71
72
73/* spcp8x5 spec register define */
74#define MCR_CONTROL_LINE_RTS 0x02
75#define MCR_CONTROL_LINE_DTR 0x01
76#define MCR_DTR 0x01
77#define MCR_RTS 0x02
78
79#define MSR_STATUS_LINE_DCD 0x80
80#define MSR_STATUS_LINE_RI 0x40
81#define MSR_STATUS_LINE_DSR 0x20
82#define MSR_STATUS_LINE_CTS 0x10
83
84/* verdor command here , we should define myself */
85#define SET_DEFAULT 0x40
86#define SET_DEFAULT_TYPE 0x20
87
88#define SET_UART_FORMAT 0x40
89#define SET_UART_FORMAT_TYPE 0x21
90#define SET_UART_FORMAT_SIZE_5 0x00
91#define SET_UART_FORMAT_SIZE_6 0x01
92#define SET_UART_FORMAT_SIZE_7 0x02
93#define SET_UART_FORMAT_SIZE_8 0x03
94#define SET_UART_FORMAT_STOP_1 0x00
95#define SET_UART_FORMAT_STOP_2 0x04
96#define SET_UART_FORMAT_PAR_NONE 0x00
97#define SET_UART_FORMAT_PAR_ODD 0x10
98#define SET_UART_FORMAT_PAR_EVEN 0x30
99#define SET_UART_FORMAT_PAR_MASK 0xD0
100#define SET_UART_FORMAT_PAR_SPACE 0x90
101
102#define GET_UART_STATUS_TYPE 0xc0
103#define GET_UART_STATUS 0x22
104#define GET_UART_STATUS_MSR 0x06
105
106#define SET_UART_STATUS 0x40
107#define SET_UART_STATUS_TYPE 0x23
108#define SET_UART_STATUS_MCR 0x0004
109#define SET_UART_STATUS_MCR_DTR 0x01
110#define SET_UART_STATUS_MCR_RTS 0x02
111#define SET_UART_STATUS_MCR_LOOP 0x10
112
113#define SET_WORKING_MODE 0x40
114#define SET_WORKING_MODE_TYPE 0x24
115#define SET_WORKING_MODE_U2C 0x00
116#define SET_WORKING_MODE_RS485 0x01
117#define SET_WORKING_MODE_PDMA 0x02
118#define SET_WORKING_MODE_SPP 0x03
119
120#define SET_FLOWCTL_CHAR 0x40
121#define SET_FLOWCTL_CHAR_TYPE 0x25
122
123#define GET_VERSION 0xc0
124#define GET_VERSION_TYPE 0x26
125
126#define SET_REGISTER 0x40
127#define SET_REGISTER_TYPE 0x27
128
129#define GET_REGISTER 0xc0
130#define GET_REGISTER_TYPE 0x28
131
132#define SET_RAM 0x40
133#define SET_RAM_TYPE 0x31
134
135#define GET_RAM 0xc0
136#define GET_RAM_TYPE 0x32
137
138/* how come ??? */
139#define UART_STATE 0x08
140#define UART_STATE_TRANSIENT_MASK 0x74
141#define UART_DCD 0x01
142#define UART_DSR 0x02
143#define UART_BREAK_ERROR 0x04
144#define UART_RING 0x08
145#define UART_FRAME_ERROR 0x10
146#define UART_PARITY_ERROR 0x20
147#define UART_OVERRUN_ERROR 0x40
148#define UART_CTS 0x80
149
150enum spcp8x5_type {
151 SPCP825_007_TYPE,
152 SPCP825_008_TYPE,
153 SPCP825_PHILIP_TYPE,
154 SPCP825_INTERMATIC_TYPE,
155 SPCP835_TYPE,
156};
157
158/* 1st in 1st out buffer 4 driver */
159struct ringbuf {
160 unsigned int buf_size;
161 char *buf_buf;
162 char *buf_get;
163 char *buf_put;
164};
165
166/* alloc the ring buf and alloc the buffer itself */
167static inline struct ringbuf *alloc_ringbuf(unsigned int size)
168{
169 struct ringbuf *pb;
170
171 if (size == 0)
172 return NULL;
173
174 pb = kmalloc(sizeof(*pb), GFP_KERNEL);
175 if (pb == NULL)
176 return NULL;
177
178 pb->buf_buf = kmalloc(size, GFP_KERNEL);
179 if (pb->buf_buf == NULL) {
180 kfree(pb);
181 return NULL;
182 }
183
184 pb->buf_size = size;
185 pb->buf_get = pb->buf_put = pb->buf_buf;
186
187 return pb;
188}
189
190/* free the ring buf and the buffer itself */
191static inline void free_ringbuf(struct ringbuf *pb)
192{
193 if (pb != NULL) {
194 kfree(pb->buf_buf);
195 kfree(pb);
196 }
197}
198
199/* clear pipo , juest repoint the pointer here */
200static inline void clear_ringbuf(struct ringbuf *pb)
201{
202 if (pb != NULL)
203 pb->buf_get = pb->buf_put;
204}
205
206/* get the number of data in the pipo */
207static inline unsigned int ringbuf_avail_data(struct ringbuf *pb)
208{
209 if (pb == NULL)
210 return 0;
211 return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size);
212}
213
214/* get the number of space in the pipo */
215static inline unsigned int ringbuf_avail_space(struct ringbuf *pb)
216{
217 if (pb == NULL)
218 return 0;
219 return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size);
220}
221
222/* put count data into pipo */
223static unsigned int put_ringbuf(struct ringbuf *pb, const char *buf,
224 unsigned int count)
225{
226 unsigned int len;
227
228 if (pb == NULL)
229 return 0;
230
231 len = ringbuf_avail_space(pb);
232 if (count > len)
233 count = len;
234
235 if (count == 0)
236 return 0;
237
238 len = pb->buf_buf + pb->buf_size - pb->buf_put;
239 if (count > len) {
240 memcpy(pb->buf_put, buf, len);
241 memcpy(pb->buf_buf, buf+len, count - len);
242 pb->buf_put = pb->buf_buf + count - len;
243 } else {
244 memcpy(pb->buf_put, buf, count);
245 if (count < len)
246 pb->buf_put += count;
247 else /* count == len */
248 pb->buf_put = pb->buf_buf;
249 }
250 return count;
251}
252
253/* get count data from pipo */
254static unsigned int get_ringbuf(struct ringbuf *pb, char *buf,
255 unsigned int count)
256{
257 unsigned int len;
258
259 if (pb == NULL || buf == NULL)
260 return 0;
261
262 len = ringbuf_avail_data(pb);
263 if (count > len)
264 count = len;
265
266 if (count == 0)
267 return 0;
268
269 len = pb->buf_buf + pb->buf_size - pb->buf_get;
270 if (count > len) {
271 memcpy(buf, pb->buf_get, len);
272 memcpy(buf+len, pb->buf_buf, count - len);
273 pb->buf_get = pb->buf_buf + count - len;
274 } else {
275 memcpy(buf, pb->buf_get, count);
276 if (count < len)
277 pb->buf_get += count;
278 else /* count == len */
279 pb->buf_get = pb->buf_buf;
280 }
281
282 return count;
283}
284
285static struct usb_driver spcp8x5_driver = {
286 .name = "spcp8x5",
287 .probe = usb_serial_probe,
288 .disconnect = usb_serial_disconnect,
289 .id_table = id_table,
290 .no_dynamic_id = 1,
291};
292
293
294struct spcp8x5_private {
295 spinlock_t lock;
296 struct ringbuf *buf;
297 int write_urb_in_use;
298 enum spcp8x5_type type;
299 wait_queue_head_t delta_msr_wait;
300 u8 line_control;
301 u8 line_status;
302 u8 termios_initialized;
303};
304
305/* desc : when device plug in,this function would be called.
306 * thanks to usb_serial subsystem,then do almost every things for us. And what
307 * we should do just alloc the buffer */
308static int spcp8x5_startup(struct usb_serial *serial)
309{
310 struct spcp8x5_private *priv;
311 int i;
312 enum spcp8x5_type type = SPCP825_007_TYPE;
313
314 if (serial->dev->descriptor.idProduct == 0x0201)
315 type = SPCP825_007_TYPE;
316 else if (serial->dev->descriptor.idProduct == 0x0231)
317 type = SPCP835_TYPE;
318 else if (serial->dev->descriptor.idProduct == 0x0235)
319 type = SPCP825_008_TYPE;
320 else if (serial->dev->descriptor.idProduct == 0x0204)
321 type = SPCP825_INTERMATIC_TYPE;
322 else if (serial->dev->descriptor.idProduct == 0x0471 &&
323 serial->dev->descriptor.idVendor == 0x081e)
324 type = SPCP825_PHILIP_TYPE;
325 dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type);
326
327 for (i = 0; i < serial->num_ports; ++i) {
328 priv = kzalloc(sizeof(struct spcp8x5_private), GFP_KERNEL);
329 if (!priv)
330 goto cleanup;
331
332 spin_lock_init(&priv->lock);
333 priv->buf = alloc_ringbuf(SPCP8x5_BUF_SIZE);
334 if (priv->buf == NULL)
335 goto cleanup2;
336
337 init_waitqueue_head(&priv->delta_msr_wait);
338 priv->type = type;
339 usb_set_serial_port_data(serial->port[i] , priv);
340
341 }
342
343 return 0;
344
345cleanup2:
346 kfree(priv);
347cleanup:
348 for (--i; i >= 0; --i) {
349 priv = usb_get_serial_port_data(serial->port[i]);
350 free_ringbuf(priv->buf);
351 kfree(priv);
352 usb_set_serial_port_data(serial->port[i] , NULL);
353 }
354 return -ENOMEM;
355}
356
357/* call when the device plug out. free all the memory alloced by probe */
358static void spcp8x5_shutdown(struct usb_serial *serial)
359{
360 int i;
361 struct spcp8x5_private *priv;
362
363 for (i = 0; i < serial->num_ports; i++) {
364 priv = usb_get_serial_port_data(serial->port[i]);
365 if (priv) {
366 free_ringbuf(priv->buf);
367 kfree(priv);
368 usb_set_serial_port_data(serial->port[i] , NULL);
369 }
370 }
371}
372
373/* set the modem control line of the device.
374 * NOTE spcp825-007 not supported this */
375static int spcp8x5_set_ctrlLine(struct usb_device *dev, u8 value,
376 enum spcp8x5_type type)
377{
378 int retval;
379 u8 mcr = 0 ;
380
381 if (type == SPCP825_007_TYPE)
382 return -EPERM;
383
384 mcr = (unsigned short)value;
385 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
386 SET_UART_STATUS_TYPE, SET_UART_STATUS,
387 mcr, 0x04, NULL, 0, 100);
388 if (retval != 0)
389 dev_dbg(&dev->dev, "usb_control_msg return %#x\n", retval);
390 return retval;
391}
392
393/* get the modem status register of the device
394 * NOTE spcp825-007 not supported this */
395static int spcp8x5_get_msr(struct usb_device *dev, u8 *status,
396 enum spcp8x5_type type)
397{
398 u8 *status_buffer;
399 int ret;
400
401 /* I return Permited not support here but seem inval device
402 * is more fix */
403 if (type == SPCP825_007_TYPE)
404 return -EPERM;
405 if (status == NULL)
406 return -EINVAL;
407
408 status_buffer = kmalloc(1, GFP_KERNEL);
409 if (!status_buffer)
410 return -ENOMEM;
411 status_buffer[0] = status[0];
412
413 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
414 GET_UART_STATUS, GET_UART_STATUS_TYPE,
415 0, GET_UART_STATUS_MSR, status_buffer, 1, 100);
416 if (ret < 0)
417 dev_dbg(&dev->dev, "Get MSR = 0x%p failed (error = %d)",
418 status_buffer, ret);
419
420 dev_dbg(&dev->dev, "0xc0:0x22:0:6 %d - 0x%p ", ret, status_buffer);
421 status[0] = status_buffer[0];
422 kfree(status_buffer);
423
424 return ret;
425}
426
427/* select the work mode.
428 * NOTE this function not supported by spcp825-007 */
429static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
430 u16 index, enum spcp8x5_type type)
431{
432 int ret;
433
434 /* I return Permited not support here but seem inval device
435 * is more fix */
436 if (type == SPCP825_007_TYPE)
437 return;
438
439 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
440 SET_WORKING_MODE_TYPE, SET_WORKING_MODE,
441 value, index, NULL, 0, 100);
442 dev_dbg(&dev->dev, "value = %#x , index = %#x\n", value, index);
443 if (ret < 0)
444 dev_dbg(&dev->dev,
445 "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret);
446}
447
448/* close the serial port. We should wait for data sending to device 1st and
449 * then kill all urb. */
450static void spcp8x5_close(struct usb_serial_port *port, struct file *filp)
451{
452 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
453 unsigned long flags;
454 unsigned int c_cflag;
455 int bps;
456 long timeout;
457 wait_queue_t wait;
458 int result;
459
460 dbg("%s - port %d", __func__, port->number);
461
462 /* wait for data to drain from the buffer */
463 spin_lock_irqsave(&priv->lock, flags);
464 timeout = SPCP8x5_CLOSING_WAIT;
465 init_waitqueue_entry(&wait, current);
466 add_wait_queue(&port->tty->write_wait, &wait);
467 for (;;) {
468 set_current_state(TASK_INTERRUPTIBLE);
469 if (ringbuf_avail_data(priv->buf) == 0 ||
470 timeout == 0 || signal_pending(current))
471 break;
472 spin_unlock_irqrestore(&priv->lock, flags);
473 timeout = schedule_timeout(timeout);
474 spin_lock_irqsave(&priv->lock, flags);
475 }
476 set_current_state(TASK_RUNNING);
477 remove_wait_queue(&port->tty->write_wait, &wait);
478
479 /* clear out any remaining data in the buffer */
480 clear_ringbuf(priv->buf);
481 spin_unlock_irqrestore(&priv->lock, flags);
482
483 /* wait for characters to drain from the device (this is long enough
484 * for the entire all byte spcp8x5 hardware buffer to drain with no
485 * flow control for data rates of 1200 bps or more, for lower rates we
486 * should really know how much data is in the buffer to compute a delay
487 * that is not unnecessarily long) */
488 bps = tty_get_baud_rate(port->tty);
489 if (bps > 1200)
490 timeout = max((HZ*2560) / bps, HZ/10);
491 else
492 timeout = 2*HZ;
493 set_current_state(TASK_INTERRUPTIBLE);
494 schedule_timeout(timeout);
495
496 /* clear control lines */
497 if (port->tty) {
498 c_cflag = port->tty->termios->c_cflag;
499 if (c_cflag & HUPCL) {
500 spin_lock_irqsave(&priv->lock, flags);
501 priv->line_control = 0;
502 spin_unlock_irqrestore(&priv->lock, flags);
503 spcp8x5_set_ctrlLine(port->serial->dev, 0 , priv->type);
504 }
505 }
506
507 /* kill urb */
508 if (port->write_urb != NULL) {
509 result = usb_unlink_urb(port->write_urb);
510 if (result)
511 dev_dbg(&port->dev,
512 "usb_unlink_urb(write_urb) = %d\n", result);
513 }
514 result = usb_unlink_urb(port->read_urb);
515 if (result)
516 dev_dbg(&port->dev, "usb_unlink_urb(read_urb) = %d\n", result);
517}
518
519/* set the serial param for transfer. we should check if we really need to
520 * transfer. then if be set flow contorl we should do this too. */
521static void spcp8x5_set_termios(struct usb_serial_port *port,
522 struct ktermios *old_termios)
523{
524 struct usb_serial *serial = port->serial;
525 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
526 unsigned long flags;
527 unsigned int cflag = port->tty->termios->c_cflag;
528 unsigned int old_cflag = old_termios->c_cflag;
529 unsigned short uartdata;
530 unsigned char buf[2] = {0, 0};
531 int baud;
532 int i;
533 u8 control;
534
535 if ((!port->tty) || (!port->tty->termios))
536 return;
537
538 /* for the 1st time call this function */
539 spin_lock_irqsave(&priv->lock, flags);
540 if (!priv->termios_initialized) {
541 *(port->tty->termios) = tty_std_termios;
542 port->tty->termios->c_cflag = B115200 | CS8 | CREAD |
543 HUPCL | CLOCAL;
544 priv->termios_initialized = 1;
545 }
546 spin_unlock_irqrestore(&priv->lock, flags);
547
548 /* check that they really want us to change something */
549 if (!tty_termios_hw_change(port->tty->termios, old_termios))
550 return;
551
552 /* set DTR/RTS active */
553 spin_lock_irqsave(&priv->lock, flags);
554 control = priv->line_control;
555 if ((old_cflag & CBAUD) == B0) {
556 priv->line_control |= MCR_DTR;
557 if (!(old_cflag & CRTSCTS))
558 priv->line_control |= MCR_RTS;
559 }
560 if (control != priv->line_control) {
561 control = priv->line_control;
562 spin_unlock_irqrestore(&priv->lock, flags);
563 spcp8x5_set_ctrlLine(serial->dev, control , priv->type);
564 } else {
565 spin_unlock_irqrestore(&priv->lock, flags);
566 }
567
568 /* Set Baud Rate */
569 baud = tty_get_baud_rate(port->tty);;
570 switch (baud) {
571 case 300: buf[0] = 0x00; break;
572 case 600: buf[0] = 0x01; break;
573 case 1200: buf[0] = 0x02; break;
574 case 2400: buf[0] = 0x03; break;
575 case 4800: buf[0] = 0x04; break;
576 case 9600: buf[0] = 0x05; break;
577 case 19200: buf[0] = 0x07; break;
578 case 38400: buf[0] = 0x09; break;
579 case 57600: buf[0] = 0x0a; break;
580 case 115200: buf[0] = 0x0b; break;
581 case 230400: buf[0] = 0x0c; break;
582 case 460800: buf[0] = 0x0d; break;
583 case 921600: buf[0] = 0x0e; break;
584/* case 1200000: buf[0] = 0x0f; break; */
585/* case 2400000: buf[0] = 0x10; break; */
586 case 3000000: buf[0] = 0x11; break;
587/* case 6000000: buf[0] = 0x12; break; */
588 case 0:
589 case 1000000:
590 buf[0] = 0x0b; break;
591 default:
592 err("spcp825 driver does not support the baudrate "
593 "requested, using default of 9600.");
594 }
595
596 /* Set Data Length : 00:5bit, 01:6bit, 10:7bit, 11:8bit */
597 if (cflag & CSIZE) {
598 switch (cflag & CSIZE) {
599 case CS5:
600 buf[1] |= SET_UART_FORMAT_SIZE_5;
601 break;
602 case CS6:
603 buf[1] |= SET_UART_FORMAT_SIZE_6;
604 break;
605 case CS7:
606 buf[1] |= SET_UART_FORMAT_SIZE_7;
607 break;
608 default:
609 case CS8:
610 buf[1] |= SET_UART_FORMAT_SIZE_8;
611 break;
612 }
613 }
614
615 /* Set Stop bit2 : 0:1bit 1:2bit */
616 buf[1] |= (cflag & CSTOPB) ? SET_UART_FORMAT_STOP_2 :
617 SET_UART_FORMAT_STOP_1;
618
619 /* Set Parity bit3-4 01:Odd 11:Even */
620 if (cflag & PARENB) {
621 buf[1] |= (cflag & PARODD) ?
622 SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ;
623 } else
624 buf[1] |= SET_UART_FORMAT_PAR_NONE;
625
626 uartdata = buf[0] | buf[1]<<8;
627
628 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
629 SET_UART_FORMAT_TYPE, SET_UART_FORMAT,
630 uartdata, 0, NULL, 0, 100);
631 if (i < 0)
632 err("Set UART format %#x failed (error = %d)", uartdata, i);
633 dbg("0x21:0x40:0:0 %d\n", i);
634
635 if (cflag & CRTSCTS) {
636 /* enable hardware flow control */
637 spcp8x5_set_workMode(serial->dev, 0x000a,
638 SET_WORKING_MODE_U2C, priv->type);
639 }
640 return;
641}
642
643/* open the serial port. do some usb system call. set termios and get the line
644 * status of the device. then submit the read urb */
645static int spcp8x5_open(struct usb_serial_port *port, struct file *filp)
646{
647 struct ktermios tmp_termios;
648 struct usb_serial *serial = port->serial;
649 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
650 int ret;
651 unsigned long flags;
652 u8 status = 0x30;
653 /* status 0x30 means DSR and CTS = 1 other CDC RI and delta = 0 */
654
655 dbg("%s - port %d", __func__, port->number);
656
657 usb_clear_halt(serial->dev, port->write_urb->pipe);
658 usb_clear_halt(serial->dev, port->read_urb->pipe);
659
660 ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
661 0x09, 0x00,
662 0x01, 0x00, NULL, 0x00, 100);
663 if (ret)
664 return ret;
665
666 spin_lock_irqsave(&priv->lock, flags);
667 if (port->tty->termios->c_cflag & CBAUD)
668 priv->line_control = MCR_DTR | MCR_RTS;
669 else
670 priv->line_control = 0;
671 spin_unlock_irqrestore(&priv->lock, flags);
672
673 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type);
674
675 /* Setup termios */
676 if (port->tty)
677 spcp8x5_set_termios(port, &tmp_termios);
678
679 spcp8x5_get_msr(serial->dev, &status, priv->type);
680
681 /* may be we should update uart status here but now we did not do */
682 spin_lock_irqsave(&priv->lock, flags);
683 priv->line_status = status & 0xf0 ;
684 spin_unlock_irqrestore(&priv->lock, flags);
685
686 /* FIXME: need to assert RTS and DTR if CRTSCTS off */
687
688 dbg("%s - submitting read urb", __func__);
689 port->read_urb->dev = serial->dev;
690 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
691 if (ret) {
692 spcp8x5_close(port, NULL);
693 return -EPROTO;
694 }
695 return 0;
696}
697
698/* bulk read call back function. check the status of the urb. if transfer
699 * failed return. then update the status and the tty send data to tty subsys.
700 * submit urb again.
701 */
702static void spcp8x5_read_bulk_callback(struct urb *urb)
703{
704 struct usb_serial_port *port = urb->context;
705 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
706 struct tty_struct *tty;
707 unsigned char *data = urb->transfer_buffer;
708 unsigned long flags;
709 int i;
710 int result;
711 u8 status = 0;
712 char tty_flag;
713
714 dev_dbg(&port->dev, "start, urb->status = %d, "
715 "urb->actual_length = %d\n,", urb->status, urb->actual_length);
716
717 /* check the urb status */
718 if (urb->status) {
719 if (!port->open_count)
720 return;
721 if (urb->status == -EPROTO) {
722 /* spcp8x5 mysteriously fails with -EPROTO */
723 /* reschedule the read */
724 urb->status = 0;
725 urb->dev = port->serial->dev;
726 result = usb_submit_urb(urb , GFP_ATOMIC);
727 if (result)
728 dev_dbg(&port->dev,
729 "failed submitting read urb %d\n",
730 result);
731 return;
732 }
733 dev_dbg(&port->dev, "unable to handle the error, exiting.\n");
734 return;
735 }
736
737 /* get tty_flag from status */
738 tty_flag = TTY_NORMAL;
739
740 spin_lock_irqsave(&priv->lock, flags);
741 status = priv->line_status;
742 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
743 spin_unlock_irqrestore(&priv->lock, flags);
744 /* wake up the wait for termios */
745 wake_up_interruptible(&priv->delta_msr_wait);
746
747 /* break takes precedence over parity, which takes precedence over
748 * framing errors */
749 if (status & UART_BREAK_ERROR)
750 tty_flag = TTY_BREAK;
751 else if (status & UART_PARITY_ERROR)
752 tty_flag = TTY_PARITY;
753 else if (status & UART_FRAME_ERROR)
754 tty_flag = TTY_FRAME;
755 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
756
757 tty = port->tty;
758 if (tty && urb->actual_length) {
759 tty_buffer_request_room(tty, urb->actual_length + 1);
760 /* overrun is special, not associated with a char */
761 if (status & UART_OVERRUN_ERROR)
762 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
763 for (i = 0; i < urb->actual_length; ++i)
764 tty_insert_flip_char(tty, data[i], tty_flag);
765 tty_flip_buffer_push(tty);
766 }
767
768 /* Schedule the next read _if_ we are still open */
769 if (port->open_count) {
770 urb->dev = port->serial->dev;
771 result = usb_submit_urb(urb , GFP_ATOMIC);
772 if (result)
773 dev_dbg(&port->dev, "failed submitting read urb %d\n",
774 result);
775 }
776
777 return;
778}
779
780/* get data from ring buffer and then write to usb bus */
781static void spcp8x5_send(struct usb_serial_port *port)
782{
783 int count, result;
784 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
785 unsigned long flags;
786
787 spin_lock_irqsave(&priv->lock, flags);
788
789 if (priv->write_urb_in_use) {
790 dev_dbg(&port->dev, "write urb still used\n");
791 spin_unlock_irqrestore(&priv->lock, flags);
792 return;
793 }
794
795 /* send the 1st urb for writting */
796 memset(port->write_urb->transfer_buffer , 0x00 , port->bulk_out_size);
797 count = get_ringbuf(priv->buf, port->write_urb->transfer_buffer,
798 port->bulk_out_size);
799
800 if (count == 0) {
801 spin_unlock_irqrestore(&priv->lock, flags);
802 return;
803 }
804
805 /* update the urb status */
806 priv->write_urb_in_use = 1;
807
808 spin_unlock_irqrestore(&priv->lock, flags);
809
810 port->write_urb->transfer_buffer_length = count;
811 port->write_urb->dev = port->serial->dev;
812
813 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
814 if (result) {
815 dev_dbg(&port->dev, "failed submitting write urb, error %d\n",
816 result);
817 priv->write_urb_in_use = 0;
818 /* TODO: reschedule spcp8x5_send */
819 }
820
821
822 schedule_work(&port->work);
823}
824
825/* this is the call back function for write urb. NOTE we should not sleep in
826 * this routine. check the urb return code and then submit the write urb again
827 * to hold the write loop */
828static void spcp8x5_write_bulk_callback(struct urb *urb)
829{
830 struct usb_serial_port *port = urb->context;
831 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
832 int result;
833
834 switch (urb->status) {
835 case 0:
836 /* success */
837 break;
838 case -ECONNRESET:
839 case -ENOENT:
840 case -ESHUTDOWN:
841 /* this urb is terminated, clean up */
842 dev_dbg(&port->dev, "urb shutting down with status: %d\n",
843 urb->status);
844 priv->write_urb_in_use = 0;
845 return;
846 default:
847 /* error in the urb, so we have to resubmit it */
848 dbg("%s - Overflow in write", __func__);
849 dbg("%s - nonzero write bulk status received: %d",
850 __func__, urb->status);
851 port->write_urb->transfer_buffer_length = 1;
852 port->write_urb->dev = port->serial->dev;
853 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
854 if (result)
855 dev_dbg(&port->dev,
856 "failed resubmitting write urb %d\n", result);
857 else
858 return;
859 }
860
861 priv->write_urb_in_use = 0;
862
863 /* send any buffered data */
864 spcp8x5_send(port);
865}
866
867/* write data to ring buffer. and then start the write transfer */
868static int spcp8x5_write(struct usb_serial_port *port,
869 const unsigned char *buf, int count)
870{
871 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
872 unsigned long flags;
873
874 dev_dbg(&port->dev, "%d bytes\n", count);
875
876 if (!count)
877 return count;
878
879 spin_lock_irqsave(&priv->lock, flags);
880 count = put_ringbuf(priv->buf, buf, count);
881 spin_unlock_irqrestore(&priv->lock, flags);
882
883 spcp8x5_send(port);
884
885 return count;
886}
887
888static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
889 unsigned int arg)
890{
891 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
892 unsigned long flags;
893 unsigned int prevstatus;
894 unsigned int status;
895 unsigned int changed;
896
897 spin_lock_irqsave(&priv->lock, flags);
898 prevstatus = priv->line_status;
899 spin_unlock_irqrestore(&priv->lock, flags);
900
901 while (1) {
902 /* wake up in bulk read */
903 interruptible_sleep_on(&priv->delta_msr_wait);
904
905 /* see if a signal did it */
906 if (signal_pending(current))
907 return -ERESTARTSYS;
908
909 spin_lock_irqsave(&priv->lock, flags);
910 status = priv->line_status;
911 spin_unlock_irqrestore(&priv->lock, flags);
912
913 changed = prevstatus^status;
914
915 if (((arg & TIOCM_RNG) && (changed & MSR_STATUS_LINE_RI)) ||
916 ((arg & TIOCM_DSR) && (changed & MSR_STATUS_LINE_DSR)) ||
917 ((arg & TIOCM_CD) && (changed & MSR_STATUS_LINE_DCD)) ||
918 ((arg & TIOCM_CTS) && (changed & MSR_STATUS_LINE_CTS)))
919 return 0;
920
921 prevstatus = status;
922 }
923 /* NOTREACHED */
924 return 0;
925}
926
927static int spcp8x5_ioctl(struct usb_serial_port *port, struct file *file,
928 unsigned int cmd, unsigned long arg)
929{
930 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
931
932 switch (cmd) {
933 case TIOCMIWAIT:
934 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
935 return spcp8x5_wait_modem_info(port, arg);
936
937 default:
938 dbg("%s not supported = 0x%04x", __func__, cmd);
939 break;
940 }
941
942 return -ENOIOCTLCMD;
943}
944
945static int spcp8x5_tiocmset(struct usb_serial_port *port, struct file *file,
946 unsigned int set, unsigned int clear)
947{
948 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
949 unsigned long flags;
950 u8 control;
951
952 spin_lock_irqsave(&priv->lock, flags);
953 if (set & TIOCM_RTS)
954 priv->line_control |= MCR_RTS;
955 if (set & TIOCM_DTR)
956 priv->line_control |= MCR_DTR;
957 if (clear & TIOCM_RTS)
958 priv->line_control &= ~MCR_RTS;
959 if (clear & TIOCM_DTR)
960 priv->line_control &= ~MCR_DTR;
961 control = priv->line_control;
962 spin_unlock_irqrestore(&priv->lock, flags);
963
964 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
965}
966
967static int spcp8x5_tiocmget(struct usb_serial_port *port, struct file *file)
968{
969 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
970 unsigned long flags;
971 unsigned int mcr;
972 unsigned int status;
973 unsigned int result;
974
975 spin_lock_irqsave(&priv->lock, flags);
976 mcr = priv->line_control;
977 status = priv->line_status;
978 spin_unlock_irqrestore(&priv->lock, flags);
979
980 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
981 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
982 | ((status & MSR_STATUS_LINE_CTS) ? TIOCM_CTS : 0)
983 | ((status & MSR_STATUS_LINE_DSR) ? TIOCM_DSR : 0)
984 | ((status & MSR_STATUS_LINE_RI) ? TIOCM_RI : 0)
985 | ((status & MSR_STATUS_LINE_DCD) ? TIOCM_CD : 0);
986
987 return result;
988}
989
990/* get the avail space room in ring buffer */
991static int spcp8x5_write_room(struct usb_serial_port *port)
992{
993 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
994 int room = 0;
995 unsigned long flags;
996
997 spin_lock_irqsave(&priv->lock, flags);
998 room = ringbuf_avail_space(priv->buf);
999 spin_unlock_irqrestore(&priv->lock, flags);
1000
1001 return room;
1002}
1003
1004/* get the number of avail data in write ring buffer */
1005static int spcp8x5_chars_in_buffer(struct usb_serial_port *port)
1006{
1007 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
1008 int chars = 0;
1009 unsigned long flags;
1010
1011 spin_lock_irqsave(&priv->lock, flags);
1012 chars = ringbuf_avail_data(priv->buf);
1013 spin_unlock_irqrestore(&priv->lock, flags);
1014
1015 return chars;
1016}
1017
1018/* All of the device info needed for the spcp8x5 SIO serial converter */
1019static struct usb_serial_driver spcp8x5_device = {
1020 .driver = {
1021 .owner = THIS_MODULE,
1022 .name = "SPCP8x5",
1023 },
1024 .id_table = id_table,
1025 .num_ports = 1,
1026 .open = spcp8x5_open,
1027 .close = spcp8x5_close,
1028 .write = spcp8x5_write,
1029 .set_termios = spcp8x5_set_termios,
1030 .ioctl = spcp8x5_ioctl,
1031 .tiocmget = spcp8x5_tiocmget,
1032 .tiocmset = spcp8x5_tiocmset,
1033 .write_room = spcp8x5_write_room,
1034 .read_bulk_callback = spcp8x5_read_bulk_callback,
1035 .write_bulk_callback = spcp8x5_write_bulk_callback,
1036 .chars_in_buffer = spcp8x5_chars_in_buffer,
1037 .attach = spcp8x5_startup,
1038 .shutdown = spcp8x5_shutdown,
1039};
1040
1041static int __init spcp8x5_init(void)
1042{
1043 int retval;
1044 retval = usb_serial_register(&spcp8x5_device);
1045 if (retval)
1046 goto failed_usb_serial_register;
1047 retval = usb_register(&spcp8x5_driver);
1048 if (retval)
1049 goto failed_usb_register;
1050 info(DRIVER_DESC " " DRIVER_VERSION);
1051 return 0;
1052failed_usb_register:
1053 usb_serial_deregister(&spcp8x5_device);
1054failed_usb_serial_register:
1055 return retval;
1056}
1057
1058static void __exit spcp8x5_exit(void)
1059{
1060 usb_deregister(&spcp8x5_driver);
1061 usb_serial_deregister(&spcp8x5_device);
1062}
1063
1064module_init(spcp8x5_init);
1065module_exit(spcp8x5_exit);
1066
1067MODULE_DESCRIPTION(DRIVER_DESC);
1068MODULE_VERSION(DRIVER_VERSION);
1069MODULE_LICENSE("GPL");
1070
1071module_param(debug, bool, S_IRUGO | S_IWUSR);
1072MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 3a3776677339..a1c8aef01417 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -264,9 +264,6 @@ static struct usb_serial_driver ti_1port_device = {
264 .description = "TI USB 3410 1 port adapter", 264 .description = "TI USB 3410 1 port adapter",
265 .usb_driver = &ti_usb_driver, 265 .usb_driver = &ti_usb_driver,
266 .id_table = ti_id_table_3410, 266 .id_table = ti_id_table_3410,
267 .num_interrupt_in = NUM_DONT_CARE,
268 .num_bulk_in = NUM_DONT_CARE,
269 .num_bulk_out = 1,
270 .num_ports = 1, 267 .num_ports = 1,
271 .attach = ti_startup, 268 .attach = ti_startup,
272 .shutdown = ti_shutdown, 269 .shutdown = ti_shutdown,
@@ -295,9 +292,6 @@ static struct usb_serial_driver ti_2port_device = {
295 .description = "TI USB 5052 2 port adapter", 292 .description = "TI USB 5052 2 port adapter",
296 .usb_driver = &ti_usb_driver, 293 .usb_driver = &ti_usb_driver,
297 .id_table = ti_id_table_5052, 294 .id_table = ti_id_table_5052,
298 .num_interrupt_in = 1,
299 .num_bulk_in = 2,
300 .num_bulk_out = 2,
301 .num_ports = 2, 295 .num_ports = 2,
302 .attach = ti_startup, 296 .attach = ti_startup,
303 .shutdown = ti_shutdown, 297 .shutdown = ti_shutdown,
@@ -414,14 +408,14 @@ static int ti_startup(struct usb_serial *serial)
414 408
415 409
416 dbg("%s - product 0x%4X, num configurations %d, configuration value %d", 410 dbg("%s - product 0x%4X, num configurations %d, configuration value %d",
417 __FUNCTION__, le16_to_cpu(dev->descriptor.idProduct), 411 __func__, le16_to_cpu(dev->descriptor.idProduct),
418 dev->descriptor.bNumConfigurations, 412 dev->descriptor.bNumConfigurations,
419 dev->actconfig->desc.bConfigurationValue); 413 dev->actconfig->desc.bConfigurationValue);
420 414
421 /* create device structure */ 415 /* create device structure */
422 tdev = kzalloc(sizeof(struct ti_device), GFP_KERNEL); 416 tdev = kzalloc(sizeof(struct ti_device), GFP_KERNEL);
423 if (tdev == NULL) { 417 if (tdev == NULL) {
424 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 418 dev_err(&dev->dev, "%s - out of memory\n", __func__);
425 return -ENOMEM; 419 return -ENOMEM;
426 } 420 }
427 mutex_init(&tdev->td_open_close_lock); 421 mutex_init(&tdev->td_open_close_lock);
@@ -431,7 +425,7 @@ static int ti_startup(struct usb_serial *serial)
431 /* determine device type */ 425 /* determine device type */
432 if (usb_match_id(serial->interface, ti_id_table_3410)) 426 if (usb_match_id(serial->interface, ti_id_table_3410))
433 tdev->td_is_3410 = 1; 427 tdev->td_is_3410 = 1;
434 dbg("%s - device type is %s", __FUNCTION__, tdev->td_is_3410 ? "3410" : "5052"); 428 dbg("%s - device type is %s", __func__, tdev->td_is_3410 ? "3410" : "5052");
435 429
436 /* if we have only 1 configuration, download firmware */ 430 /* if we have only 1 configuration, download firmware */
437 if (dev->descriptor.bNumConfigurations == 1) { 431 if (dev->descriptor.bNumConfigurations == 1) {
@@ -465,7 +459,7 @@ static int ti_startup(struct usb_serial *serial)
465 for (i = 0; i < serial->num_ports; ++i) { 459 for (i = 0; i < serial->num_ports; ++i) {
466 tport = kzalloc(sizeof(struct ti_port), GFP_KERNEL); 460 tport = kzalloc(sizeof(struct ti_port), GFP_KERNEL);
467 if (tport == NULL) { 461 if (tport == NULL) {
468 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 462 dev_err(&dev->dev, "%s - out of memory\n", __func__);
469 status = -ENOMEM; 463 status = -ENOMEM;
470 goto free_tports; 464 goto free_tports;
471 } 465 }
@@ -477,7 +471,7 @@ static int ti_startup(struct usb_serial *serial)
477 init_waitqueue_head(&tport->tp_write_wait); 471 init_waitqueue_head(&tport->tp_write_wait);
478 tport->tp_write_buf = ti_buf_alloc(); 472 tport->tp_write_buf = ti_buf_alloc();
479 if (tport->tp_write_buf == NULL) { 473 if (tport->tp_write_buf == NULL) {
480 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 474 dev_err(&dev->dev, "%s - out of memory\n", __func__);
481 kfree(tport); 475 kfree(tport);
482 status = -ENOMEM; 476 status = -ENOMEM;
483 goto free_tports; 477 goto free_tports;
@@ -510,7 +504,7 @@ static void ti_shutdown(struct usb_serial *serial)
510 struct ti_device *tdev = usb_get_serial_data(serial); 504 struct ti_device *tdev = usb_get_serial_data(serial);
511 struct ti_port *tport; 505 struct ti_port *tport;
512 506
513 dbg("%s", __FUNCTION__); 507 dbg("%s", __func__);
514 508
515 for (i=0; i < serial->num_ports; ++i) { 509 for (i=0; i < serial->num_ports; ++i) {
516 tport = usb_get_serial_port_data(serial->port[i]); 510 tport = usb_get_serial_port_data(serial->port[i]);
@@ -538,7 +532,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
538 TI_PIPE_TIMEOUT_ENABLE | 532 TI_PIPE_TIMEOUT_ENABLE |
539 (TI_TRANSFER_TIMEOUT << 2)); 533 (TI_TRANSFER_TIMEOUT << 2));
540 534
541 dbg("%s - port %d", __FUNCTION__, port->number); 535 dbg("%s - port %d", __func__, port->number);
542 536
543 if (tport == NULL) 537 if (tport == NULL)
544 return -ENODEV; 538 return -ENODEV;
@@ -563,10 +557,10 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
563 557
564 /* start interrupt urb the first time a port is opened on this device */ 558 /* start interrupt urb the first time a port is opened on this device */
565 if (tdev->td_open_port_count == 0) { 559 if (tdev->td_open_port_count == 0) {
566 dbg("%s - start interrupt in urb", __FUNCTION__); 560 dbg("%s - start interrupt in urb", __func__);
567 urb = tdev->td_serial->port[0]->interrupt_in_urb; 561 urb = tdev->td_serial->port[0]->interrupt_in_urb;
568 if (!urb) { 562 if (!urb) {
569 dev_err(&port->dev, "%s - no interrupt urb\n", __FUNCTION__); 563 dev_err(&port->dev, "%s - no interrupt urb\n", __func__);
570 status = -EINVAL; 564 status = -EINVAL;
571 goto release_lock; 565 goto release_lock;
572 } 566 }
@@ -575,40 +569,40 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
575 urb->dev = dev; 569 urb->dev = dev;
576 status = usb_submit_urb(urb, GFP_KERNEL); 570 status = usb_submit_urb(urb, GFP_KERNEL);
577 if (status) { 571 if (status) {
578 dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __FUNCTION__, status); 572 dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __func__, status);
579 goto release_lock; 573 goto release_lock;
580 } 574 }
581 } 575 }
582 576
583 ti_set_termios(port, port->tty->termios); 577 ti_set_termios(port, port->tty->termios);
584 578
585 dbg("%s - sending TI_OPEN_PORT", __FUNCTION__); 579 dbg("%s - sending TI_OPEN_PORT", __func__);
586 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 580 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
587 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 581 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
588 if (status) { 582 if (status) {
589 dev_err(&port->dev, "%s - cannot send open command, %d\n", __FUNCTION__, status); 583 dev_err(&port->dev, "%s - cannot send open command, %d\n", __func__, status);
590 goto unlink_int_urb; 584 goto unlink_int_urb;
591 } 585 }
592 586
593 dbg("%s - sending TI_START_PORT", __FUNCTION__); 587 dbg("%s - sending TI_START_PORT", __func__);
594 status = ti_command_out_sync(tdev, TI_START_PORT, 588 status = ti_command_out_sync(tdev, TI_START_PORT,
595 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 589 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
596 if (status) { 590 if (status) {
597 dev_err(&port->dev, "%s - cannot send start command, %d\n", __FUNCTION__, status); 591 dev_err(&port->dev, "%s - cannot send start command, %d\n", __func__, status);
598 goto unlink_int_urb; 592 goto unlink_int_urb;
599 } 593 }
600 594
601 dbg("%s - sending TI_PURGE_PORT", __FUNCTION__); 595 dbg("%s - sending TI_PURGE_PORT", __func__);
602 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 596 status = ti_command_out_sync(tdev, TI_PURGE_PORT,
603 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0); 597 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0);
604 if (status) { 598 if (status) {
605 dev_err(&port->dev, "%s - cannot clear input buffers, %d\n", __FUNCTION__, status); 599 dev_err(&port->dev, "%s - cannot clear input buffers, %d\n", __func__, status);
606 goto unlink_int_urb; 600 goto unlink_int_urb;
607 } 601 }
608 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 602 status = ti_command_out_sync(tdev, TI_PURGE_PORT,
609 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0); 603 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0);
610 if (status) { 604 if (status) {
611 dev_err(&port->dev, "%s - cannot clear output buffers, %d\n", __FUNCTION__, status); 605 dev_err(&port->dev, "%s - cannot clear output buffers, %d\n", __func__, status);
612 goto unlink_int_urb; 606 goto unlink_int_urb;
613 } 607 }
614 608
@@ -619,27 +613,27 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
619 613
620 ti_set_termios(port, port->tty->termios); 614 ti_set_termios(port, port->tty->termios);
621 615
622 dbg("%s - sending TI_OPEN_PORT (2)", __FUNCTION__); 616 dbg("%s - sending TI_OPEN_PORT (2)", __func__);
623 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 617 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
624 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 618 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0);
625 if (status) { 619 if (status) {
626 dev_err(&port->dev, "%s - cannot send open command (2), %d\n", __FUNCTION__, status); 620 dev_err(&port->dev, "%s - cannot send open command (2), %d\n", __func__, status);
627 goto unlink_int_urb; 621 goto unlink_int_urb;
628 } 622 }
629 623
630 dbg("%s - sending TI_START_PORT (2)", __FUNCTION__); 624 dbg("%s - sending TI_START_PORT (2)", __func__);
631 status = ti_command_out_sync(tdev, TI_START_PORT, 625 status = ti_command_out_sync(tdev, TI_START_PORT,
632 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 626 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
633 if (status) { 627 if (status) {
634 dev_err(&port->dev, "%s - cannot send start command (2), %d\n", __FUNCTION__, status); 628 dev_err(&port->dev, "%s - cannot send start command (2), %d\n", __func__, status);
635 goto unlink_int_urb; 629 goto unlink_int_urb;
636 } 630 }
637 631
638 /* start read urb */ 632 /* start read urb */
639 dbg("%s - start read urb", __FUNCTION__); 633 dbg("%s - start read urb", __func__);
640 urb = port->read_urb; 634 urb = port->read_urb;
641 if (!urb) { 635 if (!urb) {
642 dev_err(&port->dev, "%s - no read urb\n", __FUNCTION__); 636 dev_err(&port->dev, "%s - no read urb\n", __func__);
643 status = -EINVAL; 637 status = -EINVAL;
644 goto unlink_int_urb; 638 goto unlink_int_urb;
645 } 639 }
@@ -649,7 +643,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
649 urb->dev = dev; 643 urb->dev = dev;
650 status = usb_submit_urb(urb, GFP_KERNEL); 644 status = usb_submit_urb(urb, GFP_KERNEL);
651 if (status) { 645 if (status) {
652 dev_err(&port->dev, "%s - submit read urb failed, %d\n", __FUNCTION__, status); 646 dev_err(&port->dev, "%s - submit read urb failed, %d\n", __func__, status);
653 goto unlink_int_urb; 647 goto unlink_int_urb;
654 } 648 }
655 649
@@ -663,7 +657,7 @@ unlink_int_urb:
663 usb_kill_urb(port->serial->port[0]->interrupt_in_urb); 657 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
664release_lock: 658release_lock:
665 mutex_unlock(&tdev->td_open_close_lock); 659 mutex_unlock(&tdev->td_open_close_lock);
666 dbg("%s - exit %d", __FUNCTION__, status); 660 dbg("%s - exit %d", __func__, status);
667 return status; 661 return status;
668} 662}
669 663
@@ -676,7 +670,7 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
676 int status; 670 int status;
677 int do_unlock; 671 int do_unlock;
678 672
679 dbg("%s - port %d", __FUNCTION__, port->number); 673 dbg("%s - port %d", __func__, port->number);
680 674
681 tdev = usb_get_serial_data(port->serial); 675 tdev = usb_get_serial_data(port->serial);
682 tport = usb_get_serial_port_data(port); 676 tport = usb_get_serial_port_data(port);
@@ -693,11 +687,11 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
693 687
694 port_number = port->number - port->serial->minor; 688 port_number = port->number - port->serial->minor;
695 689
696 dbg("%s - sending TI_CLOSE_PORT", __FUNCTION__); 690 dbg("%s - sending TI_CLOSE_PORT", __func__);
697 status = ti_command_out_sync(tdev, TI_CLOSE_PORT, 691 status = ti_command_out_sync(tdev, TI_CLOSE_PORT,
698 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 692 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0);
699 if (status) 693 if (status)
700 dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __FUNCTION__, status); 694 dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __func__, status);
701 695
702 /* if mutex_lock is interrupted, continue anyway */ 696 /* if mutex_lock is interrupted, continue anyway */
703 do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock); 697 do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock);
@@ -710,7 +704,7 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
710 if (do_unlock) 704 if (do_unlock)
711 mutex_unlock(&tdev->td_open_close_lock); 705 mutex_unlock(&tdev->td_open_close_lock);
712 706
713 dbg("%s - exit", __FUNCTION__); 707 dbg("%s - exit", __func__);
714} 708}
715 709
716 710
@@ -720,10 +714,10 @@ static int ti_write(struct usb_serial_port *port, const unsigned char *data,
720 struct ti_port *tport = usb_get_serial_port_data(port); 714 struct ti_port *tport = usb_get_serial_port_data(port);
721 unsigned long flags; 715 unsigned long flags;
722 716
723 dbg("%s - port %d", __FUNCTION__, port->number); 717 dbg("%s - port %d", __func__, port->number);
724 718
725 if (count == 0) { 719 if (count == 0) {
726 dbg("%s - write request of 0 bytes", __FUNCTION__); 720 dbg("%s - write request of 0 bytes", __func__);
727 return 0; 721 return 0;
728 } 722 }
729 723
@@ -746,7 +740,7 @@ static int ti_write_room(struct usb_serial_port *port)
746 int room = 0; 740 int room = 0;
747 unsigned long flags; 741 unsigned long flags;
748 742
749 dbg("%s - port %d", __FUNCTION__, port->number); 743 dbg("%s - port %d", __func__, port->number);
750 744
751 if (tport == NULL) 745 if (tport == NULL)
752 return -ENODEV; 746 return -ENODEV;
@@ -755,7 +749,7 @@ static int ti_write_room(struct usb_serial_port *port)
755 room = ti_buf_space_avail(tport->tp_write_buf); 749 room = ti_buf_space_avail(tport->tp_write_buf);
756 spin_unlock_irqrestore(&tport->tp_lock, flags); 750 spin_unlock_irqrestore(&tport->tp_lock, flags);
757 751
758 dbg("%s - returns %d", __FUNCTION__, room); 752 dbg("%s - returns %d", __func__, room);
759 return room; 753 return room;
760} 754}
761 755
@@ -766,7 +760,7 @@ static int ti_chars_in_buffer(struct usb_serial_port *port)
766 int chars = 0; 760 int chars = 0;
767 unsigned long flags; 761 unsigned long flags;
768 762
769 dbg("%s - port %d", __FUNCTION__, port->number); 763 dbg("%s - port %d", __func__, port->number);
770 764
771 if (tport == NULL) 765 if (tport == NULL)
772 return -ENODEV; 766 return -ENODEV;
@@ -775,7 +769,7 @@ static int ti_chars_in_buffer(struct usb_serial_port *port)
775 chars = ti_buf_data_avail(tport->tp_write_buf); 769 chars = ti_buf_data_avail(tport->tp_write_buf);
776 spin_unlock_irqrestore(&tport->tp_lock, flags); 770 spin_unlock_irqrestore(&tport->tp_lock, flags);
777 771
778 dbg("%s - returns %d", __FUNCTION__, chars); 772 dbg("%s - returns %d", __func__, chars);
779 return chars; 773 return chars;
780} 774}
781 775
@@ -785,14 +779,14 @@ static void ti_throttle(struct usb_serial_port *port)
785 struct ti_port *tport = usb_get_serial_port_data(port); 779 struct ti_port *tport = usb_get_serial_port_data(port);
786 struct tty_struct *tty; 780 struct tty_struct *tty;
787 781
788 dbg("%s - port %d", __FUNCTION__, port->number); 782 dbg("%s - port %d", __func__, port->number);
789 783
790 if (tport == NULL) 784 if (tport == NULL)
791 return; 785 return;
792 786
793 tty = port->tty; 787 tty = port->tty;
794 if (!tty) { 788 if (!tty) {
795 dbg("%s - no tty", __FUNCTION__); 789 dbg("%s - no tty", __func__);
796 return; 790 return;
797 } 791 }
798 792
@@ -808,21 +802,21 @@ static void ti_unthrottle(struct usb_serial_port *port)
808 struct tty_struct *tty; 802 struct tty_struct *tty;
809 int status; 803 int status;
810 804
811 dbg("%s - port %d", __FUNCTION__, port->number); 805 dbg("%s - port %d", __func__, port->number);
812 806
813 if (tport == NULL) 807 if (tport == NULL)
814 return; 808 return;
815 809
816 tty = port->tty; 810 tty = port->tty;
817 if (!tty) { 811 if (!tty) {
818 dbg("%s - no tty", __FUNCTION__); 812 dbg("%s - no tty", __func__);
819 return; 813 return;
820 } 814 }
821 815
822 if (I_IXOFF(tty) || C_CRTSCTS(tty)) { 816 if (I_IXOFF(tty) || C_CRTSCTS(tty)) {
823 status = ti_restart_read(tport, tty); 817 status = ti_restart_read(tport, tty);
824 if (status) 818 if (status)
825 dev_err(&port->dev, "%s - cannot restart read, %d\n", __FUNCTION__, status); 819 dev_err(&port->dev, "%s - cannot restart read, %d\n", __func__, status);
826 } 820 }
827} 821}
828 822
@@ -834,24 +828,24 @@ static int ti_ioctl(struct usb_serial_port *port, struct file *file,
834 struct async_icount cnow; 828 struct async_icount cnow;
835 struct async_icount cprev; 829 struct async_icount cprev;
836 830
837 dbg("%s - port %d, cmd = 0x%04X", __FUNCTION__, port->number, cmd); 831 dbg("%s - port %d, cmd = 0x%04X", __func__, port->number, cmd);
838 832
839 if (tport == NULL) 833 if (tport == NULL)
840 return -ENODEV; 834 return -ENODEV;
841 835
842 switch (cmd) { 836 switch (cmd) {
843 case TIOCGSERIAL: 837 case TIOCGSERIAL:
844 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__, port->number); 838 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
845 return ti_get_serial_info(tport, (struct serial_struct __user *)arg); 839 return ti_get_serial_info(tport, (struct serial_struct __user *)arg);
846 break; 840 break;
847 841
848 case TIOCSSERIAL: 842 case TIOCSSERIAL:
849 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__, port->number); 843 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number);
850 return ti_set_serial_info(tport, (struct serial_struct __user *)arg); 844 return ti_set_serial_info(tport, (struct serial_struct __user *)arg);
851 break; 845 break;
852 846
853 case TIOCMIWAIT: 847 case TIOCMIWAIT:
854 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__, port->number); 848 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
855 cprev = tport->tp_icount; 849 cprev = tport->tp_icount;
856 while (1) { 850 while (1) {
857 interruptible_sleep_on(&tport->tp_msr_wait); 851 interruptible_sleep_on(&tport->tp_msr_wait);
@@ -872,7 +866,7 @@ static int ti_ioctl(struct usb_serial_port *port, struct file *file,
872 break; 866 break;
873 867
874 case TIOCGICOUNT: 868 case TIOCGICOUNT:
875 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__, port->number, tport->tp_icount.rx, tport->tp_icount.tx); 869 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, port->number, tport->tp_icount.rx, tport->tp_icount.tx);
876 if (copy_to_user((void __user *)arg, &tport->tp_icount, sizeof(tport->tp_icount))) 870 if (copy_to_user((void __user *)arg, &tport->tp_icount, sizeof(tport->tp_icount)))
877 return -EFAULT; 871 return -EFAULT;
878 return 0; 872 return 0;
@@ -894,20 +888,20 @@ static void ti_set_termios(struct usb_serial_port *port,
894 int port_number = port->number - port->serial->minor; 888 int port_number = port->number - port->serial->minor;
895 unsigned int mcr; 889 unsigned int mcr;
896 890
897 dbg("%s - port %d", __FUNCTION__, port->number); 891 dbg("%s - port %d", __func__, port->number);
898 892
899 cflag = tty->termios->c_cflag; 893 cflag = tty->termios->c_cflag;
900 iflag = tty->termios->c_iflag; 894 iflag = tty->termios->c_iflag;
901 895
902 dbg("%s - cflag %08x, iflag %08x", __FUNCTION__, cflag, iflag); 896 dbg("%s - cflag %08x, iflag %08x", __func__, cflag, iflag);
903 dbg("%s - old clfag %08x, old iflag %08x", __FUNCTION__, old_termios->c_cflag, old_termios->c_iflag); 897 dbg("%s - old clfag %08x, old iflag %08x", __func__, old_termios->c_cflag, old_termios->c_iflag);
904 898
905 if (tport == NULL) 899 if (tport == NULL)
906 return; 900 return;
907 901
908 config = kmalloc(sizeof(*config), GFP_KERNEL); 902 config = kmalloc(sizeof(*config), GFP_KERNEL);
909 if (!config) { 903 if (!config) {
910 dev_err(&port->dev, "%s - out of memory\n", __FUNCTION__); 904 dev_err(&port->dev, "%s - out of memory\n", __func__);
911 return; 905 return;
912 } 906 }
913 907
@@ -991,7 +985,7 @@ static void ti_set_termios(struct usb_serial_port *port,
991 tty_encode_baud_rate(tty, baud, baud); 985 tty_encode_baud_rate(tty, baud, baud);
992 986
993 dbg("%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d", 987 dbg("%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d",
994 __FUNCTION__, baud, config->wBaudRate, config->wFlags, config->bDataBits, config->bParity, config->bStopBits, config->cXon, config->cXoff, config->bUartMode); 988 __func__, baud, config->wBaudRate, config->wFlags, config->bDataBits, config->bParity, config->bStopBits, config->cXon, config->cXoff, config->bUartMode);
995 989
996 cpu_to_be16s(&config->wBaudRate); 990 cpu_to_be16s(&config->wBaudRate);
997 cpu_to_be16s(&config->wFlags); 991 cpu_to_be16s(&config->wFlags);
@@ -1000,7 +994,7 @@ static void ti_set_termios(struct usb_serial_port *port,
1000 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, 994 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config,
1001 sizeof(*config)); 995 sizeof(*config));
1002 if (status) 996 if (status)
1003 dev_err(&port->dev, "%s - cannot set config on port %d, %d\n", __FUNCTION__, port_number, status); 997 dev_err(&port->dev, "%s - cannot set config on port %d, %d\n", __func__, port_number, status);
1004 998
1005 /* SET_CONFIG asserts RTS and DTR, reset them correctly */ 999 /* SET_CONFIG asserts RTS and DTR, reset them correctly */
1006 mcr = tport->tp_shadow_mcr; 1000 mcr = tport->tp_shadow_mcr;
@@ -1009,7 +1003,7 @@ static void ti_set_termios(struct usb_serial_port *port,
1009 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); 1003 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS);
1010 status = ti_set_mcr(tport, mcr); 1004 status = ti_set_mcr(tport, mcr);
1011 if (status) 1005 if (status)
1012 dev_err(&port->dev, "%s - cannot set modem control on port %d, %d\n", __FUNCTION__, port_number, status); 1006 dev_err(&port->dev, "%s - cannot set modem control on port %d, %d\n", __func__, port_number, status);
1013 1007
1014 kfree(config); 1008 kfree(config);
1015} 1009}
@@ -1021,14 +1015,17 @@ static int ti_tiocmget(struct usb_serial_port *port, struct file *file)
1021 unsigned int result; 1015 unsigned int result;
1022 unsigned int msr; 1016 unsigned int msr;
1023 unsigned int mcr; 1017 unsigned int mcr;
1018 unsigned long flags;
1024 1019
1025 dbg("%s - port %d", __FUNCTION__, port->number); 1020 dbg("%s - port %d", __func__, port->number);
1026 1021
1027 if (tport == NULL) 1022 if (tport == NULL)
1028 return -ENODEV; 1023 return -ENODEV;
1029 1024
1025 spin_lock_irqsave(&tport->tp_lock, flags);
1030 msr = tport->tp_msr; 1026 msr = tport->tp_msr;
1031 mcr = tport->tp_shadow_mcr; 1027 mcr = tport->tp_shadow_mcr;
1028 spin_unlock_irqrestore(&tport->tp_lock, flags);
1032 1029
1033 result = ((mcr & TI_MCR_DTR) ? TIOCM_DTR : 0) 1030 result = ((mcr & TI_MCR_DTR) ? TIOCM_DTR : 0)
1034 | ((mcr & TI_MCR_RTS) ? TIOCM_RTS : 0) 1031 | ((mcr & TI_MCR_RTS) ? TIOCM_RTS : 0)
@@ -1038,7 +1035,7 @@ static int ti_tiocmget(struct usb_serial_port *port, struct file *file)
1038 | ((msr & TI_MSR_RI) ? TIOCM_RI : 0) 1035 | ((msr & TI_MSR_RI) ? TIOCM_RI : 0)
1039 | ((msr & TI_MSR_DSR) ? TIOCM_DSR : 0); 1036 | ((msr & TI_MSR_DSR) ? TIOCM_DSR : 0);
1040 1037
1041 dbg("%s - 0x%04X", __FUNCTION__, result); 1038 dbg("%s - 0x%04X", __func__, result);
1042 1039
1043 return result; 1040 return result;
1044} 1041}
@@ -1049,12 +1046,14 @@ static int ti_tiocmset(struct usb_serial_port *port, struct file *file,
1049{ 1046{
1050 struct ti_port *tport = usb_get_serial_port_data(port); 1047 struct ti_port *tport = usb_get_serial_port_data(port);
1051 unsigned int mcr; 1048 unsigned int mcr;
1049 unsigned long flags;
1052 1050
1053 dbg("%s - port %d", __FUNCTION__, port->number); 1051 dbg("%s - port %d", __func__, port->number);
1054 1052
1055 if (tport == NULL) 1053 if (tport == NULL)
1056 return -ENODEV; 1054 return -ENODEV;
1057 1055
1056 spin_lock_irqsave(&tport->tp_lock, flags);
1058 mcr = tport->tp_shadow_mcr; 1057 mcr = tport->tp_shadow_mcr;
1059 1058
1060 if (set & TIOCM_RTS) 1059 if (set & TIOCM_RTS)
@@ -1070,6 +1069,7 @@ static int ti_tiocmset(struct usb_serial_port *port, struct file *file,
1070 mcr &= ~TI_MCR_DTR; 1069 mcr &= ~TI_MCR_DTR;
1071 if (clear & TIOCM_LOOP) 1070 if (clear & TIOCM_LOOP)
1072 mcr &= ~TI_MCR_LOOP; 1071 mcr &= ~TI_MCR_LOOP;
1072 spin_unlock_irqrestore(&tport->tp_lock, flags);
1073 1073
1074 return ti_set_mcr(tport, mcr); 1074 return ti_set_mcr(tport, mcr);
1075} 1075}
@@ -1080,7 +1080,7 @@ static void ti_break(struct usb_serial_port *port, int break_state)
1080 struct ti_port *tport = usb_get_serial_port_data(port); 1080 struct ti_port *tport = usb_get_serial_port_data(port);
1081 int status; 1081 int status;
1082 1082
1083 dbg("%s - state = %d", __FUNCTION__, break_state); 1083 dbg("%s - state = %d", __func__, break_state);
1084 1084
1085 if (tport == NULL) 1085 if (tport == NULL)
1086 return; 1086 return;
@@ -1092,13 +1092,13 @@ static void ti_break(struct usb_serial_port *port, int break_state)
1092 TI_LCR_BREAK, break_state == -1 ? TI_LCR_BREAK : 0); 1092 TI_LCR_BREAK, break_state == -1 ? TI_LCR_BREAK : 0);
1093 1093
1094 if (status) 1094 if (status)
1095 dbg("%s - error setting break, %d", __FUNCTION__, status); 1095 dbg("%s - error setting break, %d", __func__, status);
1096} 1096}
1097 1097
1098 1098
1099static void ti_interrupt_callback(struct urb *urb) 1099static void ti_interrupt_callback(struct urb *urb)
1100{ 1100{
1101 struct ti_device *tdev = (struct ti_device *)urb->context; 1101 struct ti_device *tdev = urb->context;
1102 struct usb_serial_port *port; 1102 struct usb_serial_port *port;
1103 struct usb_serial *serial = tdev->td_serial; 1103 struct usb_serial *serial = tdev->td_serial;
1104 struct ti_port *tport; 1104 struct ti_port *tport;
@@ -1111,7 +1111,7 @@ static void ti_interrupt_callback(struct urb *urb)
1111 int retval; 1111 int retval;
1112 __u8 msr; 1112 __u8 msr;
1113 1113
1114 dbg("%s", __FUNCTION__); 1114 dbg("%s", __func__);
1115 1115
1116 switch (status) { 1116 switch (status) {
1117 case 0: 1117 case 0:
@@ -1119,33 +1119,33 @@ static void ti_interrupt_callback(struct urb *urb)
1119 case -ECONNRESET: 1119 case -ECONNRESET:
1120 case -ENOENT: 1120 case -ENOENT:
1121 case -ESHUTDOWN: 1121 case -ESHUTDOWN:
1122 dbg("%s - urb shutting down, %d", __FUNCTION__, status); 1122 dbg("%s - urb shutting down, %d", __func__, status);
1123 tdev->td_urb_error = 1; 1123 tdev->td_urb_error = 1;
1124 return; 1124 return;
1125 default: 1125 default:
1126 dev_err(dev, "%s - nonzero urb status, %d\n", 1126 dev_err(dev, "%s - nonzero urb status, %d\n",
1127 __FUNCTION__, status); 1127 __func__, status);
1128 tdev->td_urb_error = 1; 1128 tdev->td_urb_error = 1;
1129 goto exit; 1129 goto exit;
1130 } 1130 }
1131 1131
1132 if (length != 2) { 1132 if (length != 2) {
1133 dbg("%s - bad packet size, %d", __FUNCTION__, length); 1133 dbg("%s - bad packet size, %d", __func__, length);
1134 goto exit; 1134 goto exit;
1135 } 1135 }
1136 1136
1137 if (data[0] == TI_CODE_HARDWARE_ERROR) { 1137 if (data[0] == TI_CODE_HARDWARE_ERROR) {
1138 dev_err(dev, "%s - hardware error, %d\n", __FUNCTION__, data[1]); 1138 dev_err(dev, "%s - hardware error, %d\n", __func__, data[1]);
1139 goto exit; 1139 goto exit;
1140 } 1140 }
1141 1141
1142 port_number = TI_GET_PORT_FROM_CODE(data[0]); 1142 port_number = TI_GET_PORT_FROM_CODE(data[0]);
1143 function = TI_GET_FUNC_FROM_CODE(data[0]); 1143 function = TI_GET_FUNC_FROM_CODE(data[0]);
1144 1144
1145 dbg("%s - port_number %d, function %d, data 0x%02X", __FUNCTION__, port_number, function, data[1]); 1145 dbg("%s - port_number %d, function %d, data 0x%02X", __func__, port_number, function, data[1]);
1146 1146
1147 if (port_number >= serial->num_ports) { 1147 if (port_number >= serial->num_ports) {
1148 dev_err(dev, "%s - bad port number, %d\n", __FUNCTION__, port_number); 1148 dev_err(dev, "%s - bad port number, %d\n", __func__, port_number);
1149 goto exit; 1149 goto exit;
1150 } 1150 }
1151 1151
@@ -1157,17 +1157,17 @@ static void ti_interrupt_callback(struct urb *urb)
1157 1157
1158 switch (function) { 1158 switch (function) {
1159 case TI_CODE_DATA_ERROR: 1159 case TI_CODE_DATA_ERROR:
1160 dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n", __FUNCTION__, port_number, data[1]); 1160 dev_err(dev, "%s - DATA ERROR, port %d, data 0x%02X\n", __func__, port_number, data[1]);
1161 break; 1161 break;
1162 1162
1163 case TI_CODE_MODEM_STATUS: 1163 case TI_CODE_MODEM_STATUS:
1164 msr = data[1]; 1164 msr = data[1];
1165 dbg("%s - port %d, msr 0x%02X", __FUNCTION__, port_number, msr); 1165 dbg("%s - port %d, msr 0x%02X", __func__, port_number, msr);
1166 ti_handle_new_msr(tport, msr); 1166 ti_handle_new_msr(tport, msr);
1167 break; 1167 break;
1168 1168
1169 default: 1169 default:
1170 dev_err(dev, "%s - unknown interrupt code, 0x%02X\n", __FUNCTION__, data[1]); 1170 dev_err(dev, "%s - unknown interrupt code, 0x%02X\n", __func__, data[1]);
1171 break; 1171 break;
1172 } 1172 }
1173 1173
@@ -1175,19 +1175,19 @@ exit:
1175 retval = usb_submit_urb(urb, GFP_ATOMIC); 1175 retval = usb_submit_urb(urb, GFP_ATOMIC);
1176 if (retval) 1176 if (retval)
1177 dev_err(dev, "%s - resubmit interrupt urb failed, %d\n", 1177 dev_err(dev, "%s - resubmit interrupt urb failed, %d\n",
1178 __FUNCTION__, retval); 1178 __func__, retval);
1179} 1179}
1180 1180
1181 1181
1182static void ti_bulk_in_callback(struct urb *urb) 1182static void ti_bulk_in_callback(struct urb *urb)
1183{ 1183{
1184 struct ti_port *tport = (struct ti_port *)urb->context; 1184 struct ti_port *tport = urb->context;
1185 struct usb_serial_port *port = tport->tp_port; 1185 struct usb_serial_port *port = tport->tp_port;
1186 struct device *dev = &urb->dev->dev; 1186 struct device *dev = &urb->dev->dev;
1187 int status = urb->status; 1187 int status = urb->status;
1188 int retval = 0; 1188 int retval = 0;
1189 1189
1190 dbg("%s", __FUNCTION__); 1190 dbg("%s", __func__);
1191 1191
1192 switch (status) { 1192 switch (status) {
1193 case 0: 1193 case 0:
@@ -1195,13 +1195,13 @@ static void ti_bulk_in_callback(struct urb *urb)
1195 case -ECONNRESET: 1195 case -ECONNRESET:
1196 case -ENOENT: 1196 case -ENOENT:
1197 case -ESHUTDOWN: 1197 case -ESHUTDOWN:
1198 dbg("%s - urb shutting down, %d", __FUNCTION__, status); 1198 dbg("%s - urb shutting down, %d", __func__, status);
1199 tport->tp_tdev->td_urb_error = 1; 1199 tport->tp_tdev->td_urb_error = 1;
1200 wake_up_interruptible(&tport->tp_write_wait); 1200 wake_up_interruptible(&tport->tp_write_wait);
1201 return; 1201 return;
1202 default: 1202 default:
1203 dev_err(dev, "%s - nonzero urb status, %d\n", 1203 dev_err(dev, "%s - nonzero urb status, %d\n",
1204 __FUNCTION__, status ); 1204 __func__, status );
1205 tport->tp_tdev->td_urb_error = 1; 1205 tport->tp_tdev->td_urb_error = 1;
1206 wake_up_interruptible(&tport->tp_write_wait); 1206 wake_up_interruptible(&tport->tp_write_wait);
1207 } 1207 }
@@ -1210,16 +1210,16 @@ static void ti_bulk_in_callback(struct urb *urb)
1210 goto exit; 1210 goto exit;
1211 1211
1212 if (status) { 1212 if (status) {
1213 dev_err(dev, "%s - stopping read!\n", __FUNCTION__); 1213 dev_err(dev, "%s - stopping read!\n", __func__);
1214 return; 1214 return;
1215 } 1215 }
1216 1216
1217 if (port->tty && urb->actual_length) { 1217 if (port->tty && urb->actual_length) {
1218 usb_serial_debug_data(debug, dev, __FUNCTION__, 1218 usb_serial_debug_data(debug, dev, __func__,
1219 urb->actual_length, urb->transfer_buffer); 1219 urb->actual_length, urb->transfer_buffer);
1220 1220
1221 if (!tport->tp_is_open) 1221 if (!tport->tp_is_open)
1222 dbg("%s - port closed, dropping data", __FUNCTION__); 1222 dbg("%s - port closed, dropping data", __func__);
1223 else 1223 else
1224 ti_recv(&urb->dev->dev, port->tty, urb->transfer_buffer, 1224 ti_recv(&urb->dev->dev, port->tty, urb->transfer_buffer,
1225 urb->actual_length); 1225 urb->actual_length);
@@ -1241,18 +1241,18 @@ exit:
1241 spin_unlock(&tport->tp_lock); 1241 spin_unlock(&tport->tp_lock);
1242 if (retval) 1242 if (retval)
1243 dev_err(dev, "%s - resubmit read urb failed, %d\n", 1243 dev_err(dev, "%s - resubmit read urb failed, %d\n",
1244 __FUNCTION__, retval); 1244 __func__, retval);
1245} 1245}
1246 1246
1247 1247
1248static void ti_bulk_out_callback(struct urb *urb) 1248static void ti_bulk_out_callback(struct urb *urb)
1249{ 1249{
1250 struct ti_port *tport = (struct ti_port *)urb->context; 1250 struct ti_port *tport = urb->context;
1251 struct usb_serial_port *port = tport->tp_port; 1251 struct usb_serial_port *port = tport->tp_port;
1252 struct device *dev = &urb->dev->dev; 1252 struct device *dev = &urb->dev->dev;
1253 int status = urb->status; 1253 int status = urb->status;
1254 1254
1255 dbg("%s - port %d", __FUNCTION__, port->number); 1255 dbg("%s - port %d", __func__, port->number);
1256 1256
1257 tport->tp_write_urb_in_use = 0; 1257 tport->tp_write_urb_in_use = 0;
1258 1258
@@ -1262,13 +1262,13 @@ static void ti_bulk_out_callback(struct urb *urb)
1262 case -ECONNRESET: 1262 case -ECONNRESET:
1263 case -ENOENT: 1263 case -ENOENT:
1264 case -ESHUTDOWN: 1264 case -ESHUTDOWN:
1265 dbg("%s - urb shutting down, %d", __FUNCTION__, status); 1265 dbg("%s - urb shutting down, %d", __func__, status);
1266 tport->tp_tdev->td_urb_error = 1; 1266 tport->tp_tdev->td_urb_error = 1;
1267 wake_up_interruptible(&tport->tp_write_wait); 1267 wake_up_interruptible(&tport->tp_write_wait);
1268 return; 1268 return;
1269 default: 1269 default:
1270 dev_err(dev, "%s - nonzero urb status, %d\n", 1270 dev_err(dev, "%s - nonzero urb status, %d\n",
1271 __FUNCTION__, status); 1271 __func__, status);
1272 tport->tp_tdev->td_urb_error = 1; 1272 tport->tp_tdev->td_urb_error = 1;
1273 wake_up_interruptible(&tport->tp_write_wait); 1273 wake_up_interruptible(&tport->tp_write_wait);
1274 } 1274 }
@@ -1286,7 +1286,7 @@ static void ti_recv(struct device *dev, struct tty_struct *tty,
1286 do { 1286 do {
1287 cnt = tty_buffer_request_room(tty, length); 1287 cnt = tty_buffer_request_room(tty, length);
1288 if (cnt < length) { 1288 if (cnt < length) {
1289 dev_err(dev, "%s - dropping data, %d bytes lost\n", __FUNCTION__, length - cnt); 1289 dev_err(dev, "%s - dropping data, %d bytes lost\n", __func__, length - cnt);
1290 if(cnt == 0) 1290 if(cnt == 0)
1291 break; 1291 break;
1292 } 1292 }
@@ -1307,7 +1307,7 @@ static void ti_send(struct ti_port *tport)
1307 unsigned long flags; 1307 unsigned long flags;
1308 1308
1309 1309
1310 dbg("%s - port %d", __FUNCTION__, port->number); 1310 dbg("%s - port %d", __func__, port->number);
1311 1311
1312 spin_lock_irqsave(&tport->tp_lock, flags); 1312 spin_lock_irqsave(&tport->tp_lock, flags);
1313 1313
@@ -1329,7 +1329,7 @@ static void ti_send(struct ti_port *tport)
1329 1329
1330 spin_unlock_irqrestore(&tport->tp_lock, flags); 1330 spin_unlock_irqrestore(&tport->tp_lock, flags);
1331 1331
1332 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); 1332 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer);
1333 1333
1334 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 1334 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
1335 usb_sndbulkpipe(port->serial->dev, 1335 usb_sndbulkpipe(port->serial->dev,
@@ -1339,7 +1339,7 @@ static void ti_send(struct ti_port *tport)
1339 1339
1340 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 1340 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1341 if (result) { 1341 if (result) {
1342 dev_err(&port->dev, "%s - submit write urb failed, %d\n", __FUNCTION__, result); 1342 dev_err(&port->dev, "%s - submit write urb failed, %d\n", __func__, result);
1343 tport->tp_write_urb_in_use = 0; 1343 tport->tp_write_urb_in_use = 0;
1344 /* TODO: reschedule ti_send */ 1344 /* TODO: reschedule ti_send */
1345 } else { 1345 } else {
@@ -1357,14 +1357,17 @@ static void ti_send(struct ti_port *tport)
1357 1357
1358static int ti_set_mcr(struct ti_port *tport, unsigned int mcr) 1358static int ti_set_mcr(struct ti_port *tport, unsigned int mcr)
1359{ 1359{
1360 unsigned long flags;
1360 int status; 1361 int status;
1361 1362
1362 status = ti_write_byte(tport->tp_tdev, 1363 status = ti_write_byte(tport->tp_tdev,
1363 tport->tp_uart_base_addr + TI_UART_OFFSET_MCR, 1364 tport->tp_uart_base_addr + TI_UART_OFFSET_MCR,
1364 TI_MCR_RTS | TI_MCR_DTR | TI_MCR_LOOP, mcr); 1365 TI_MCR_RTS | TI_MCR_DTR | TI_MCR_LOOP, mcr);
1365 1366
1367 spin_lock_irqsave(&tport->tp_lock, flags);
1366 if (!status) 1368 if (!status)
1367 tport->tp_shadow_mcr = mcr; 1369 tport->tp_shadow_mcr = mcr;
1370 spin_unlock_irqrestore(&tport->tp_lock, flags);
1368 1371
1369 return status; 1372 return status;
1370} 1373}
@@ -1378,23 +1381,23 @@ static int ti_get_lsr(struct ti_port *tport)
1378 int port_number = port->number - port->serial->minor; 1381 int port_number = port->number - port->serial->minor;
1379 struct ti_port_status *data; 1382 struct ti_port_status *data;
1380 1383
1381 dbg("%s - port %d", __FUNCTION__, port->number); 1384 dbg("%s - port %d", __func__, port->number);
1382 1385
1383 size = sizeof(struct ti_port_status); 1386 size = sizeof(struct ti_port_status);
1384 data = kmalloc(size, GFP_KERNEL); 1387 data = kmalloc(size, GFP_KERNEL);
1385 if (!data) { 1388 if (!data) {
1386 dev_err(&port->dev, "%s - out of memory\n", __FUNCTION__); 1389 dev_err(&port->dev, "%s - out of memory\n", __func__);
1387 return -ENOMEM; 1390 return -ENOMEM;
1388 } 1391 }
1389 1392
1390 status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, 1393 status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS,
1391 (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size); 1394 (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size);
1392 if (status) { 1395 if (status) {
1393 dev_err(&port->dev, "%s - get port status command failed, %d\n", __FUNCTION__, status); 1396 dev_err(&port->dev, "%s - get port status command failed, %d\n", __func__, status);
1394 goto free_data; 1397 goto free_data;
1395 } 1398 }
1396 1399
1397 dbg("%s - lsr 0x%02X", __FUNCTION__, data->bLSR); 1400 dbg("%s - lsr 0x%02X", __func__, data->bLSR);
1398 1401
1399 tport->tp_lsr = data->bLSR; 1402 tport->tp_lsr = data->bLSR;
1400 1403
@@ -1455,7 +1458,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1455 struct tty_struct *tty; 1458 struct tty_struct *tty;
1456 unsigned long flags; 1459 unsigned long flags;
1457 1460
1458 dbg("%s - msr 0x%02X", __FUNCTION__, msr); 1461 dbg("%s - msr 0x%02X", __func__, msr);
1459 1462
1460 if (msr & TI_MSR_DELTA_MASK) { 1463 if (msr & TI_MSR_DELTA_MASK) {
1461 spin_lock_irqsave(&tport->tp_lock, flags); 1464 spin_lock_irqsave(&tport->tp_lock, flags);
@@ -1493,7 +1496,7 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
1493 struct usb_serial_port *port = tport->tp_port; 1496 struct usb_serial_port *port = tport->tp_port;
1494 wait_queue_t wait; 1497 wait_queue_t wait;
1495 1498
1496 dbg("%s - port %d", __FUNCTION__, port->number); 1499 dbg("%s - port %d", __func__, port->number);
1497 1500
1498 spin_lock_irq(&tport->tp_lock); 1501 spin_lock_irq(&tport->tp_lock);
1499 1502
@@ -1625,12 +1628,12 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
1625 struct ti_write_data_bytes *data; 1628 struct ti_write_data_bytes *data;
1626 struct device *dev = &tdev->td_serial->dev->dev; 1629 struct device *dev = &tdev->td_serial->dev->dev;
1627 1630
1628 dbg("%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X", __FUNCTION__, addr, mask, byte); 1631 dbg("%s - addr 0x%08lX, mask 0x%02X, byte 0x%02X", __func__, addr, mask, byte);
1629 1632
1630 size = sizeof(struct ti_write_data_bytes) + 2; 1633 size = sizeof(struct ti_write_data_bytes) + 2;
1631 data = kmalloc(size, GFP_KERNEL); 1634 data = kmalloc(size, GFP_KERNEL);
1632 if (!data) { 1635 if (!data) {
1633 dev_err(dev, "%s - out of memory\n", __FUNCTION__); 1636 dev_err(dev, "%s - out of memory\n", __func__);
1634 return -ENOMEM; 1637 return -ENOMEM;
1635 } 1638 }
1636 1639
@@ -1646,7 +1649,7 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
1646 (__u8 *)data, size); 1649 (__u8 *)data, size);
1647 1650
1648 if (status < 0) 1651 if (status < 0)
1649 dev_err(dev, "%s - failed, %d\n", __FUNCTION__, status); 1652 dev_err(dev, "%s - failed, %d\n", __func__, status);
1650 1653
1651 kfree(data); 1654 kfree(data);
1652 1655
@@ -1673,7 +1676,7 @@ static int ti_download_firmware(struct ti_device *tdev,
1673 buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header); 1676 buffer_size = TI_FIRMWARE_BUF_SIZE + sizeof(struct ti_firmware_header);
1674 buffer = kmalloc(buffer_size, GFP_KERNEL); 1677 buffer = kmalloc(buffer_size, GFP_KERNEL);
1675 if (!buffer) { 1678 if (!buffer) {
1676 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 1679 dev_err(&dev->dev, "%s - out of memory\n", __func__);
1677 return -ENOMEM; 1680 return -ENOMEM;
1678 } 1681 }
1679 1682
@@ -1687,7 +1690,7 @@ static int ti_download_firmware(struct ti_device *tdev,
1687 header->wLength = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_firmware_header))); 1690 header->wLength = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_firmware_header)));
1688 header->bCheckSum = cs; 1691 header->bCheckSum = cs;
1689 1692
1690 dbg("%s - downloading firmware", __FUNCTION__); 1693 dbg("%s - downloading firmware", __func__);
1691 for (pos = 0; pos < buffer_size; pos += done) { 1694 for (pos = 0; pos < buffer_size; pos += done) {
1692 len = min(buffer_size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE); 1695 len = min(buffer_size - pos, TI_DOWNLOAD_MAX_PACKET_SIZE);
1693 status = usb_bulk_msg(dev, pipe, buffer+pos, len, &done, 1000); 1696 status = usb_bulk_msg(dev, pipe, buffer+pos, len, &done, 1000);
@@ -1698,11 +1701,11 @@ static int ti_download_firmware(struct ti_device *tdev,
1698 kfree(buffer); 1701 kfree(buffer);
1699 1702
1700 if (status) { 1703 if (status) {
1701 dev_err(&dev->dev, "%s - error downloading firmware, %d\n", __FUNCTION__, status); 1704 dev_err(&dev->dev, "%s - error downloading firmware, %d\n", __func__, status);
1702 return status; 1705 return status;
1703 } 1706 }
1704 1707
1705 dbg("%s - download successful", __FUNCTION__); 1708 dbg("%s - download successful", __func__);
1706 1709
1707 return 0; 1710 return 0;
1708} 1711}
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 2138ba8aeb69..a9934a3f9845 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -81,7 +81,7 @@ static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_po
81 unsigned int i, j; 81 unsigned int i, j;
82 int good_spot; 82 int good_spot;
83 83
84 dbg("%s %d", __FUNCTION__, num_ports); 84 dbg("%s %d", __func__, num_ports);
85 85
86 *minor = 0; 86 *minor = 0;
87 mutex_lock(&table_lock); 87 mutex_lock(&table_lock);
@@ -101,7 +101,7 @@ static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_po
101 101
102 *minor = i; 102 *minor = i;
103 j = 0; 103 j = 0;
104 dbg("%s - minor base = %d", __FUNCTION__, *minor); 104 dbg("%s - minor base = %d", __func__, *minor);
105 for (i = *minor; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) { 105 for (i = *minor; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) {
106 serial_table[i] = serial; 106 serial_table[i] = serial;
107 serial->port[j++]->number = i; 107 serial->port[j++]->number = i;
@@ -117,7 +117,7 @@ static void return_serial(struct usb_serial *serial)
117{ 117{
118 int i; 118 int i;
119 119
120 dbg("%s", __FUNCTION__); 120 dbg("%s", __func__);
121 121
122 if (serial == NULL) 122 if (serial == NULL)
123 return; 123 return;
@@ -135,7 +135,7 @@ static void destroy_serial(struct kref *kref)
135 135
136 serial = to_usb_serial(kref); 136 serial = to_usb_serial(kref);
137 137
138 dbg("%s - %s", __FUNCTION__, serial->type->description); 138 dbg("%s - %s", __func__, serial->type->description);
139 139
140 serial->type->shutdown(serial); 140 serial->type->shutdown(serial);
141 141
@@ -187,7 +187,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
187 unsigned int portNumber; 187 unsigned int portNumber;
188 int retval; 188 int retval;
189 189
190 dbg("%s", __FUNCTION__); 190 dbg("%s", __func__);
191 191
192 /* get the serial object associated with this tty pointer */ 192 /* get the serial object associated with this tty pointer */
193 serial = usb_serial_get_by_index(tty->index); 193 serial = usb_serial_get_by_index(tty->index);
@@ -259,7 +259,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
259 if (!port) 259 if (!port)
260 return; 260 return;
261 261
262 dbg("%s - port %d", __FUNCTION__, port->number); 262 dbg("%s - port %d", __func__, port->number);
263 263
264 mutex_lock(&port->mutex); 264 mutex_lock(&port->mutex);
265 265
@@ -299,11 +299,11 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int
299 if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) 299 if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED)
300 goto exit; 300 goto exit;
301 301
302 dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count); 302 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
303 303
304 if (!port->open_count) { 304 if (!port->open_count) {
305 retval = -EINVAL; 305 retval = -EINVAL;
306 dbg("%s - port not opened", __FUNCTION__); 306 dbg("%s - port not opened", __func__);
307 goto exit; 307 goto exit;
308 } 308 }
309 309
@@ -322,10 +322,10 @@ static int serial_write_room (struct tty_struct *tty)
322 if (!port) 322 if (!port)
323 goto exit; 323 goto exit;
324 324
325 dbg("%s - port %d", __FUNCTION__, port->number); 325 dbg("%s - port %d", __func__, port->number);
326 326
327 if (!port->open_count) { 327 if (!port->open_count) {
328 dbg("%s - port not open", __FUNCTION__); 328 dbg("%s - port not open", __func__);
329 goto exit; 329 goto exit;
330 } 330 }
331 331
@@ -344,10 +344,10 @@ static int serial_chars_in_buffer (struct tty_struct *tty)
344 if (!port) 344 if (!port)
345 goto exit; 345 goto exit;
346 346
347 dbg("%s = port %d", __FUNCTION__, port->number); 347 dbg("%s = port %d", __func__, port->number);
348 348
349 if (!port->open_count) { 349 if (!port->open_count) {
350 dbg("%s - port not open", __FUNCTION__); 350 dbg("%s - port not open", __func__);
351 goto exit; 351 goto exit;
352 } 352 }
353 353
@@ -365,10 +365,10 @@ static void serial_throttle (struct tty_struct * tty)
365 if (!port) 365 if (!port)
366 return; 366 return;
367 367
368 dbg("%s - port %d", __FUNCTION__, port->number); 368 dbg("%s - port %d", __func__, port->number);
369 369
370 if (!port->open_count) { 370 if (!port->open_count) {
371 dbg ("%s - port not open", __FUNCTION__); 371 dbg ("%s - port not open", __func__);
372 return; 372 return;
373 } 373 }
374 374
@@ -384,10 +384,10 @@ static void serial_unthrottle (struct tty_struct * tty)
384 if (!port) 384 if (!port)
385 return; 385 return;
386 386
387 dbg("%s - port %d", __FUNCTION__, port->number); 387 dbg("%s - port %d", __func__, port->number);
388 388
389 if (!port->open_count) { 389 if (!port->open_count) {
390 dbg("%s - port not open", __FUNCTION__); 390 dbg("%s - port not open", __func__);
391 return; 391 return;
392 } 392 }
393 393
@@ -401,13 +401,15 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in
401 struct usb_serial_port *port = tty->driver_data; 401 struct usb_serial_port *port = tty->driver_data;
402 int retval = -ENODEV; 402 int retval = -ENODEV;
403 403
404 lock_kernel();
404 if (!port) 405 if (!port)
405 goto exit; 406 goto exit;
406 407
407 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); 408 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
408 409
410 /* Caution - port->open_count is BKL protected */
409 if (!port->open_count) { 411 if (!port->open_count) {
410 dbg ("%s - port not open", __FUNCTION__); 412 dbg ("%s - port not open", __func__);
411 goto exit; 413 goto exit;
412 } 414 }
413 415
@@ -416,8 +418,8 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in
416 retval = port->serial->type->ioctl(port, file, cmd, arg); 418 retval = port->serial->type->ioctl(port, file, cmd, arg);
417 else 419 else
418 retval = -ENOIOCTLCMD; 420 retval = -ENOIOCTLCMD;
419
420exit: 421exit:
422 unlock_kernel();
421 return retval; 423 return retval;
422} 424}
423 425
@@ -428,10 +430,10 @@ static void serial_set_termios (struct tty_struct *tty, struct ktermios * old)
428 if (!port) 430 if (!port)
429 return; 431 return;
430 432
431 dbg("%s - port %d", __FUNCTION__, port->number); 433 dbg("%s - port %d", __func__, port->number);
432 434
433 if (!port->open_count) { 435 if (!port->open_count) {
434 dbg("%s - port not open", __FUNCTION__); 436 dbg("%s - port not open", __func__);
435 return; 437 return;
436 } 438 }
437 439
@@ -446,19 +448,24 @@ static void serial_break (struct tty_struct *tty, int break_state)
446{ 448{
447 struct usb_serial_port *port = tty->driver_data; 449 struct usb_serial_port *port = tty->driver_data;
448 450
449 if (!port) 451 lock_kernel();
452 if (!port) {
453 unlock_kernel();
450 return; 454 return;
455 }
451 456
452 dbg("%s - port %d", __FUNCTION__, port->number); 457 dbg("%s - port %d", __func__, port->number);
453 458
454 if (!port->open_count) { 459 if (!port->open_count) {
455 dbg("%s - port not open", __FUNCTION__); 460 dbg("%s - port not open", __func__);
461 unlock_kernel();
456 return; 462 return;
457 } 463 }
458 464
459 /* pass on to the driver specific version of this function if it is available */ 465 /* pass on to the driver specific version of this function if it is available */
460 if (port->serial->type->break_ctl) 466 if (port->serial->type->break_ctl)
461 port->serial->type->break_ctl(port, break_state); 467 port->serial->type->break_ctl(port, break_state);
468 unlock_kernel();
462} 469}
463 470
464static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) 471static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
@@ -469,7 +476,7 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
469 off_t begin = 0; 476 off_t begin = 0;
470 char tmp[40]; 477 char tmp[40];
471 478
472 dbg("%s", __FUNCTION__); 479 dbg("%s", __func__);
473 length += sprintf (page, "usbserinfo:1.0 driver:2.0\n"); 480 length += sprintf (page, "usbserinfo:1.0 driver:2.0\n");
474 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { 481 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
475 serial = usb_serial_get_by_index(i); 482 serial = usb_serial_get_by_index(i);
@@ -515,10 +522,10 @@ static int serial_tiocmget (struct tty_struct *tty, struct file *file)
515 if (!port) 522 if (!port)
516 return -ENODEV; 523 return -ENODEV;
517 524
518 dbg("%s - port %d", __FUNCTION__, port->number); 525 dbg("%s - port %d", __func__, port->number);
519 526
520 if (!port->open_count) { 527 if (!port->open_count) {
521 dbg("%s - port not open", __FUNCTION__); 528 dbg("%s - port not open", __func__);
522 return -ENODEV; 529 return -ENODEV;
523 } 530 }
524 531
@@ -536,10 +543,10 @@ static int serial_tiocmset (struct tty_struct *tty, struct file *file,
536 if (!port) 543 if (!port)
537 return -ENODEV; 544 return -ENODEV;
538 545
539 dbg("%s - port %d", __FUNCTION__, port->number); 546 dbg("%s - port %d", __func__, port->number);
540 547
541 if (!port->open_count) { 548 if (!port->open_count) {
542 dbg("%s - port not open", __FUNCTION__); 549 dbg("%s - port not open", __func__);
543 return -ENODEV; 550 return -ENODEV;
544 } 551 }
545 552
@@ -565,7 +572,7 @@ static void usb_serial_port_work(struct work_struct *work)
565 container_of(work, struct usb_serial_port, work); 572 container_of(work, struct usb_serial_port, work);
566 struct tty_struct *tty; 573 struct tty_struct *tty;
567 574
568 dbg("%s - port %d", __FUNCTION__, port->number); 575 dbg("%s - port %d", __func__, port->number);
569 576
570 if (!port) 577 if (!port)
571 return; 578 return;
@@ -581,7 +588,7 @@ static void port_release(struct device *dev)
581{ 588{
582 struct usb_serial_port *port = to_usb_serial_port(dev); 589 struct usb_serial_port *port = to_usb_serial_port(dev);
583 590
584 dbg ("%s - %s", __FUNCTION__, dev->bus_id); 591 dbg ("%s - %s", __func__, dev->bus_id);
585 port_free(port); 592 port_free(port);
586} 593}
587 594
@@ -627,7 +634,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
627 634
628 serial = kzalloc(sizeof(*serial), GFP_KERNEL); 635 serial = kzalloc(sizeof(*serial), GFP_KERNEL);
629 if (!serial) { 636 if (!serial) {
630 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 637 dev_err(&dev->dev, "%s - out of memory\n", __func__);
631 return NULL; 638 return NULL;
632 } 639 }
633 serial->dev = usb_get_dev(dev); 640 serial->dev = usb_get_dev(dev);
@@ -722,7 +729,7 @@ int usb_serial_probe(struct usb_interface *interface,
722 serial = create_serial (dev, interface, type); 729 serial = create_serial (dev, interface, type);
723 if (!serial) { 730 if (!serial) {
724 unlock_kernel(); 731 unlock_kernel();
725 dev_err(&interface->dev, "%s - out of memory\n", __FUNCTION__); 732 dev_err(&interface->dev, "%s - out of memory\n", __func__);
726 return -ENOMEM; 733 return -ENOMEM;
727 } 734 }
728 735
@@ -854,22 +861,6 @@ int usb_serial_probe(struct usb_interface *interface,
854 serial->num_interrupt_in = num_interrupt_in; 861 serial->num_interrupt_in = num_interrupt_in;
855 serial->num_interrupt_out = num_interrupt_out; 862 serial->num_interrupt_out = num_interrupt_out;
856 863
857#if 0
858 /* check that the device meets the driver's requirements */
859 if ((type->num_interrupt_in != NUM_DONT_CARE &&
860 type->num_interrupt_in != num_interrupt_in)
861 || (type->num_interrupt_out != NUM_DONT_CARE &&
862 type->num_interrupt_out != num_interrupt_out)
863 || (type->num_bulk_in != NUM_DONT_CARE &&
864 type->num_bulk_in != num_bulk_in)
865 || (type->num_bulk_out != NUM_DONT_CARE &&
866 type->num_bulk_out != num_bulk_out)) {
867 dbg("wrong number of endpoints");
868 kfree(serial);
869 return -EIO;
870 }
871#endif
872
873 /* found all that we need */ 864 /* found all that we need */
874 dev_info(&interface->dev, "%s converter detected\n", 865 dev_info(&interface->dev, "%s converter detected\n",
875 type->description); 866 type->description);
@@ -883,7 +874,7 @@ int usb_serial_probe(struct usb_interface *interface,
883 serial->num_port_pointers = max_endpoints; 874 serial->num_port_pointers = max_endpoints;
884 unlock_kernel(); 875 unlock_kernel();
885 876
886 dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints); 877 dbg("%s - setting up %d port structures for this device", __func__, max_endpoints);
887 for (i = 0; i < max_endpoints; ++i) { 878 for (i = 0; i < max_endpoints; ++i) {
888 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); 879 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
889 if (!port) 880 if (!port)
@@ -1031,7 +1022,7 @@ int usb_serial_probe(struct usb_interface *interface,
1031 port->dev.release = &port_release; 1022 port->dev.release = &port_release;
1032 1023
1033 snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number); 1024 snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number);
1034 dbg ("%s - registering %s", __FUNCTION__, port->dev.bus_id); 1025 dbg ("%s - registering %s", __func__, port->dev.bus_id);
1035 retval = device_register(&port->dev); 1026 retval = device_register(&port->dev);
1036 if (retval) 1027 if (retval)
1037 dev_err(&port->dev, "Error registering port device, " 1028 dev_err(&port->dev, "Error registering port device, "
@@ -1090,7 +1081,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
1090 struct usb_serial_port *port; 1081 struct usb_serial_port *port;
1091 1082
1092 usb_serial_console_disconnect(serial); 1083 usb_serial_console_disconnect(serial);
1093 dbg ("%s", __FUNCTION__); 1084 dbg ("%s", __func__);
1094 1085
1095 mutex_lock(&serial->disc_mutex); 1086 mutex_lock(&serial->disc_mutex);
1096 usb_set_intfdata (interface, NULL); 1087 usb_set_intfdata (interface, NULL);
@@ -1174,7 +1165,7 @@ static int __init usb_serial_init(void)
1174 1165
1175 result = bus_register(&usb_serial_bus_type); 1166 result = bus_register(&usb_serial_bus_type);
1176 if (result) { 1167 if (result) {
1177 err("%s - registering bus driver failed", __FUNCTION__); 1168 err("%s - registering bus driver failed", __func__);
1178 goto exit_bus; 1169 goto exit_bus;
1179 } 1170 }
1180 1171
@@ -1188,24 +1179,26 @@ static int __init usb_serial_init(void)
1188 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1179 usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1189 usb_serial_tty_driver->init_termios = tty_std_termios; 1180 usb_serial_tty_driver->init_termios = tty_std_termios;
1190 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1181 usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1182 usb_serial_tty_driver->init_termios.c_ispeed = 9600;
1183 usb_serial_tty_driver->init_termios.c_ospeed = 9600;
1191 tty_set_operations(usb_serial_tty_driver, &serial_ops); 1184 tty_set_operations(usb_serial_tty_driver, &serial_ops);
1192 result = tty_register_driver(usb_serial_tty_driver); 1185 result = tty_register_driver(usb_serial_tty_driver);
1193 if (result) { 1186 if (result) {
1194 err("%s - tty_register_driver failed", __FUNCTION__); 1187 err("%s - tty_register_driver failed", __func__);
1195 goto exit_reg_driver; 1188 goto exit_reg_driver;
1196 } 1189 }
1197 1190
1198 /* register the USB driver */ 1191 /* register the USB driver */
1199 result = usb_register(&usb_serial_driver); 1192 result = usb_register(&usb_serial_driver);
1200 if (result < 0) { 1193 if (result < 0) {
1201 err("%s - usb_register failed", __FUNCTION__); 1194 err("%s - usb_register failed", __func__);
1202 goto exit_tty; 1195 goto exit_tty;
1203 } 1196 }
1204 1197
1205 /* register the generic driver, if we should */ 1198 /* register the generic driver, if we should */
1206 result = usb_serial_generic_register(debug); 1199 result = usb_serial_generic_register(debug);
1207 if (result < 0) { 1200 if (result < 0) {
1208 err("%s - registering generic driver failed", __FUNCTION__); 1201 err("%s - registering generic driver failed", __func__);
1209 goto exit_generic; 1202 goto exit_generic;
1210 } 1203 }
1211 1204
@@ -1223,7 +1216,7 @@ exit_reg_driver:
1223 bus_unregister(&usb_serial_bus_type); 1216 bus_unregister(&usb_serial_bus_type);
1224 1217
1225exit_bus: 1218exit_bus:
1226 err ("%s - returning with error %d", __FUNCTION__, result); 1219 err ("%s - returning with error %d", __func__, result);
1227 put_tty_driver(usb_serial_tty_driver); 1220 put_tty_driver(usb_serial_tty_driver);
1228 return result; 1221 return result;
1229} 1222}
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c
index 257a5e436873..f9fc926b56d8 100644
--- a/drivers/usb/serial/usb_debug.c
+++ b/drivers/usb/serial/usb_debug.c
@@ -35,9 +35,6 @@ static struct usb_serial_driver debug_device = {
35 .name = "debug", 35 .name = "debug",
36 }, 36 },
37 .id_table = id_table, 37 .id_table = id_table,
38 .num_interrupt_in = NUM_DONT_CARE,
39 .num_bulk_in = NUM_DONT_CARE,
40 .num_bulk_out = NUM_DONT_CARE,
41 .num_ports = 1, 38 .num_ports = 1,
42}; 39};
43 40
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index c2b01f7c3197..5fc20122145f 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -189,9 +189,6 @@ static struct usb_serial_driver handspring_device = {
189 .description = "Handspring Visor / Palm OS", 189 .description = "Handspring Visor / Palm OS",
190 .usb_driver = &visor_driver, 190 .usb_driver = &visor_driver,
191 .id_table = id_table, 191 .id_table = id_table,
192 .num_interrupt_in = NUM_DONT_CARE,
193 .num_bulk_in = 2,
194 .num_bulk_out = NUM_DONT_CARE,
195 .num_ports = 2, 192 .num_ports = 2,
196 .open = visor_open, 193 .open = visor_open,
197 .close = visor_close, 194 .close = visor_close,
@@ -219,9 +216,6 @@ static struct usb_serial_driver clie_5_device = {
219 .description = "Sony Clie 5.0", 216 .description = "Sony Clie 5.0",
220 .usb_driver = &visor_driver, 217 .usb_driver = &visor_driver,
221 .id_table = clie_id_5_table, 218 .id_table = clie_id_5_table,
222 .num_interrupt_in = NUM_DONT_CARE,
223 .num_bulk_in = 2,
224 .num_bulk_out = 2,
225 .num_ports = 2, 219 .num_ports = 2,
226 .open = visor_open, 220 .open = visor_open,
227 .close = visor_close, 221 .close = visor_close,
@@ -249,9 +243,6 @@ static struct usb_serial_driver clie_3_5_device = {
249 .description = "Sony Clie 3.5", 243 .description = "Sony Clie 3.5",
250 .usb_driver = &visor_driver, 244 .usb_driver = &visor_driver,
251 .id_table = clie_id_3_5_table, 245 .id_table = clie_id_3_5_table,
252 .num_interrupt_in = 0,
253 .num_bulk_in = 1,
254 .num_bulk_out = 1,
255 .num_ports = 1, 246 .num_ports = 1,
256 .open = visor_open, 247 .open = visor_open,
257 .close = visor_close, 248 .close = visor_close,
@@ -290,7 +281,7 @@ static int visor_open (struct usb_serial_port *port, struct file *filp)
290 unsigned long flags; 281 unsigned long flags;
291 int result = 0; 282 int result = 0;
292 283
293 dbg("%s - port %d", __FUNCTION__, port->number); 284 dbg("%s - port %d", __func__, port->number);
294 285
295 if (!port->read_urb) { 286 if (!port->read_urb) {
296 /* this is needed for some brain dead Sony devices */ 287 /* this is needed for some brain dead Sony devices */
@@ -322,16 +313,16 @@ static int visor_open (struct usb_serial_port *port, struct file *filp)
322 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 313 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
323 if (result) { 314 if (result) {
324 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", 315 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n",
325 __FUNCTION__, result); 316 __func__, result);
326 goto exit; 317 goto exit;
327 } 318 }
328 319
329 if (port->interrupt_in_urb) { 320 if (port->interrupt_in_urb) {
330 dbg("%s - adding interrupt input for treo", __FUNCTION__); 321 dbg("%s - adding interrupt input for treo", __func__);
331 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 322 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
332 if (result) 323 if (result)
333 dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", 324 dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n",
334 __FUNCTION__, result); 325 __func__, result);
335 } 326 }
336exit: 327exit:
337 return result; 328 return result;
@@ -343,7 +334,7 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
343 struct visor_private *priv = usb_get_serial_port_data(port); 334 struct visor_private *priv = usb_get_serial_port_data(port);
344 unsigned char *transfer_buffer; 335 unsigned char *transfer_buffer;
345 336
346 dbg("%s - port %d", __FUNCTION__, port->number); 337 dbg("%s - port %d", __func__, port->number);
347 338
348 /* shutdown our urbs */ 339 /* shutdown our urbs */
349 usb_kill_urb(port->read_urb); 340 usb_kill_urb(port->read_urb);
@@ -379,12 +370,12 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
379 unsigned long flags; 370 unsigned long flags;
380 int status; 371 int status;
381 372
382 dbg("%s - port %d", __FUNCTION__, port->number); 373 dbg("%s - port %d", __func__, port->number);
383 374
384 spin_lock_irqsave(&priv->lock, flags); 375 spin_lock_irqsave(&priv->lock, flags);
385 if (priv->outstanding_urbs > URB_UPPER_LIMIT) { 376 if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
386 spin_unlock_irqrestore(&priv->lock, flags); 377 spin_unlock_irqrestore(&priv->lock, flags);
387 dbg("%s - write limit hit\n", __FUNCTION__); 378 dbg("%s - write limit hit\n", __func__);
388 return 0; 379 return 0;
389 } 380 }
390 priv->outstanding_urbs++; 381 priv->outstanding_urbs++;
@@ -406,7 +397,7 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
406 397
407 memcpy (buffer, buf, count); 398 memcpy (buffer, buf, count);
408 399
409 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer); 400 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
410 401
411 usb_fill_bulk_urb (urb, serial->dev, 402 usb_fill_bulk_urb (urb, serial->dev,
412 usb_sndbulkpipe (serial->dev, 403 usb_sndbulkpipe (serial->dev,
@@ -418,7 +409,7 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
418 status = usb_submit_urb(urb, GFP_ATOMIC); 409 status = usb_submit_urb(urb, GFP_ATOMIC);
419 if (status) { 410 if (status) {
420 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", 411 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n",
421 __FUNCTION__, status); 412 __func__, status);
422 count = status; 413 count = status;
423 goto error; 414 goto error;
424 } else { 415 } else {
@@ -449,7 +440,7 @@ static int visor_write_room (struct usb_serial_port *port)
449 struct visor_private *priv = usb_get_serial_port_data(port); 440 struct visor_private *priv = usb_get_serial_port_data(port);
450 unsigned long flags; 441 unsigned long flags;
451 442
452 dbg("%s - port %d", __FUNCTION__, port->number); 443 dbg("%s - port %d", __func__, port->number);
453 444
454 /* 445 /*
455 * We really can take anything the user throws at us 446 * We really can take anything the user throws at us
@@ -460,7 +451,7 @@ static int visor_write_room (struct usb_serial_port *port)
460 spin_lock_irqsave(&priv->lock, flags); 451 spin_lock_irqsave(&priv->lock, flags);
461 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) { 452 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) {
462 spin_unlock_irqrestore(&priv->lock, flags); 453 spin_unlock_irqrestore(&priv->lock, flags);
463 dbg("%s - write limit hit\n", __FUNCTION__); 454 dbg("%s - write limit hit\n", __func__);
464 return 0; 455 return 0;
465 } 456 }
466 spin_unlock_irqrestore(&priv->lock, flags); 457 spin_unlock_irqrestore(&priv->lock, flags);
@@ -471,13 +462,15 @@ static int visor_write_room (struct usb_serial_port *port)
471 462
472static int visor_chars_in_buffer (struct usb_serial_port *port) 463static int visor_chars_in_buffer (struct usb_serial_port *port)
473{ 464{
474 dbg("%s - port %d", __FUNCTION__, port->number); 465 dbg("%s - port %d", __func__, port->number);
475 466
476 /* 467 /*
477 * We can't really account for how much data we 468 * We can't really account for how much data we
478 * have sent out, but hasn't made it through to the 469 * have sent out, but hasn't made it through to the
479 * device, so just tell the tty layer that everything 470 * device, so just tell the tty layer that everything
480 * is flushed. 471 * is flushed.
472 *
473 * FIXME: Should walk outstanding_urbs
481 */ 474 */
482 return 0; 475 return 0;
483} 476}
@@ -485,7 +478,7 @@ static int visor_chars_in_buffer (struct usb_serial_port *port)
485 478
486static void visor_write_bulk_callback (struct urb *urb) 479static void visor_write_bulk_callback (struct urb *urb)
487{ 480{
488 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 481 struct usb_serial_port *port = urb->context;
489 struct visor_private *priv = usb_get_serial_port_data(port); 482 struct visor_private *priv = usb_get_serial_port_data(port);
490 int status = urb->status; 483 int status = urb->status;
491 unsigned long flags; 484 unsigned long flags;
@@ -493,11 +486,11 @@ static void visor_write_bulk_callback (struct urb *urb)
493 /* free up the transfer buffer, as usb_free_urb() does not do this */ 486 /* free up the transfer buffer, as usb_free_urb() does not do this */
494 kfree (urb->transfer_buffer); 487 kfree (urb->transfer_buffer);
495 488
496 dbg("%s - port %d", __FUNCTION__, port->number); 489 dbg("%s - port %d", __func__, port->number);
497 490
498 if (status) 491 if (status)
499 dbg("%s - nonzero write bulk status received: %d", 492 dbg("%s - nonzero write bulk status received: %d",
500 __FUNCTION__, status); 493 __func__, status);
501 494
502 spin_lock_irqsave(&priv->lock, flags); 495 spin_lock_irqsave(&priv->lock, flags);
503 --priv->outstanding_urbs; 496 --priv->outstanding_urbs;
@@ -509,7 +502,7 @@ static void visor_write_bulk_callback (struct urb *urb)
509 502
510static void visor_read_bulk_callback (struct urb *urb) 503static void visor_read_bulk_callback (struct urb *urb)
511{ 504{
512 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 505 struct usb_serial_port *port = urb->context;
513 struct visor_private *priv = usb_get_serial_port_data(port); 506 struct visor_private *priv = usb_get_serial_port_data(port);
514 unsigned char *data = urb->transfer_buffer; 507 unsigned char *data = urb->transfer_buffer;
515 int status = urb->status; 508 int status = urb->status;
@@ -517,15 +510,15 @@ static void visor_read_bulk_callback (struct urb *urb)
517 int result; 510 int result;
518 int available_room; 511 int available_room;
519 512
520 dbg("%s - port %d", __FUNCTION__, port->number); 513 dbg("%s - port %d", __func__, port->number);
521 514
522 if (status) { 515 if (status) {
523 dbg("%s - nonzero read bulk status received: %d", 516 dbg("%s - nonzero read bulk status received: %d",
524 __FUNCTION__, status); 517 __func__, status);
525 return; 518 return;
526 } 519 }
527 520
528 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 521 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
529 522
530 tty = port->tty; 523 tty = port->tty;
531 if (tty && urb->actual_length) { 524 if (tty && urb->actual_length) {
@@ -551,7 +544,7 @@ static void visor_read_bulk_callback (struct urb *urb)
551 visor_read_bulk_callback, port); 544 visor_read_bulk_callback, port);
552 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 545 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
553 if (result) 546 if (result)
554 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 547 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
555 } else { 548 } else {
556 priv->actually_throttled = 1; 549 priv->actually_throttled = 1;
557 } 550 }
@@ -560,7 +553,7 @@ static void visor_read_bulk_callback (struct urb *urb)
560 553
561static void visor_read_int_callback (struct urb *urb) 554static void visor_read_int_callback (struct urb *urb)
562{ 555{
563 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 556 struct usb_serial_port *port = urb->context;
564 int status = urb->status; 557 int status = urb->status;
565 int result; 558 int result;
566 559
@@ -573,11 +566,11 @@ static void visor_read_int_callback (struct urb *urb)
573 case -ESHUTDOWN: 566 case -ESHUTDOWN:
574 /* this urb is terminated, clean up */ 567 /* this urb is terminated, clean up */
575 dbg("%s - urb shutting down with status: %d", 568 dbg("%s - urb shutting down with status: %d",
576 __FUNCTION__, status); 569 __func__, status);
577 return; 570 return;
578 default: 571 default:
579 dbg("%s - nonzero urb status received: %d", 572 dbg("%s - nonzero urb status received: %d",
580 __FUNCTION__, status); 573 __func__, status);
581 goto exit; 574 goto exit;
582 } 575 }
583 576
@@ -588,14 +581,14 @@ static void visor_read_int_callback (struct urb *urb)
588 * Rumor has it this endpoint is used to notify when data 581 * Rumor has it this endpoint is used to notify when data
589 * is ready to be read from the bulk ones. 582 * is ready to be read from the bulk ones.
590 */ 583 */
591 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, 584 usb_serial_debug_data(debug, &port->dev, __func__,
592 urb->actual_length, urb->transfer_buffer); 585 urb->actual_length, urb->transfer_buffer);
593 586
594exit: 587exit:
595 result = usb_submit_urb (urb, GFP_ATOMIC); 588 result = usb_submit_urb (urb, GFP_ATOMIC);
596 if (result) 589 if (result)
597 dev_err(&urb->dev->dev, "%s - Error %d submitting interrupt urb\n", 590 dev_err(&urb->dev->dev, "%s - Error %d submitting interrupt urb\n",
598 __FUNCTION__, result); 591 __func__, result);
599} 592}
600 593
601static void visor_throttle (struct usb_serial_port *port) 594static void visor_throttle (struct usb_serial_port *port)
@@ -603,7 +596,7 @@ static void visor_throttle (struct usb_serial_port *port)
603 struct visor_private *priv = usb_get_serial_port_data(port); 596 struct visor_private *priv = usb_get_serial_port_data(port);
604 unsigned long flags; 597 unsigned long flags;
605 598
606 dbg("%s - port %d", __FUNCTION__, port->number); 599 dbg("%s - port %d", __func__, port->number);
607 spin_lock_irqsave(&priv->lock, flags); 600 spin_lock_irqsave(&priv->lock, flags);
608 priv->throttled = 1; 601 priv->throttled = 1;
609 spin_unlock_irqrestore(&priv->lock, flags); 602 spin_unlock_irqrestore(&priv->lock, flags);
@@ -616,7 +609,7 @@ static void visor_unthrottle (struct usb_serial_port *port)
616 unsigned long flags; 609 unsigned long flags;
617 int result; 610 int result;
618 611
619 dbg("%s - port %d", __FUNCTION__, port->number); 612 dbg("%s - port %d", __func__, port->number);
620 spin_lock_irqsave(&priv->lock, flags); 613 spin_lock_irqsave(&priv->lock, flags);
621 priv->throttled = 0; 614 priv->throttled = 0;
622 priv->actually_throttled = 0; 615 priv->actually_throttled = 0;
@@ -625,7 +618,7 @@ static void visor_unthrottle (struct usb_serial_port *port)
625 port->read_urb->dev = port->serial->dev; 618 port->read_urb->dev = port->serial->dev;
626 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 619 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
627 if (result) 620 if (result)
628 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 621 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result);
629} 622}
630 623
631static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id) 624static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id)
@@ -638,11 +631,11 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
638 int i; 631 int i;
639 int num_ports = 0; 632 int num_ports = 0;
640 633
641 dbg("%s", __FUNCTION__); 634 dbg("%s", __func__);
642 635
643 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL); 636 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL);
644 if (!transfer_buffer) { 637 if (!transfer_buffer) {
645 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __FUNCTION__, 638 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
646 sizeof(*connection_info)); 639 sizeof(*connection_info));
647 return -ENOMEM; 640 return -ENOMEM;
648 } 641 }
@@ -655,7 +648,7 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
655 sizeof(*connection_info), 300); 648 sizeof(*connection_info), 300);
656 if (retval < 0) { 649 if (retval < 0) {
657 dev_err(dev, "%s - error %d getting connection information\n", 650 dev_err(dev, "%s - error %d getting connection information\n",
658 __FUNCTION__, retval); 651 __func__, retval);
659 goto exit; 652 goto exit;
660 } 653 }
661 654
@@ -715,7 +708,7 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
715 0x02, 300); 708 0x02, 300);
716 if (retval < 0) 709 if (retval < 0)
717 dev_err(dev, "%s - error %d getting bytes available request\n", 710 dev_err(dev, "%s - error %d getting bytes available request\n",
718 __FUNCTION__, retval); 711 __func__, retval);
719 retval = 0; 712 retval = 0;
720 713
721exit: 714exit:
@@ -731,11 +724,11 @@ static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_i
731 unsigned char *transfer_buffer; 724 unsigned char *transfer_buffer;
732 int retval; 725 int retval;
733 726
734 dbg("%s", __FUNCTION__); 727 dbg("%s", __func__);
735 728
736 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL); 729 transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL);
737 if (!transfer_buffer) { 730 if (!transfer_buffer) {
738 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __FUNCTION__, 731 dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
739 sizeof(*connection_info)); 732 sizeof(*connection_info));
740 return -ENOMEM; 733 return -ENOMEM;
741 } 734 }
@@ -747,9 +740,9 @@ static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_i
747 sizeof (*connection_info), 300); 740 sizeof (*connection_info), 300);
748 if (retval < 0) 741 if (retval < 0)
749 dev_err(dev, "%s - error %d getting connection info\n", 742 dev_err(dev, "%s - error %d getting connection info\n",
750 __FUNCTION__, retval); 743 __func__, retval);
751 else 744 else
752 usb_serial_debug_data(debug, &serial->dev->dev, __FUNCTION__, 745 usb_serial_debug_data(debug, &serial->dev->dev, __func__,
753 retval, transfer_buffer); 746 retval, transfer_buffer);
754 747
755 kfree (transfer_buffer); 748 kfree (transfer_buffer);
@@ -762,7 +755,7 @@ static int visor_probe (struct usb_serial *serial, const struct usb_device_id *i
762 int retval = 0; 755 int retval = 0;
763 int (*startup) (struct usb_serial *serial, const struct usb_device_id *id); 756 int (*startup) (struct usb_serial *serial, const struct usb_device_id *id);
764 757
765 dbg("%s", __FUNCTION__); 758 dbg("%s", __func__);
766 759
767 if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 760 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
768 err("active config #%d != 1 ??", 761 err("active config #%d != 1 ??",
@@ -816,7 +809,7 @@ static int clie_3_5_startup (struct usb_serial *serial)
816 int result; 809 int result;
817 u8 data; 810 u8 data;
818 811
819 dbg("%s", __FUNCTION__); 812 dbg("%s", __func__);
820 813
821 /* 814 /*
822 * Note that PEG-300 series devices expect the following two calls. 815 * Note that PEG-300 series devices expect the following two calls.
@@ -827,11 +820,11 @@ static int clie_3_5_startup (struct usb_serial *serial)
827 USB_REQ_GET_CONFIGURATION, USB_DIR_IN, 820 USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
828 0, 0, &data, 1, 3000); 821 0, 0, &data, 1, 3000);
829 if (result < 0) { 822 if (result < 0) {
830 dev_err(dev, "%s: get config number failed: %d\n", __FUNCTION__, result); 823 dev_err(dev, "%s: get config number failed: %d\n", __func__, result);
831 return result; 824 return result;
832 } 825 }
833 if (result != 1) { 826 if (result != 1) {
834 dev_err(dev, "%s: get config number bad return length: %d\n", __FUNCTION__, result); 827 dev_err(dev, "%s: get config number bad return length: %d\n", __func__, result);
835 return -EIO; 828 return -EIO;
836 } 829 }
837 830
@@ -841,11 +834,11 @@ static int clie_3_5_startup (struct usb_serial *serial)
841 USB_DIR_IN | USB_RECIP_INTERFACE, 834 USB_DIR_IN | USB_RECIP_INTERFACE,
842 0, 0, &data, 1, 3000); 835 0, 0, &data, 1, 3000);
843 if (result < 0) { 836 if (result < 0) {
844 dev_err(dev, "%s: get interface number failed: %d\n", __FUNCTION__, result); 837 dev_err(dev, "%s: get interface number failed: %d\n", __func__, result);
845 return result; 838 return result;
846 } 839 }
847 if (result != 1) { 840 if (result != 1) {
848 dev_err(dev, "%s: get interface number bad return length: %d\n", __FUNCTION__, result); 841 dev_err(dev, "%s: get interface number bad return length: %d\n", __func__, result);
849 return -EIO; 842 return -EIO;
850 } 843 }
851 844
@@ -863,7 +856,7 @@ static int treo_attach (struct usb_serial *serial)
863 (serial->num_interrupt_in == 0)) 856 (serial->num_interrupt_in == 0))
864 goto generic_startup; 857 goto generic_startup;
865 858
866 dbg("%s", __FUNCTION__); 859 dbg("%s", __func__);
867 860
868 /* 861 /*
869 * It appears that Treos and Kyoceras want to use the 862 * It appears that Treos and Kyoceras want to use the
@@ -894,7 +887,7 @@ generic_startup:
894 887
895static int clie_5_attach (struct usb_serial *serial) 888static int clie_5_attach (struct usb_serial *serial)
896{ 889{
897 dbg("%s", __FUNCTION__); 890 dbg("%s", __func__);
898 891
899 /* TH55 registers 2 ports. 892 /* TH55 registers 2 ports.
900 Communication in from the UX50/TH55 uses bulk_in_endpointAddress from port 0 893 Communication in from the UX50/TH55 uses bulk_in_endpointAddress from port 0
@@ -918,7 +911,7 @@ static void visor_shutdown (struct usb_serial *serial)
918 struct visor_private *priv; 911 struct visor_private *priv;
919 int i; 912 int i;
920 913
921 dbg("%s", __FUNCTION__); 914 dbg("%s", __func__);
922 915
923 for (i = 0; i < serial->num_ports; i++) { 916 for (i = 0; i < serial->num_ports; i++) {
924 priv = usb_get_serial_port_data(serial->port[i]); 917 priv = usb_get_serial_port_data(serial->port[i]);
@@ -931,7 +924,7 @@ static void visor_shutdown (struct usb_serial *serial)
931 924
932static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 925static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
933{ 926{
934 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); 927 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
935 928
936 return -ENOIOCTLCMD; 929 return -ENOIOCTLCMD;
937} 930}
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 38726ef3132b..e96bf8663ffc 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -164,9 +164,6 @@ static struct usb_serial_driver whiteheat_fake_device = {
164 .description = "Connect Tech - WhiteHEAT - (prerenumeration)", 164 .description = "Connect Tech - WhiteHEAT - (prerenumeration)",
165 .usb_driver = &whiteheat_driver, 165 .usb_driver = &whiteheat_driver,
166 .id_table = id_table_prerenumeration, 166 .id_table = id_table_prerenumeration,
167 .num_interrupt_in = NUM_DONT_CARE,
168 .num_bulk_in = NUM_DONT_CARE,
169 .num_bulk_out = NUM_DONT_CARE,
170 .num_ports = 1, 167 .num_ports = 1,
171 .probe = whiteheat_firmware_download, 168 .probe = whiteheat_firmware_download,
172 .attach = whiteheat_firmware_attach, 169 .attach = whiteheat_firmware_attach,
@@ -180,9 +177,6 @@ static struct usb_serial_driver whiteheat_device = {
180 .description = "Connect Tech - WhiteHEAT", 177 .description = "Connect Tech - WhiteHEAT",
181 .usb_driver = &whiteheat_driver, 178 .usb_driver = &whiteheat_driver,
182 .id_table = id_table_std, 179 .id_table = id_table_std,
183 .num_interrupt_in = NUM_DONT_CARE,
184 .num_bulk_in = NUM_DONT_CARE,
185 .num_bulk_out = NUM_DONT_CARE,
186 .num_ports = 4, 180 .num_ports = 4,
187 .attach = whiteheat_attach, 181 .attach = whiteheat_attach,
188 .shutdown = whiteheat_shutdown, 182 .shutdown = whiteheat_shutdown,
@@ -225,7 +219,7 @@ struct whiteheat_urb_wrap {
225struct whiteheat_private { 219struct whiteheat_private {
226 spinlock_t lock; 220 spinlock_t lock;
227 __u8 flags; 221 __u8 flags;
228 __u8 mcr; 222 __u8 mcr; /* FIXME: no locking on mcr */
229 struct list_head rx_urbs_free; 223 struct list_head rx_urbs_free;
230 struct list_head rx_urbs_submitted; 224 struct list_head rx_urbs_submitted;
231 struct list_head rx_urb_q; 225 struct list_head rx_urb_q;
@@ -288,7 +282,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
288 int response; 282 int response;
289 const struct whiteheat_hex_record *record; 283 const struct whiteheat_hex_record *record;
290 284
291 dbg("%s", __FUNCTION__); 285 dbg("%s", __func__);
292 286
293 response = ezusb_set_reset (serial, 1); 287 response = ezusb_set_reset (serial, 1);
294 288
@@ -298,7 +292,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
298 (unsigned char *)record->data, record->data_size, 0xa0); 292 (unsigned char *)record->data, record->data_size, 0xa0);
299 if (response < 0) { 293 if (response < 0) {
300 err("%s - ezusb_writememory failed for loader (%d %04X %p %d)", 294 err("%s - ezusb_writememory failed for loader (%d %04X %p %d)",
301 __FUNCTION__, response, record->address, record->data, record->data_size); 295 __func__, response, record->address, record->data, record->data_size);
302 break; 296 break;
303 } 297 }
304 ++record; 298 ++record;
@@ -315,7 +309,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
315 (unsigned char *)record->data, record->data_size, 0xa3); 309 (unsigned char *)record->data, record->data_size, 0xa3);
316 if (response < 0) { 310 if (response < 0) {
317 err("%s - ezusb_writememory failed for first firmware step (%d %04X %p %d)", 311 err("%s - ezusb_writememory failed for first firmware step (%d %04X %p %d)",
318 __FUNCTION__, response, record->address, record->data, record->data_size); 312 __func__, response, record->address, record->data, record->data_size);
319 break; 313 break;
320 } 314 }
321 ++record; 315 ++record;
@@ -329,7 +323,7 @@ static int whiteheat_firmware_download (struct usb_serial *serial, const struct
329 (unsigned char *)record->data, record->data_size, 0xa0); 323 (unsigned char *)record->data, record->data_size, 0xa0);
330 if (response < 0) { 324 if (response < 0) {
331 err("%s - ezusb_writememory failed for second firmware step (%d %04X %p %d)", 325 err("%s - ezusb_writememory failed for second firmware step (%d %04X %p %d)",
332 __FUNCTION__, response, record->address, record->data, record->data_size); 326 __func__, response, record->address, record->data, record->data_size);
333 break; 327 break;
334 } 328 }
335 ++record; 329 ++record;
@@ -567,7 +561,7 @@ static void whiteheat_shutdown (struct usb_serial *serial)
567 struct list_head *tmp2; 561 struct list_head *tmp2;
568 int i; 562 int i;
569 563
570 dbg("%s", __FUNCTION__); 564 dbg("%s", __func__);
571 565
572 /* free up our private data for our command port */ 566 /* free up our private data for our command port */
573 command_port = serial->port[COMMAND_PORT]; 567 command_port = serial->port[COMMAND_PORT];
@@ -604,7 +598,7 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
604 int retval = 0; 598 int retval = 0;
605 struct ktermios old_term; 599 struct ktermios old_term;
606 600
607 dbg("%s - port %d", __FUNCTION__, port->number); 601 dbg("%s - port %d", __func__, port->number);
608 602
609 retval = start_command_port(port->serial); 603 retval = start_command_port(port->serial);
610 if (retval) 604 if (retval)
@@ -637,14 +631,14 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
637 /* Start reading from the device */ 631 /* Start reading from the device */
638 retval = start_port_read(port); 632 retval = start_port_read(port);
639 if (retval) { 633 if (retval) {
640 err("%s - failed submitting read urb, error %d", __FUNCTION__, retval); 634 err("%s - failed submitting read urb, error %d", __func__, retval);
641 firm_close(port); 635 firm_close(port);
642 stop_command_port(port->serial); 636 stop_command_port(port->serial);
643 goto exit; 637 goto exit;
644 } 638 }
645 639
646exit: 640exit:
647 dbg("%s - exit, retval = %d", __FUNCTION__, retval); 641 dbg("%s - exit, retval = %d", __func__, retval);
648 return retval; 642 return retval;
649} 643}
650 644
@@ -657,7 +651,7 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
657 struct list_head *tmp; 651 struct list_head *tmp;
658 struct list_head *tmp2; 652 struct list_head *tmp2;
659 653
660 dbg("%s - port %d", __FUNCTION__, port->number); 654 dbg("%s - port %d", __func__, port->number);
661 655
662 mutex_lock(&port->serial->disc_mutex); 656 mutex_lock(&port->serial->disc_mutex);
663 /* filp is NULL when called from usb_serial_disconnect */ 657 /* filp is NULL when called from usb_serial_disconnect */
@@ -732,10 +726,10 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu
732 unsigned long flags; 726 unsigned long flags;
733 struct list_head *tmp; 727 struct list_head *tmp;
734 728
735 dbg("%s - port %d", __FUNCTION__, port->number); 729 dbg("%s - port %d", __func__, port->number);
736 730
737 if (count == 0) { 731 if (count == 0) {
738 dbg("%s - write request of 0 bytes", __FUNCTION__); 732 dbg("%s - write request of 0 bytes", __func__);
739 return (0); 733 return (0);
740 } 734 }
741 735
@@ -754,13 +748,13 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu
754 bytes = (count > port->bulk_out_size) ? port->bulk_out_size : count; 748 bytes = (count > port->bulk_out_size) ? port->bulk_out_size : count;
755 memcpy (urb->transfer_buffer, buf + sent, bytes); 749 memcpy (urb->transfer_buffer, buf + sent, bytes);
756 750
757 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, bytes, urb->transfer_buffer); 751 usb_serial_debug_data(debug, &port->dev, __func__, bytes, urb->transfer_buffer);
758 752
759 urb->dev = serial->dev; 753 urb->dev = serial->dev;
760 urb->transfer_buffer_length = bytes; 754 urb->transfer_buffer_length = bytes;
761 result = usb_submit_urb(urb, GFP_ATOMIC); 755 result = usb_submit_urb(urb, GFP_ATOMIC);
762 if (result) { 756 if (result) {
763 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 757 err("%s - failed submitting write urb, error %d", __func__, result);
764 sent = result; 758 sent = result;
765 spin_lock_irqsave(&info->lock, flags); 759 spin_lock_irqsave(&info->lock, flags);
766 list_add(tmp, &info->tx_urbs_free); 760 list_add(tmp, &info->tx_urbs_free);
@@ -786,7 +780,7 @@ static int whiteheat_write_room(struct usb_serial_port *port)
786 int room = 0; 780 int room = 0;
787 unsigned long flags; 781 unsigned long flags;
788 782
789 dbg("%s - port %d", __FUNCTION__, port->number); 783 dbg("%s - port %d", __func__, port->number);
790 784
791 spin_lock_irqsave(&info->lock, flags); 785 spin_lock_irqsave(&info->lock, flags);
792 list_for_each(tmp, &info->tx_urbs_free) 786 list_for_each(tmp, &info->tx_urbs_free)
@@ -794,7 +788,7 @@ static int whiteheat_write_room(struct usb_serial_port *port)
794 spin_unlock_irqrestore(&info->lock, flags); 788 spin_unlock_irqrestore(&info->lock, flags);
795 room *= port->bulk_out_size; 789 room *= port->bulk_out_size;
796 790
797 dbg("%s - returns %d", __FUNCTION__, room); 791 dbg("%s - returns %d", __func__, room);
798 return (room); 792 return (room);
799} 793}
800 794
@@ -804,7 +798,7 @@ static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file)
804 struct whiteheat_private *info = usb_get_serial_port_data(port); 798 struct whiteheat_private *info = usb_get_serial_port_data(port);
805 unsigned int modem_signals = 0; 799 unsigned int modem_signals = 0;
806 800
807 dbg("%s - port %d", __FUNCTION__, port->number); 801 dbg("%s - port %d", __func__, port->number);
808 802
809 firm_get_dtr_rts(port); 803 firm_get_dtr_rts(port);
810 if (info->mcr & UART_MCR_DTR) 804 if (info->mcr & UART_MCR_DTR)
@@ -821,7 +815,7 @@ static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file,
821{ 815{
822 struct whiteheat_private *info = usb_get_serial_port_data(port); 816 struct whiteheat_private *info = usb_get_serial_port_data(port);
823 817
824 dbg("%s - port %d", __FUNCTION__, port->number); 818 dbg("%s - port %d", __func__, port->number);
825 819
826 if (set & TIOCM_RTS) 820 if (set & TIOCM_RTS)
827 info->mcr |= UART_MCR_RTS; 821 info->mcr |= UART_MCR_RTS;
@@ -844,7 +838,7 @@ static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, un
844 struct serial_struct serstruct; 838 struct serial_struct serstruct;
845 void __user *user_arg = (void __user *)arg; 839 void __user *user_arg = (void __user *)arg;
846 840
847 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); 841 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
848 842
849 switch (cmd) { 843 switch (cmd) {
850 case TIOCGSERIAL: 844 case TIOCGSERIAL:
@@ -886,7 +880,7 @@ static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, un
886 880
887static void whiteheat_set_termios(struct usb_serial_port *port, struct ktermios *old_termios) 881static void whiteheat_set_termios(struct usb_serial_port *port, struct ktermios *old_termios)
888{ 882{
889 dbg("%s -port %d", __FUNCTION__, port->number); 883 dbg("%s -port %d", __func__, port->number);
890 firm_setup_port(port); 884 firm_setup_port(port);
891} 885}
892 886
@@ -904,7 +898,7 @@ static int whiteheat_chars_in_buffer(struct usb_serial_port *port)
904 int chars = 0; 898 int chars = 0;
905 unsigned long flags; 899 unsigned long flags;
906 900
907 dbg("%s - port %d", __FUNCTION__, port->number); 901 dbg("%s - port %d", __func__, port->number);
908 902
909 spin_lock_irqsave(&info->lock, flags); 903 spin_lock_irqsave(&info->lock, flags);
910 list_for_each(tmp, &info->tx_urbs_submitted) { 904 list_for_each(tmp, &info->tx_urbs_submitted) {
@@ -913,7 +907,7 @@ static int whiteheat_chars_in_buffer(struct usb_serial_port *port)
913 } 907 }
914 spin_unlock_irqrestore(&info->lock, flags); 908 spin_unlock_irqrestore(&info->lock, flags);
915 909
916 dbg ("%s - returns %d", __FUNCTION__, chars); 910 dbg ("%s - returns %d", __func__, chars);
917 return chars; 911 return chars;
918} 912}
919 913
@@ -923,7 +917,7 @@ static void whiteheat_throttle (struct usb_serial_port *port)
923 struct whiteheat_private *info = usb_get_serial_port_data(port); 917 struct whiteheat_private *info = usb_get_serial_port_data(port);
924 unsigned long flags; 918 unsigned long flags;
925 919
926 dbg("%s - port %d", __FUNCTION__, port->number); 920 dbg("%s - port %d", __func__, port->number);
927 921
928 spin_lock_irqsave(&info->lock, flags); 922 spin_lock_irqsave(&info->lock, flags);
929 info->flags |= THROTTLED; 923 info->flags |= THROTTLED;
@@ -939,7 +933,7 @@ static void whiteheat_unthrottle (struct usb_serial_port *port)
939 int actually_throttled; 933 int actually_throttled;
940 unsigned long flags; 934 unsigned long flags;
941 935
942 dbg("%s - port %d", __FUNCTION__, port->number); 936 dbg("%s - port %d", __func__, port->number);
943 937
944 spin_lock_irqsave(&info->lock, flags); 938 spin_lock_irqsave(&info->lock, flags);
945 actually_throttled = info->flags & ACTUALLY_THROTTLED; 939 actually_throttled = info->flags & ACTUALLY_THROTTLED;
@@ -960,7 +954,7 @@ static void command_port_write_callback(struct urb *urb)
960{ 954{
961 int status = urb->status; 955 int status = urb->status;
962 956
963 dbg("%s", __FUNCTION__); 957 dbg("%s", __func__);
964 958
965 if (status) { 959 if (status) {
966 dbg("nonzero urb status: %d", status); 960 dbg("nonzero urb status: %d", status);
@@ -971,28 +965,28 @@ static void command_port_write_callback(struct urb *urb)
971 965
972static void command_port_read_callback(struct urb *urb) 966static void command_port_read_callback(struct urb *urb)
973{ 967{
974 struct usb_serial_port *command_port = (struct usb_serial_port *)urb->context; 968 struct usb_serial_port *command_port = urb->context;
975 struct whiteheat_command_private *command_info; 969 struct whiteheat_command_private *command_info;
976 int status = urb->status; 970 int status = urb->status;
977 unsigned char *data = urb->transfer_buffer; 971 unsigned char *data = urb->transfer_buffer;
978 int result; 972 int result;
979 973
980 dbg("%s", __FUNCTION__); 974 dbg("%s", __func__);
981 975
982 command_info = usb_get_serial_port_data(command_port); 976 command_info = usb_get_serial_port_data(command_port);
983 if (!command_info) { 977 if (!command_info) {
984 dbg ("%s - command_info is NULL, exiting.", __FUNCTION__); 978 dbg ("%s - command_info is NULL, exiting.", __func__);
985 return; 979 return;
986 } 980 }
987 if (status) { 981 if (status) {
988 dbg("%s - nonzero urb status: %d", __FUNCTION__, status); 982 dbg("%s - nonzero urb status: %d", __func__, status);
989 if (status != -ENOENT) 983 if (status != -ENOENT)
990 command_info->command_finished = WHITEHEAT_CMD_FAILURE; 984 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
991 wake_up(&command_info->wait_command); 985 wake_up(&command_info->wait_command);
992 return; 986 return;
993 } 987 }
994 988
995 usb_serial_debug_data(debug, &command_port->dev, __FUNCTION__, urb->actual_length, data); 989 usb_serial_debug_data(debug, &command_port->dev, __func__, urb->actual_length, data);
996 990
997 if (data[0] == WHITEHEAT_CMD_COMPLETE) { 991 if (data[0] == WHITEHEAT_CMD_COMPLETE) {
998 command_info->command_finished = WHITEHEAT_CMD_COMPLETE; 992 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
@@ -1002,38 +996,38 @@ static void command_port_read_callback(struct urb *urb)
1002 wake_up(&command_info->wait_command); 996 wake_up(&command_info->wait_command);
1003 } else if (data[0] == WHITEHEAT_EVENT) { 997 } else if (data[0] == WHITEHEAT_EVENT) {
1004 /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */ 998 /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */
1005 dbg("%s - event received", __FUNCTION__); 999 dbg("%s - event received", __func__);
1006 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) { 1000 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
1007 memcpy(command_info->result_buffer, &data[1], urb->actual_length - 1); 1001 memcpy(command_info->result_buffer, &data[1], urb->actual_length - 1);
1008 command_info->command_finished = WHITEHEAT_CMD_COMPLETE; 1002 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
1009 wake_up(&command_info->wait_command); 1003 wake_up(&command_info->wait_command);
1010 } else { 1004 } else {
1011 dbg("%s - bad reply from firmware", __FUNCTION__); 1005 dbg("%s - bad reply from firmware", __func__);
1012 } 1006 }
1013 1007
1014 /* Continue trying to always read */ 1008 /* Continue trying to always read */
1015 command_port->read_urb->dev = command_port->serial->dev; 1009 command_port->read_urb->dev = command_port->serial->dev;
1016 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC); 1010 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
1017 if (result) 1011 if (result)
1018 dbg("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 1012 dbg("%s - failed resubmitting read urb, error %d", __func__, result);
1019} 1013}
1020 1014
1021 1015
1022static void whiteheat_read_callback(struct urb *urb) 1016static void whiteheat_read_callback(struct urb *urb)
1023{ 1017{
1024 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1018 struct usb_serial_port *port = urb->context;
1025 struct whiteheat_urb_wrap *wrap; 1019 struct whiteheat_urb_wrap *wrap;
1026 unsigned char *data = urb->transfer_buffer; 1020 unsigned char *data = urb->transfer_buffer;
1027 struct whiteheat_private *info = usb_get_serial_port_data(port); 1021 struct whiteheat_private *info = usb_get_serial_port_data(port);
1028 int status = urb->status; 1022 int status = urb->status;
1029 1023
1030 dbg("%s - port %d", __FUNCTION__, port->number); 1024 dbg("%s - port %d", __func__, port->number);
1031 1025
1032 spin_lock(&info->lock); 1026 spin_lock(&info->lock);
1033 wrap = urb_to_wrap(urb, &info->rx_urbs_submitted); 1027 wrap = urb_to_wrap(urb, &info->rx_urbs_submitted);
1034 if (!wrap) { 1028 if (!wrap) {
1035 spin_unlock(&info->lock); 1029 spin_unlock(&info->lock);
1036 err("%s - Not my urb!", __FUNCTION__); 1030 err("%s - Not my urb!", __func__);
1037 return; 1031 return;
1038 } 1032 }
1039 list_del(&wrap->list); 1033 list_del(&wrap->list);
@@ -1041,14 +1035,14 @@ static void whiteheat_read_callback(struct urb *urb)
1041 1035
1042 if (status) { 1036 if (status) {
1043 dbg("%s - nonzero read bulk status received: %d", 1037 dbg("%s - nonzero read bulk status received: %d",
1044 __FUNCTION__, status); 1038 __func__, status);
1045 spin_lock(&info->lock); 1039 spin_lock(&info->lock);
1046 list_add(&wrap->list, &info->rx_urbs_free); 1040 list_add(&wrap->list, &info->rx_urbs_free);
1047 spin_unlock(&info->lock); 1041 spin_unlock(&info->lock);
1048 return; 1042 return;
1049 } 1043 }
1050 1044
1051 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 1045 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
1052 1046
1053 spin_lock(&info->lock); 1047 spin_lock(&info->lock);
1054 list_add_tail(&wrap->list, &info->rx_urb_q); 1048 list_add_tail(&wrap->list, &info->rx_urb_q);
@@ -1065,18 +1059,18 @@ static void whiteheat_read_callback(struct urb *urb)
1065 1059
1066static void whiteheat_write_callback(struct urb *urb) 1060static void whiteheat_write_callback(struct urb *urb)
1067{ 1061{
1068 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1062 struct usb_serial_port *port = urb->context;
1069 struct whiteheat_private *info = usb_get_serial_port_data(port); 1063 struct whiteheat_private *info = usb_get_serial_port_data(port);
1070 struct whiteheat_urb_wrap *wrap; 1064 struct whiteheat_urb_wrap *wrap;
1071 int status = urb->status; 1065 int status = urb->status;
1072 1066
1073 dbg("%s - port %d", __FUNCTION__, port->number); 1067 dbg("%s - port %d", __func__, port->number);
1074 1068
1075 spin_lock(&info->lock); 1069 spin_lock(&info->lock);
1076 wrap = urb_to_wrap(urb, &info->tx_urbs_submitted); 1070 wrap = urb_to_wrap(urb, &info->tx_urbs_submitted);
1077 if (!wrap) { 1071 if (!wrap) {
1078 spin_unlock(&info->lock); 1072 spin_unlock(&info->lock);
1079 err("%s - Not my urb!", __FUNCTION__); 1073 err("%s - Not my urb!", __func__);
1080 return; 1074 return;
1081 } 1075 }
1082 list_move(&wrap->list, &info->tx_urbs_free); 1076 list_move(&wrap->list, &info->tx_urbs_free);
@@ -1084,7 +1078,7 @@ static void whiteheat_write_callback(struct urb *urb)
1084 1078
1085 if (status) { 1079 if (status) {
1086 dbg("%s - nonzero write bulk status received: %d", 1080 dbg("%s - nonzero write bulk status received: %d",
1087 __FUNCTION__, status); 1081 __func__, status);
1088 return; 1082 return;
1089 } 1083 }
1090 1084
@@ -1104,7 +1098,7 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d
1104 int retval = 0; 1098 int retval = 0;
1105 int t; 1099 int t;
1106 1100
1107 dbg("%s - command %d", __FUNCTION__, command); 1101 dbg("%s - command %d", __func__, command);
1108 1102
1109 command_port = port->serial->port[COMMAND_PORT]; 1103 command_port = port->serial->port[COMMAND_PORT];
1110 command_info = usb_get_serial_port_data(command_port); 1104 command_info = usb_get_serial_port_data(command_port);
@@ -1118,7 +1112,7 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d
1118 command_port->write_urb->dev = port->serial->dev; 1112 command_port->write_urb->dev = port->serial->dev;
1119 retval = usb_submit_urb (command_port->write_urb, GFP_NOIO); 1113 retval = usb_submit_urb (command_port->write_urb, GFP_NOIO);
1120 if (retval) { 1114 if (retval) {
1121 dbg("%s - submit urb failed", __FUNCTION__); 1115 dbg("%s - submit urb failed", __func__);
1122 goto exit; 1116 goto exit;
1123 } 1117 }
1124 1118
@@ -1129,19 +1123,19 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d
1129 usb_kill_urb(command_port->write_urb); 1123 usb_kill_urb(command_port->write_urb);
1130 1124
1131 if (command_info->command_finished == false) { 1125 if (command_info->command_finished == false) {
1132 dbg("%s - command timed out.", __FUNCTION__); 1126 dbg("%s - command timed out.", __func__);
1133 retval = -ETIMEDOUT; 1127 retval = -ETIMEDOUT;
1134 goto exit; 1128 goto exit;
1135 } 1129 }
1136 1130
1137 if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) { 1131 if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
1138 dbg("%s - command failed.", __FUNCTION__); 1132 dbg("%s - command failed.", __func__);
1139 retval = -EIO; 1133 retval = -EIO;
1140 goto exit; 1134 goto exit;
1141 } 1135 }
1142 1136
1143 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) { 1137 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
1144 dbg("%s - command completed.", __FUNCTION__); 1138 dbg("%s - command completed.", __func__);
1145 switch (command) { 1139 switch (command) {
1146 case WHITEHEAT_GET_DTR_RTS: 1140 case WHITEHEAT_GET_DTR_RTS:
1147 info = usb_get_serial_port_data(port); 1141 info = usb_get_serial_port_data(port);
@@ -1186,7 +1180,7 @@ static int firm_setup_port(struct usb_serial_port *port) {
1186 default: 1180 default:
1187 case CS8: port_settings.bits = 8; break; 1181 case CS8: port_settings.bits = 8; break;
1188 } 1182 }
1189 dbg("%s - data bits = %d", __FUNCTION__, port_settings.bits); 1183 dbg("%s - data bits = %d", __func__, port_settings.bits);
1190 1184
1191 /* determine the parity */ 1185 /* determine the parity */
1192 if (cflag & PARENB) 1186 if (cflag & PARENB)
@@ -1202,21 +1196,21 @@ static int firm_setup_port(struct usb_serial_port *port) {
1202 port_settings.parity = WHITEHEAT_PAR_EVEN; 1196 port_settings.parity = WHITEHEAT_PAR_EVEN;
1203 else 1197 else
1204 port_settings.parity = WHITEHEAT_PAR_NONE; 1198 port_settings.parity = WHITEHEAT_PAR_NONE;
1205 dbg("%s - parity = %c", __FUNCTION__, port_settings.parity); 1199 dbg("%s - parity = %c", __func__, port_settings.parity);
1206 1200
1207 /* figure out the stop bits requested */ 1201 /* figure out the stop bits requested */
1208 if (cflag & CSTOPB) 1202 if (cflag & CSTOPB)
1209 port_settings.stop = 2; 1203 port_settings.stop = 2;
1210 else 1204 else
1211 port_settings.stop = 1; 1205 port_settings.stop = 1;
1212 dbg("%s - stop bits = %d", __FUNCTION__, port_settings.stop); 1206 dbg("%s - stop bits = %d", __func__, port_settings.stop);
1213 1207
1214 /* figure out the flow control settings */ 1208 /* figure out the flow control settings */
1215 if (cflag & CRTSCTS) 1209 if (cflag & CRTSCTS)
1216 port_settings.hflow = (WHITEHEAT_HFLOW_CTS | WHITEHEAT_HFLOW_RTS); 1210 port_settings.hflow = (WHITEHEAT_HFLOW_CTS | WHITEHEAT_HFLOW_RTS);
1217 else 1211 else
1218 port_settings.hflow = WHITEHEAT_HFLOW_NONE; 1212 port_settings.hflow = WHITEHEAT_HFLOW_NONE;
1219 dbg("%s - hardware flow control = %s %s %s %s", __FUNCTION__, 1213 dbg("%s - hardware flow control = %s %s %s %s", __func__,
1220 (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "", 1214 (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
1221 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "", 1215 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
1222 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "", 1216 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
@@ -1227,15 +1221,15 @@ static int firm_setup_port(struct usb_serial_port *port) {
1227 port_settings.sflow = WHITEHEAT_SFLOW_RXTX; 1221 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
1228 else 1222 else
1229 port_settings.sflow = WHITEHEAT_SFLOW_NONE; 1223 port_settings.sflow = WHITEHEAT_SFLOW_NONE;
1230 dbg("%s - software flow control = %c", __FUNCTION__, port_settings.sflow); 1224 dbg("%s - software flow control = %c", __func__, port_settings.sflow);
1231 1225
1232 port_settings.xon = START_CHAR(port->tty); 1226 port_settings.xon = START_CHAR(port->tty);
1233 port_settings.xoff = STOP_CHAR(port->tty); 1227 port_settings.xoff = STOP_CHAR(port->tty);
1234 dbg("%s - XON = %2x, XOFF = %2x", __FUNCTION__, port_settings.xon, port_settings.xoff); 1228 dbg("%s - XON = %2x, XOFF = %2x", __func__, port_settings.xon, port_settings.xoff);
1235 1229
1236 /* get the baud rate wanted */ 1230 /* get the baud rate wanted */
1237 port_settings.baud = tty_get_baud_rate(port->tty); 1231 port_settings.baud = tty_get_baud_rate(port->tty);
1238 dbg("%s - baud rate = %d", __FUNCTION__, port_settings.baud); 1232 dbg("%s - baud rate = %d", __func__, port_settings.baud);
1239 1233
1240 /* fixme: should set validated settings */ 1234 /* fixme: should set validated settings */
1241 tty_encode_baud_rate(port->tty, port_settings.baud, port_settings.baud); 1235 tty_encode_baud_rate(port->tty, port_settings.baud, port_settings.baud);
@@ -1318,7 +1312,7 @@ static int start_command_port(struct usb_serial *serial)
1318 command_port->read_urb->dev = serial->dev; 1312 command_port->read_urb->dev = serial->dev;
1319 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL); 1313 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
1320 if (retval) { 1314 if (retval) {
1321 err("%s - failed submitting read urb, error %d", __FUNCTION__, retval); 1315 err("%s - failed submitting read urb, error %d", __func__, retval);
1322 goto exit; 1316 goto exit;
1323 } 1317 }
1324 } 1318 }
@@ -1454,7 +1448,7 @@ static void rx_data_softint(struct work_struct *work)
1454 urb->dev = port->serial->dev; 1448 urb->dev = port->serial->dev;
1455 result = usb_submit_urb(urb, GFP_ATOMIC); 1449 result = usb_submit_urb(urb, GFP_ATOMIC);
1456 if (result) { 1450 if (result) {
1457 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 1451 err("%s - failed resubmitting read urb, error %d", __func__, result);
1458 spin_lock_irqsave(&info->lock, flags); 1452 spin_lock_irqsave(&info->lock, flags);
1459 list_add(tmp, &info->rx_urbs_free); 1453 list_add(tmp, &info->rx_urbs_free);
1460 continue; 1454 continue;
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 7e53333be013..0f6d234d699b 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -32,8 +32,8 @@ config USB_STORAGE_DEBUG
32 verbose debugging messages. 32 verbose debugging messages.
33 33
34config USB_STORAGE_DATAFAB 34config USB_STORAGE_DATAFAB
35 bool "Datafab Compact Flash Reader support (EXPERIMENTAL)" 35 bool "Datafab Compact Flash Reader support"
36 depends on USB_STORAGE && EXPERIMENTAL 36 depends on USB_STORAGE
37 help 37 help
38 Support for certain Datafab CompactFlash readers. 38 Support for certain Datafab CompactFlash readers.
39 Datafab has a web page at <http://www.datafabusa.com/>. 39 Datafab has a web page at <http://www.datafabusa.com/>.
@@ -69,8 +69,8 @@ config USB_STORAGE_DPCM
69 There is a web page at <http://www.ziocorp.com/products/>. 69 There is a web page at <http://www.ziocorp.com/products/>.
70 70
71config USB_STORAGE_USBAT 71config USB_STORAGE_USBAT
72 bool "USBAT/USBAT02-based storage support (EXPERIMENTAL)" 72 bool "USBAT/USBAT02-based storage support"
73 depends on USB_STORAGE && EXPERIMENTAL 73 depends on USB_STORAGE
74 help 74 help
75 Say Y here to include additional code to support storage devices 75 Say Y here to include additional code to support storage devices
76 based on the SCM/Shuttle USBAT/USBAT02 processors. 76 based on the SCM/Shuttle USBAT/USBAT02 processors.
@@ -90,30 +90,30 @@ config USB_STORAGE_USBAT
90 - Sandisk ImageMate SDDR-05b 90 - Sandisk ImageMate SDDR-05b
91 91
92config USB_STORAGE_SDDR09 92config USB_STORAGE_SDDR09
93 bool "SanDisk SDDR-09 (and other SmartMedia) support (EXPERIMENTAL)" 93 bool "SanDisk SDDR-09 (and other SmartMedia) support"
94 depends on USB_STORAGE && EXPERIMENTAL 94 depends on USB_STORAGE
95 help 95 help
96 Say Y here to include additional code to support the Sandisk SDDR-09 96 Say Y here to include additional code to support the Sandisk SDDR-09
97 SmartMedia reader in the USB Mass Storage driver. 97 SmartMedia reader in the USB Mass Storage driver.
98 Also works for the Microtech Zio! SmartMedia reader. 98 Also works for the Microtech Zio! SmartMedia reader.
99 99
100config USB_STORAGE_SDDR55 100config USB_STORAGE_SDDR55
101 bool "SanDisk SDDR-55 SmartMedia support (EXPERIMENTAL)" 101 bool "SanDisk SDDR-55 SmartMedia support"
102 depends on USB_STORAGE && EXPERIMENTAL 102 depends on USB_STORAGE
103 help 103 help
104 Say Y here to include additional code to support the Sandisk SDDR-55 104 Say Y here to include additional code to support the Sandisk SDDR-55
105 SmartMedia reader in the USB Mass Storage driver. 105 SmartMedia reader in the USB Mass Storage driver.
106 106
107config USB_STORAGE_JUMPSHOT 107config USB_STORAGE_JUMPSHOT
108 bool "Lexar Jumpshot Compact Flash Reader (EXPERIMENTAL)" 108 bool "Lexar Jumpshot Compact Flash Reader"
109 depends on USB_STORAGE && EXPERIMENTAL 109 depends on USB_STORAGE
110 help 110 help
111 Say Y here to include additional code to support the Lexar Jumpshot 111 Say Y here to include additional code to support the Lexar Jumpshot
112 USB CompactFlash reader. 112 USB CompactFlash reader.
113 113
114config USB_STORAGE_ALAUDA 114config USB_STORAGE_ALAUDA
115 bool "Olympus MAUSB-10/Fuji DPC-R1 support (EXPERIMENTAL)" 115 bool "Olympus MAUSB-10/Fuji DPC-R1 support"
116 depends on USB_STORAGE && EXPERIMENTAL 116 depends on USB_STORAGE
117 help 117 help
118 Say Y here to include additional code to support the Olympus MAUSB-10 118 Say Y here to include additional code to support the Olympus MAUSB-10
119 and Fujifilm DPC-R1 USB Card reader/writer devices. 119 and Fujifilm DPC-R1 USB Card reader/writer devices.
@@ -122,8 +122,8 @@ config USB_STORAGE_ALAUDA
122 XD and SmartMedia cards. 122 XD and SmartMedia cards.
123 123
124config USB_STORAGE_ONETOUCH 124config USB_STORAGE_ONETOUCH
125 bool "Support OneTouch Button on Maxtor Hard Drives (EXPERIMENTAL)" 125 bool "Support OneTouch Button on Maxtor Hard Drives"
126 depends on USB_STORAGE && INPUT_EVDEV && EXPERIMENTAL && !PM 126 depends on USB_STORAGE && INPUT_EVDEV
127 help 127 help
128 Say Y here to include additional code to support the Maxtor OneTouch 128 Say Y here to include additional code to support the Maxtor OneTouch
129 USB hard drive's onetouch button. 129 USB hard drive's onetouch button.
@@ -145,6 +145,17 @@ config USB_STORAGE_KARMA
145 on the resulting scsi device node returns the Karma to normal 145 on the resulting scsi device node returns the Karma to normal
146 operation. 146 operation.
147 147
148config USB_STORAGE_CYPRESS_ATACB
149 bool "SAT emulation on Cypress USB/ATA Bridge with ATACB"
150 depends on USB_STORAGE
151 ---help---
152 Say Y here if you want to use SAT (ata pass through) on devices based
153 on the Cypress USB/ATA bridge supporting ATACB. This will allow you
154 to use tools to tune and monitor your drive (like hdparm or smartctl).
155
156 If you say no here your device will still work with the standard usb
157 mass storage class.
158
148config USB_LIBUSUAL 159config USB_LIBUSUAL
149 bool "The shared table of common (or usual) storage devices" 160 bool "The shared table of common (or usual) storage devices"
150 depends on USB 161 depends on USB
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile
index 023969b4385b..4c596c766c53 100644
--- a/drivers/usb/storage/Makefile
+++ b/drivers/usb/storage/Makefile
@@ -21,6 +21,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o
21usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA) += alauda.o 21usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA) += alauda.o
22usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o 22usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o
23usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA) += karma.o 23usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA) += karma.o
24usb-storage-obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += cypress_atacb.o
24 25
25usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ 26usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \
26 initializers.o $(usb-storage-obj-y) 27 initializers.o $(usb-storage-obj-y)
diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c
new file mode 100644
index 000000000000..d88824b3511c
--- /dev/null
+++ b/drivers/usb/storage/cypress_atacb.c
@@ -0,0 +1,200 @@
1/*
2 * Support for emulating SAT (ata pass through) on devices based
3 * on the Cypress USB/ATA bridge supporting ATACB.
4 *
5 * Copyright (c) 2008 Matthieu Castet (castet.matthieu@free.fr)
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <scsi/scsi.h>
23#include <scsi/scsi_cmnd.h>
24#include <scsi/scsi_eh.h>
25#include <linux/ata.h>
26
27#include "usb.h"
28#include "protocol.h"
29#include "scsiglue.h"
30#include "debug.h"
31
32/*
33 * ATACB is a protocol used on cypress usb<->ata bridge to
34 * send raw ATA command over mass storage
35 * There is a ATACB2 protocol that support LBA48 on newer chip.
36 * More info that be found on cy7c68310_8.pdf and cy7c68300c_8.pdf
37 * datasheet from cypress.com.
38 */
39void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
40{
41 unsigned char save_cmnd[MAX_COMMAND_SIZE];
42
43 if (likely(srb->cmnd[0] != ATA_16 && srb->cmnd[0] != ATA_12)) {
44 usb_stor_transparent_scsi_command(srb, us);
45 return;
46 }
47
48 memcpy(save_cmnd, srb->cmnd, sizeof(save_cmnd));
49 memset(srb->cmnd, 0, sizeof(srb->cmnd));
50
51 /* check if we support the command */
52 if (save_cmnd[1] >> 5) /* MULTIPLE_COUNT */
53 goto invalid_fld;
54 /* check protocol */
55 switch((save_cmnd[1] >> 1) & 0xf) {
56 case 3: /*no DATA */
57 case 4: /* PIO in */
58 case 5: /* PIO out */
59 break;
60 default:
61 goto invalid_fld;
62 }
63
64 /* first build the ATACB command */
65 srb->cmd_len = 16;
66
67 srb->cmnd[0] = 0x24; /* bVSCBSignature : vendor-specific command
68 this value can change, but most(all ?) manufacturers
69 keep the cypress default : 0x24 */
70 srb->cmnd[1] = 0x24; /* bVSCBSubCommand : 0x24 for ATACB */
71
72 srb->cmnd[3] = 0xff - 1; /* features, sector count, lba low, lba med
73 lba high, device, command are valid */
74 srb->cmnd[4] = 1; /* TransferBlockCount : 512 */
75
76 if (save_cmnd[0] == ATA_16) {
77 srb->cmnd[ 6] = save_cmnd[ 4]; /* features */
78 srb->cmnd[ 7] = save_cmnd[ 6]; /* sector count */
79 srb->cmnd[ 8] = save_cmnd[ 8]; /* lba low */
80 srb->cmnd[ 9] = save_cmnd[10]; /* lba med */
81 srb->cmnd[10] = save_cmnd[12]; /* lba high */
82 srb->cmnd[11] = save_cmnd[13]; /* device */
83 srb->cmnd[12] = save_cmnd[14]; /* command */
84
85 if (save_cmnd[1] & 0x01) {/* extended bit set for LBA48 */
86 /* this could be supported by atacb2 */
87 if (save_cmnd[3] || save_cmnd[5] || save_cmnd[7] || save_cmnd[9]
88 || save_cmnd[11])
89 goto invalid_fld;
90 }
91 }
92 else { /* ATA12 */
93 srb->cmnd[ 6] = save_cmnd[3]; /* features */
94 srb->cmnd[ 7] = save_cmnd[4]; /* sector count */
95 srb->cmnd[ 8] = save_cmnd[5]; /* lba low */
96 srb->cmnd[ 9] = save_cmnd[6]; /* lba med */
97 srb->cmnd[10] = save_cmnd[7]; /* lba high */
98 srb->cmnd[11] = save_cmnd[8]; /* device */
99 srb->cmnd[12] = save_cmnd[9]; /* command */
100
101 }
102 /* Filter SET_FEATURES - XFER MODE command */
103 if ((srb->cmnd[12] == ATA_CMD_SET_FEATURES)
104 && (srb->cmnd[6] == SETFEATURES_XFER))
105 goto invalid_fld;
106
107 if (srb->cmnd[12] == ATA_CMD_ID_ATA || srb->cmnd[12] == ATA_CMD_ID_ATAPI)
108 srb->cmnd[2] |= (1<<7); /* set IdentifyPacketDevice for these cmds */
109
110
111 usb_stor_transparent_scsi_command(srb, us);
112
113 /* if the device doesn't support ATACB
114 */
115 if (srb->result == SAM_STAT_CHECK_CONDITION &&
116 memcmp(srb->sense_buffer, usb_stor_sense_invalidCDB,
117 sizeof(usb_stor_sense_invalidCDB)) == 0) {
118 US_DEBUGP("cypress atacb not supported ???\n");
119 goto end;
120 }
121
122 /* if ck_cond flags is set, and there wasn't critical error,
123 * build the special sense
124 */
125 if ((srb->result != (DID_ERROR << 16) &&
126 srb->result != (DID_ABORT << 16)) &&
127 save_cmnd[2] & 0x20) {
128 struct scsi_eh_save ses;
129 unsigned char regs[8];
130 unsigned char *sb = srb->sense_buffer;
131 unsigned char *desc = sb + 8;
132 int tmp_result;
133
134 /* build the command for
135 * reading the ATA registers */
136 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, 0);
137 srb->sdb.length = sizeof(regs);
138 sg_init_one(&ses.sense_sgl, regs, srb->sdb.length);
139 srb->sdb.table.sgl = &ses.sense_sgl;
140 srb->sc_data_direction = DMA_FROM_DEVICE;
141 srb->sdb.table.nents = 1;
142 /* we use the same command as before, but we set
143 * the read taskfile bit, for not executing atacb command,
144 * but reading register selected in srb->cmnd[4]
145 */
146 srb->cmnd[2] = 1;
147
148 usb_stor_transparent_scsi_command(srb, us);
149 tmp_result = srb->result;
150 scsi_eh_restore_cmnd(srb, &ses);
151 /* we fail to get registers, report invalid command */
152 if (tmp_result != SAM_STAT_GOOD)
153 goto invalid_fld;
154
155 /* build the sense */
156 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
157
158 /* set sk, asc for a good command */
159 sb[1] = RECOVERED_ERROR;
160 sb[2] = 0; /* ATA PASS THROUGH INFORMATION AVAILABLE */
161 sb[3] = 0x1D;
162
163 /* XXX we should generate sk, asc, ascq from status and error
164 * regs
165 * (see 11.1 Error translation ­ ATA device error to SCSI error map)
166 * and ata_to_sense_error from libata.
167 */
168
169 /* Sense data is current and format is descriptor. */
170 sb[0] = 0x72;
171 desc[0] = 0x09; /* ATA_RETURN_DESCRIPTOR */
172
173 /* set length of additional sense data */
174 sb[7] = 14;
175 desc[1] = 12;
176
177 /* Copy registers into sense buffer. */
178 desc[ 2] = 0x00;
179 desc[ 3] = regs[1]; /* features */
180 desc[ 5] = regs[2]; /* sector count */
181 desc[ 7] = regs[3]; /* lba low */
182 desc[ 9] = regs[4]; /* lba med */
183 desc[11] = regs[5]; /* lba high */
184 desc[12] = regs[6]; /* device */
185 desc[13] = regs[7]; /* command */
186
187 srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
188 }
189 goto end;
190invalid_fld:
191 srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
192
193 memcpy(srb->sense_buffer,
194 usb_stor_sense_invalidCDB,
195 sizeof(usb_stor_sense_invalidCDB));
196end:
197 memcpy(srb->cmnd, save_cmnd, sizeof(save_cmnd));
198 if (srb->cmnd[0] == ATA_12)
199 srb->cmd_len = 12;
200}
diff --git a/drivers/usb/storage/cypress_atacb.h b/drivers/usb/storage/cypress_atacb.h
new file mode 100644
index 000000000000..fbada898d56b
--- /dev/null
+++ b/drivers/usb/storage/cypress_atacb.h
@@ -0,0 +1,25 @@
1/*
2 * Support for emulating SAT (ata pass through) on devices based
3 * on the Cypress USB/ATA bridge supporting ATACB.
4 *
5 * Copyright (c) 2008 Matthieu Castet (castet.matthieu@free.fr)
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef _CYPRESS_ATACB_H_
23#define _CYPRESS_ATACB_H_
24extern void cypress_atacb_passthrough(struct scsi_cmnd*, struct us_data*);
25#endif
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c
index 55b952084f0c..a28d49122e7a 100644
--- a/drivers/usb/storage/libusual.c
+++ b/drivers/usb/storage/libusual.c
@@ -9,6 +9,7 @@
9#include <linux/usb_usual.h> 9#include <linux/usb_usual.h>
10#include <linux/vmalloc.h> 10#include <linux/vmalloc.h>
11#include <linux/kthread.h> 11#include <linux/kthread.h>
12#include <linux/mutex.h>
12 13
13/* 14/*
14 */ 15 */
@@ -30,7 +31,7 @@ static atomic_t usu_bias = ATOMIC_INIT(USB_US_DEFAULT_BIAS);
30#define BIAS_NAME_SIZE (sizeof("usb-storage")) 31#define BIAS_NAME_SIZE (sizeof("usb-storage"))
31static const char *bias_names[3] = { "none", "usb-storage", "ub" }; 32static const char *bias_names[3] = { "none", "usb-storage", "ub" };
32 33
33static struct semaphore usu_init_notify; 34static DEFINE_MUTEX(usu_probe_mutex);
34static DECLARE_COMPLETION(usu_end_notify); 35static DECLARE_COMPLETION(usu_end_notify);
35static atomic_t total_threads = ATOMIC_INIT(0); 36static atomic_t total_threads = ATOMIC_INIT(0);
36 37
@@ -178,10 +179,7 @@ static int usu_probe_thread(void *arg)
178 int rc; 179 int rc;
179 unsigned long flags; 180 unsigned long flags;
180 181
181 /* A completion does not work here because it's counted. */ 182 mutex_lock(&usu_probe_mutex);
182 down(&usu_init_notify);
183 up(&usu_init_notify);
184
185 rc = request_module(bias_names[type]); 183 rc = request_module(bias_names[type]);
186 spin_lock_irqsave(&usu_lock, flags); 184 spin_lock_irqsave(&usu_lock, flags);
187 if (rc == 0 && (st->fls & USU_MOD_FL_PRESENT) == 0) { 185 if (rc == 0 && (st->fls & USU_MOD_FL_PRESENT) == 0) {
@@ -194,6 +192,7 @@ static int usu_probe_thread(void *arg)
194 } 192 }
195 st->fls &= ~USU_MOD_FL_THREAD; 193 st->fls &= ~USU_MOD_FL_THREAD;
196 spin_unlock_irqrestore(&usu_lock, flags); 194 spin_unlock_irqrestore(&usu_lock, flags);
195 mutex_unlock(&usu_probe_mutex);
197 196
198 complete_and_exit(&usu_end_notify, 0); 197 complete_and_exit(&usu_end_notify, 0);
199} 198}
@@ -204,10 +203,9 @@ static int __init usb_usual_init(void)
204{ 203{
205 int rc; 204 int rc;
206 205
207 sema_init(&usu_init_notify, 0); 206 mutex_lock(&usu_probe_mutex);
208
209 rc = usb_register(&usu_driver); 207 rc = usb_register(&usu_driver);
210 up(&usu_init_notify); 208 mutex_unlock(&usu_probe_mutex);
211 return rc; 209 return rc;
212} 210}
213 211
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 8c1e2954f3b9..3fcde9f0fa5f 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -73,6 +73,7 @@ static const char* host_info(struct Scsi_Host *host)
73static int slave_alloc (struct scsi_device *sdev) 73static int slave_alloc (struct scsi_device *sdev)
74{ 74{
75 struct us_data *us = host_to_us(sdev->host); 75 struct us_data *us = host_to_us(sdev->host);
76 struct usb_host_endpoint *bulk_in_ep;
76 77
77 /* 78 /*
78 * Set the INQUIRY transfer length to 36. We don't use any of 79 * Set the INQUIRY transfer length to 36. We don't use any of
@@ -84,12 +85,13 @@ static int slave_alloc (struct scsi_device *sdev)
84 /* Scatter-gather buffers (all but the last) must have a length 85 /* Scatter-gather buffers (all but the last) must have a length
85 * divisible by the bulk maxpacket size. Otherwise a data packet 86 * divisible by the bulk maxpacket size. Otherwise a data packet
86 * would end up being short, causing a premature end to the data 87 * would end up being short, causing a premature end to the data
87 * transfer. Since high-speed bulk pipes have a maxpacket size 88 * transfer. We'll use the maxpacket value of the bulk-IN pipe
88 * of 512, we'll use that as the scsi device queue's DMA alignment 89 * to set the SCSI device queue's DMA alignment mask.
89 * mask. Guaranteeing proper alignment of the first buffer will 90 */
90 * have the desired effect because, except at the beginning and 91 bulk_in_ep = us->pusb_dev->ep_in[usb_pipeendpoint(us->recv_bulk_pipe)];
91 * the end, scatter-gather buffers follow page boundaries. */ 92 blk_queue_update_dma_alignment(sdev->request_queue,
92 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); 93 le16_to_cpu(bulk_in_ep->desc.wMaxPacketSize) - 1);
94 /* wMaxPacketSize must be a power of 2 */
93 95
94 /* 96 /*
95 * The UFI spec treates the Peripheral Qualifier bits in an 97 * The UFI spec treates the Peripheral Qualifier bits in an
@@ -132,7 +134,7 @@ static int slave_configure(struct scsi_device *sdev)
132 /* Disk-type devices use MODE SENSE(6) if the protocol 134 /* Disk-type devices use MODE SENSE(6) if the protocol
133 * (SubClass) is Transparent SCSI, otherwise they use 135 * (SubClass) is Transparent SCSI, otherwise they use
134 * MODE SENSE(10). */ 136 * MODE SENSE(10). */
135 if (us->subclass != US_SC_SCSI) 137 if (us->subclass != US_SC_SCSI && us->subclass != US_SC_CYP_ATACB)
136 sdev->use_10_for_ms = 1; 138 sdev->use_10_for_ms = 1;
137 139
138 /* Many disks only accept MODE SENSE transfer lengths of 140 /* Many disks only accept MODE SENSE transfer lengths of
@@ -226,12 +228,12 @@ static int queuecommand(struct scsi_cmnd *srb,
226{ 228{
227 struct us_data *us = host_to_us(srb->device->host); 229 struct us_data *us = host_to_us(srb->device->host);
228 230
229 US_DEBUGP("%s called\n", __FUNCTION__); 231 US_DEBUGP("%s called\n", __func__);
230 232
231 /* check for state-transition errors */ 233 /* check for state-transition errors */
232 if (us->srb != NULL) { 234 if (us->srb != NULL) {
233 printk(KERN_ERR USB_STORAGE "Error in %s: us->srb = %p\n", 235 printk(KERN_ERR USB_STORAGE "Error in %s: us->srb = %p\n",
234 __FUNCTION__, us->srb); 236 __func__, us->srb);
235 return SCSI_MLQUEUE_HOST_BUSY; 237 return SCSI_MLQUEUE_HOST_BUSY;
236 } 238 }
237 239
@@ -260,7 +262,7 @@ static int command_abort(struct scsi_cmnd *srb)
260{ 262{
261 struct us_data *us = host_to_us(srb->device->host); 263 struct us_data *us = host_to_us(srb->device->host);
262 264
263 US_DEBUGP("%s called\n", __FUNCTION__); 265 US_DEBUGP("%s called\n", __func__);
264 266
265 /* us->srb together with the TIMED_OUT, RESETTING, and ABORTING 267 /* us->srb together with the TIMED_OUT, RESETTING, and ABORTING
266 * bits are protected by the host lock. */ 268 * bits are protected by the host lock. */
@@ -297,7 +299,7 @@ static int device_reset(struct scsi_cmnd *srb)
297 struct us_data *us = host_to_us(srb->device->host); 299 struct us_data *us = host_to_us(srb->device->host);
298 int result; 300 int result;
299 301
300 US_DEBUGP("%s called\n", __FUNCTION__); 302 US_DEBUGP("%s called\n", __func__);
301 303
302 /* lock the device pointers and do the reset */ 304 /* lock the device pointers and do the reset */
303 mutex_lock(&(us->dev_mutex)); 305 mutex_lock(&(us->dev_mutex));
@@ -313,7 +315,7 @@ static int bus_reset(struct scsi_cmnd *srb)
313 struct us_data *us = host_to_us(srb->device->host); 315 struct us_data *us = host_to_us(srb->device->host);
314 int result; 316 int result;
315 317
316 US_DEBUGP("%s called\n", __FUNCTION__); 318 US_DEBUGP("%s called\n", __func__);
317 result = usb_stor_port_reset(us); 319 result = usb_stor_port_reset(us);
318 return result < 0 ? FAILED : SUCCESS; 320 return result < 0 ? FAILED : SUCCESS;
319} 321}
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index bdd4334bed5a..6610d2dd1e7f 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -110,7 +110,7 @@
110 */ 110 */
111static void usb_stor_blocking_completion(struct urb *urb) 111static void usb_stor_blocking_completion(struct urb *urb)
112{ 112{
113 struct completion *urb_done_ptr = (struct completion *)urb->context; 113 struct completion *urb_done_ptr = urb->context;
114 114
115 complete(urb_done_ptr); 115 complete(urb_done_ptr);
116} 116}
@@ -198,7 +198,7 @@ int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
198 int status; 198 int status;
199 199
200 US_DEBUGP("%s: rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n", 200 US_DEBUGP("%s: rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
201 __FUNCTION__, request, requesttype, 201 __func__, request, requesttype,
202 value, index, size); 202 value, index, size);
203 203
204 /* fill in the devrequest structure */ 204 /* fill in the devrequest structure */
@@ -250,7 +250,7 @@ int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
250 usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe), 250 usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe),
251 usb_pipeout(pipe), 0); 251 usb_pipeout(pipe), 0);
252 252
253 US_DEBUGP("%s: result = %d\n", __FUNCTION__, result); 253 US_DEBUGP("%s: result = %d\n", __func__, result);
254 return result; 254 return result;
255} 255}
256 256
@@ -332,7 +332,7 @@ int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
332 int result; 332 int result;
333 333
334 US_DEBUGP("%s: rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n", 334 US_DEBUGP("%s: rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
335 __FUNCTION__, request, requesttype, 335 __func__, request, requesttype,
336 value, index, size); 336 value, index, size);
337 337
338 /* fill in the devrequest structure */ 338 /* fill in the devrequest structure */
@@ -366,7 +366,7 @@ static int usb_stor_intr_transfer(struct us_data *us, void *buf,
366 unsigned int pipe = us->recv_intr_pipe; 366 unsigned int pipe = us->recv_intr_pipe;
367 unsigned int maxp; 367 unsigned int maxp;
368 368
369 US_DEBUGP("%s: xfer %u bytes\n", __FUNCTION__, length); 369 US_DEBUGP("%s: xfer %u bytes\n", __func__, length);
370 370
371 /* calculate the max packet size */ 371 /* calculate the max packet size */
372 maxp = usb_maxpacket(us->pusb_dev, pipe, usb_pipeout(pipe)); 372 maxp = usb_maxpacket(us->pusb_dev, pipe, usb_pipeout(pipe));
@@ -393,7 +393,7 @@ int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
393{ 393{
394 int result; 394 int result;
395 395
396 US_DEBUGP("%s: xfer %u bytes\n", __FUNCTION__, length); 396 US_DEBUGP("%s: xfer %u bytes\n", __func__, length);
397 397
398 /* fill and submit the URB */ 398 /* fill and submit the URB */
399 usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length, 399 usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length,
@@ -424,7 +424,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
424 return USB_STOR_XFER_ERROR; 424 return USB_STOR_XFER_ERROR;
425 425
426 /* initialize the scatter-gather request block */ 426 /* initialize the scatter-gather request block */
427 US_DEBUGP("%s: xfer %u bytes, %d entries\n", __FUNCTION__, 427 US_DEBUGP("%s: xfer %u bytes, %d entries\n", __func__,
428 length, num_sg); 428 length, num_sg);
429 result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0, 429 result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0,
430 sg, num_sg, length, GFP_NOIO); 430 sg, num_sg, length, GFP_NOIO);
@@ -603,7 +603,8 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
603 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, US_SENSE_SIZE); 603 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, US_SENSE_SIZE);
604 604
605 /* FIXME: we must do the protocol translation here */ 605 /* FIXME: we must do the protocol translation here */
606 if (us->subclass == US_SC_RBC || us->subclass == US_SC_SCSI) 606 if (us->subclass == US_SC_RBC || us->subclass == US_SC_SCSI ||
607 us->subclass == US_SC_CYP_ATACB)
607 srb->cmd_len = 6; 608 srb->cmd_len = 6;
608 else 609 else
609 srb->cmd_len = 12; 610 srb->cmd_len = 12;
@@ -700,7 +701,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
700/* Stop the current URB transfer */ 701/* Stop the current URB transfer */
701void usb_stor_stop_transport(struct us_data *us) 702void usb_stor_stop_transport(struct us_data *us)
702{ 703{
703 US_DEBUGP("%s called\n", __FUNCTION__); 704 US_DEBUGP("%s called\n", __func__);
704 705
705 /* If the state machine is blocked waiting for an URB, 706 /* If the state machine is blocked waiting for an URB,
706 * let's wake it up. The test_and_clear_bit() call 707 * let's wake it up. The test_and_clear_bit() call
@@ -1134,7 +1135,7 @@ static int usb_stor_reset_common(struct us_data *us,
1134 1135
1135int usb_stor_CB_reset(struct us_data *us) 1136int usb_stor_CB_reset(struct us_data *us)
1136{ 1137{
1137 US_DEBUGP("%s called\n", __FUNCTION__); 1138 US_DEBUGP("%s called\n", __func__);
1138 1139
1139 memset(us->iobuf, 0xFF, CB_RESET_CMD_SIZE); 1140 memset(us->iobuf, 0xFF, CB_RESET_CMD_SIZE);
1140 us->iobuf[0] = SEND_DIAGNOSTIC; 1141 us->iobuf[0] = SEND_DIAGNOSTIC;
@@ -1149,7 +1150,7 @@ int usb_stor_CB_reset(struct us_data *us)
1149 */ 1150 */
1150int usb_stor_Bulk_reset(struct us_data *us) 1151int usb_stor_Bulk_reset(struct us_data *us)
1151{ 1152{
1152 US_DEBUGP("%s called\n", __FUNCTION__); 1153 US_DEBUGP("%s called\n", __func__);
1153 1154
1154 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST, 1155 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST,
1155 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1156 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 91252075e6e1..732bf52a775e 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1719,6 +1719,14 @@ UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001,
1719 US_SC_DEVICE, US_PR_DEVICE, NULL, 1719 US_SC_DEVICE, US_PR_DEVICE, NULL,
1720 US_FL_CAPACITY_HEURISTICS), 1720 US_FL_CAPACITY_HEURISTICS),
1721 1721
1722#ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB
1723UNUSUAL_DEV( 0x04b4, 0x6830, 0x0000, 0x9999,
1724 "Cypress",
1725 "Cypress AT2LP",
1726 US_SC_CYP_ATACB, US_PR_BULK, NULL,
1727 0),
1728#endif
1729
1722/* Control/Bulk transport for all SubClass values */ 1730/* Control/Bulk transport for all SubClass values */
1723USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR), 1731USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR),
1724USUAL_DEV(US_SC_8020, US_PR_CB, USB_US_TYPE_STOR), 1732USUAL_DEV(US_SC_8020, US_PR_CB, USB_US_TYPE_STOR),
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index ac6114eea0c3..a856effad3bd 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -101,6 +101,9 @@
101#ifdef CONFIG_USB_STORAGE_KARMA 101#ifdef CONFIG_USB_STORAGE_KARMA
102#include "karma.h" 102#include "karma.h"
103#endif 103#endif
104#ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB
105#include "cypress_atacb.h"
106#endif
104 107
105/* Some informational data */ 108/* Some informational data */
106MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>"); 109MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
@@ -187,7 +190,7 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message)
187 /* Wait until no command is running */ 190 /* Wait until no command is running */
188 mutex_lock(&us->dev_mutex); 191 mutex_lock(&us->dev_mutex);
189 192
190 US_DEBUGP("%s\n", __FUNCTION__); 193 US_DEBUGP("%s\n", __func__);
191 if (us->suspend_resume_hook) 194 if (us->suspend_resume_hook)
192 (us->suspend_resume_hook)(us, US_SUSPEND); 195 (us->suspend_resume_hook)(us, US_SUSPEND);
193 196
@@ -204,7 +207,7 @@ static int storage_resume(struct usb_interface *iface)
204 207
205 mutex_lock(&us->dev_mutex); 208 mutex_lock(&us->dev_mutex);
206 209
207 US_DEBUGP("%s\n", __FUNCTION__); 210 US_DEBUGP("%s\n", __func__);
208 if (us->suspend_resume_hook) 211 if (us->suspend_resume_hook)
209 (us->suspend_resume_hook)(us, US_RESUME); 212 (us->suspend_resume_hook)(us, US_RESUME);
210 213
@@ -216,7 +219,7 @@ static int storage_reset_resume(struct usb_interface *iface)
216{ 219{
217 struct us_data *us = usb_get_intfdata(iface); 220 struct us_data *us = usb_get_intfdata(iface);
218 221
219 US_DEBUGP("%s\n", __FUNCTION__); 222 US_DEBUGP("%s\n", __func__);
220 223
221 /* Report the reset to the SCSI core */ 224 /* Report the reset to the SCSI core */
222 usb_stor_report_bus_reset(us); 225 usb_stor_report_bus_reset(us);
@@ -237,7 +240,7 @@ static int storage_pre_reset(struct usb_interface *iface)
237{ 240{
238 struct us_data *us = usb_get_intfdata(iface); 241 struct us_data *us = usb_get_intfdata(iface);
239 242
240 US_DEBUGP("%s\n", __FUNCTION__); 243 US_DEBUGP("%s\n", __func__);
241 244
242 /* Make sure no command runs during the reset */ 245 /* Make sure no command runs during the reset */
243 mutex_lock(&us->dev_mutex); 246 mutex_lock(&us->dev_mutex);
@@ -248,7 +251,7 @@ static int storage_post_reset(struct usb_interface *iface)
248{ 251{
249 struct us_data *us = usb_get_intfdata(iface); 252 struct us_data *us = usb_get_intfdata(iface);
250 253
251 US_DEBUGP("%s\n", __FUNCTION__); 254 US_DEBUGP("%s\n", __func__);
252 255
253 /* Report the reset to the SCSI core */ 256 /* Report the reset to the SCSI core */
254 usb_stor_report_bus_reset(us); 257 usb_stor_report_bus_reset(us);
@@ -434,7 +437,7 @@ SkipForAbort:
434/* Associate our private data with the USB device */ 437/* Associate our private data with the USB device */
435static int associate_dev(struct us_data *us, struct usb_interface *intf) 438static int associate_dev(struct us_data *us, struct usb_interface *intf)
436{ 439{
437 US_DEBUGP("-- %s\n", __FUNCTION__); 440 US_DEBUGP("-- %s\n", __func__);
438 441
439 /* Fill in the device-related fields */ 442 /* Fill in the device-related fields */
440 us->pusb_dev = interface_to_usbdev(intf); 443 us->pusb_dev = interface_to_usbdev(intf);
@@ -708,6 +711,13 @@ static int get_protocol(struct us_data *us)
708 break; 711 break;
709#endif 712#endif
710 713
714#ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB
715 case US_SC_CYP_ATACB:
716 us->protocol_name = "Transparent SCSI with Cypress ATACB";
717 us->proto_handler = cypress_atacb_passthrough;
718 break;
719#endif
720
711 default: 721 default:
712 return -EIO; 722 return -EIO;
713 } 723 }
@@ -806,7 +816,7 @@ static int usb_stor_acquire_resources(struct us_data *us)
806/* Release all our dynamic resources */ 816/* Release all our dynamic resources */
807static void usb_stor_release_resources(struct us_data *us) 817static void usb_stor_release_resources(struct us_data *us)
808{ 818{
809 US_DEBUGP("-- %s\n", __FUNCTION__); 819 US_DEBUGP("-- %s\n", __func__);
810 820
811 /* Tell the control thread to exit. The SCSI host must 821 /* Tell the control thread to exit. The SCSI host must
812 * already have been removed so it won't try to queue 822 * already have been removed so it won't try to queue
@@ -832,7 +842,7 @@ static void usb_stor_release_resources(struct us_data *us)
832/* Dissociate from the USB device */ 842/* Dissociate from the USB device */
833static void dissociate_dev(struct us_data *us) 843static void dissociate_dev(struct us_data *us)
834{ 844{
835 US_DEBUGP("-- %s\n", __FUNCTION__); 845 US_DEBUGP("-- %s\n", __func__);
836 846
837 kfree(us->sensebuf); 847 kfree(us->sensebuf);
838 848
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index c815a40e167f..be76084c8d7e 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -88,7 +88,7 @@ static int skel_open(struct inode *inode, struct file *file)
88 interface = usb_find_interface(&skel_driver, subminor); 88 interface = usb_find_interface(&skel_driver, subminor);
89 if (!interface) { 89 if (!interface) {
90 err ("%s - error, can't find device for minor %d", 90 err ("%s - error, can't find device for minor %d",
91 __FUNCTION__, subminor); 91 __func__, subminor);
92 retval = -ENODEV; 92 retval = -ENODEV;
93 goto exit; 93 goto exit;
94 } 94 }
@@ -212,7 +212,7 @@ static void skel_write_bulk_callback(struct urb *urb)
212{ 212{
213 struct usb_skel *dev; 213 struct usb_skel *dev;
214 214
215 dev = (struct usb_skel *)urb->context; 215 dev = urb->context;
216 216
217 /* sync/async unlink faults aren't errors */ 217 /* sync/async unlink faults aren't errors */
218 if (urb->status) { 218 if (urb->status) {
@@ -220,7 +220,7 @@ static void skel_write_bulk_callback(struct urb *urb)
220 urb->status == -ECONNRESET || 220 urb->status == -ECONNRESET ||
221 urb->status == -ESHUTDOWN)) 221 urb->status == -ESHUTDOWN))
222 err("%s - nonzero write bulk status received: %d", 222 err("%s - nonzero write bulk status received: %d",
223 __FUNCTION__, urb->status); 223 __func__, urb->status);
224 224
225 spin_lock(&dev->err_lock); 225 spin_lock(&dev->err_lock);
226 dev->errors = urb->status; 226 dev->errors = urb->status;
@@ -301,7 +301,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou
301 retval = usb_submit_urb(urb, GFP_KERNEL); 301 retval = usb_submit_urb(urb, GFP_KERNEL);
302 mutex_unlock(&dev->io_mutex); 302 mutex_unlock(&dev->io_mutex);
303 if (retval) { 303 if (retval) {
304 err("%s - failed submitting write urb, error %d", __FUNCTION__, retval); 304 err("%s - failed submitting write urb, error %d", __func__, retval);
305 goto error_unanchor; 305 goto error_unanchor;
306 } 306 }
307 307
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 1bd5fb30237d..e3dc8f8d0c3e 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1930,6 +1930,20 @@ config FB_VIRTUAL
1930 1930
1931 If unsure, say N. 1931 If unsure, say N.
1932 1932
1933config XEN_FBDEV_FRONTEND
1934 tristate "Xen virtual frame buffer support"
1935 depends on FB && XEN
1936 select FB_SYS_FILLRECT
1937 select FB_SYS_COPYAREA
1938 select FB_SYS_IMAGEBLIT
1939 select FB_SYS_FOPS
1940 select FB_DEFERRED_IO
1941 default y
1942 help
1943 This driver implements the front-end of the Xen virtual
1944 frame buffer driver. It communicates with a back-end
1945 in another domain.
1946
1933source "drivers/video/omap/Kconfig" 1947source "drivers/video/omap/Kconfig"
1934 1948
1935source "drivers/video/backlight/Kconfig" 1949source "drivers/video/backlight/Kconfig"
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 11c0e5e05f21..f172b9b73314 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -114,6 +114,7 @@ obj-$(CONFIG_FB_PS3) += ps3fb.o
114obj-$(CONFIG_FB_SM501) += sm501fb.o 114obj-$(CONFIG_FB_SM501) += sm501fb.o
115obj-$(CONFIG_FB_XILINX) += xilinxfb.o 115obj-$(CONFIG_FB_XILINX) += xilinxfb.o
116obj-$(CONFIG_FB_OMAP) += omap/ 116obj-$(CONFIG_FB_OMAP) += omap/
117obj-$(CONFIG_XEN_FBDEV_FRONTEND) += xen-fbfront.o
117 118
118# Platform or fallback drivers go here 119# Platform or fallback drivers go here
119obj-$(CONFIG_FB_UVESA) += uvesafb.o 120obj-$(CONFIG_FB_UVESA) += uvesafb.o
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
new file mode 100644
index 000000000000..619a6f8d65a2
--- /dev/null
+++ b/drivers/video/xen-fbfront.c
@@ -0,0 +1,550 @@
1/*
2 * Xen para-virtual frame buffer device
3 *
4 * Copyright (C) 2005-2006 Anthony Liguori <aliguori@us.ibm.com>
5 * Copyright (C) 2006-2008 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
6 *
7 * Based on linux/drivers/video/q40fb.c
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 */
13
14/*
15 * TODO:
16 *
17 * Switch to grant tables when they become capable of dealing with the
18 * frame buffer.
19 */
20
21#include <linux/kernel.h>
22#include <linux/errno.h>
23#include <linux/fb.h>
24#include <linux/module.h>
25#include <linux/vmalloc.h>
26#include <linux/mm.h>
27#include <asm/xen/hypervisor.h>
28#include <xen/events.h>
29#include <xen/page.h>
30#include <xen/interface/io/fbif.h>
31#include <xen/interface/io/protocols.h>
32#include <xen/xenbus.h>
33
34struct xenfb_info {
35 unsigned char *fb;
36 struct fb_info *fb_info;
37 int x1, y1, x2, y2; /* dirty rectangle,
38 protected by dirty_lock */
39 spinlock_t dirty_lock;
40 int nr_pages;
41 int irq;
42 struct xenfb_page *page;
43 unsigned long *mfns;
44 int update_wanted; /* XENFB_TYPE_UPDATE wanted */
45
46 struct xenbus_device *xbdev;
47};
48
49static u32 xenfb_mem_len = XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8;
50
51static int xenfb_remove(struct xenbus_device *);
52static void xenfb_init_shared_page(struct xenfb_info *);
53static int xenfb_connect_backend(struct xenbus_device *, struct xenfb_info *);
54static void xenfb_disconnect_backend(struct xenfb_info *);
55
56static void xenfb_do_update(struct xenfb_info *info,
57 int x, int y, int w, int h)
58{
59 union xenfb_out_event event;
60 u32 prod;
61
62 event.type = XENFB_TYPE_UPDATE;
63 event.update.x = x;
64 event.update.y = y;
65 event.update.width = w;
66 event.update.height = h;
67
68 prod = info->page->out_prod;
69 /* caller ensures !xenfb_queue_full() */
70 mb(); /* ensure ring space available */
71 XENFB_OUT_RING_REF(info->page, prod) = event;
72 wmb(); /* ensure ring contents visible */
73 info->page->out_prod = prod + 1;
74
75 notify_remote_via_irq(info->irq);
76}
77
78static int xenfb_queue_full(struct xenfb_info *info)
79{
80 u32 cons, prod;
81
82 prod = info->page->out_prod;
83 cons = info->page->out_cons;
84 return prod - cons == XENFB_OUT_RING_LEN;
85}
86
87static void xenfb_refresh(struct xenfb_info *info,
88 int x1, int y1, int w, int h)
89{
90 unsigned long flags;
91 int y2 = y1 + h - 1;
92 int x2 = x1 + w - 1;
93
94 if (!info->update_wanted)
95 return;
96
97 spin_lock_irqsave(&info->dirty_lock, flags);
98
99 /* Combine with dirty rectangle: */
100 if (info->y1 < y1)
101 y1 = info->y1;
102 if (info->y2 > y2)
103 y2 = info->y2;
104 if (info->x1 < x1)
105 x1 = info->x1;
106 if (info->x2 > x2)
107 x2 = info->x2;
108
109 if (xenfb_queue_full(info)) {
110 /* Can't send right now, stash it in the dirty rectangle */
111 info->x1 = x1;
112 info->x2 = x2;
113 info->y1 = y1;
114 info->y2 = y2;
115 spin_unlock_irqrestore(&info->dirty_lock, flags);
116 return;
117 }
118
119 /* Clear dirty rectangle: */
120 info->x1 = info->y1 = INT_MAX;
121 info->x2 = info->y2 = 0;
122
123 spin_unlock_irqrestore(&info->dirty_lock, flags);
124
125 if (x1 <= x2 && y1 <= y2)
126 xenfb_do_update(info, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
127}
128
129static void xenfb_deferred_io(struct fb_info *fb_info,
130 struct list_head *pagelist)
131{
132 struct xenfb_info *info = fb_info->par;
133 struct page *page;
134 unsigned long beg, end;
135 int y1, y2, miny, maxy;
136
137 miny = INT_MAX;
138 maxy = 0;
139 list_for_each_entry(page, pagelist, lru) {
140 beg = page->index << PAGE_SHIFT;
141 end = beg + PAGE_SIZE - 1;
142 y1 = beg / fb_info->fix.line_length;
143 y2 = end / fb_info->fix.line_length;
144 if (y2 >= fb_info->var.yres)
145 y2 = fb_info->var.yres - 1;
146 if (miny > y1)
147 miny = y1;
148 if (maxy < y2)
149 maxy = y2;
150 }
151 xenfb_refresh(info, 0, miny, fb_info->var.xres, maxy - miny + 1);
152}
153
154static struct fb_deferred_io xenfb_defio = {
155 .delay = HZ / 20,
156 .deferred_io = xenfb_deferred_io,
157};
158
159static int xenfb_setcolreg(unsigned regno, unsigned red, unsigned green,
160 unsigned blue, unsigned transp,
161 struct fb_info *info)
162{
163 u32 v;
164
165 if (regno > info->cmap.len)
166 return 1;
167
168#define CNVT_TOHW(val, width) ((((val)<<(width))+0x7FFF-(val))>>16)
169 red = CNVT_TOHW(red, info->var.red.length);
170 green = CNVT_TOHW(green, info->var.green.length);
171 blue = CNVT_TOHW(blue, info->var.blue.length);
172 transp = CNVT_TOHW(transp, info->var.transp.length);
173#undef CNVT_TOHW
174
175 v = (red << info->var.red.offset) |
176 (green << info->var.green.offset) |
177 (blue << info->var.blue.offset);
178
179 switch (info->var.bits_per_pixel) {
180 case 16:
181 case 24:
182 case 32:
183 ((u32 *)info->pseudo_palette)[regno] = v;
184 break;
185 }
186
187 return 0;
188}
189
190static void xenfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
191{
192 struct xenfb_info *info = p->par;
193
194 sys_fillrect(p, rect);
195 xenfb_refresh(info, rect->dx, rect->dy, rect->width, rect->height);
196}
197
198static void xenfb_imageblit(struct fb_info *p, const struct fb_image *image)
199{
200 struct xenfb_info *info = p->par;
201
202 sys_imageblit(p, image);
203 xenfb_refresh(info, image->dx, image->dy, image->width, image->height);
204}
205
206static void xenfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
207{
208 struct xenfb_info *info = p->par;
209
210 sys_copyarea(p, area);
211 xenfb_refresh(info, area->dx, area->dy, area->width, area->height);
212}
213
214static ssize_t xenfb_write(struct fb_info *p, const char __user *buf,
215 size_t count, loff_t *ppos)
216{
217 struct xenfb_info *info = p->par;
218 ssize_t res;
219
220 res = fb_sys_write(p, buf, count, ppos);
221 xenfb_refresh(info, 0, 0, info->page->width, info->page->height);
222 return res;
223}
224
225static struct fb_ops xenfb_fb_ops = {
226 .owner = THIS_MODULE,
227 .fb_read = fb_sys_read,
228 .fb_write = xenfb_write,
229 .fb_setcolreg = xenfb_setcolreg,
230 .fb_fillrect = xenfb_fillrect,
231 .fb_copyarea = xenfb_copyarea,
232 .fb_imageblit = xenfb_imageblit,
233};
234
235static irqreturn_t xenfb_event_handler(int rq, void *dev_id)
236{
237 /*
238 * No in events recognized, simply ignore them all.
239 * If you need to recognize some, see xen-kbdfront's
240 * input_handler() for how to do that.
241 */
242 struct xenfb_info *info = dev_id;
243 struct xenfb_page *page = info->page;
244
245 if (page->in_cons != page->in_prod) {
246 info->page->in_cons = info->page->in_prod;
247 notify_remote_via_irq(info->irq);
248 }
249
250 /* Flush dirty rectangle: */
251 xenfb_refresh(info, INT_MAX, INT_MAX, -INT_MAX, -INT_MAX);
252
253 return IRQ_HANDLED;
254}
255
256static int __devinit xenfb_probe(struct xenbus_device *dev,
257 const struct xenbus_device_id *id)
258{
259 struct xenfb_info *info;
260 struct fb_info *fb_info;
261 int ret;
262
263 info = kzalloc(sizeof(*info), GFP_KERNEL);
264 if (info == NULL) {
265 xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
266 return -ENOMEM;
267 }
268 dev->dev.driver_data = info;
269 info->xbdev = dev;
270 info->irq = -1;
271 info->x1 = info->y1 = INT_MAX;
272 spin_lock_init(&info->dirty_lock);
273
274 info->fb = vmalloc(xenfb_mem_len);
275 if (info->fb == NULL)
276 goto error_nomem;
277 memset(info->fb, 0, xenfb_mem_len);
278
279 info->nr_pages = (xenfb_mem_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
280
281 info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
282 if (!info->mfns)
283 goto error_nomem;
284
285 /* set up shared page */
286 info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
287 if (!info->page)
288 goto error_nomem;
289
290 xenfb_init_shared_page(info);
291
292 /* abusing framebuffer_alloc() to allocate pseudo_palette */
293 fb_info = framebuffer_alloc(sizeof(u32) * 256, NULL);
294 if (fb_info == NULL)
295 goto error_nomem;
296
297 /* complete the abuse: */
298 fb_info->pseudo_palette = fb_info->par;
299 fb_info->par = info;
300
301 fb_info->screen_base = info->fb;
302
303 fb_info->fbops = &xenfb_fb_ops;
304 fb_info->var.xres_virtual = fb_info->var.xres = info->page->width;
305 fb_info->var.yres_virtual = fb_info->var.yres = info->page->height;
306 fb_info->var.bits_per_pixel = info->page->depth;
307
308 fb_info->var.red = (struct fb_bitfield){16, 8, 0};
309 fb_info->var.green = (struct fb_bitfield){8, 8, 0};
310 fb_info->var.blue = (struct fb_bitfield){0, 8, 0};
311
312 fb_info->var.activate = FB_ACTIVATE_NOW;
313 fb_info->var.height = -1;
314 fb_info->var.width = -1;
315 fb_info->var.vmode = FB_VMODE_NONINTERLACED;
316
317 fb_info->fix.visual = FB_VISUAL_TRUECOLOR;
318 fb_info->fix.line_length = info->page->line_length;
319 fb_info->fix.smem_start = 0;
320 fb_info->fix.smem_len = xenfb_mem_len;
321 strcpy(fb_info->fix.id, "xen");
322 fb_info->fix.type = FB_TYPE_PACKED_PIXELS;
323 fb_info->fix.accel = FB_ACCEL_NONE;
324
325 fb_info->flags = FBINFO_FLAG_DEFAULT;
326
327 ret = fb_alloc_cmap(&fb_info->cmap, 256, 0);
328 if (ret < 0) {
329 framebuffer_release(fb_info);
330 xenbus_dev_fatal(dev, ret, "fb_alloc_cmap");
331 goto error;
332 }
333
334 fb_info->fbdefio = &xenfb_defio;
335 fb_deferred_io_init(fb_info);
336
337 ret = register_framebuffer(fb_info);
338 if (ret) {
339 fb_deferred_io_cleanup(fb_info);
340 fb_dealloc_cmap(&fb_info->cmap);
341 framebuffer_release(fb_info);
342 xenbus_dev_fatal(dev, ret, "register_framebuffer");
343 goto error;
344 }
345 info->fb_info = fb_info;
346
347 ret = xenfb_connect_backend(dev, info);
348 if (ret < 0)
349 goto error;
350
351 return 0;
352
353 error_nomem:
354 ret = -ENOMEM;
355 xenbus_dev_fatal(dev, ret, "allocating device memory");
356 error:
357 xenfb_remove(dev);
358 return ret;
359}
360
361static int xenfb_resume(struct xenbus_device *dev)
362{
363 struct xenfb_info *info = dev->dev.driver_data;
364
365 xenfb_disconnect_backend(info);
366 xenfb_init_shared_page(info);
367 return xenfb_connect_backend(dev, info);
368}
369
370static int xenfb_remove(struct xenbus_device *dev)
371{
372 struct xenfb_info *info = dev->dev.driver_data;
373
374 xenfb_disconnect_backend(info);
375 if (info->fb_info) {
376 fb_deferred_io_cleanup(info->fb_info);
377 unregister_framebuffer(info->fb_info);
378 fb_dealloc_cmap(&info->fb_info->cmap);
379 framebuffer_release(info->fb_info);
380 }
381 free_page((unsigned long)info->page);
382 vfree(info->mfns);
383 vfree(info->fb);
384 kfree(info);
385
386 return 0;
387}
388
389static unsigned long vmalloc_to_mfn(void *address)
390{
391 return pfn_to_mfn(vmalloc_to_pfn(address));
392}
393
394static void xenfb_init_shared_page(struct xenfb_info *info)
395{
396 int i;
397
398 for (i = 0; i < info->nr_pages; i++)
399 info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
400
401 info->page->pd[0] = vmalloc_to_mfn(info->mfns);
402 info->page->pd[1] = 0;
403 info->page->width = XENFB_WIDTH;
404 info->page->height = XENFB_HEIGHT;
405 info->page->depth = XENFB_DEPTH;
406 info->page->line_length = (info->page->depth / 8) * info->page->width;
407 info->page->mem_length = xenfb_mem_len;
408 info->page->in_cons = info->page->in_prod = 0;
409 info->page->out_cons = info->page->out_prod = 0;
410}
411
412static int xenfb_connect_backend(struct xenbus_device *dev,
413 struct xenfb_info *info)
414{
415 int ret, evtchn;
416 struct xenbus_transaction xbt;
417
418 ret = xenbus_alloc_evtchn(dev, &evtchn);
419 if (ret)
420 return ret;
421 ret = bind_evtchn_to_irqhandler(evtchn, xenfb_event_handler,
422 0, dev->devicetype, info);
423 if (ret < 0) {
424 xenbus_free_evtchn(dev, evtchn);
425 xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
426 return ret;
427 }
428 info->irq = ret;
429
430 again:
431 ret = xenbus_transaction_start(&xbt);
432 if (ret) {
433 xenbus_dev_fatal(dev, ret, "starting transaction");
434 return ret;
435 }
436 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
437 virt_to_mfn(info->page));
438 if (ret)
439 goto error_xenbus;
440 ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
441 evtchn);
442 if (ret)
443 goto error_xenbus;
444 ret = xenbus_printf(xbt, dev->nodename, "protocol", "%s",
445 XEN_IO_PROTO_ABI_NATIVE);
446 if (ret)
447 goto error_xenbus;
448 ret = xenbus_printf(xbt, dev->nodename, "feature-update", "1");
449 if (ret)
450 goto error_xenbus;
451 ret = xenbus_transaction_end(xbt, 0);
452 if (ret) {
453 if (ret == -EAGAIN)
454 goto again;
455 xenbus_dev_fatal(dev, ret, "completing transaction");
456 return ret;
457 }
458
459 xenbus_switch_state(dev, XenbusStateInitialised);
460 return 0;
461
462 error_xenbus:
463 xenbus_transaction_end(xbt, 1);
464 xenbus_dev_fatal(dev, ret, "writing xenstore");
465 return ret;
466}
467
468static void xenfb_disconnect_backend(struct xenfb_info *info)
469{
470 if (info->irq >= 0)
471 unbind_from_irqhandler(info->irq, info);
472 info->irq = -1;
473}
474
475static void xenfb_backend_changed(struct xenbus_device *dev,
476 enum xenbus_state backend_state)
477{
478 struct xenfb_info *info = dev->dev.driver_data;
479 int val;
480
481 switch (backend_state) {
482 case XenbusStateInitialising:
483 case XenbusStateInitialised:
484 case XenbusStateUnknown:
485 case XenbusStateClosed:
486 break;
487
488 case XenbusStateInitWait:
489InitWait:
490 xenbus_switch_state(dev, XenbusStateConnected);
491 break;
492
493 case XenbusStateConnected:
494 /*
495 * Work around xenbus race condition: If backend goes
496 * through InitWait to Connected fast enough, we can
497 * get Connected twice here.
498 */
499 if (dev->state != XenbusStateConnected)
500 goto InitWait; /* no InitWait seen yet, fudge it */
501
502 if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
503 "request-update", "%d", &val) < 0)
504 val = 0;
505 if (val)
506 info->update_wanted = 1;
507 break;
508
509 case XenbusStateClosing:
510 xenbus_frontend_closed(dev);
511 break;
512 }
513}
514
515static struct xenbus_device_id xenfb_ids[] = {
516 { "vfb" },
517 { "" }
518};
519
520static struct xenbus_driver xenfb = {
521 .name = "vfb",
522 .owner = THIS_MODULE,
523 .ids = xenfb_ids,
524 .probe = xenfb_probe,
525 .remove = xenfb_remove,
526 .resume = xenfb_resume,
527 .otherend_changed = xenfb_backend_changed,
528};
529
530static int __init xenfb_init(void)
531{
532 if (!is_running_on_xen())
533 return -ENODEV;
534
535 /* Nothing to do if running in dom0. */
536 if (is_initial_xendomain())
537 return -ENODEV;
538
539 return xenbus_register_frontend(&xenfb);
540}
541
542static void __exit xenfb_cleanup(void)
543{
544 xenbus_unregister_driver(&xenfb);
545}
546
547module_init(xenfb_init);
548module_exit(xenfb_cleanup);
549
550MODULE_LICENSE("GPL");
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
new file mode 100644
index 000000000000..4b75a16de009
--- /dev/null
+++ b/drivers/xen/Kconfig
@@ -0,0 +1,19 @@
1config XEN_BALLOON
2 bool "Xen memory balloon driver"
3 depends on XEN
4 default y
5 help
6 The balloon driver allows the Xen domain to request more memory from
7 the system to expand the domain's memory allocation, or alternatively
8 return unneeded memory to the system.
9
10config XEN_SCRUB_PAGES
11 bool "Scrub pages before returning them to system"
12 depends on XEN_BALLOON
13 default y
14 help
15 Scrub pages before returning them to the system for reuse by
16 other domains. This makes sure that any confidential data
17 is not accidentally visible to other domains. Is it more
18 secure, but slightly less efficient.
19 If in doubt, say yes.
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 56592f0d6cef..37af04f1ffd9 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -1,2 +1,4 @@
1obj-y += grant-table.o 1obj-y += grant-table.o features.o events.o
2obj-y += xenbus/ 2obj-y += xenbus/
3obj-$(CONFIG_XEN_XENCOMM) += xencomm.o
4obj-$(CONFIG_XEN_BALLOON) += balloon.o
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
new file mode 100644
index 000000000000..ab25ba6cbbb9
--- /dev/null
+++ b/drivers/xen/balloon.c
@@ -0,0 +1,712 @@
1/******************************************************************************
2 * balloon.c
3 *
4 * Xen balloon driver - enables returning/claiming memory to/from Xen.
5 *
6 * Copyright (c) 2003, B Dragovic
7 * Copyright (c) 2003-2004, M Williamson, K Fraser
8 * Copyright (c) 2005 Dan M. Smith, IBM Corporation
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation; or, when distributed
13 * separately from the Linux kernel or incorporated into other
14 * software packages, subject to the following license:
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a copy
17 * of this source file (the "Software"), to deal in the Software without
18 * restriction, including without limitation the rights to use, copy, modify,
19 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
20 * and to permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 * IN THE SOFTWARE.
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/sched.h>
38#include <linux/errno.h>
39#include <linux/mm.h>
40#include <linux/bootmem.h>
41#include <linux/pagemap.h>
42#include <linux/highmem.h>
43#include <linux/mutex.h>
44#include <linux/highmem.h>
45#include <linux/list.h>
46#include <linux/sysdev.h>
47
48#include <asm/xen/hypervisor.h>
49#include <asm/page.h>
50#include <asm/pgalloc.h>
51#include <asm/pgtable.h>
52#include <asm/uaccess.h>
53#include <asm/tlb.h>
54
55#include <xen/interface/memory.h>
56#include <xen/balloon.h>
57#include <xen/xenbus.h>
58#include <xen/features.h>
59#include <xen/page.h>
60
61#define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10))
62
63#define BALLOON_CLASS_NAME "memory"
64
65struct balloon_stats {
66 /* We aim for 'current allocation' == 'target allocation'. */
67 unsigned long current_pages;
68 unsigned long target_pages;
69 /* We may hit the hard limit in Xen. If we do then we remember it. */
70 unsigned long hard_limit;
71 /*
72 * Drivers may alter the memory reservation independently, but they
73 * must inform the balloon driver so we avoid hitting the hard limit.
74 */
75 unsigned long driver_pages;
76 /* Number of pages in high- and low-memory balloons. */
77 unsigned long balloon_low;
78 unsigned long balloon_high;
79};
80
81static DEFINE_MUTEX(balloon_mutex);
82
83static struct sys_device balloon_sysdev;
84
85static int register_balloon(struct sys_device *sysdev);
86
87/*
88 * Protects atomic reservation decrease/increase against concurrent increases.
89 * Also protects non-atomic updates of current_pages and driver_pages, and
90 * balloon lists.
91 */
92static DEFINE_SPINLOCK(balloon_lock);
93
94static struct balloon_stats balloon_stats;
95
96/* We increase/decrease in batches which fit in a page */
97static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
98
99/* VM /proc information for memory */
100extern unsigned long totalram_pages;
101
102#ifdef CONFIG_HIGHMEM
103extern unsigned long totalhigh_pages;
104#define inc_totalhigh_pages() (totalhigh_pages++)
105#define dec_totalhigh_pages() (totalhigh_pages--)
106#else
107#define inc_totalhigh_pages() do {} while(0)
108#define dec_totalhigh_pages() do {} while(0)
109#endif
110
111/* List of ballooned pages, threaded through the mem_map array. */
112static LIST_HEAD(ballooned_pages);
113
114/* Main work function, always executed in process context. */
115static void balloon_process(struct work_struct *work);
116static DECLARE_WORK(balloon_worker, balloon_process);
117static struct timer_list balloon_timer;
118
119/* When ballooning out (allocating memory to return to Xen) we don't really
120 want the kernel to try too hard since that can trigger the oom killer. */
121#define GFP_BALLOON \
122 (GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC)
123
124static void scrub_page(struct page *page)
125{
126#ifdef CONFIG_XEN_SCRUB_PAGES
127 if (PageHighMem(page)) {
128 void *v = kmap(page);
129 clear_page(v);
130 kunmap(v);
131 } else {
132 void *v = page_address(page);
133 clear_page(v);
134 }
135#endif
136}
137
138/* balloon_append: add the given page to the balloon. */
139static void balloon_append(struct page *page)
140{
141 /* Lowmem is re-populated first, so highmem pages go at list tail. */
142 if (PageHighMem(page)) {
143 list_add_tail(&page->lru, &ballooned_pages);
144 balloon_stats.balloon_high++;
145 dec_totalhigh_pages();
146 } else {
147 list_add(&page->lru, &ballooned_pages);
148 balloon_stats.balloon_low++;
149 }
150}
151
152/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
153static struct page *balloon_retrieve(void)
154{
155 struct page *page;
156
157 if (list_empty(&ballooned_pages))
158 return NULL;
159
160 page = list_entry(ballooned_pages.next, struct page, lru);
161 list_del(&page->lru);
162
163 if (PageHighMem(page)) {
164 balloon_stats.balloon_high--;
165 inc_totalhigh_pages();
166 }
167 else
168 balloon_stats.balloon_low--;
169
170 return page;
171}
172
173static struct page *balloon_first_page(void)
174{
175 if (list_empty(&ballooned_pages))
176 return NULL;
177 return list_entry(ballooned_pages.next, struct page, lru);
178}
179
180static struct page *balloon_next_page(struct page *page)
181{
182 struct list_head *next = page->lru.next;
183 if (next == &ballooned_pages)
184 return NULL;
185 return list_entry(next, struct page, lru);
186}
187
188static void balloon_alarm(unsigned long unused)
189{
190 schedule_work(&balloon_worker);
191}
192
193static unsigned long current_target(void)
194{
195 unsigned long target = min(balloon_stats.target_pages, balloon_stats.hard_limit);
196
197 target = min(target,
198 balloon_stats.current_pages +
199 balloon_stats.balloon_low +
200 balloon_stats.balloon_high);
201
202 return target;
203}
204
205static int increase_reservation(unsigned long nr_pages)
206{
207 unsigned long pfn, i, flags;
208 struct page *page;
209 long rc;
210 struct xen_memory_reservation reservation = {
211 .address_bits = 0,
212 .extent_order = 0,
213 .domid = DOMID_SELF
214 };
215
216 if (nr_pages > ARRAY_SIZE(frame_list))
217 nr_pages = ARRAY_SIZE(frame_list);
218
219 spin_lock_irqsave(&balloon_lock, flags);
220
221 page = balloon_first_page();
222 for (i = 0; i < nr_pages; i++) {
223 BUG_ON(page == NULL);
224 frame_list[i] = page_to_pfn(page);;
225 page = balloon_next_page(page);
226 }
227
228 reservation.extent_start = (unsigned long)frame_list;
229 reservation.nr_extents = nr_pages;
230 rc = HYPERVISOR_memory_op(
231 XENMEM_populate_physmap, &reservation);
232 if (rc < nr_pages) {
233 if (rc > 0) {
234 int ret;
235
236 /* We hit the Xen hard limit: reprobe. */
237 reservation.nr_extents = rc;
238 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
239 &reservation);
240 BUG_ON(ret != rc);
241 }
242 if (rc >= 0)
243 balloon_stats.hard_limit = (balloon_stats.current_pages + rc -
244 balloon_stats.driver_pages);
245 goto out;
246 }
247
248 for (i = 0; i < nr_pages; i++) {
249 page = balloon_retrieve();
250 BUG_ON(page == NULL);
251
252 pfn = page_to_pfn(page);
253 BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) &&
254 phys_to_machine_mapping_valid(pfn));
255
256 set_phys_to_machine(pfn, frame_list[i]);
257
258 /* Link back into the page tables if not highmem. */
259 if (pfn < max_low_pfn) {
260 int ret;
261 ret = HYPERVISOR_update_va_mapping(
262 (unsigned long)__va(pfn << PAGE_SHIFT),
263 mfn_pte(frame_list[i], PAGE_KERNEL),
264 0);
265 BUG_ON(ret);
266 }
267
268 /* Relinquish the page back to the allocator. */
269 ClearPageReserved(page);
270 init_page_count(page);
271 __free_page(page);
272 }
273
274 balloon_stats.current_pages += nr_pages;
275 totalram_pages = balloon_stats.current_pages;
276
277 out:
278 spin_unlock_irqrestore(&balloon_lock, flags);
279
280 return 0;
281}
282
283static int decrease_reservation(unsigned long nr_pages)
284{
285 unsigned long pfn, i, flags;
286 struct page *page;
287 int need_sleep = 0;
288 int ret;
289 struct xen_memory_reservation reservation = {
290 .address_bits = 0,
291 .extent_order = 0,
292 .domid = DOMID_SELF
293 };
294
295 if (nr_pages > ARRAY_SIZE(frame_list))
296 nr_pages = ARRAY_SIZE(frame_list);
297
298 for (i = 0; i < nr_pages; i++) {
299 if ((page = alloc_page(GFP_BALLOON)) == NULL) {
300 nr_pages = i;
301 need_sleep = 1;
302 break;
303 }
304
305 pfn = page_to_pfn(page);
306 frame_list[i] = pfn_to_mfn(pfn);
307
308 scrub_page(page);
309 }
310
311 /* Ensure that ballooned highmem pages don't have kmaps. */
312 kmap_flush_unused();
313 flush_tlb_all();
314
315 spin_lock_irqsave(&balloon_lock, flags);
316
317 /* No more mappings: invalidate P2M and add to balloon. */
318 for (i = 0; i < nr_pages; i++) {
319 pfn = mfn_to_pfn(frame_list[i]);
320 set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
321 balloon_append(pfn_to_page(pfn));
322 }
323
324 reservation.extent_start = (unsigned long)frame_list;
325 reservation.nr_extents = nr_pages;
326 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
327 BUG_ON(ret != nr_pages);
328
329 balloon_stats.current_pages -= nr_pages;
330 totalram_pages = balloon_stats.current_pages;
331
332 spin_unlock_irqrestore(&balloon_lock, flags);
333
334 return need_sleep;
335}
336
337/*
338 * We avoid multiple worker processes conflicting via the balloon mutex.
339 * We may of course race updates of the target counts (which are protected
340 * by the balloon lock), or with changes to the Xen hard limit, but we will
341 * recover from these in time.
342 */
343static void balloon_process(struct work_struct *work)
344{
345 int need_sleep = 0;
346 long credit;
347
348 mutex_lock(&balloon_mutex);
349
350 do {
351 credit = current_target() - balloon_stats.current_pages;
352 if (credit > 0)
353 need_sleep = (increase_reservation(credit) != 0);
354 if (credit < 0)
355 need_sleep = (decrease_reservation(-credit) != 0);
356
357#ifndef CONFIG_PREEMPT
358 if (need_resched())
359 schedule();
360#endif
361 } while ((credit != 0) && !need_sleep);
362
363 /* Schedule more work if there is some still to be done. */
364 if (current_target() != balloon_stats.current_pages)
365 mod_timer(&balloon_timer, jiffies + HZ);
366
367 mutex_unlock(&balloon_mutex);
368}
369
370/* Resets the Xen limit, sets new target, and kicks off processing. */
371void balloon_set_new_target(unsigned long target)
372{
373 /* No need for lock. Not read-modify-write updates. */
374 balloon_stats.hard_limit = ~0UL;
375 balloon_stats.target_pages = target;
376 schedule_work(&balloon_worker);
377}
378
379static struct xenbus_watch target_watch =
380{
381 .node = "memory/target"
382};
383
384/* React to a change in the target key */
385static void watch_target(struct xenbus_watch *watch,
386 const char **vec, unsigned int len)
387{
388 unsigned long long new_target;
389 int err;
390
391 err = xenbus_scanf(XBT_NIL, "memory", "target", "%llu", &new_target);
392 if (err != 1) {
393 /* This is ok (for domain0 at least) - so just return */
394 return;
395 }
396
397 /* The given memory/target value is in KiB, so it needs converting to
398 * pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10.
399 */
400 balloon_set_new_target(new_target >> (PAGE_SHIFT - 10));
401}
402
403static int balloon_init_watcher(struct notifier_block *notifier,
404 unsigned long event,
405 void *data)
406{
407 int err;
408
409 err = register_xenbus_watch(&target_watch);
410 if (err)
411 printk(KERN_ERR "Failed to set balloon watcher\n");
412
413 return NOTIFY_DONE;
414}
415
416static struct notifier_block xenstore_notifier;
417
418static int __init balloon_init(void)
419{
420 unsigned long pfn;
421 struct page *page;
422
423 if (!is_running_on_xen())
424 return -ENODEV;
425
426 pr_info("xen_balloon: Initialising balloon driver.\n");
427
428 balloon_stats.current_pages = min(xen_start_info->nr_pages, max_pfn);
429 totalram_pages = balloon_stats.current_pages;
430 balloon_stats.target_pages = balloon_stats.current_pages;
431 balloon_stats.balloon_low = 0;
432 balloon_stats.balloon_high = 0;
433 balloon_stats.driver_pages = 0UL;
434 balloon_stats.hard_limit = ~0UL;
435
436 init_timer(&balloon_timer);
437 balloon_timer.data = 0;
438 balloon_timer.function = balloon_alarm;
439
440 register_balloon(&balloon_sysdev);
441
442 /* Initialise the balloon with excess memory space. */
443 for (pfn = xen_start_info->nr_pages; pfn < max_pfn; pfn++) {
444 page = pfn_to_page(pfn);
445 if (!PageReserved(page))
446 balloon_append(page);
447 }
448
449 target_watch.callback = watch_target;
450 xenstore_notifier.notifier_call = balloon_init_watcher;
451
452 register_xenstore_notifier(&xenstore_notifier);
453
454 return 0;
455}
456
457subsys_initcall(balloon_init);
458
459static void balloon_exit(void)
460{
461 /* XXX - release balloon here */
462 return;
463}
464
465module_exit(balloon_exit);
466
467static void balloon_update_driver_allowance(long delta)
468{
469 unsigned long flags;
470
471 spin_lock_irqsave(&balloon_lock, flags);
472 balloon_stats.driver_pages += delta;
473 spin_unlock_irqrestore(&balloon_lock, flags);
474}
475
476static int dealloc_pte_fn(
477 pte_t *pte, struct page *pmd_page, unsigned long addr, void *data)
478{
479 unsigned long mfn = pte_mfn(*pte);
480 int ret;
481 struct xen_memory_reservation reservation = {
482 .nr_extents = 1,
483 .extent_order = 0,
484 .domid = DOMID_SELF
485 };
486 reservation.extent_start = (unsigned long)&mfn;
487 set_pte_at(&init_mm, addr, pte, __pte_ma(0ull));
488 set_phys_to_machine(__pa(addr) >> PAGE_SHIFT, INVALID_P2M_ENTRY);
489 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
490 BUG_ON(ret != 1);
491 return 0;
492}
493
494static struct page **alloc_empty_pages_and_pagevec(int nr_pages)
495{
496 unsigned long vaddr, flags;
497 struct page *page, **pagevec;
498 int i, ret;
499
500 pagevec = kmalloc(sizeof(page) * nr_pages, GFP_KERNEL);
501 if (pagevec == NULL)
502 return NULL;
503
504 for (i = 0; i < nr_pages; i++) {
505 page = pagevec[i] = alloc_page(GFP_KERNEL);
506 if (page == NULL)
507 goto err;
508
509 vaddr = (unsigned long)page_address(page);
510
511 scrub_page(page);
512
513 spin_lock_irqsave(&balloon_lock, flags);
514
515 if (xen_feature(XENFEAT_auto_translated_physmap)) {
516 unsigned long gmfn = page_to_pfn(page);
517 struct xen_memory_reservation reservation = {
518 .nr_extents = 1,
519 .extent_order = 0,
520 .domid = DOMID_SELF
521 };
522 reservation.extent_start = (unsigned long)&gmfn;
523 ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
524 &reservation);
525 if (ret == 1)
526 ret = 0; /* success */
527 } else {
528 ret = apply_to_page_range(&init_mm, vaddr, PAGE_SIZE,
529 dealloc_pte_fn, NULL);
530 }
531
532 if (ret != 0) {
533 spin_unlock_irqrestore(&balloon_lock, flags);
534 __free_page(page);
535 goto err;
536 }
537
538 totalram_pages = --balloon_stats.current_pages;
539
540 spin_unlock_irqrestore(&balloon_lock, flags);
541 }
542
543 out:
544 schedule_work(&balloon_worker);
545 flush_tlb_all();
546 return pagevec;
547
548 err:
549 spin_lock_irqsave(&balloon_lock, flags);
550 while (--i >= 0)
551 balloon_append(pagevec[i]);
552 spin_unlock_irqrestore(&balloon_lock, flags);
553 kfree(pagevec);
554 pagevec = NULL;
555 goto out;
556}
557
558static void free_empty_pages_and_pagevec(struct page **pagevec, int nr_pages)
559{
560 unsigned long flags;
561 int i;
562
563 if (pagevec == NULL)
564 return;
565
566 spin_lock_irqsave(&balloon_lock, flags);
567 for (i = 0; i < nr_pages; i++) {
568 BUG_ON(page_count(pagevec[i]) != 1);
569 balloon_append(pagevec[i]);
570 }
571 spin_unlock_irqrestore(&balloon_lock, flags);
572
573 kfree(pagevec);
574
575 schedule_work(&balloon_worker);
576}
577
578static void balloon_release_driver_page(struct page *page)
579{
580 unsigned long flags;
581
582 spin_lock_irqsave(&balloon_lock, flags);
583 balloon_append(page);
584 balloon_stats.driver_pages--;
585 spin_unlock_irqrestore(&balloon_lock, flags);
586
587 schedule_work(&balloon_worker);
588}
589
590
591#define BALLOON_SHOW(name, format, args...) \
592 static ssize_t show_##name(struct sys_device *dev, \
593 char *buf) \
594 { \
595 return sprintf(buf, format, ##args); \
596 } \
597 static SYSDEV_ATTR(name, S_IRUGO, show_##name, NULL)
598
599BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(balloon_stats.current_pages));
600BALLOON_SHOW(low_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_low));
601BALLOON_SHOW(high_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_high));
602BALLOON_SHOW(hard_limit_kb,
603 (balloon_stats.hard_limit!=~0UL) ? "%lu\n" : "???\n",
604 (balloon_stats.hard_limit!=~0UL) ? PAGES2KB(balloon_stats.hard_limit) : 0);
605BALLOON_SHOW(driver_kb, "%lu\n", PAGES2KB(balloon_stats.driver_pages));
606
607static ssize_t show_target_kb(struct sys_device *dev, char *buf)
608{
609 return sprintf(buf, "%lu\n", PAGES2KB(balloon_stats.target_pages));
610}
611
612static ssize_t store_target_kb(struct sys_device *dev,
613 const char *buf,
614 size_t count)
615{
616 char memstring[64], *endchar;
617 unsigned long long target_bytes;
618
619 if (!capable(CAP_SYS_ADMIN))
620 return -EPERM;
621
622 if (count <= 1)
623 return -EBADMSG; /* runt */
624 if (count > sizeof(memstring))
625 return -EFBIG; /* too long */
626 strcpy(memstring, buf);
627
628 target_bytes = memparse(memstring, &endchar);
629 balloon_set_new_target(target_bytes >> PAGE_SHIFT);
630
631 return count;
632}
633
634static SYSDEV_ATTR(target_kb, S_IRUGO | S_IWUSR,
635 show_target_kb, store_target_kb);
636
637static struct sysdev_attribute *balloon_attrs[] = {
638 &attr_target_kb,
639};
640
641static struct attribute *balloon_info_attrs[] = {
642 &attr_current_kb.attr,
643 &attr_low_kb.attr,
644 &attr_high_kb.attr,
645 &attr_hard_limit_kb.attr,
646 &attr_driver_kb.attr,
647 NULL
648};
649
650static struct attribute_group balloon_info_group = {
651 .name = "info",
652 .attrs = balloon_info_attrs,
653};
654
655static struct sysdev_class balloon_sysdev_class = {
656 .name = BALLOON_CLASS_NAME,
657};
658
659static int register_balloon(struct sys_device *sysdev)
660{
661 int i, error;
662
663 error = sysdev_class_register(&balloon_sysdev_class);
664 if (error)
665 return error;
666
667 sysdev->id = 0;
668 sysdev->cls = &balloon_sysdev_class;
669
670 error = sysdev_register(sysdev);
671 if (error) {
672 sysdev_class_unregister(&balloon_sysdev_class);
673 return error;
674 }
675
676 for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++) {
677 error = sysdev_create_file(sysdev, balloon_attrs[i]);
678 if (error)
679 goto fail;
680 }
681
682 error = sysfs_create_group(&sysdev->kobj, &balloon_info_group);
683 if (error)
684 goto fail;
685
686 return 0;
687
688 fail:
689 while (--i >= 0)
690 sysdev_remove_file(sysdev, balloon_attrs[i]);
691 sysdev_unregister(sysdev);
692 sysdev_class_unregister(&balloon_sysdev_class);
693 return error;
694}
695
696static void unregister_balloon(struct sys_device *sysdev)
697{
698 int i;
699
700 sysfs_remove_group(&sysdev->kobj, &balloon_info_group);
701 for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++)
702 sysdev_remove_file(sysdev, balloon_attrs[i]);
703 sysdev_unregister(sysdev);
704 sysdev_class_unregister(&balloon_sysdev_class);
705}
706
707static void balloon_sysfs_exit(void)
708{
709 unregister_balloon(&balloon_sysdev);
710}
711
712MODULE_LICENSE("GPL");
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
new file mode 100644
index 000000000000..4f0f22b020ea
--- /dev/null
+++ b/drivers/xen/events.c
@@ -0,0 +1,674 @@
1/*
2 * Xen event channels
3 *
4 * Xen models interrupts with abstract event channels. Because each
5 * domain gets 1024 event channels, but NR_IRQ is not that large, we
6 * must dynamically map irqs<->event channels. The event channels
7 * interface with the rest of the kernel by defining a xen interrupt
8 * chip. When an event is recieved, it is mapped to an irq and sent
9 * through the normal interrupt processing path.
10 *
11 * There are four kinds of events which can be mapped to an event
12 * channel:
13 *
14 * 1. Inter-domain notifications. This includes all the virtual
15 * device events, since they're driven by front-ends in another domain
16 * (typically dom0).
17 * 2. VIRQs, typically used for timers. These are per-cpu events.
18 * 3. IPIs.
19 * 4. Hardware interrupts. Not supported at present.
20 *
21 * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
22 */
23
24#include <linux/linkage.h>
25#include <linux/interrupt.h>
26#include <linux/irq.h>
27#include <linux/module.h>
28#include <linux/string.h>
29
30#include <asm/ptrace.h>
31#include <asm/irq.h>
32#include <asm/sync_bitops.h>
33#include <asm/xen/hypercall.h>
34#include <asm/xen/hypervisor.h>
35
36#include <xen/xen-ops.h>
37#include <xen/events.h>
38#include <xen/interface/xen.h>
39#include <xen/interface/event_channel.h>
40
41/*
42 * This lock protects updates to the following mapping and reference-count
43 * arrays. The lock does not need to be acquired to read the mapping tables.
44 */
45static DEFINE_SPINLOCK(irq_mapping_update_lock);
46
47/* IRQ <-> VIRQ mapping. */
48static DEFINE_PER_CPU(int, virq_to_irq[NR_VIRQS]) = {[0 ... NR_VIRQS-1] = -1};
49
50/* IRQ <-> IPI mapping */
51static DEFINE_PER_CPU(int, ipi_to_irq[XEN_NR_IPIS]) = {[0 ... XEN_NR_IPIS-1] = -1};
52
53/* Packed IRQ information: binding type, sub-type index, and event channel. */
54struct packed_irq
55{
56 unsigned short evtchn;
57 unsigned char index;
58 unsigned char type;
59};
60
61static struct packed_irq irq_info[NR_IRQS];
62
63/* Binding types. */
64enum {
65 IRQT_UNBOUND,
66 IRQT_PIRQ,
67 IRQT_VIRQ,
68 IRQT_IPI,
69 IRQT_EVTCHN
70};
71
72/* Convenient shorthand for packed representation of an unbound IRQ. */
73#define IRQ_UNBOUND mk_irq_info(IRQT_UNBOUND, 0, 0)
74
75static int evtchn_to_irq[NR_EVENT_CHANNELS] = {
76 [0 ... NR_EVENT_CHANNELS-1] = -1
77};
78static unsigned long cpu_evtchn_mask[NR_CPUS][NR_EVENT_CHANNELS/BITS_PER_LONG];
79static u8 cpu_evtchn[NR_EVENT_CHANNELS];
80
81/* Reference counts for bindings to IRQs. */
82static int irq_bindcount[NR_IRQS];
83
84/* Xen will never allocate port zero for any purpose. */
85#define VALID_EVTCHN(chn) ((chn) != 0)
86
87/*
88 * Force a proper event-channel callback from Xen after clearing the
89 * callback mask. We do this in a very simple manner, by making a call
90 * down into Xen. The pending flag will be checked by Xen on return.
91 */
92void force_evtchn_callback(void)
93{
94 (void)HYPERVISOR_xen_version(0, NULL);
95}
96EXPORT_SYMBOL_GPL(force_evtchn_callback);
97
98static struct irq_chip xen_dynamic_chip;
99
100/* Constructor for packed IRQ information. */
101static inline struct packed_irq mk_irq_info(u32 type, u32 index, u32 evtchn)
102{
103 return (struct packed_irq) { evtchn, index, type };
104}
105
106/*
107 * Accessors for packed IRQ information.
108 */
109static inline unsigned int evtchn_from_irq(int irq)
110{
111 return irq_info[irq].evtchn;
112}
113
114static inline unsigned int index_from_irq(int irq)
115{
116 return irq_info[irq].index;
117}
118
119static inline unsigned int type_from_irq(int irq)
120{
121 return irq_info[irq].type;
122}
123
124static inline unsigned long active_evtchns(unsigned int cpu,
125 struct shared_info *sh,
126 unsigned int idx)
127{
128 return (sh->evtchn_pending[idx] &
129 cpu_evtchn_mask[cpu][idx] &
130 ~sh->evtchn_mask[idx]);
131}
132
133static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
134{
135 int irq = evtchn_to_irq[chn];
136
137 BUG_ON(irq == -1);
138#ifdef CONFIG_SMP
139 irq_desc[irq].affinity = cpumask_of_cpu(cpu);
140#endif
141
142 __clear_bit(chn, cpu_evtchn_mask[cpu_evtchn[chn]]);
143 __set_bit(chn, cpu_evtchn_mask[cpu]);
144
145 cpu_evtchn[chn] = cpu;
146}
147
148static void init_evtchn_cpu_bindings(void)
149{
150#ifdef CONFIG_SMP
151 int i;
152 /* By default all event channels notify CPU#0. */
153 for (i = 0; i < NR_IRQS; i++)
154 irq_desc[i].affinity = cpumask_of_cpu(0);
155#endif
156
157 memset(cpu_evtchn, 0, sizeof(cpu_evtchn));
158 memset(cpu_evtchn_mask[0], ~0, sizeof(cpu_evtchn_mask[0]));
159}
160
161static inline unsigned int cpu_from_evtchn(unsigned int evtchn)
162{
163 return cpu_evtchn[evtchn];
164}
165
166static inline void clear_evtchn(int port)
167{
168 struct shared_info *s = HYPERVISOR_shared_info;
169 sync_clear_bit(port, &s->evtchn_pending[0]);
170}
171
172static inline void set_evtchn(int port)
173{
174 struct shared_info *s = HYPERVISOR_shared_info;
175 sync_set_bit(port, &s->evtchn_pending[0]);
176}
177
178
179/**
180 * notify_remote_via_irq - send event to remote end of event channel via irq
181 * @irq: irq of event channel to send event to
182 *
183 * Unlike notify_remote_via_evtchn(), this is safe to use across
184 * save/restore. Notifications on a broken connection are silently
185 * dropped.
186 */
187void notify_remote_via_irq(int irq)
188{
189 int evtchn = evtchn_from_irq(irq);
190
191 if (VALID_EVTCHN(evtchn))
192 notify_remote_via_evtchn(evtchn);
193}
194EXPORT_SYMBOL_GPL(notify_remote_via_irq);
195
196static void mask_evtchn(int port)
197{
198 struct shared_info *s = HYPERVISOR_shared_info;
199 sync_set_bit(port, &s->evtchn_mask[0]);
200}
201
202static void unmask_evtchn(int port)
203{
204 struct shared_info *s = HYPERVISOR_shared_info;
205 unsigned int cpu = get_cpu();
206
207 BUG_ON(!irqs_disabled());
208
209 /* Slow path (hypercall) if this is a non-local port. */
210 if (unlikely(cpu != cpu_from_evtchn(port))) {
211 struct evtchn_unmask unmask = { .port = port };
212 (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask);
213 } else {
214 struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu);
215
216 sync_clear_bit(port, &s->evtchn_mask[0]);
217
218 /*
219 * The following is basically the equivalent of
220 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose
221 * the interrupt edge' if the channel is masked.
222 */
223 if (sync_test_bit(port, &s->evtchn_pending[0]) &&
224 !sync_test_and_set_bit(port / BITS_PER_LONG,
225 &vcpu_info->evtchn_pending_sel))
226 vcpu_info->evtchn_upcall_pending = 1;
227 }
228
229 put_cpu();
230}
231
232static int find_unbound_irq(void)
233{
234 int irq;
235
236 /* Only allocate from dynirq range */
237 for (irq = 0; irq < NR_IRQS; irq++)
238 if (irq_bindcount[irq] == 0)
239 break;
240
241 if (irq == NR_IRQS)
242 panic("No available IRQ to bind to: increase NR_IRQS!\n");
243
244 return irq;
245}
246
247int bind_evtchn_to_irq(unsigned int evtchn)
248{
249 int irq;
250
251 spin_lock(&irq_mapping_update_lock);
252
253 irq = evtchn_to_irq[evtchn];
254
255 if (irq == -1) {
256 irq = find_unbound_irq();
257
258 dynamic_irq_init(irq);
259 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
260 handle_level_irq, "event");
261
262 evtchn_to_irq[evtchn] = irq;
263 irq_info[irq] = mk_irq_info(IRQT_EVTCHN, 0, evtchn);
264 }
265
266 irq_bindcount[irq]++;
267
268 spin_unlock(&irq_mapping_update_lock);
269
270 return irq;
271}
272EXPORT_SYMBOL_GPL(bind_evtchn_to_irq);
273
274static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)
275{
276 struct evtchn_bind_ipi bind_ipi;
277 int evtchn, irq;
278
279 spin_lock(&irq_mapping_update_lock);
280
281 irq = per_cpu(ipi_to_irq, cpu)[ipi];
282 if (irq == -1) {
283 irq = find_unbound_irq();
284 if (irq < 0)
285 goto out;
286
287 dynamic_irq_init(irq);
288 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
289 handle_level_irq, "ipi");
290
291 bind_ipi.vcpu = cpu;
292 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi,
293 &bind_ipi) != 0)
294 BUG();
295 evtchn = bind_ipi.port;
296
297 evtchn_to_irq[evtchn] = irq;
298 irq_info[irq] = mk_irq_info(IRQT_IPI, ipi, evtchn);
299
300 per_cpu(ipi_to_irq, cpu)[ipi] = irq;
301
302 bind_evtchn_to_cpu(evtchn, cpu);
303 }
304
305 irq_bindcount[irq]++;
306
307 out:
308 spin_unlock(&irq_mapping_update_lock);
309 return irq;
310}
311
312
313static int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
314{
315 struct evtchn_bind_virq bind_virq;
316 int evtchn, irq;
317
318 spin_lock(&irq_mapping_update_lock);
319
320 irq = per_cpu(virq_to_irq, cpu)[virq];
321
322 if (irq == -1) {
323 bind_virq.virq = virq;
324 bind_virq.vcpu = cpu;
325 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
326 &bind_virq) != 0)
327 BUG();
328 evtchn = bind_virq.port;
329
330 irq = find_unbound_irq();
331
332 dynamic_irq_init(irq);
333 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
334 handle_level_irq, "virq");
335
336 evtchn_to_irq[evtchn] = irq;
337 irq_info[irq] = mk_irq_info(IRQT_VIRQ, virq, evtchn);
338
339 per_cpu(virq_to_irq, cpu)[virq] = irq;
340
341 bind_evtchn_to_cpu(evtchn, cpu);
342 }
343
344 irq_bindcount[irq]++;
345
346 spin_unlock(&irq_mapping_update_lock);
347
348 return irq;
349}
350
351static void unbind_from_irq(unsigned int irq)
352{
353 struct evtchn_close close;
354 int evtchn = evtchn_from_irq(irq);
355
356 spin_lock(&irq_mapping_update_lock);
357
358 if (VALID_EVTCHN(evtchn) && (--irq_bindcount[irq] == 0)) {
359 close.port = evtchn;
360 if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
361 BUG();
362
363 switch (type_from_irq(irq)) {
364 case IRQT_VIRQ:
365 per_cpu(virq_to_irq, cpu_from_evtchn(evtchn))
366 [index_from_irq(irq)] = -1;
367 break;
368 default:
369 break;
370 }
371
372 /* Closed ports are implicitly re-bound to VCPU0. */
373 bind_evtchn_to_cpu(evtchn, 0);
374
375 evtchn_to_irq[evtchn] = -1;
376 irq_info[irq] = IRQ_UNBOUND;
377
378 dynamic_irq_init(irq);
379 }
380
381 spin_unlock(&irq_mapping_update_lock);
382}
383
384int bind_evtchn_to_irqhandler(unsigned int evtchn,
385 irq_handler_t handler,
386 unsigned long irqflags,
387 const char *devname, void *dev_id)
388{
389 unsigned int irq;
390 int retval;
391
392 irq = bind_evtchn_to_irq(evtchn);
393 retval = request_irq(irq, handler, irqflags, devname, dev_id);
394 if (retval != 0) {
395 unbind_from_irq(irq);
396 return retval;
397 }
398
399 return irq;
400}
401EXPORT_SYMBOL_GPL(bind_evtchn_to_irqhandler);
402
403int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
404 irq_handler_t handler,
405 unsigned long irqflags, const char *devname, void *dev_id)
406{
407 unsigned int irq;
408 int retval;
409
410 irq = bind_virq_to_irq(virq, cpu);
411 retval = request_irq(irq, handler, irqflags, devname, dev_id);
412 if (retval != 0) {
413 unbind_from_irq(irq);
414 return retval;
415 }
416
417 return irq;
418}
419EXPORT_SYMBOL_GPL(bind_virq_to_irqhandler);
420
421int bind_ipi_to_irqhandler(enum ipi_vector ipi,
422 unsigned int cpu,
423 irq_handler_t handler,
424 unsigned long irqflags,
425 const char *devname,
426 void *dev_id)
427{
428 int irq, retval;
429
430 irq = bind_ipi_to_irq(ipi, cpu);
431 if (irq < 0)
432 return irq;
433
434 retval = request_irq(irq, handler, irqflags, devname, dev_id);
435 if (retval != 0) {
436 unbind_from_irq(irq);
437 return retval;
438 }
439
440 return irq;
441}
442
443void unbind_from_irqhandler(unsigned int irq, void *dev_id)
444{
445 free_irq(irq, dev_id);
446 unbind_from_irq(irq);
447}
448EXPORT_SYMBOL_GPL(unbind_from_irqhandler);
449
450void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector)
451{
452 int irq = per_cpu(ipi_to_irq, cpu)[vector];
453 BUG_ON(irq < 0);
454 notify_remote_via_irq(irq);
455}
456
457irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
458{
459 struct shared_info *sh = HYPERVISOR_shared_info;
460 int cpu = smp_processor_id();
461 int i;
462 unsigned long flags;
463 static DEFINE_SPINLOCK(debug_lock);
464
465 spin_lock_irqsave(&debug_lock, flags);
466
467 printk("vcpu %d\n ", cpu);
468
469 for_each_online_cpu(i) {
470 struct vcpu_info *v = per_cpu(xen_vcpu, i);
471 printk("%d: masked=%d pending=%d event_sel %08lx\n ", i,
472 (get_irq_regs() && i == cpu) ? xen_irqs_disabled(get_irq_regs()) : v->evtchn_upcall_mask,
473 v->evtchn_upcall_pending,
474 v->evtchn_pending_sel);
475 }
476 printk("pending:\n ");
477 for(i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--)
478 printk("%08lx%s", sh->evtchn_pending[i],
479 i % 8 == 0 ? "\n " : " ");
480 printk("\nmasks:\n ");
481 for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
482 printk("%08lx%s", sh->evtchn_mask[i],
483 i % 8 == 0 ? "\n " : " ");
484
485 printk("\nunmasked:\n ");
486 for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
487 printk("%08lx%s", sh->evtchn_pending[i] & ~sh->evtchn_mask[i],
488 i % 8 == 0 ? "\n " : " ");
489
490 printk("\npending list:\n");
491 for(i = 0; i < NR_EVENT_CHANNELS; i++) {
492 if (sync_test_bit(i, sh->evtchn_pending)) {
493 printk(" %d: event %d -> irq %d\n",
494 cpu_evtchn[i], i,
495 evtchn_to_irq[i]);
496 }
497 }
498
499 spin_unlock_irqrestore(&debug_lock, flags);
500
501 return IRQ_HANDLED;
502}
503
504
505/*
506 * Search the CPUs pending events bitmasks. For each one found, map
507 * the event number to an irq, and feed it into do_IRQ() for
508 * handling.
509 *
510 * Xen uses a two-level bitmap to speed searching. The first level is
511 * a bitset of words which contain pending event bits. The second
512 * level is a bitset of pending events themselves.
513 */
514void xen_evtchn_do_upcall(struct pt_regs *regs)
515{
516 int cpu = get_cpu();
517 struct shared_info *s = HYPERVISOR_shared_info;
518 struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu);
519 static DEFINE_PER_CPU(unsigned, nesting_count);
520 unsigned count;
521
522 do {
523 unsigned long pending_words;
524
525 vcpu_info->evtchn_upcall_pending = 0;
526
527 if (__get_cpu_var(nesting_count)++)
528 goto out;
529
530#ifndef CONFIG_X86 /* No need for a barrier -- XCHG is a barrier on x86. */
531 /* Clear master flag /before/ clearing selector flag. */
532 rmb();
533#endif
534 pending_words = xchg(&vcpu_info->evtchn_pending_sel, 0);
535 while (pending_words != 0) {
536 unsigned long pending_bits;
537 int word_idx = __ffs(pending_words);
538 pending_words &= ~(1UL << word_idx);
539
540 while ((pending_bits = active_evtchns(cpu, s, word_idx)) != 0) {
541 int bit_idx = __ffs(pending_bits);
542 int port = (word_idx * BITS_PER_LONG) + bit_idx;
543 int irq = evtchn_to_irq[port];
544
545 if (irq != -1)
546 xen_do_IRQ(irq, regs);
547 }
548 }
549
550 BUG_ON(!irqs_disabled());
551
552 count = __get_cpu_var(nesting_count);
553 __get_cpu_var(nesting_count) = 0;
554 } while(count != 1);
555
556out:
557 put_cpu();
558}
559
560/* Rebind an evtchn so that it gets delivered to a specific cpu */
561static void rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
562{
563 struct evtchn_bind_vcpu bind_vcpu;
564 int evtchn = evtchn_from_irq(irq);
565
566 if (!VALID_EVTCHN(evtchn))
567 return;
568
569 /* Send future instances of this interrupt to other vcpu. */
570 bind_vcpu.port = evtchn;
571 bind_vcpu.vcpu = tcpu;
572
573 /*
574 * If this fails, it usually just indicates that we're dealing with a
575 * virq or IPI channel, which don't actually need to be rebound. Ignore
576 * it, but don't do the xenlinux-level rebind in that case.
577 */
578 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0)
579 bind_evtchn_to_cpu(evtchn, tcpu);
580}
581
582
583static void set_affinity_irq(unsigned irq, cpumask_t dest)
584{
585 unsigned tcpu = first_cpu(dest);
586 rebind_irq_to_cpu(irq, tcpu);
587}
588
589int resend_irq_on_evtchn(unsigned int irq)
590{
591 int masked, evtchn = evtchn_from_irq(irq);
592 struct shared_info *s = HYPERVISOR_shared_info;
593
594 if (!VALID_EVTCHN(evtchn))
595 return 1;
596
597 masked = sync_test_and_set_bit(evtchn, s->evtchn_mask);
598 sync_set_bit(evtchn, s->evtchn_pending);
599 if (!masked)
600 unmask_evtchn(evtchn);
601
602 return 1;
603}
604
605static void enable_dynirq(unsigned int irq)
606{
607 int evtchn = evtchn_from_irq(irq);
608
609 if (VALID_EVTCHN(evtchn))
610 unmask_evtchn(evtchn);
611}
612
613static void disable_dynirq(unsigned int irq)
614{
615 int evtchn = evtchn_from_irq(irq);
616
617 if (VALID_EVTCHN(evtchn))
618 mask_evtchn(evtchn);
619}
620
621static void ack_dynirq(unsigned int irq)
622{
623 int evtchn = evtchn_from_irq(irq);
624
625 move_native_irq(irq);
626
627 if (VALID_EVTCHN(evtchn))
628 clear_evtchn(evtchn);
629}
630
631static int retrigger_dynirq(unsigned int irq)
632{
633 int evtchn = evtchn_from_irq(irq);
634 struct shared_info *sh = HYPERVISOR_shared_info;
635 int ret = 0;
636
637 if (VALID_EVTCHN(evtchn)) {
638 int masked;
639
640 masked = sync_test_and_set_bit(evtchn, sh->evtchn_mask);
641 sync_set_bit(evtchn, sh->evtchn_pending);
642 if (!masked)
643 unmask_evtchn(evtchn);
644 ret = 1;
645 }
646
647 return ret;
648}
649
650static struct irq_chip xen_dynamic_chip __read_mostly = {
651 .name = "xen-dyn",
652 .mask = disable_dynirq,
653 .unmask = enable_dynirq,
654 .ack = ack_dynirq,
655 .set_affinity = set_affinity_irq,
656 .retrigger = retrigger_dynirq,
657};
658
659void __init xen_init_IRQ(void)
660{
661 int i;
662
663 init_evtchn_cpu_bindings();
664
665 /* No event channels are 'live' right now. */
666 for (i = 0; i < NR_EVENT_CHANNELS; i++)
667 mask_evtchn(i);
668
669 /* Dynamic IRQ space is currently unbound. Zero the refcnts. */
670 for (i = 0; i < NR_IRQS; i++)
671 irq_bindcount[i] = 0;
672
673 irq_ctx_init(smp_processor_id());
674}
diff --git a/drivers/xen/features.c b/drivers/xen/features.c
new file mode 100644
index 000000000000..0707714e40d6
--- /dev/null
+++ b/drivers/xen/features.c
@@ -0,0 +1,29 @@
1/******************************************************************************
2 * features.c
3 *
4 * Xen feature flags.
5 *
6 * Copyright (c) 2006, Ian Campbell, XenSource Inc.
7 */
8#include <linux/types.h>
9#include <linux/cache.h>
10#include <linux/module.h>
11#include <asm/xen/hypervisor.h>
12#include <xen/features.h>
13
14u8 xen_features[XENFEAT_NR_SUBMAPS * 32] __read_mostly;
15EXPORT_SYMBOL_GPL(xen_features);
16
17void xen_setup_features(void)
18{
19 struct xen_feature_info fi;
20 int i, j;
21
22 for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) {
23 fi.submap_idx = i;
24 if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
25 break;
26 for (j = 0; j < 32; j++)
27 xen_features[i * 32 + j] = !!(fi.submap & 1<<j);
28 }
29}
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index d85dc6d41c2a..52b6b41b909d 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -439,24 +439,6 @@ static inline unsigned int max_nr_grant_frames(void)
439 return xen_max; 439 return xen_max;
440} 440}
441 441
442static int map_pte_fn(pte_t *pte, struct page *pmd_page,
443 unsigned long addr, void *data)
444{
445 unsigned long **frames = (unsigned long **)data;
446
447 set_pte_at(&init_mm, addr, pte, mfn_pte((*frames)[0], PAGE_KERNEL));
448 (*frames)++;
449 return 0;
450}
451
452static int unmap_pte_fn(pte_t *pte, struct page *pmd_page,
453 unsigned long addr, void *data)
454{
455
456 set_pte_at(&init_mm, addr, pte, __pte(0));
457 return 0;
458}
459
460static int gnttab_map(unsigned int start_idx, unsigned int end_idx) 442static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
461{ 443{
462 struct gnttab_setup_table setup; 444 struct gnttab_setup_table setup;
@@ -470,7 +452,7 @@ static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
470 452
471 setup.dom = DOMID_SELF; 453 setup.dom = DOMID_SELF;
472 setup.nr_frames = nr_gframes; 454 setup.nr_frames = nr_gframes;
473 setup.frame_list = frames; 455 set_xen_guest_handle(setup.frame_list, frames);
474 456
475 rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); 457 rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
476 if (rc == -ENOSYS) { 458 if (rc == -ENOSYS) {
@@ -480,17 +462,9 @@ static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
480 462
481 BUG_ON(rc || setup.status); 463 BUG_ON(rc || setup.status);
482 464
483 if (shared == NULL) { 465 rc = arch_gnttab_map_shared(frames, nr_gframes, max_nr_grant_frames(),
484 struct vm_struct *area; 466 &shared);
485 area = alloc_vm_area(PAGE_SIZE * max_nr_grant_frames());
486 BUG_ON(area == NULL);
487 shared = area->addr;
488 }
489 rc = apply_to_page_range(&init_mm, (unsigned long)shared,
490 PAGE_SIZE * nr_gframes,
491 map_pte_fn, &frames);
492 BUG_ON(rc); 467 BUG_ON(rc);
493 frames -= nr_gframes; /* adjust after map_pte_fn() */
494 468
495 kfree(frames); 469 kfree(frames);
496 470
@@ -506,10 +480,7 @@ static int gnttab_resume(void)
506 480
507static int gnttab_suspend(void) 481static int gnttab_suspend(void)
508{ 482{
509 apply_to_page_range(&init_mm, (unsigned long)shared, 483 arch_gnttab_unmap_shared(shared, nr_grant_frames);
510 PAGE_SIZE * nr_grant_frames,
511 unmap_pte_fn, NULL);
512
513 return 0; 484 return 0;
514} 485}
515 486
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 9fd2f70ab46d..0f86b0ff7879 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -399,7 +399,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
399 399
400 *vaddr = NULL; 400 *vaddr = NULL;
401 401
402 area = alloc_vm_area(PAGE_SIZE); 402 area = xen_alloc_vm_area(PAGE_SIZE);
403 if (!area) 403 if (!area)
404 return -ENOMEM; 404 return -ENOMEM;
405 405
@@ -409,7 +409,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
409 BUG(); 409 BUG();
410 410
411 if (op.status != GNTST_okay) { 411 if (op.status != GNTST_okay) {
412 free_vm_area(area); 412 xen_free_vm_area(area);
413 xenbus_dev_fatal(dev, op.status, 413 xenbus_dev_fatal(dev, op.status,
414 "mapping in shared page %d from domain %d", 414 "mapping in shared page %d from domain %d",
415 gnt_ref, dev->otherend_id); 415 gnt_ref, dev->otherend_id);
@@ -508,7 +508,7 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
508 BUG(); 508 BUG();
509 509
510 if (op.status == GNTST_okay) 510 if (op.status == GNTST_okay)
511 free_vm_area(area); 511 xen_free_vm_area(area);
512 else 512 else
513 xenbus_dev_error(dev, op.status, 513 xenbus_dev_error(dev, op.status,
514 "unmapping page at handle %d error %d", 514 "unmapping page at handle %d error %d",
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 4750de316ad3..57ceb5346b74 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -88,6 +88,16 @@ int xenbus_match(struct device *_dev, struct device_driver *_drv)
88 return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; 88 return match_device(drv->ids, to_xenbus_device(_dev)) != NULL;
89} 89}
90 90
91static int xenbus_uevent(struct device *_dev, struct kobj_uevent_env *env)
92{
93 struct xenbus_device *dev = to_xenbus_device(_dev);
94
95 if (add_uevent_var(env, "MODALIAS=xen:%s", dev->devicetype))
96 return -ENOMEM;
97
98 return 0;
99}
100
91/* device/<type>/<id> => <type>-<id> */ 101/* device/<type>/<id> => <type>-<id> */
92static int frontend_bus_id(char bus_id[BUS_ID_SIZE], const char *nodename) 102static int frontend_bus_id(char bus_id[BUS_ID_SIZE], const char *nodename)
93{ 103{
@@ -166,6 +176,7 @@ static struct xen_bus_type xenbus_frontend = {
166 .bus = { 176 .bus = {
167 .name = "xen", 177 .name = "xen",
168 .match = xenbus_match, 178 .match = xenbus_match,
179 .uevent = xenbus_uevent,
169 .probe = xenbus_dev_probe, 180 .probe = xenbus_dev_probe,
170 .remove = xenbus_dev_remove, 181 .remove = xenbus_dev_remove,
171 .shutdown = xenbus_dev_shutdown, 182 .shutdown = xenbus_dev_shutdown,
@@ -438,6 +449,12 @@ static ssize_t xendev_show_devtype(struct device *dev,
438} 449}
439DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL); 450DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL);
440 451
452static ssize_t xendev_show_modalias(struct device *dev,
453 struct device_attribute *attr, char *buf)
454{
455 return sprintf(buf, "xen:%s\n", to_xenbus_device(dev)->devicetype);
456}
457DEVICE_ATTR(modalias, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_modalias, NULL);
441 458
442int xenbus_probe_node(struct xen_bus_type *bus, 459int xenbus_probe_node(struct xen_bus_type *bus,
443 const char *type, 460 const char *type,
@@ -492,10 +509,16 @@ int xenbus_probe_node(struct xen_bus_type *bus,
492 509
493 err = device_create_file(&xendev->dev, &dev_attr_devtype); 510 err = device_create_file(&xendev->dev, &dev_attr_devtype);
494 if (err) 511 if (err)
495 goto fail_remove_file; 512 goto fail_remove_nodename;
513
514 err = device_create_file(&xendev->dev, &dev_attr_modalias);
515 if (err)
516 goto fail_remove_devtype;
496 517
497 return 0; 518 return 0;
498fail_remove_file: 519fail_remove_devtype:
520 device_remove_file(&xendev->dev, &dev_attr_devtype);
521fail_remove_nodename:
499 device_remove_file(&xendev->dev, &dev_attr_nodename); 522 device_remove_file(&xendev->dev, &dev_attr_nodename);
500fail_unregister: 523fail_unregister:
501 device_unregister(&xendev->dev); 524 device_unregister(&xendev->dev);
@@ -846,6 +869,7 @@ static int is_disconnected_device(struct device *dev, void *data)
846{ 869{
847 struct xenbus_device *xendev = to_xenbus_device(dev); 870 struct xenbus_device *xendev = to_xenbus_device(dev);
848 struct device_driver *drv = data; 871 struct device_driver *drv = data;
872 struct xenbus_driver *xendrv;
849 873
850 /* 874 /*
851 * A device with no driver will never connect. We care only about 875 * A device with no driver will never connect. We care only about
@@ -858,7 +882,9 @@ static int is_disconnected_device(struct device *dev, void *data)
858 if (drv && (dev->driver != drv)) 882 if (drv && (dev->driver != drv))
859 return 0; 883 return 0;
860 884
861 return (xendev->state != XenbusStateConnected); 885 xendrv = to_xenbus_driver(dev->driver);
886 return (xendev->state != XenbusStateConnected ||
887 (xendrv->is_ready && !xendrv->is_ready(xendev)));
862} 888}
863 889
864static int exists_disconnected_device(struct device_driver *drv) 890static int exists_disconnected_device(struct device_driver *drv)
diff --git a/drivers/xen/xencomm.c b/drivers/xen/xencomm.c
new file mode 100644
index 000000000000..797cb4e31f07
--- /dev/null
+++ b/drivers/xen/xencomm.c
@@ -0,0 +1,232 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Copyright (C) IBM Corp. 2006
17 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 */
20
21#include <linux/gfp.h>
22#include <linux/mm.h>
23#include <asm/page.h>
24#include <xen/xencomm.h>
25#include <xen/interface/xen.h>
26#ifdef __ia64__
27#include <asm/xen/xencomm.h> /* for is_kern_addr() */
28#endif
29
30#ifdef HAVE_XEN_PLATFORM_COMPAT_H
31#include <xen/platform-compat.h>
32#endif
33
34static int xencomm_init(struct xencomm_desc *desc,
35 void *buffer, unsigned long bytes)
36{
37 unsigned long recorded = 0;
38 int i = 0;
39
40 while ((recorded < bytes) && (i < desc->nr_addrs)) {
41 unsigned long vaddr = (unsigned long)buffer + recorded;
42 unsigned long paddr;
43 int offset;
44 int chunksz;
45
46 offset = vaddr % PAGE_SIZE; /* handle partial pages */
47 chunksz = min(PAGE_SIZE - offset, bytes - recorded);
48
49 paddr = xencomm_vtop(vaddr);
50 if (paddr == ~0UL) {
51 printk(KERN_DEBUG "%s: couldn't translate vaddr %lx\n",
52 __func__, vaddr);
53 return -EINVAL;
54 }
55
56 desc->address[i++] = paddr;
57 recorded += chunksz;
58 }
59
60 if (recorded < bytes) {
61 printk(KERN_DEBUG
62 "%s: could only translate %ld of %ld bytes\n",
63 __func__, recorded, bytes);
64 return -ENOSPC;
65 }
66
67 /* mark remaining addresses invalid (just for safety) */
68 while (i < desc->nr_addrs)
69 desc->address[i++] = XENCOMM_INVALID;
70
71 desc->magic = XENCOMM_MAGIC;
72
73 return 0;
74}
75
76static struct xencomm_desc *xencomm_alloc(gfp_t gfp_mask,
77 void *buffer, unsigned long bytes)
78{
79 struct xencomm_desc *desc;
80 unsigned long buffer_ulong = (unsigned long)buffer;
81 unsigned long start = buffer_ulong & PAGE_MASK;
82 unsigned long end = (buffer_ulong + bytes) | ~PAGE_MASK;
83 unsigned long nr_addrs = (end - start + 1) >> PAGE_SHIFT;
84 unsigned long size = sizeof(*desc) +
85 sizeof(desc->address[0]) * nr_addrs;
86
87 /*
88 * slab allocator returns at least sizeof(void*) aligned pointer.
89 * When sizeof(*desc) > sizeof(void*), struct xencomm_desc might
90 * cross page boundary.
91 */
92 if (sizeof(*desc) > sizeof(void *)) {
93 unsigned long order = get_order(size);
94 desc = (struct xencomm_desc *)__get_free_pages(gfp_mask,
95 order);
96 if (desc == NULL)
97 return NULL;
98
99 desc->nr_addrs =
100 ((PAGE_SIZE << order) - sizeof(struct xencomm_desc)) /
101 sizeof(*desc->address);
102 } else {
103 desc = kmalloc(size, gfp_mask);
104 if (desc == NULL)
105 return NULL;
106
107 desc->nr_addrs = nr_addrs;
108 }
109 return desc;
110}
111
112void xencomm_free(struct xencomm_handle *desc)
113{
114 if (desc && !((ulong)desc & XENCOMM_INLINE_FLAG)) {
115 struct xencomm_desc *desc__ = (struct xencomm_desc *)desc;
116 if (sizeof(*desc__) > sizeof(void *)) {
117 unsigned long size = sizeof(*desc__) +
118 sizeof(desc__->address[0]) * desc__->nr_addrs;
119 unsigned long order = get_order(size);
120 free_pages((unsigned long)__va(desc), order);
121 } else
122 kfree(__va(desc));
123 }
124}
125
126static int xencomm_create(void *buffer, unsigned long bytes,
127 struct xencomm_desc **ret, gfp_t gfp_mask)
128{
129 struct xencomm_desc *desc;
130 int rc;
131
132 pr_debug("%s: %p[%ld]\n", __func__, buffer, bytes);
133
134 if (bytes == 0) {
135 /* don't create a descriptor; Xen recognizes NULL. */
136 BUG_ON(buffer != NULL);
137 *ret = NULL;
138 return 0;
139 }
140
141 BUG_ON(buffer == NULL); /* 'bytes' is non-zero */
142
143 desc = xencomm_alloc(gfp_mask, buffer, bytes);
144 if (!desc) {
145 printk(KERN_DEBUG "%s failure\n", "xencomm_alloc");
146 return -ENOMEM;
147 }
148
149 rc = xencomm_init(desc, buffer, bytes);
150 if (rc) {
151 printk(KERN_DEBUG "%s failure: %d\n", "xencomm_init", rc);
152 xencomm_free((struct xencomm_handle *)__pa(desc));
153 return rc;
154 }
155
156 *ret = desc;
157 return 0;
158}
159
160/* check if memory address is within VMALLOC region */
161static int is_phys_contiguous(unsigned long addr)
162{
163 if (!is_kernel_addr(addr))
164 return 0;
165
166 return (addr < VMALLOC_START) || (addr >= VMALLOC_END);
167}
168
169static struct xencomm_handle *xencomm_create_inline(void *ptr)
170{
171 unsigned long paddr;
172
173 BUG_ON(!is_phys_contiguous((unsigned long)ptr));
174
175 paddr = (unsigned long)xencomm_pa(ptr);
176 BUG_ON(paddr & XENCOMM_INLINE_FLAG);
177 return (struct xencomm_handle *)(paddr | XENCOMM_INLINE_FLAG);
178}
179
180/* "mini" routine, for stack-based communications: */
181static int xencomm_create_mini(void *buffer,
182 unsigned long bytes, struct xencomm_mini *xc_desc,
183 struct xencomm_desc **ret)
184{
185 int rc = 0;
186 struct xencomm_desc *desc;
187 BUG_ON(((unsigned long)xc_desc) % sizeof(*xc_desc) != 0);
188
189 desc = (void *)xc_desc;
190
191 desc->nr_addrs = XENCOMM_MINI_ADDRS;
192
193 rc = xencomm_init(desc, buffer, bytes);
194 if (!rc)
195 *ret = desc;
196
197 return rc;
198}
199
200struct xencomm_handle *xencomm_map(void *ptr, unsigned long bytes)
201{
202 int rc;
203 struct xencomm_desc *desc;
204
205 if (is_phys_contiguous((unsigned long)ptr))
206 return xencomm_create_inline(ptr);
207
208 rc = xencomm_create(ptr, bytes, &desc, GFP_KERNEL);
209
210 if (rc || desc == NULL)
211 return NULL;
212
213 return xencomm_pa(desc);
214}
215
216struct xencomm_handle *__xencomm_map_no_alloc(void *ptr, unsigned long bytes,
217 struct xencomm_mini *xc_desc)
218{
219 int rc;
220 struct xencomm_desc *desc = NULL;
221
222 if (is_phys_contiguous((unsigned long)ptr))
223 return xencomm_create_inline(ptr);
224
225 rc = xencomm_create_mini(ptr, bytes, xc_desc,
226 &desc);
227
228 if (rc)
229 return NULL;
230
231 return xencomm_pa(desc);
232}